Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */ 
  package org.jboss.security.mapping.providers;
    
 import java.util.List;
 import java.util.Map;
 
Role Mapping Provider that picks up the roles from the options and then appends them to the passed Group

Author(s):
Anil Saldhana
Version:
$Revision$
Since:
Aug 24, 2006
 
 public class OptionsRoleMappingProvider implements MappingProvider<RoleGroup
 { 
    //Standard Strings
    private static final String REPLACE_ROLES_STRING = "replaceRoles";
    private static final String ROLES_MAP = "rolesMap";
    
    private MappingResult<RoleGroupresult;
 
    private Map<String,Objectoptions = null;
    
    private Properties roleMapProperties = null;
   
   
Specifies
 
    private boolean REPLACE_ROLES = false;
    
    public void init(Map<String,Objectopt)
    {
      this. = opt;
      if( != null)
      {
         {
             = "true".equalsIgnoreCase((String).get()); 
         }
         if(.containsKey())
         {
             = (Properties).get();
         } 
      } 
    }
    
    public void setMappingResult(MappingResult<RoleGroupres)
    { 
        = res;
    }
    
    public void performMapping(Map<String,ObjectcontextMapRoleGroup mappedObject)
    { 
       ArrayList<RoleremoveMembers = new ArrayList<Role>();
       ArrayList<RoleaddMembers = new ArrayList<Role>(); 
 
       List<RolerolesList = mappedObject.getRoles();
       if(rolesList != null)
       {
          for(Role rrolesList)
          {
             String commaSeparatedRoles = .getProperty(r.getRoleName());
             if(commaSeparatedRoles != null)
             {
                String[] tokens = MappingProviderUtil.getRolesFromCommaSeparatedString(commaSeparatedRoles);
                int len = tokens != null ? tokens.length : 0;
                for(int i = 0; i < leni++)
                {
                   if(this.)
                      removeMembers.add(r); 
                   addMembers.add(new SimpleRole(tokens[i])); 
                }
             }  
          }
       } 
       
       //Go through  the remove list
       for(Role p:removeMembers)
       {
          mappedObject.removeRole(p);
       }
       //Go through the add list
       for(Role p:addMembers)
       {
          mappedObject.addRole(p);
      }
      
      .setMappedObject(mappedObject);
   }   
   
   
   public boolean supports(Class<?> p)
   {
      if(RoleGroup.class.isAssignableFrom(p))
         return true;
      return false;
   }
New to GrepCode? Check out our FAQ X