[Building Sakai] Effecting permissions when using role switcher

David Wafula davidwaf at gmail.com
Thu Dec 1 00:03:14 PST 2011


Hi all,
Am using the following code to implement access to various resources based
on roles. If am logged in as student, it works accordingly. If am logged in
as instructor, works accordingly. BUT, if am logged in as instructor and i
use role-switch, say to "View as Student", the role does'nt change, it
still sticks to instructor permissions. Anything i could be missing ? Here
is the code:

    public boolean checkPermissions(String authzGroupName, String
functionName) {
        try {

            //Get current site
            String currentSiteId =
toolManager.getCurrentPlacement().getContext();
            Site site = siteService.getSite(currentSiteId);

            //Get role of current user
            User currentUser = userDirectoryService.getCurrentUser();
            Role currentUserRole = site.getUserRole(currentUser.getId());
            String userRoleId = currentUserRole.getId();

            //Check if users are registered with these roles. If so, convert
            boolean checkMaintain = userRoleId.equalsIgnoreCase("maintain");
            boolean checkAdmin = userRoleId.equalsIgnoreCase("admin");
            boolean checkAccess = userRoleId.equalsIgnoreCase("access");
            boolean checkRegistered =
userRoleId.equalsIgnoreCase("registered");

            if (checkMaintain || checkAdmin || checkRegistered) {
                userRoleId = "Instructor";

            } else if (checkAccess) {
                userRoleId = "Student";

            }

            AuthzGroup ag = authzGroupService.getAuthzGroup(authzGroupName);

            //Get roles
            Role role = ag.getRole(userRoleId);


            if (role == null) {
                return false;
            }

            //Flag for setting if user has permissions
            boolean hasPerms = false;

            hasPerms = role.isAllowed(functionName);

            return hasPerms;
        } catch (Exception ex) {
            LOG.warn("Error with StartHere.checkPermissions()", ex);
        }
        return false;
    }

-- 
David Wafula
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20111201/6641f1c8/attachment.html 


More information about the sakai-dev mailing list