...
- Use the ToolManager service to get the current context
Code Block java java String currentContext = toolManager.getCurrentPlacement().getContext();
- Note: You could also retrieve the context in other ways, this is just the common one
- Use the SiteService to get the site reference from the context
Code Block java java String siteRef = siteService.siteReference(context);
- Note: This could also be a group reference instead of a site reference (in theory)
- Create a Collection of the references and pass that to the AuthzGroupService to get the Set of userIds
Code Block java java java.util.List azGroups = new java.util.ArrayList(); azGroups.add(siteRef); java.util.Set userIds = authzGroupService.getUsersIsAllowed("tool.permission", azGroups);
- Note: In this case, tool.permission is the permission you registered earlier with the FunctionManager
Setting the permissions for the !site.template (or any template)
- Note: You have to be careful with this because it will overwrite the current permissions that the user has setup
- Setup a constant for the site template string
Code Block java java private final static String SITE_TEMPLATE = "!site.template";
- Use the AuthzGroupService to get the AuthzGroup for SITE_TEMPLATE
Code Block java java try { AuthzGroup ag = authzGroupService.getAuthzGroup(SITE_TEMPLATE);
- Use the AuthzGroupService to check if ag can be updated
Code Block java java if (authzGroupService.allowUpdate(ag.getId())) {
- Use the AuthzGroup to set the maintain role to have the permission for the tool and the AuthzGroupService to save the group
Code Block java java Role r = ag.getRole(ag.getMaintainRole()); r.allowFunction("tool.permission"); authzGroupService.save(ag); log.info("Added Permissions to group:" + SITE_TEMPLATE);
- Log warnings and handle exceptions
Code Block java java } else { log.warn("Cannot update authz group: " + SITE_TEMPLATE); } } catch (GroupNotDefinedException e) { log.error("Could not find group: " + SITE_TEMPLATE + ", default perms will not be assigned"); } catch (AuthzPermissionException e) { log.error("Could not save group: " + SITE_TEMPLATE); }