Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Use the AuthzGroupService to get the set of ids related to a permission (tool.permission), then iterate through the Set
    Code Block
    java
    java
    java.util.Set authzGroupIds = authzGroupService.getAuthzGroupsIsAllowed(userId, "tool.permission", null);
    java.util.Iterator it = authzGroupIds.iterator();
    while (it.hasNext()) {
    	   String authzGroupId = (String) it.next();
    
  2. Use the EntityManager to convert the authzGroupIds to Reference objects and then test if the type of object is a site
    Code Block
    java
    java
    	   Reference r = entityManager.newReference(authzGroupId);
    	   if(r.isKnownType()) {
    		
          if(r.getType().equals(SiteService.SITE_SUBTYPE)) {
    			
             // do something since this is a site
    
  3. Get the siteId or context from the Reference or use the SiteService to convert the siteId into a Site object
    Code Block
    java
    java
    			         String siteId = r.getId();
    			
             String context = r.getId();
    			
             try {
    				            Site site = siteService.getSite(siteId);
    			         } catch (IdUnusedException e) {
    				
                // invalid site Id returned
    				            throw new RuntimeException("Could not get site from siteId:" + siteId);
    			
             }
    
  4. Get the groupId from the Reference or use the SiteService to get the Group object
    Code Block
    java
    java
    
    		
             } else if (r.getType().equals(SiteService.GROUP_SUBTYPE)) {
    			
                // do something since this is a site group
    			            String groupId = r.getId();
    			
                String context = r.getId();
    			            Group group = siteService.findGroup(groupId);
    			
                if (group != null) {
    				               // found a valid group so do something
    			}
    		}
    	
             }
          }
       }
    }
    

...

  1. Setup a constant for the site template string
    Code Block
    java
    java
    private final static String SITE_TEMPLATE = "!site.template";
    
  2. Use the AuthzGroupService to get the AuthzGroup for SITE_TEMPLATE
    Code Block
    java
    java
    try {
       	AuthzGroup ag = authzGroupService.getAuthzGroup(SITE_TEMPLATE);
    
  3. Use the AuthzGroupService to check if ag can be updated
    Code Block
    java
    java
    
      	 if (authzGroupService.allowUpdate(ag.getId())) {
    
  4. 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);
    
  5. 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);
    }