|  1 |     | 
     | 
  |  2 |     | 
     | 
  |  3 |     | 
     | 
  |  4 |     | 
     | 
  |  5 |     | 
     | 
  |  6 |     | 
     | 
  |  7 |     | 
     | 
  |  8 |     | 
     | 
  |  9 |     | 
     | 
  |  10 |     | 
     | 
  |  11 |     | 
     | 
  |  12 |     | 
     | 
  |  13 |     | 
     | 
  |  14 |     | 
     | 
  |  15 |     | 
     | 
  |  16 |     | 
   package org.kuali.rice.kim.service.impl;  | 
  |  17 |     | 
     | 
  |  18 |     | 
   import java.util.ArrayList;  | 
  |  19 |     | 
   import java.util.Collections;  | 
  |  20 |     | 
   import java.util.HashMap;  | 
  |  21 |     | 
   import java.util.Iterator;  | 
  |  22 |     | 
   import java.util.List;  | 
  |  23 |     | 
   import java.util.Map;  | 
  |  24 |     | 
     | 
  |  25 |     | 
   import javax.jws.WebService;  | 
  |  26 |     | 
   import javax.servlet.http.HttpServletRequest;  | 
  |  27 |     | 
     | 
  |  28 |     | 
   import org.apache.commons.lang.exception.ExceptionUtils;  | 
  |  29 |     | 
   import org.apache.log4j.Logger;  | 
  |  30 |     | 
   import org.kuali.rice.core.util.MaxAgeSoftReference;  | 
  |  31 |     | 
   import org.kuali.rice.core.util.MaxSizeMap;  | 
  |  32 |     | 
   import org.kuali.rice.core.xml.dto.AttributeSet;  | 
  |  33 |     | 
   import org.kuali.rice.kim.bo.entity.KimEntity;  | 
  |  34 |     | 
   import org.kuali.rice.kim.bo.entity.KimPrincipal;  | 
  |  35 |     | 
   import org.kuali.rice.kim.bo.entity.dto.KimEntityDefaultInfo;  | 
  |  36 |     | 
   import org.kuali.rice.kim.bo.entity.dto.KimEntityInfo;  | 
  |  37 |     | 
   import org.kuali.rice.kim.bo.entity.dto.KimPrincipalInfo;  | 
  |  38 |     | 
   import org.kuali.rice.kim.bo.group.dto.GroupInfo;  | 
  |  39 |     | 
   import org.kuali.rice.kim.bo.reference.dto.AddressTypeInfo;  | 
  |  40 |     | 
   import org.kuali.rice.kim.bo.reference.dto.AffiliationTypeInfo;  | 
  |  41 |     | 
   import org.kuali.rice.kim.bo.reference.dto.CitizenshipStatusInfo;  | 
  |  42 |     | 
   import org.kuali.rice.kim.bo.reference.dto.EmailTypeInfo;  | 
  |  43 |     | 
   import org.kuali.rice.kim.bo.reference.dto.EmploymentStatusInfo;  | 
  |  44 |     | 
   import org.kuali.rice.kim.bo.reference.dto.EmploymentTypeInfo;  | 
  |  45 |     | 
   import org.kuali.rice.kim.bo.reference.dto.EntityNameTypeInfo;  | 
  |  46 |     | 
   import org.kuali.rice.kim.bo.reference.dto.EntityTypeInfo;  | 
  |  47 |     | 
   import org.kuali.rice.kim.bo.reference.dto.ExternalIdentifierTypeInfo;  | 
  |  48 |     | 
   import org.kuali.rice.kim.bo.reference.dto.KimCodeInfoBase;  | 
  |  49 |     | 
   import org.kuali.rice.kim.bo.reference.dto.PhoneTypeInfo;  | 
  |  50 |     | 
   import org.kuali.rice.kim.bo.role.dto.KimPermissionInfo;  | 
  |  51 |     | 
   import org.kuali.rice.kim.bo.role.dto.KimResponsibilityInfo;  | 
  |  52 |     | 
   import org.kuali.rice.kim.bo.role.dto.PermissionAssigneeInfo;  | 
  |  53 |     | 
   import org.kuali.rice.kim.bo.role.dto.ResponsibilityActionInfo;  | 
  |  54 |     | 
   import org.kuali.rice.kim.service.AuthenticationService;  | 
  |  55 |     | 
   import org.kuali.rice.kim.service.GroupService;  | 
  |  56 |     | 
   import org.kuali.rice.kim.service.GroupUpdateService;  | 
  |  57 |     | 
   import org.kuali.rice.kim.service.IdentityManagementService;  | 
  |  58 |     | 
   import org.kuali.rice.kim.service.IdentityService;  | 
  |  59 |     | 
   import org.kuali.rice.kim.service.IdentityUpdateService;  | 
  |  60 |     | 
   import org.kuali.rice.kim.service.KIMServiceLocator;  | 
  |  61 |     | 
   import org.kuali.rice.kim.service.KIMServiceLocatorInternal;  | 
  |  62 |     | 
   import org.kuali.rice.kim.service.PermissionService;  | 
  |  63 |     | 
   import org.kuali.rice.kim.service.ResponsibilityService;  | 
  |  64 |     | 
   import org.kuali.rice.kim.util.KIMWebServiceConstants;  | 
  |  65 |     | 
   import org.springframework.beans.factory.InitializingBean;  | 
  |  66 |     | 
     | 
  |  67 |     | 
   @WebService(endpointInterface = KIMWebServiceConstants.IdentityManagementService.INTERFACE_CLASS, serviceName = KIMWebServiceConstants.IdentityManagementService.WEB_SERVICE_NAME, portName = KIMWebServiceConstants.IdentityManagementService.WEB_SERVICE_PORT, targetNamespace = KIMWebServiceConstants.MODULE_TARGET_NAMESPACE)  | 
  |  68 |    0 |    public class IdentityManagementServiceImpl implements IdentityManagementService, InitializingBean { | 
  |  69 |    0 |            private static final Logger LOG = Logger.getLogger( IdentityManagementServiceImpl.class );  | 
  |  70 |     | 
     | 
  |  71 |     | 
           private AuthenticationService authenticationService;  | 
  |  72 |     | 
           private PermissionService permissionService;  | 
  |  73 |     | 
           private ResponsibilityService responsibilityService;  | 
  |  74 |     | 
           private IdentityService identityService;  | 
  |  75 |     | 
           private GroupService groupService;  | 
  |  76 |     | 
           private GroupUpdateService groupUpdateService;  | 
  |  77 |     | 
           private IdentityUpdateService identityUpdateService;  | 
  |  78 |     | 
     | 
  |  79 |     | 
     | 
  |  80 |     | 
             | 
  |  81 |    0 |            protected int entityPrincipalCacheMaxSize = 200;  | 
  |  82 |    0 |            protected int entityPrincipalCacheMaxAgeSeconds = 30;  | 
  |  83 |    0 |            protected int groupCacheMaxSize = 200;  | 
  |  84 |    0 |            protected int groupCacheMaxAgeSeconds = 30;  | 
  |  85 |    0 |            protected int permissionCacheMaxSize = 200;  | 
  |  86 |    0 |            protected int permissionCacheMaxAgeSeconds = 30;  | 
  |  87 |    0 |            protected int responsibilityCacheMaxSize = 200;  | 
  |  88 |    0 |            protected int responsibilityCacheMaxAgeSeconds = 30;  | 
  |  89 |     | 
     | 
  |  90 |     | 
           protected Map<String,MaxAgeSoftReference<KimEntityDefaultInfo>> entityDefaultInfoCache;  | 
  |  91 |     | 
           protected Map<String,MaxAgeSoftReference<KimEntity>> entityCache;  | 
  |  92 |     | 
           protected Map<String,MaxAgeSoftReference<KimEntityInfo>> entityInfoCache;  | 
  |  93 |     | 
           protected Map<String,MaxAgeSoftReference<KimPrincipalInfo>> principalByIdCache;  | 
  |  94 |     | 
           protected Map<String,MaxAgeSoftReference<KimPrincipalInfo>> principalByNameCache;  | 
  |  95 |     | 
           protected Map<String,MaxAgeSoftReference<GroupInfo>> groupByIdCache;  | 
  |  96 |     | 
           protected Map<String,MaxAgeSoftReference<GroupInfo>> groupByNameCache;  | 
  |  97 |     | 
           protected Map<String,MaxAgeSoftReference<List<String>>> groupIdsForPrincipalCache;  | 
  |  98 |     | 
           protected Map<String,MaxAgeSoftReference<List<? extends GroupInfo>>> groupsForPrincipalCache;  | 
  |  99 |     | 
           protected Map<String,MaxAgeSoftReference<Boolean>> isMemberOfGroupCache;  | 
  |  100 |     | 
           protected Map<String,MaxAgeSoftReference<Boolean>> isGroupMemberOfGroupCache;  | 
  |  101 |     | 
           protected Map<String,MaxAgeSoftReference<List<String>>> groupMemberPrincipalIdsCache;  | 
  |  102 |     | 
           protected Map<String,MaxAgeSoftReference<Boolean>> hasPermissionCache;  | 
  |  103 |     | 
           protected Map<String,MaxAgeSoftReference<Boolean>> hasPermissionByTemplateCache;  | 
  |  104 |     | 
           protected Map<String,MaxAgeSoftReference<Boolean>> isAuthorizedCache;  | 
  |  105 |     | 
           protected Map<String,MaxAgeSoftReference<Boolean>> isAuthorizedByTemplateNameCache;  | 
  |  106 |     | 
       protected Map<String,MaxAgeSoftReference<Boolean>> isPermissionDefinedForTemplateNameCache;  | 
  |  107 |     | 
     | 
  |  108 |    0 |        protected HashMap<String,KimCodeInfoBase> kimReferenceTypeCache = new HashMap<String, KimCodeInfoBase>();  | 
  |  109 |     | 
     | 
  |  110 |     | 
           public void afterPropertiesSet() throws Exception { | 
  |  111 |    0 |                    entityDefaultInfoCache = Collections.synchronizedMap( new MaxSizeMap<String,MaxAgeSoftReference<KimEntityDefaultInfo>>( entityPrincipalCacheMaxSize ) );  | 
  |  112 |    0 |                    entityCache = Collections.synchronizedMap( new MaxSizeMap<String,MaxAgeSoftReference<KimEntity>>( entityPrincipalCacheMaxSize ) );  | 
  |  113 |    0 |                    entityInfoCache = Collections.synchronizedMap( new MaxSizeMap<String, MaxAgeSoftReference<KimEntityInfo>>(entityPrincipalCacheMaxSize));  | 
  |  114 |    0 |                    principalByIdCache = Collections.synchronizedMap( new MaxSizeMap<String,MaxAgeSoftReference<KimPrincipalInfo>>( entityPrincipalCacheMaxSize ) );  | 
  |  115 |    0 |                    principalByNameCache = Collections.synchronizedMap( new MaxSizeMap<String,MaxAgeSoftReference<KimPrincipalInfo>>( entityPrincipalCacheMaxSize ) );  | 
  |  116 |    0 |                    groupByIdCache = Collections.synchronizedMap( new MaxSizeMap<String,MaxAgeSoftReference<GroupInfo>>( groupCacheMaxSize ) );  | 
  |  117 |    0 |                    groupByNameCache = Collections.synchronizedMap( new MaxSizeMap<String,MaxAgeSoftReference<GroupInfo>>( groupCacheMaxSize ) );  | 
  |  118 |    0 |                    groupIdsForPrincipalCache = Collections.synchronizedMap( new MaxSizeMap<String,MaxAgeSoftReference<List<String>>>( groupCacheMaxSize ) );  | 
  |  119 |    0 |                    groupsForPrincipalCache = Collections.synchronizedMap( new MaxSizeMap<String,MaxAgeSoftReference<List<? extends GroupInfo>>>( groupCacheMaxSize ) );  | 
  |  120 |    0 |                    isMemberOfGroupCache = Collections.synchronizedMap( new MaxSizeMap<String,MaxAgeSoftReference<Boolean>>( groupCacheMaxSize ) );  | 
  |  121 |    0 |                    groupMemberPrincipalIdsCache = Collections.synchronizedMap( new MaxSizeMap<String,MaxAgeSoftReference<List<String>>>( groupCacheMaxSize ) );  | 
  |  122 |    0 |                    hasPermissionCache = Collections.synchronizedMap( new MaxSizeMap<String,MaxAgeSoftReference<Boolean>>( permissionCacheMaxSize ) );  | 
  |  123 |    0 |                    hasPermissionByTemplateCache = Collections.synchronizedMap( new MaxSizeMap<String,MaxAgeSoftReference<Boolean>>( permissionCacheMaxSize ) );  | 
  |  124 |    0 |                    isPermissionDefinedForTemplateNameCache = Collections.synchronizedMap( new MaxSizeMap<String,MaxAgeSoftReference<Boolean>>( permissionCacheMaxSize ) );  | 
  |  125 |    0 |                    isAuthorizedByTemplateNameCache = Collections.synchronizedMap( new MaxSizeMap<String,MaxAgeSoftReference<Boolean>>( permissionCacheMaxSize ) );  | 
  |  126 |    0 |                    isAuthorizedCache = Collections.synchronizedMap( new MaxSizeMap<String,MaxAgeSoftReference<Boolean>>( permissionCacheMaxSize ) );  | 
  |  127 |    0 |            }  | 
  |  128 |     | 
     | 
  |  129 |     | 
           public void flushAllCaches() { | 
  |  130 |    0 |                    flushEntityPrincipalCaches();  | 
  |  131 |    0 |                    flushGroupCaches();  | 
  |  132 |    0 |                    flushPermissionCaches();  | 
  |  133 |    0 |                    flushResponsibilityCaches();  | 
  |  134 |    0 |            }  | 
  |  135 |     | 
     | 
  |  136 |     | 
           public void flushEntityPrincipalCaches() { | 
  |  137 |    0 |                    entityDefaultInfoCache.clear();  | 
  |  138 |    0 |                    entityCache.clear();  | 
  |  139 |    0 |                    principalByIdCache.clear();  | 
  |  140 |    0 |                    principalByNameCache.clear();  | 
  |  141 |    0 |            }  | 
  |  142 |     | 
     | 
  |  143 |     | 
           public void flushGroupCaches() { | 
  |  144 |    0 |                    groupByIdCache.clear();  | 
  |  145 |    0 |                    groupByNameCache.clear();  | 
  |  146 |    0 |                    groupIdsForPrincipalCache.clear();  | 
  |  147 |    0 |                    groupsForPrincipalCache.clear();  | 
  |  148 |    0 |                    isMemberOfGroupCache.clear();  | 
  |  149 |    0 |                    groupMemberPrincipalIdsCache.clear();  | 
  |  150 |    0 |            }  | 
  |  151 |     | 
     | 
  |  152 |     | 
           public void flushPermissionCaches() { | 
  |  153 |    0 |                    hasPermissionCache.clear();  | 
  |  154 |    0 |                    hasPermissionByTemplateCache.clear();  | 
  |  155 |    0 |                    isPermissionDefinedForTemplateNameCache.clear();  | 
  |  156 |    0 |                    isAuthorizedByTemplateNameCache.clear();  | 
  |  157 |    0 |                    isAuthorizedCache.clear();  | 
  |  158 |    0 |            }  | 
  |  159 |     | 
     | 
  |  160 |     | 
           public void flushResponsibilityCaches() { | 
  |  161 |     | 
                     | 
  |  162 |    0 |            }  | 
  |  163 |     | 
     | 
  |  164 |     | 
           protected KimEntityDefaultInfo getEntityDefaultInfoFromCache( String entityId ) { | 
  |  165 |    0 |                    MaxAgeSoftReference<KimEntityDefaultInfo> entityRef = entityDefaultInfoCache.get( "entityId="+entityId );  | 
  |  166 |    0 |                    if ( entityRef != null ) { | 
  |  167 |    0 |                            return entityRef.get();  | 
  |  168 |     | 
                   }  | 
  |  169 |    0 |                    return null;  | 
  |  170 |     | 
           }  | 
  |  171 |     | 
     | 
  |  172 |     | 
           protected KimEntityDefaultInfo getEntityDefaultInfoFromCacheByPrincipalId( String principalId ) { | 
  |  173 |    0 |                    MaxAgeSoftReference<KimEntityDefaultInfo> entityRef = entityDefaultInfoCache.get( "principalId="+principalId );  | 
  |  174 |    0 |                    if ( entityRef != null ) { | 
  |  175 |    0 |                            return entityRef.get();  | 
  |  176 |     | 
                   }  | 
  |  177 |    0 |                    return null;  | 
  |  178 |     | 
           }  | 
  |  179 |     | 
     | 
  |  180 |     | 
           protected KimEntityDefaultInfo getEntityDefaultInfoFromCacheByPrincipalName( String principalName ) { | 
  |  181 |    0 |                    MaxAgeSoftReference<KimEntityDefaultInfo> entityRef = entityDefaultInfoCache.get( "principalName="+principalName );  | 
  |  182 |    0 |                    if ( entityRef != null ) { | 
  |  183 |    0 |                            return entityRef.get();  | 
  |  184 |     | 
                   }  | 
  |  185 |    0 |                    return null;  | 
  |  186 |     | 
           }  | 
  |  187 |     | 
     | 
  |  188 |     | 
           protected KimEntityInfo getEntityInfoFromCache( String entityId ) { | 
  |  189 |    0 |                    MaxAgeSoftReference<KimEntityInfo> entityRef = entityInfoCache.get( "entityId="+entityId );  | 
  |  190 |    0 |                    if ( entityRef != null ) { | 
  |  191 |    0 |                            return entityRef.get();  | 
  |  192 |     | 
                   }  | 
  |  193 |    0 |                    return null;  | 
  |  194 |     | 
           }  | 
  |  195 |     | 
     | 
  |  196 |     | 
           protected KimEntityInfo getEntityInfoFromCacheByPrincipalId( String principalId ) { | 
  |  197 |    0 |                    MaxAgeSoftReference<KimEntityInfo> entityRef = entityInfoCache.get( "principalId="+principalId );  | 
  |  198 |    0 |                    if ( entityRef != null ) { | 
  |  199 |    0 |                            return entityRef.get();  | 
  |  200 |     | 
                   }  | 
  |  201 |    0 |                    return null;  | 
  |  202 |     | 
           }  | 
  |  203 |     | 
     | 
  |  204 |     | 
           protected KimEntityInfo getEntityInfoFromCacheByPrincipalName( String principalName ) { | 
  |  205 |    0 |                    MaxAgeSoftReference<KimEntityInfo> entityRef = entityInfoCache.get( "principalName="+principalName );  | 
  |  206 |    0 |                    if ( entityRef != null ) { | 
  |  207 |    0 |                            return entityRef.get();  | 
  |  208 |     | 
                   }  | 
  |  209 |    0 |                    return null;  | 
  |  210 |     | 
           }  | 
  |  211 |     | 
     | 
  |  212 |     | 
           protected KimEntity getEntityFromCache( String entityId ) { | 
  |  213 |    0 |                    MaxAgeSoftReference<KimEntity> entityRef = entityCache.get( "entityId="+entityId );  | 
  |  214 |    0 |                    if ( entityRef != null ) { | 
  |  215 |    0 |                            return entityRef.get();  | 
  |  216 |     | 
                   }  | 
  |  217 |    0 |                    return null;  | 
  |  218 |     | 
           }  | 
  |  219 |     | 
     | 
  |  220 |     | 
           protected KimEntity getEntityFromCacheByPrincipalId( String principalId ) { | 
  |  221 |    0 |                    MaxAgeSoftReference<KimEntity> entityRef = entityCache.get( "principalId="+principalId );  | 
  |  222 |    0 |                    if ( entityRef != null ) { | 
  |  223 |    0 |                            return entityRef.get();  | 
  |  224 |     | 
                   }  | 
  |  225 |    0 |                    return null;  | 
  |  226 |     | 
           }  | 
  |  227 |     | 
     | 
  |  228 |     | 
           protected KimEntity getEntityFromCacheByPrincipalName( String principalName ) { | 
  |  229 |    0 |                    MaxAgeSoftReference<KimEntity> entityRef = entityCache.get( "principalName="+principalName );  | 
  |  230 |    0 |                    if ( entityRef != null ) { | 
  |  231 |    0 |                            return entityRef.get();  | 
  |  232 |     | 
                   }  | 
  |  233 |    0 |                    return null;  | 
  |  234 |     | 
           }  | 
  |  235 |     | 
     | 
  |  236 |     | 
           protected KimPrincipalInfo getPrincipalByIdCache( String principalId ) { | 
  |  237 |    0 |                    MaxAgeSoftReference<KimPrincipalInfo> principalRef = principalByIdCache.get( principalId );  | 
  |  238 |    0 |                    if ( principalRef != null ) { | 
  |  239 |    0 |                            return principalRef.get();  | 
  |  240 |     | 
                   }  | 
  |  241 |    0 |                    return null;  | 
  |  242 |     | 
           }  | 
  |  243 |     | 
     | 
  |  244 |     | 
           protected KimPrincipalInfo getPrincipalByNameCache( String principalName ) { | 
  |  245 |    0 |                    MaxAgeSoftReference<KimPrincipalInfo> principalRef = principalByNameCache.get( principalName );  | 
  |  246 |    0 |                    if ( principalRef != null ) { | 
  |  247 |    0 |                            return principalRef.get();  | 
  |  248 |     | 
                   }  | 
  |  249 |    0 |                    return null;  | 
  |  250 |     | 
           }  | 
  |  251 |     | 
     | 
  |  252 |     | 
           protected GroupInfo getGroupByIdCache( String groupId ) { | 
  |  253 |    0 |                    MaxAgeSoftReference<GroupInfo> groupRef = groupByIdCache.get( groupId );  | 
  |  254 |    0 |                    if ( groupRef != null ) { | 
  |  255 |    0 |                            return groupRef.get();  | 
  |  256 |     | 
                   }  | 
  |  257 |    0 |                    return null;  | 
  |  258 |     | 
           }  | 
  |  259 |     | 
     | 
  |  260 |     | 
           protected GroupInfo getGroupByNameCache( String groupName ) { | 
  |  261 |    0 |                    MaxAgeSoftReference<GroupInfo> groupRef = groupByNameCache.get( groupName );  | 
  |  262 |    0 |                    if ( groupRef != null ) { | 
  |  263 |    0 |                            return groupRef.get();  | 
  |  264 |     | 
                   }  | 
  |  265 |    0 |                    return null;  | 
  |  266 |     | 
           }  | 
  |  267 |     | 
     | 
  |  268 |     | 
           protected List<String> getGroupIdsForPrincipalCache( String principalId ) { | 
  |  269 |    0 |                    MaxAgeSoftReference<List<String>> groupIdsRef = groupIdsForPrincipalCache.get( principalId );  | 
  |  270 |    0 |                    if ( groupIdsRef != null ) { | 
  |  271 |    0 |                            return groupIdsRef.get();  | 
  |  272 |     | 
                   }  | 
  |  273 |    0 |                    return null;  | 
  |  274 |     | 
           }  | 
  |  275 |     | 
     | 
  |  276 |     | 
           protected List<? extends GroupInfo> getGroupsForPrincipalCache( String principalId ) { | 
  |  277 |    0 |                    MaxAgeSoftReference<List<? extends GroupInfo>> groupsRef = groupsForPrincipalCache.get( principalId );  | 
  |  278 |    0 |                    if ( groupsRef != null ) { | 
  |  279 |    0 |                            return groupsRef.get();  | 
  |  280 |     | 
                   }  | 
  |  281 |    0 |                    return null;  | 
  |  282 |     | 
           }  | 
  |  283 |     | 
     | 
  |  284 |     | 
           protected Boolean getIsMemberOfGroupCache( String principalId, String groupId ) { | 
  |  285 |    0 |                    MaxAgeSoftReference<Boolean> isMemberRef = isMemberOfGroupCache.get( principalId + "-" + groupId );  | 
  |  286 |    0 |                    if ( isMemberRef != null ) { | 
  |  287 |    0 |                            return isMemberRef.get();  | 
  |  288 |     | 
                   }  | 
  |  289 |    0 |                    return null;  | 
  |  290 |     | 
           }  | 
  |  291 |     | 
     | 
  |  292 |     | 
           protected Boolean getIsGroupMemberOfGroupCache( String potentialMemberId, String potentialParentId )  | 
  |  293 |     | 
           { | 
  |  294 |    0 |                    MaxAgeSoftReference<Boolean> isMemberRef = isGroupMemberOfGroupCache.get( potentialMemberId + "-" + potentialParentId );  | 
  |  295 |    0 |                    if ( isMemberRef != null ) { | 
  |  296 |    0 |                            return isMemberRef.get();  | 
  |  297 |     | 
                   }  | 
  |  298 |    0 |                    return null;  | 
  |  299 |     | 
           }  | 
  |  300 |     | 
     | 
  |  301 |     | 
           protected List<String> getGroupMemberPrincipalIdsCache( String groupId ) { | 
  |  302 |    0 |                    MaxAgeSoftReference<List<String>> memberIdsRef = groupMemberPrincipalIdsCache.get( groupId );  | 
  |  303 |    0 |                    if ( memberIdsRef != null ) { | 
  |  304 |    0 |                            return memberIdsRef.get();  | 
  |  305 |     | 
                   }  | 
  |  306 |    0 |                    return null;  | 
  |  307 |     | 
           }  | 
  |  308 |     | 
     | 
  |  309 |     | 
           protected Boolean getHasPermissionCache( String key ) { | 
  |  310 |    0 |                    MaxAgeSoftReference<Boolean> hasPermissionRef = hasPermissionCache.get( key );  | 
  |  311 |    0 |                    if ( hasPermissionRef != null ) { | 
  |  312 |    0 |                            return hasPermissionRef.get();  | 
  |  313 |     | 
                   }  | 
  |  314 |    0 |                    return null;  | 
  |  315 |     | 
           }  | 
  |  316 |     | 
     | 
  |  317 |     | 
           protected Boolean getHasPermissionByTemplateCache( String key ) { | 
  |  318 |    0 |                    MaxAgeSoftReference<Boolean> hasPermissionRef = hasPermissionByTemplateCache.get( key );  | 
  |  319 |    0 |                    if ( hasPermissionRef != null ) { | 
  |  320 |    0 |                            return hasPermissionRef.get();  | 
  |  321 |     | 
                   }  | 
  |  322 |    0 |                    return null;  | 
  |  323 |     | 
           }  | 
  |  324 |     | 
     | 
  |  325 |     | 
           protected Boolean getIsAuthorizedByTemplateNameFromCache( String key ) { | 
  |  326 |    0 |                    MaxAgeSoftReference<Boolean> cacheEntryRef = isAuthorizedByTemplateNameCache.get( key );  | 
  |  327 |    0 |                    if ( cacheEntryRef != null ) { | 
  |  328 |    0 |                            return cacheEntryRef.get();  | 
  |  329 |     | 
                   }  | 
  |  330 |    0 |                    return null;  | 
  |  331 |     | 
           }  | 
  |  332 |     | 
     | 
  |  333 |     | 
           protected Boolean getIsAuthorizedFromCache( String key ) { | 
  |  334 |    0 |                    MaxAgeSoftReference<Boolean> cacheEntryRef = isAuthorizedCache.get( key );  | 
  |  335 |    0 |                    if ( cacheEntryRef != null ) { | 
  |  336 |    0 |                            return cacheEntryRef.get();  | 
  |  337 |     | 
                   }  | 
  |  338 |    0 |                    return null;  | 
  |  339 |     | 
           }  | 
  |  340 |     | 
     | 
  |  341 |     | 
           protected void addEntityToCache( KimEntity entity ) { | 
  |  342 |    0 |                    if ( entity != null ) { | 
  |  343 |    0 |                            entityCache.put( "entityId="+entity.getEntityId(), new MaxAgeSoftReference<KimEntity>( entityPrincipalCacheMaxAgeSeconds, entity ) );  | 
  |  344 |    0 |                            for ( KimPrincipal p : entity.getPrincipals() ) { | 
  |  345 |    0 |                                    entityCache.put( "principalId="+p.getPrincipalId(), new MaxAgeSoftReference<KimEntity>( entityPrincipalCacheMaxAgeSeconds, entity ) );  | 
  |  346 |    0 |                                    entityCache.put( "principalName="+p.getPrincipalName(), new MaxAgeSoftReference<KimEntity>( entityPrincipalCacheMaxAgeSeconds, entity ) );  | 
  |  347 |     | 
                           }  | 
  |  348 |     | 
                   }  | 
  |  349 |    0 |            }  | 
  |  350 |     | 
     | 
  |  351 |     | 
           protected void addEntityDefaultInfoToCache( KimEntityDefaultInfo entity ) { | 
  |  352 |    0 |                    if ( entity != null ) { | 
  |  353 |    0 |                            entityDefaultInfoCache.put( "entityId="+entity.getEntityId(), new MaxAgeSoftReference<KimEntityDefaultInfo>( entityPrincipalCacheMaxAgeSeconds, entity ) );  | 
  |  354 |    0 |                            for ( KimPrincipal p : entity.getPrincipals() ) { | 
  |  355 |    0 |                                    entityDefaultInfoCache.put( "principalId="+p.getPrincipalId(), new MaxAgeSoftReference<KimEntityDefaultInfo>( entityPrincipalCacheMaxAgeSeconds, entity ) );  | 
  |  356 |    0 |                                    entityDefaultInfoCache.put( "principalName="+p.getPrincipalName(), new MaxAgeSoftReference<KimEntityDefaultInfo>( entityPrincipalCacheMaxAgeSeconds, entity ) );  | 
  |  357 |     | 
                           }  | 
  |  358 |     | 
                   }  | 
  |  359 |    0 |            }  | 
  |  360 |     | 
     | 
  |  361 |     | 
           protected void addEntityInfoToCache( KimEntityInfo entity ) { | 
  |  362 |    0 |                    if ( entity != null ) { | 
  |  363 |    0 |                            entityInfoCache.put( "entityId="+entity.getEntityId(), new MaxAgeSoftReference<KimEntityInfo>( entityPrincipalCacheMaxAgeSeconds, entity ) );  | 
  |  364 |    0 |                            for ( KimPrincipal p : entity.getPrincipals() ) { | 
  |  365 |    0 |                                    entityInfoCache.put( "principalId="+p.getPrincipalId(), new MaxAgeSoftReference<KimEntityInfo>( entityPrincipalCacheMaxAgeSeconds, entity ) );  | 
  |  366 |    0 |                                    entityInfoCache.put( "principalName="+p.getPrincipalName(), new MaxAgeSoftReference<KimEntityInfo>( entityPrincipalCacheMaxAgeSeconds, entity ) );  | 
  |  367 |     | 
                           }  | 
  |  368 |     | 
                   }  | 
  |  369 |    0 |            }  | 
  |  370 |     | 
     | 
  |  371 |     | 
           protected void addPrincipalToCache( KimPrincipalInfo principal ) { | 
  |  372 |    0 |                    if ( principal != null ) { | 
  |  373 |    0 |                            principalByNameCache.put( principal.getPrincipalName(), new MaxAgeSoftReference<KimPrincipalInfo>( entityPrincipalCacheMaxAgeSeconds, principal ) );  | 
  |  374 |    0 |                            principalByIdCache.put( principal.getPrincipalId(), new MaxAgeSoftReference<KimPrincipalInfo>( entityPrincipalCacheMaxAgeSeconds, principal ) );  | 
  |  375 |     | 
                   }  | 
  |  376 |    0 |            }  | 
  |  377 |     | 
     | 
  |  378 |     | 
           protected void addGroupToCache( GroupInfo group ) { | 
  |  379 |    0 |                    if ( group != null ) { | 
  |  380 |    0 |                            groupByNameCache.put( group.getGroupName(), new MaxAgeSoftReference<GroupInfo>( groupCacheMaxAgeSeconds, group ) );  | 
  |  381 |    0 |                            groupByIdCache.put( group.getGroupId(), new MaxAgeSoftReference<GroupInfo>( groupCacheMaxAgeSeconds, group ) );  | 
  |  382 |     | 
                   }  | 
  |  383 |    0 |            }  | 
  |  384 |     | 
     | 
  |  385 |     | 
           protected void addGroupIdsForPrincipalToCache( String principalId, List<String> ids ) { | 
  |  386 |    0 |                    if ( ids != null ) { | 
  |  387 |    0 |                            groupIdsForPrincipalCache.put( principalId, new MaxAgeSoftReference<List<String>>( groupCacheMaxAgeSeconds, ids ) );  | 
  |  388 |     | 
                   }  | 
  |  389 |    0 |            }  | 
  |  390 |     | 
     | 
  |  391 |     | 
           protected void addGroupsForPrincipalToCache( String principalId, List<? extends GroupInfo> groups ) { | 
  |  392 |    0 |                    if ( groups != null ) { | 
  |  393 |    0 |                            groupsForPrincipalCache.put( principalId, new MaxAgeSoftReference<List<? extends GroupInfo>>( groupCacheMaxAgeSeconds, groups ) );  | 
  |  394 |    0 |                            List<String> groupIds = new ArrayList<String>( groups.size() );  | 
  |  395 |    0 |                            for ( GroupInfo group : groups ) { | 
  |  396 |    0 |                                    groupIds.add( group.getGroupId() );  | 
  |  397 |     | 
                           }  | 
  |  398 |    0 |                            addGroupIdsForPrincipalToCache( principalId, groupIds );  | 
  |  399 |     | 
                   }  | 
  |  400 |    0 |            }  | 
  |  401 |     | 
     | 
  |  402 |     | 
           protected void addIsMemberOfGroupToCache( String principalId, String groupId, boolean member ) { | 
  |  403 |    0 |                    isMemberOfGroupCache.put( principalId + "-" + groupId, new MaxAgeSoftReference<Boolean>( groupCacheMaxAgeSeconds, member ) );  | 
  |  404 |    0 |            }  | 
  |  405 |     | 
     | 
  |  406 |     | 
           protected void addIsGroupMemberOfGroupToCache( String potentialMemberId, String potentialParentId, boolean member )  | 
  |  407 |     | 
           { | 
  |  408 |    0 |            isMemberOfGroupCache.put( potentialMemberId + "-" + potentialParentId, new MaxAgeSoftReference<Boolean>( groupCacheMaxAgeSeconds, member ) );  | 
  |  409 |    0 |        }  | 
  |  410 |     | 
     | 
  |  411 |     | 
           protected void addGroupMemberPrincipalIdsToCache( String groupId, List<String> ids ) { | 
  |  412 |    0 |                    if ( ids != null ) { | 
  |  413 |    0 |                            groupMemberPrincipalIdsCache.put( groupId, new MaxAgeSoftReference<List<String>>( groupCacheMaxAgeSeconds, ids ) );  | 
  |  414 |     | 
                   }  | 
  |  415 |    0 |            }  | 
  |  416 |     | 
     | 
  |  417 |     | 
           protected void addHasPermissionToCache( String key, boolean hasPerm ) { | 
  |  418 |    0 |                    hasPermissionCache.put( key, new MaxAgeSoftReference<Boolean>( permissionCacheMaxAgeSeconds, hasPerm ) );  | 
  |  419 |    0 |            }  | 
  |  420 |     | 
     | 
  |  421 |     | 
           protected void addHasPermissionByTemplateToCache( String key, boolean hasPerm ) { | 
  |  422 |    0 |                    hasPermissionByTemplateCache.put( key, new MaxAgeSoftReference<Boolean>( permissionCacheMaxAgeSeconds, hasPerm ) );  | 
  |  423 |    0 |            }  | 
  |  424 |     | 
     | 
  |  425 |     | 
           protected void addIsAuthorizedByTemplateNameToCache( String key, boolean authorized ) { | 
  |  426 |    0 |                    isAuthorizedByTemplateNameCache.put( key, new MaxAgeSoftReference<Boolean>( permissionCacheMaxAgeSeconds, authorized ) );  | 
  |  427 |    0 |            }  | 
  |  428 |     | 
     | 
  |  429 |     | 
           protected void addIsAuthorizedToCache( String key, boolean authorized ) { | 
  |  430 |    0 |                    isAuthorizedCache.put( key, new MaxAgeSoftReference<Boolean>( permissionCacheMaxAgeSeconds, authorized ) );  | 
  |  431 |    0 |            }  | 
  |  432 |     | 
     | 
  |  433 |     | 
         | 
  |  434 |     | 
     | 
  |  435 |     | 
       public boolean hasPermission(String principalId, String namespaceCode, String permissionName, AttributeSet permissionDetails) { | 
  |  436 |    0 |                if ( LOG.isDebugEnabled() ) { | 
  |  437 |    0 |                        logHasPermissionCheck("Permission", principalId, namespaceCode, permissionName, permissionDetails); | 
  |  438 |     | 
               }  | 
  |  439 |    0 |                StringBuffer cacheKey = new StringBuffer();  | 
  |  440 |    0 |                cacheKey.append( principalId ).append(  '/' );  | 
  |  441 |    0 |                cacheKey.append( namespaceCode ).append( '-' ).append( permissionName ).append( '/' );  | 
  |  442 |    0 |                addAttributeSetToKey( permissionDetails, cacheKey );  | 
  |  443 |    0 |                String key = cacheKey.toString();  | 
  |  444 |    0 |                Boolean hasPerm = getHasPermissionCache(key);  | 
  |  445 |    0 |                    if (hasPerm == null) { | 
  |  446 |    0 |                            hasPerm = getPermissionService().hasPermission( principalId, namespaceCode, permissionName, permissionDetails );  | 
  |  447 |    0 |                        addHasPermissionToCache(key, hasPerm);  | 
  |  448 |    0 |                        if ( LOG.isDebugEnabled() ) { | 
  |  449 |    0 |                                LOG.debug( "Result: " + hasPerm );  | 
  |  450 |     | 
                       }  | 
  |  451 |     | 
                   } else { | 
  |  452 |    0 |                            if ( LOG.isDebugEnabled() ) { | 
  |  453 |    0 |                                    LOG.debug( "Result Found in cache using key: " + key + "\nResult: " + hasPerm );  | 
  |  454 |     | 
                           }  | 
  |  455 |     | 
                   }  | 
  |  456 |    0 |                return hasPerm;  | 
  |  457 |     | 
       }  | 
  |  458 |     | 
     | 
  |  459 |     | 
       public boolean isAuthorized(String principalId, String namespaceCode, String permissionName, AttributeSet permissionDetails, AttributeSet qualification ) { | 
  |  460 |    0 |                if ( qualification == null || qualification.isEmpty() ) { | 
  |  461 |    0 |                        return hasPermission( principalId, namespaceCode, permissionName, permissionDetails );  | 
  |  462 |     | 
               }  | 
  |  463 |    0 |                if ( LOG.isDebugEnabled() ) { | 
  |  464 |    0 |                        logAuthorizationCheck("Permission", principalId, namespaceCode, permissionName, permissionDetails, qualification); | 
  |  465 |     | 
               }  | 
  |  466 |    0 |                StringBuffer cacheKey = new StringBuffer();  | 
  |  467 |    0 |                cacheKey.append( principalId ).append(  '/' );  | 
  |  468 |    0 |                cacheKey.append( namespaceCode ).append( '-' ).append( permissionName ).append( '/' );  | 
  |  469 |    0 |                addAttributeSetToKey( permissionDetails, cacheKey );  | 
  |  470 |    0 |                cacheKey.append( '/' );  | 
  |  471 |    0 |                addAttributeSetToKey( qualification, cacheKey );  | 
  |  472 |    0 |                String key = cacheKey.toString();  | 
  |  473 |    0 |                Boolean isAuthorized = getIsAuthorizedFromCache( key );  | 
  |  474 |    0 |                if ( isAuthorized == null ) { | 
  |  475 |    0 |                        isAuthorized = getPermissionService().isAuthorized( principalId, namespaceCode, permissionName, permissionDetails, qualification );  | 
  |  476 |    0 |                        addIsAuthorizedToCache( key, isAuthorized );  | 
  |  477 |    0 |                        if ( LOG.isDebugEnabled() ) { | 
  |  478 |    0 |                                LOG.debug( "Result: " + isAuthorized );  | 
  |  479 |     | 
                       }  | 
  |  480 |     | 
                   } else { | 
  |  481 |    0 |                            if ( LOG.isDebugEnabled() ) { | 
  |  482 |    0 |                                    LOG.debug( "Result Found in cache using key: " + key + "\nResult: " + isAuthorized );  | 
  |  483 |     | 
                           }  | 
  |  484 |     | 
               }  | 
  |  485 |    0 |                return isAuthorized;  | 
  |  486 |     | 
       }  | 
  |  487 |     | 
     | 
  |  488 |     | 
       public boolean hasPermissionByTemplateName(String principalId, String namespaceCode, String permissionTemplateName, AttributeSet permissionDetails) { | 
  |  489 |    0 |                if ( LOG.isDebugEnabled() ) { | 
  |  490 |    0 |                        logHasPermissionCheck("Perm Templ", principalId, namespaceCode, permissionTemplateName, permissionDetails); | 
  |  491 |     | 
               }  | 
  |  492 |    0 |                StringBuffer cacheKey = new StringBuffer();  | 
  |  493 |    0 |                cacheKey.append( principalId ).append(  '/' );  | 
  |  494 |    0 |                cacheKey.append( namespaceCode ).append( '-' ).append( permissionTemplateName ).append( '/' );  | 
  |  495 |    0 |                addAttributeSetToKey( permissionDetails, cacheKey );  | 
  |  496 |    0 |                String key = cacheKey.toString();  | 
  |  497 |    0 |                Boolean hasPerm = getHasPermissionByTemplateCache(key);  | 
  |  498 |    0 |                    if (hasPerm == null) { | 
  |  499 |    0 |                            hasPerm = getPermissionService().hasPermissionByTemplateName( principalId, namespaceCode, permissionTemplateName, permissionDetails );  | 
  |  500 |    0 |                        addHasPermissionByTemplateToCache(key, hasPerm);  | 
  |  501 |    0 |                        if ( LOG.isDebugEnabled() ) { | 
  |  502 |    0 |                                LOG.debug( "Result: " + hasPerm );  | 
  |  503 |     | 
                       }  | 
  |  504 |     | 
                   } else { | 
  |  505 |    0 |                            if ( LOG.isDebugEnabled() ) { | 
  |  506 |    0 |                                    LOG.debug( "Result Found in cache using key: " + key + "\nResult: " + hasPerm );  | 
  |  507 |     | 
                           }  | 
  |  508 |     | 
                   }  | 
  |  509 |    0 |                return hasPerm;  | 
  |  510 |     | 
       }  | 
  |  511 |     | 
     | 
  |  512 |     | 
       public boolean isAuthorizedByTemplateName(String principalId, String namespaceCode, String permissionTemplateName, AttributeSet permissionDetails, AttributeSet qualification ) { | 
  |  513 |    0 |                if ( qualification == null || qualification.isEmpty() ) { | 
  |  514 |    0 |                        return hasPermissionByTemplateName( principalId, namespaceCode, permissionTemplateName, permissionDetails );  | 
  |  515 |     | 
               }  | 
  |  516 |    0 |                if ( LOG.isDebugEnabled() ) { | 
  |  517 |    0 |                        logAuthorizationCheck("Perm Templ", principalId, namespaceCode, permissionTemplateName, permissionDetails, qualification); | 
  |  518 |     | 
               }  | 
  |  519 |    0 |                StringBuffer cacheKey = new StringBuffer();  | 
  |  520 |    0 |                cacheKey.append( principalId ).append(  '/' );  | 
  |  521 |    0 |                cacheKey.append( namespaceCode ).append( '-' ).append( permissionTemplateName ).append( '/' );  | 
  |  522 |    0 |                addAttributeSetToKey( permissionDetails, cacheKey );  | 
  |  523 |    0 |                cacheKey.append( '/' );  | 
  |  524 |    0 |                addAttributeSetToKey( qualification, cacheKey );  | 
  |  525 |    0 |                String key = cacheKey.toString();  | 
  |  526 |    0 |                Boolean isAuthorized = getIsAuthorizedByTemplateNameFromCache( key );  | 
  |  527 |    0 |                if ( isAuthorized == null ) { | 
  |  528 |    0 |                        isAuthorized = getPermissionService().isAuthorizedByTemplateName( principalId, namespaceCode, permissionTemplateName, permissionDetails, qualification );  | 
  |  529 |    0 |                        addIsAuthorizedByTemplateNameToCache( key, isAuthorized );  | 
  |  530 |    0 |                        if ( LOG.isDebugEnabled() ) { | 
  |  531 |    0 |                                LOG.debug( "Result: " + isAuthorized );  | 
  |  532 |     | 
                       }  | 
  |  533 |     | 
                   } else { | 
  |  534 |    0 |                            if ( LOG.isDebugEnabled() ) { | 
  |  535 |    0 |                                    LOG.debug( "Result Found in cache using key: " + key + "\nResult: " + isAuthorized );  | 
  |  536 |     | 
                           }  | 
  |  537 |     | 
               }  | 
  |  538 |    0 |                return isAuthorized;  | 
  |  539 |     | 
       }  | 
  |  540 |     | 
     | 
  |  541 |     | 
           private void addAttributeSetToKey(AttributeSet attributes, StringBuffer key) { | 
  |  542 |    0 |                    if ( attributes != null ) { | 
  |  543 |    0 |                            for ( Map.Entry<String, String> entry : attributes.entrySet() ) { | 
  |  544 |    0 |                                    key.append( entry.getKey() ).append( '=' ).append( entry.getValue() ).append('|'); | 
  |  545 |     | 
                       }  | 
  |  546 |     | 
                   } else { | 
  |  547 |    0 |                            key.append( "[null]" );  | 
  |  548 |     | 
                   }  | 
  |  549 |    0 |            }  | 
  |  550 |     | 
     | 
  |  551 |     | 
         | 
  |  552 |     | 
     | 
  |  553 |     | 
     | 
  |  554 |     | 
       public List<? extends KimPermissionInfo> getAuthorizedPermissions(String principalId,  | 
  |  555 |     | 
                       String namespaceCode, String permissionName, AttributeSet permissionDetails, AttributeSet qualification) { | 
  |  556 |    0 |                return getPermissionService().getAuthorizedPermissions( principalId, namespaceCode, permissionName, permissionDetails, qualification );  | 
  |  557 |     | 
       }  | 
  |  558 |     | 
     | 
  |  559 |     | 
       public List<? extends KimPermissionInfo> getAuthorizedPermissionsByTemplateName(String principalId,  | 
  |  560 |     | 
                       String namespaceCode, String permissionTemplateName, AttributeSet permissionDetails, AttributeSet qualification) { | 
  |  561 |    0 |                return getPermissionService().getAuthorizedPermissionsByTemplateName(principalId, namespaceCode, permissionTemplateName, permissionDetails, qualification);  | 
  |  562 |     | 
       }  | 
  |  563 |     | 
     | 
  |  564 |     | 
       public boolean isPermissionDefinedForTemplateName(String namespaceCode, String permissionTemplateName, AttributeSet permissionDetails) { | 
  |  565 |    0 |                StringBuffer key = new StringBuffer();  | 
  |  566 |    0 |                key.append( namespaceCode ).append( '-' ).append( permissionTemplateName ).append( '/' );  | 
  |  567 |    0 |            addAttributeSetToKey(permissionDetails, key);  | 
  |  568 |    0 |            MaxAgeSoftReference<Boolean> resultEntry = isPermissionDefinedForTemplateNameCache.get(key.toString());  | 
  |  569 |    0 |            if ( resultEntry != null ) { | 
  |  570 |    0 |                Boolean result = resultEntry.get();  | 
  |  571 |    0 |                if ( result != null ) { | 
  |  572 |    0 |                    return result;  | 
  |  573 |     | 
               }  | 
  |  574 |     | 
           }  | 
  |  575 |    0 |            boolean result = getPermissionService().isPermissionDefinedForTemplateName(namespaceCode, permissionTemplateName, permissionDetails);  | 
  |  576 |    0 |            isPermissionDefinedForTemplateNameCache.put(key.toString(),new MaxAgeSoftReference<Boolean>( permissionCacheMaxAgeSeconds, result ));  | 
  |  577 |    0 |            return result;  | 
  |  578 |     | 
       }  | 
  |  579 |     | 
     | 
  |  580 |     | 
     | 
  |  581 |     | 
           public List<PermissionAssigneeInfo> getPermissionAssignees(String namespaceCode,  | 
  |  582 |     | 
                           String permissionName, AttributeSet permissionDetails, AttributeSet qualification) { | 
  |  583 |    0 |                    return this.permissionService.getPermissionAssignees( namespaceCode, permissionName,  | 
  |  584 |     | 
                                   permissionDetails, qualification );  | 
  |  585 |     | 
           }  | 
  |  586 |     | 
     | 
  |  587 |     | 
           public List<PermissionAssigneeInfo> getPermissionAssigneesForTemplateName(String namespaceCode,  | 
  |  588 |     | 
                           String permissionTemplateName, AttributeSet permissionDetails,  | 
  |  589 |     | 
                           AttributeSet qualification) { | 
  |  590 |    0 |                    return this.permissionService.getPermissionAssigneesForTemplateName( namespaceCode,  | 
  |  591 |     | 
                                   permissionTemplateName, permissionDetails, qualification );  | 
  |  592 |     | 
           }  | 
  |  593 |     | 
     | 
  |  594 |     | 
         | 
  |  595 |     | 
     | 
  |  596 |     | 
           public boolean isMemberOfGroup(String principalId, String groupId) { | 
  |  597 |    0 |                Boolean isMember = getIsMemberOfGroupCache(principalId, groupId);  | 
  |  598 |    0 |                    if (isMember != null) { | 
  |  599 |    0 |                            return isMember;  | 
  |  600 |     | 
                   }  | 
  |  601 |    0 |                    isMember = getGroupService().isMemberOfGroup(principalId, groupId);  | 
  |  602 |    0 |                addIsMemberOfGroupToCache(principalId, groupId, isMember);  | 
  |  603 |    0 |                return isMember;  | 
  |  604 |     | 
           }  | 
  |  605 |     | 
     | 
  |  606 |     | 
           public boolean isMemberOfGroup(String principalId, String namespaceCode, String groupName) { | 
  |  607 |    0 |                    GroupInfo group = getGroupByName(namespaceCode, groupName);  | 
  |  608 |    0 |                    if ( group == null ) { | 
  |  609 |    0 |                            return false;  | 
  |  610 |     | 
                   }  | 
  |  611 |    0 |                    return isMemberOfGroup(principalId, group.getGroupId());  | 
  |  612 |     | 
       }  | 
  |  613 |     | 
     | 
  |  614 |     | 
           public boolean isGroupMemberOfGroup(String potentialMemberId, String potentialParentId)  | 
  |  615 |     | 
           { | 
  |  616 |    0 |                Boolean isMember = getIsGroupMemberOfGroupCache(potentialMemberId, potentialParentId);  | 
  |  617 |    0 |                if(isMember != null)  | 
  |  618 |     | 
               { | 
  |  619 |    0 |                    return isMember;  | 
  |  620 |     | 
               }  | 
  |  621 |     | 
               else  | 
  |  622 |     | 
           { | 
  |  623 |    0 |                    isMember = getGroupService()  | 
  |  624 |     | 
                           .isGroupMemberOfGroup(potentialMemberId, potentialParentId);  | 
  |  625 |     | 
           }  | 
  |  626 |    0 |                addIsGroupMemberOfGroupToCache(potentialMemberId, potentialParentId, isMember);  | 
  |  627 |    0 |                return isMember;  | 
  |  628 |     | 
           }  | 
  |  629 |     | 
           public List<String> getGroupMemberPrincipalIds(String groupId) { | 
  |  630 |    0 |                List<String> ids = getGroupMemberPrincipalIdsCache(groupId);  | 
  |  631 |    0 |                    if (ids != null) { | 
  |  632 |    0 |                            return ids;  | 
  |  633 |     | 
                   }  | 
  |  634 |    0 |                    ids = getGroupService().getMemberPrincipalIds(groupId);  | 
  |  635 |    0 |                addGroupMemberPrincipalIdsToCache(groupId, ids);  | 
  |  636 |    0 |                return ids;  | 
  |  637 |     | 
           }  | 
  |  638 |     | 
     | 
  |  639 |     | 
           public List<String> getDirectGroupMemberPrincipalIds(String groupId) { | 
  |  640 |    0 |                    return getGroupService().getDirectMemberPrincipalIds(groupId);  | 
  |  641 |     | 
           }  | 
  |  642 |     | 
     | 
  |  643 |     | 
       public List<String> getGroupIdsForPrincipal(String principalId) { | 
  |  644 |    0 |                List<String> ids = getGroupIdsForPrincipalCache(principalId);  | 
  |  645 |    0 |                    if (ids != null) { | 
  |  646 |    0 |                            return ids;  | 
  |  647 |     | 
                   }  | 
  |  648 |    0 |                    ids = getGroupService().getGroupIdsForPrincipal(principalId);  | 
  |  649 |    0 |                addGroupIdsForPrincipalToCache(principalId, ids);  | 
  |  650 |    0 |                return ids;  | 
  |  651 |     | 
           }  | 
  |  652 |     | 
     | 
  |  653 |     | 
       public List<String> getGroupIdsForPrincipal(String principalId, String namespaceCode ) { | 
  |  654 |    0 |                    return getGroupService().getGroupIdsForPrincipalByNamespace(principalId, namespaceCode );  | 
  |  655 |     | 
           }  | 
  |  656 |     | 
     | 
  |  657 |     | 
       public List<? extends GroupInfo> getGroupsForPrincipal(String principalId) { | 
  |  658 |    0 |                List<? extends GroupInfo> groups = getGroupsForPrincipalCache(principalId);  | 
  |  659 |    0 |                    if (groups != null) { | 
  |  660 |    0 |                            return groups;  | 
  |  661 |     | 
                   }  | 
  |  662 |    0 |                    groups = getGroupService().getGroupsForPrincipal(principalId);  | 
  |  663 |    0 |                addGroupsForPrincipalToCache(principalId, groups);  | 
  |  664 |    0 |                return groups;  | 
  |  665 |     | 
           }  | 
  |  666 |     | 
     | 
  |  667 |     | 
       public List<? extends GroupInfo> getGroupsForPrincipal(String principalId, String namespaceCode ) { | 
  |  668 |    0 |                List<? extends GroupInfo> groups = getGroupsForPrincipalCache(principalId + "-" + namespaceCode);  | 
  |  669 |    0 |                    if (groups != null) { | 
  |  670 |    0 |                            return groups;  | 
  |  671 |     | 
                   }  | 
  |  672 |    0 |                    groups = getGroupService().getGroupsForPrincipalByNamespace(principalId, namespaceCode );  | 
  |  673 |    0 |                addGroupsForPrincipalToCache(principalId, groups);  | 
  |  674 |    0 |                return groups;  | 
  |  675 |     | 
           }  | 
  |  676 |     | 
     | 
  |  677 |     | 
       public List<String> getMemberGroupIds(String groupId) { | 
  |  678 |    0 |                    return getGroupService().getMemberGroupIds(groupId);  | 
  |  679 |     | 
           }  | 
  |  680 |     | 
     | 
  |  681 |     | 
       public List<String> getDirectMemberGroupIds(String groupId) { | 
  |  682 |    0 |                    return getGroupService().getDirectMemberGroupIds(groupId);  | 
  |  683 |     | 
           }  | 
  |  684 |     | 
     | 
  |  685 |     | 
       public GroupInfo getGroup(String groupId) { | 
  |  686 |    0 |                GroupInfo group = getGroupByIdCache(groupId);  | 
  |  687 |    0 |                    if (group != null) { | 
  |  688 |    0 |                            return group;  | 
  |  689 |     | 
                   }  | 
  |  690 |    0 |                    group = getGroupService().getGroupInfo(groupId);  | 
  |  691 |    0 |                addGroupToCache(group);  | 
  |  692 |    0 |                return group;  | 
  |  693 |     | 
           }  | 
  |  694 |     | 
     | 
  |  695 |     | 
       public GroupInfo getGroupByName(String namespaceCode, String groupName) { | 
  |  696 |    0 |                GroupInfo group = getGroupByNameCache(namespaceCode + "-" + groupName);  | 
  |  697 |    0 |                    if (group != null) { | 
  |  698 |    0 |                            return group;  | 
  |  699 |     | 
                   }  | 
  |  700 |    0 |                    group = getGroupService().getGroupInfoByName( namespaceCode, groupName );  | 
  |  701 |    0 |                addGroupToCache(group);  | 
  |  702 |    0 |                return group;  | 
  |  703 |     | 
       }  | 
  |  704 |     | 
     | 
  |  705 |     | 
       public List<String> getParentGroupIds(String groupId) { | 
  |  706 |    0 |                    return getGroupService().getParentGroupIds( groupId );  | 
  |  707 |     | 
           }  | 
  |  708 |     | 
     | 
  |  709 |     | 
       public List<String> getDirectParentGroupIds(String groupId) { | 
  |  710 |    0 |                    return getGroupService().getDirectParentGroupIds( groupId );  | 
  |  711 |     | 
           }  | 
  |  712 |     | 
     | 
  |  713 |     | 
       protected void clearGroupCachesForPrincipalAndGroup( String principalId, String groupId ) { | 
  |  714 |    0 |                if ( principalId != null ) { | 
  |  715 |    0 |                        groupIdsForPrincipalCache.remove(principalId);  | 
  |  716 |    0 |                        groupsForPrincipalCache.remove(principalId);  | 
  |  717 |    0 |                        isMemberOfGroupCache.remove(principalId + "-" + groupId);  | 
  |  718 |     | 
               } else { | 
  |  719 |     | 
                         | 
  |  720 |    0 |                        synchronized (isMemberOfGroupCache) { | 
  |  721 |    0 |                        Iterator<String> keys = isMemberOfGroupCache.keySet().iterator();  | 
  |  722 |    0 |                        while ( keys.hasNext() ) { | 
  |  723 |    0 |                                String key = keys.next();  | 
  |  724 |    0 |                                if ( key.endsWith("-"+groupId) ) { | 
  |  725 |    0 |                                        keys.remove();  | 
  |  726 |     | 
                               }  | 
  |  727 |    0 |                        }  | 
  |  728 |    0 |                            }  | 
  |  729 |     | 
                         | 
  |  730 |     | 
                         | 
  |  731 |     | 
               }  | 
  |  732 |    0 |                groupMemberPrincipalIdsCache.remove(groupId);  | 
  |  733 |    0 |        }  | 
  |  734 |     | 
     | 
  |  735 |     | 
     | 
  |  736 |     | 
       public boolean addGroupToGroup(String childId, String parentId) { | 
  |  737 |    0 |                clearGroupCachesForPrincipalAndGroup(null, parentId);  | 
  |  738 |    0 |            return getGroupUpdateService().addGroupToGroup(childId, parentId);  | 
  |  739 |     | 
       }  | 
  |  740 |     | 
     | 
  |  741 |     | 
       public boolean addPrincipalToGroup(String principalId, String groupId) { | 
  |  742 |    0 |                clearGroupCachesForPrincipalAndGroup(principalId, groupId);  | 
  |  743 |    0 |            return getGroupUpdateService().addPrincipalToGroup(principalId, groupId);  | 
  |  744 |     | 
       }  | 
  |  745 |     | 
     | 
  |  746 |     | 
       public boolean removeGroupFromGroup(String childId, String parentId) { | 
  |  747 |    0 |                clearGroupCachesForPrincipalAndGroup(null, parentId);  | 
  |  748 |    0 |            return getGroupUpdateService().removeGroupFromGroup(childId, parentId);  | 
  |  749 |     | 
       }  | 
  |  750 |     | 
     | 
  |  751 |     | 
       public boolean removePrincipalFromGroup(String principalId, String groupId) { | 
  |  752 |    0 |                clearGroupCachesForPrincipalAndGroup(principalId, groupId);  | 
  |  753 |    0 |            return getGroupUpdateService().removePrincipalFromGroup(principalId, groupId);  | 
  |  754 |     | 
       }  | 
  |  755 |     | 
     | 
  |  756 |     | 
         | 
  |  757 |     | 
     | 
  |  758 |     | 
     | 
  |  759 |     | 
     | 
  |  760 |     | 
     | 
  |  761 |     | 
     | 
  |  762 |     | 
     | 
  |  763 |     | 
           public GroupInfo createGroup(GroupInfo groupInfo) { | 
  |  764 |    0 |                clearGroupCachesForPrincipalAndGroup(null,groupInfo.getGroupId());  | 
  |  765 |    0 |                    return getGroupUpdateService().createGroup(groupInfo);  | 
  |  766 |     | 
           }  | 
  |  767 |     | 
     | 
  |  768 |     | 
             | 
  |  769 |     | 
     | 
  |  770 |     | 
     | 
  |  771 |     | 
     | 
  |  772 |     | 
     | 
  |  773 |     | 
     | 
  |  774 |     | 
           public void removeAllGroupMembers(String groupId) { | 
  |  775 |    0 |                clearGroupCachesForPrincipalAndGroup(null, groupId);  | 
  |  776 |    0 |                    getGroupUpdateService().removeAllGroupMembers(groupId);  | 
  |  777 |    0 |            }  | 
  |  778 |     | 
     | 
  |  779 |     | 
             | 
  |  780 |     | 
     | 
  |  781 |     | 
     | 
  |  782 |     | 
     | 
  |  783 |     | 
     | 
  |  784 |     | 
     | 
  |  785 |     | 
     | 
  |  786 |     | 
     | 
  |  787 |     | 
           public GroupInfo updateGroup(String groupId, GroupInfo groupInfo) { | 
  |  788 |    0 |                clearGroupCachesForPrincipalAndGroup(null, groupId);  | 
  |  789 |    0 |                    return getGroupUpdateService().updateGroup(groupId, groupInfo);  | 
  |  790 |     | 
           }  | 
  |  791 |     | 
     | 
  |  792 |     | 
     | 
  |  793 |     | 
         | 
  |  794 |     | 
     | 
  |  795 |     | 
           public KimPrincipalInfo getPrincipal(String principalId) { | 
  |  796 |    0 |                KimPrincipalInfo principal = getPrincipalByIdCache(principalId);  | 
  |  797 |    0 |                    if (principal != null) { | 
  |  798 |    0 |                            return principal;  | 
  |  799 |     | 
                   }  | 
  |  800 |    0 |                    principal = getIdentityService().getPrincipal(principalId);  | 
  |  801 |    0 |                addPrincipalToCache(principal);  | 
  |  802 |    0 |                return principal;  | 
  |  803 |     | 
           }  | 
  |  804 |     | 
     | 
  |  805 |     | 
       public KimPrincipalInfo getPrincipalByPrincipalName(String principalName) { | 
  |  806 |    0 |                KimPrincipalInfo principal = getPrincipalByNameCache(principalName);  | 
  |  807 |    0 |                    if (principal != null) { | 
  |  808 |    0 |                            return principal;  | 
  |  809 |     | 
                   }  | 
  |  810 |    0 |                    principal = getIdentityService().getPrincipalByPrincipalName(principalName);  | 
  |  811 |    0 |                addPrincipalToCache(principal);  | 
  |  812 |    0 |                return principal;  | 
  |  813 |     | 
       }  | 
  |  814 |     | 
     | 
  |  815 |     | 
         | 
  |  816 |     | 
     | 
  |  817 |     | 
     | 
  |  818 |     | 
       public KimPrincipalInfo getPrincipalByPrincipalNameAndPassword(String principalName, String password) { | 
  |  819 |     | 
                 | 
  |  820 |    0 |                return getIdentityService().getPrincipalByPrincipalNameAndPassword( principalName, password );  | 
  |  821 |     | 
       }  | 
  |  822 |     | 
     | 
  |  823 |     | 
         | 
  |  824 |     | 
     | 
  |  825 |     | 
     | 
  |  826 |     | 
     | 
  |  827 |     | 
     | 
  |  828 |     | 
       public KimEntityDefaultInfo getEntityDefaultInfo(String entityId) { | 
  |  829 |    0 |                KimEntityDefaultInfo entity = getEntityDefaultInfoFromCache( entityId );  | 
  |  830 |    0 |                if ( entity == null ) { | 
  |  831 |    0 |                        entity = getIdentityService().getEntityDefaultInfo(entityId);  | 
  |  832 |    0 |                        addEntityDefaultInfoToCache( entity );  | 
  |  833 |     | 
               }  | 
  |  834 |    0 |                return entity;  | 
  |  835 |     | 
       }  | 
  |  836 |     | 
     | 
  |  837 |     | 
         | 
  |  838 |     | 
     | 
  |  839 |     | 
     | 
  |  840 |     | 
     | 
  |  841 |     | 
     | 
  |  842 |     | 
       public KimEntityDefaultInfo getEntityDefaultInfoByPrincipalId(  | 
  |  843 |     | 
                       String principalId) { | 
  |  844 |    0 |                KimEntityDefaultInfo entity = getEntityDefaultInfoFromCacheByPrincipalId( principalId );  | 
  |  845 |    0 |                if ( entity == null ) { | 
  |  846 |    0 |                        entity = getIdentityService().getEntityDefaultInfoByPrincipalId(principalId);  | 
  |  847 |    0 |                            addEntityDefaultInfoToCache( entity );  | 
  |  848 |     | 
               }  | 
  |  849 |    0 |                return entity;  | 
  |  850 |     | 
       }  | 
  |  851 |     | 
     | 
  |  852 |     | 
         | 
  |  853 |     | 
     | 
  |  854 |     | 
     | 
  |  855 |     | 
     | 
  |  856 |     | 
     | 
  |  857 |     | 
       public KimEntityDefaultInfo getEntityDefaultInfoByPrincipalName(  | 
  |  858 |     | 
                       String principalName) { | 
  |  859 |    0 |                KimEntityDefaultInfo entity = getEntityDefaultInfoFromCacheByPrincipalName( principalName );  | 
  |  860 |    0 |                if ( entity == null ) { | 
  |  861 |    0 |                        entity = getIdentityService().getEntityDefaultInfoByPrincipalName(principalName);  | 
  |  862 |    0 |                            addEntityDefaultInfoToCache( entity );  | 
  |  863 |     | 
               }  | 
  |  864 |    0 |                return entity;  | 
  |  865 |     | 
       }  | 
  |  866 |     | 
     | 
  |  867 |     | 
         | 
  |  868 |     | 
     | 
  |  869 |     | 
     | 
  |  870 |     | 
     | 
  |  871 |     | 
     | 
  |  872 |     | 
       public List<? extends KimEntityDefaultInfo> lookupEntityDefaultInfo(  | 
  |  873 |     | 
                       Map<String, String> searchCriteria, boolean unbounded) { | 
  |  874 |    0 |                return getIdentityService().lookupEntityDefaultInfo(searchCriteria, unbounded);  | 
  |  875 |     | 
       }  | 
  |  876 |     | 
     | 
  |  877 |     | 
     | 
  |  878 |     | 
         | 
  |  879 |     | 
     | 
  |  880 |     | 
     | 
  |  881 |     | 
           public KimEntityInfo getEntityInfo(String entityId) { | 
  |  882 |    0 |                KimEntityInfo entity = getEntityInfoFromCache( entityId );  | 
  |  883 |    0 |                if ( entity == null ) { | 
  |  884 |    0 |                        entity = getIdentityService().getEntityInfo(entityId);  | 
  |  885 |    0 |                        addEntityInfoToCache( entity );  | 
  |  886 |     | 
               }  | 
  |  887 |    0 |                return entity;  | 
  |  888 |     | 
           }  | 
  |  889 |     | 
     | 
  |  890 |     | 
             | 
  |  891 |     | 
     | 
  |  892 |     | 
     | 
  |  893 |     | 
           public KimEntityInfo getEntityInfoByPrincipalId(String principalId) { | 
  |  894 |    0 |                KimEntityInfo entity = getEntityInfoFromCacheByPrincipalId( principalId );  | 
  |  895 |    0 |                if ( entity == null ) { | 
  |  896 |    0 |                        entity = getIdentityService().getEntityInfoByPrincipalId(principalId);  | 
  |  897 |    0 |                            addEntityInfoToCache( entity );  | 
  |  898 |     | 
               }  | 
  |  899 |    0 |                return entity;  | 
  |  900 |     | 
           }  | 
  |  901 |     | 
     | 
  |  902 |     | 
             | 
  |  903 |     | 
     | 
  |  904 |     | 
     | 
  |  905 |     | 
     | 
  |  906 |     | 
     | 
  |  907 |     | 
           public KimEntityInfo getEntityInfoByPrincipalName(String principalName) { | 
  |  908 |    0 |                    KimEntityInfo entity = getEntityInfoFromCacheByPrincipalName( principalName );  | 
  |  909 |    0 |                if ( entity == null ) { | 
  |  910 |    0 |                        entity = getIdentityService().getEntityInfoByPrincipalName( principalName );  | 
  |  911 |    0 |                            addEntityInfoToCache( entity );  | 
  |  912 |     | 
               }  | 
  |  913 |    0 |                return entity;  | 
  |  914 |     | 
           }  | 
  |  915 |     | 
     | 
  |  916 |     | 
             | 
  |  917 |     | 
     | 
  |  918 |     | 
     | 
  |  919 |     | 
           public List<KimEntityInfo> lookupEntityInfo(  | 
  |  920 |     | 
                           Map<String, String> searchCriteria, boolean unbounded) { | 
  |  921 |    0 |                    return getIdentityService().lookupEntityInfo(searchCriteria, unbounded);  | 
  |  922 |     | 
           }  | 
  |  923 |     | 
     | 
  |  924 |     | 
             | 
  |  925 |     | 
     | 
  |  926 |     | 
     | 
  |  927 |     | 
       public int getMatchingEntityCount(Map<String,String> searchCriteria) { | 
  |  928 |    0 |                return getIdentityService().getMatchingEntityCount( searchCriteria );  | 
  |  929 |     | 
       }  | 
  |  930 |     | 
     | 
  |  931 |     | 
           public AddressTypeInfo getAddressType( String code ) { | 
  |  932 |    0 |                    AddressTypeInfo type = (AddressTypeInfo)kimReferenceTypeCache.get(AddressTypeInfo.class.getSimpleName()+"-"+code);  | 
  |  933 |    0 |                    if ( type == null ) { | 
  |  934 |    0 |                            type = getIdentityService().getAddressType(code);  | 
  |  935 |    0 |                            kimReferenceTypeCache.put(AddressTypeInfo.class.getSimpleName()+"-"+code, type);  | 
  |  936 |     | 
                   }  | 
  |  937 |    0 |                    return type;  | 
  |  938 |     | 
           }  | 
  |  939 |     | 
           public AffiliationTypeInfo getAffiliationType( String code ) { | 
  |  940 |    0 |                    AffiliationTypeInfo type = (AffiliationTypeInfo)kimReferenceTypeCache.get(AffiliationTypeInfo.class.getSimpleName()+"-"+code);  | 
  |  941 |    0 |                    if ( type == null ) { | 
  |  942 |    0 |                            type = getIdentityService().getAffiliationType(code);  | 
  |  943 |    0 |                            kimReferenceTypeCache.put(AddressTypeInfo.class.getSimpleName()+"-"+code, type);  | 
  |  944 |     | 
                   }  | 
  |  945 |    0 |                    return type;  | 
  |  946 |     | 
           }  | 
  |  947 |     | 
           public CitizenshipStatusInfo getCitizenshipStatus( String code ) { | 
  |  948 |    0 |                    CitizenshipStatusInfo type = (CitizenshipStatusInfo)kimReferenceTypeCache.get(CitizenshipStatusInfo.class.getSimpleName()+"-"+code);  | 
  |  949 |    0 |                    if ( type == null ) { | 
  |  950 |    0 |                            type = getIdentityService().getCitizenshipStatus(code);  | 
  |  951 |    0 |                            kimReferenceTypeCache.put(CitizenshipStatusInfo.class.getSimpleName()+"-"+code, type);  | 
  |  952 |     | 
                   }  | 
  |  953 |    0 |                    return type;  | 
  |  954 |     | 
           }  | 
  |  955 |     | 
           public EmailTypeInfo getEmailType( String code ) { | 
  |  956 |    0 |                    EmailTypeInfo type = (EmailTypeInfo)kimReferenceTypeCache.get(EmailTypeInfo.class.getSimpleName()+"-"+code);  | 
  |  957 |    0 |                    if ( type == null ) { | 
  |  958 |    0 |                            type = getIdentityService().getEmailType(code);  | 
  |  959 |    0 |                            kimReferenceTypeCache.put(EmailTypeInfo.class.getSimpleName()+"-"+code, type);  | 
  |  960 |     | 
                   }  | 
  |  961 |    0 |                    return type;  | 
  |  962 |     | 
           }  | 
  |  963 |     | 
           public EmploymentStatusInfo getEmploymentStatus( String code ) { | 
  |  964 |    0 |                    EmploymentStatusInfo type = (EmploymentStatusInfo)kimReferenceTypeCache.get(EmploymentStatusInfo.class.getSimpleName()+"-"+code);  | 
  |  965 |    0 |                    if ( type == null ) { | 
  |  966 |    0 |                            type = getIdentityService().getEmploymentStatus(code);  | 
  |  967 |    0 |                            kimReferenceTypeCache.put(EmploymentStatusInfo.class.getSimpleName()+"-"+code, type);  | 
  |  968 |     | 
                   }  | 
  |  969 |    0 |                    return type;  | 
  |  970 |     | 
           }  | 
  |  971 |     | 
           public EmploymentTypeInfo getEmploymentType( String code ) { | 
  |  972 |    0 |                    EmploymentTypeInfo type = (EmploymentTypeInfo)kimReferenceTypeCache.get(EmploymentTypeInfo.class.getSimpleName()+"-"+code);  | 
  |  973 |    0 |                    if ( type == null ) { | 
  |  974 |    0 |                            type = getIdentityService().getEmploymentType(code);  | 
  |  975 |    0 |                            kimReferenceTypeCache.put(EmploymentTypeInfo.class.getSimpleName()+"-"+code, type);  | 
  |  976 |     | 
                   }  | 
  |  977 |    0 |                    return type;  | 
  |  978 |     | 
           }  | 
  |  979 |     | 
           public EntityNameTypeInfo getEntityNameType( String code ) { | 
  |  980 |    0 |                    EntityNameTypeInfo type = (EntityNameTypeInfo)kimReferenceTypeCache.get(EntityNameTypeInfo.class.getSimpleName()+"-"+code);  | 
  |  981 |    0 |                    if ( type == null ) { | 
  |  982 |    0 |                            type = getIdentityService().getEntityNameType(code);  | 
  |  983 |    0 |                            kimReferenceTypeCache.put(EntityNameTypeInfo.class.getSimpleName()+"-"+code, type);  | 
  |  984 |     | 
                   }  | 
  |  985 |    0 |                    return type;  | 
  |  986 |     | 
           }  | 
  |  987 |     | 
           public EntityTypeInfo getEntityType( String code ) { | 
  |  988 |    0 |                    EntityTypeInfo type = (EntityTypeInfo)kimReferenceTypeCache.get(EntityTypeInfo.class.getSimpleName()+"-"+code);  | 
  |  989 |    0 |                    if ( type == null ) { | 
  |  990 |    0 |                            type = getIdentityService().getEntityType(code);  | 
  |  991 |    0 |                            kimReferenceTypeCache.put(EntityTypeInfo.class.getSimpleName()+"-"+code, type);  | 
  |  992 |     | 
                   }  | 
  |  993 |    0 |                    return type;  | 
  |  994 |     | 
           }  | 
  |  995 |     | 
           public ExternalIdentifierTypeInfo getExternalIdentifierType( String code ) { | 
  |  996 |    0 |                    ExternalIdentifierTypeInfo type = (ExternalIdentifierTypeInfo)kimReferenceTypeCache.get(ExternalIdentifierTypeInfo.class.getSimpleName()+"-"+code);  | 
  |  997 |    0 |                    if ( type == null ) { | 
  |  998 |    0 |                            type = getIdentityService().getExternalIdentifierType(code);  | 
  |  999 |    0 |                            kimReferenceTypeCache.put(ExternalIdentifierTypeInfo.class.getSimpleName()+"-"+code, type);  | 
  |  1000 |     | 
                   }  | 
  |  1001 |    0 |                    return type;  | 
  |  1002 |     | 
           }  | 
  |  1003 |     | 
           public PhoneTypeInfo getPhoneType( String code ) { | 
  |  1004 |    0 |                    PhoneTypeInfo type = (PhoneTypeInfo)kimReferenceTypeCache.get(PhoneTypeInfo.class.getSimpleName()+"-"+code);  | 
  |  1005 |    0 |                    if ( type == null ) { | 
  |  1006 |    0 |                            type = getIdentityService().getPhoneType(code);  | 
  |  1007 |    0 |                            kimReferenceTypeCache.put(PhoneTypeInfo.class.getSimpleName()+"-"+code, type);  | 
  |  1008 |     | 
                   }  | 
  |  1009 |    0 |                    return type;  | 
  |  1010 |     | 
           }  | 
  |  1011 |     | 
     | 
  |  1012 |     | 
             | 
  |  1013 |     | 
     | 
  |  1014 |     | 
           public IdentityService getIdentityService() { | 
  |  1015 |    0 |                    if ( identityService == null ) { | 
  |  1016 |    0 |                            identityService = KIMServiceLocator.getIdentityService();  | 
  |  1017 |     | 
                   }  | 
  |  1018 |    0 |                    return identityService;  | 
  |  1019 |     | 
           }  | 
  |  1020 |     | 
     | 
  |  1021 |     | 
           public GroupService getGroupService() { | 
  |  1022 |    0 |                    if ( groupService == null ) { | 
  |  1023 |    0 |                            groupService = KIMServiceLocator.getGroupService();  | 
  |  1024 |     | 
                   }  | 
  |  1025 |    0 |                    return groupService;  | 
  |  1026 |     | 
           }  | 
  |  1027 |     | 
     | 
  |  1028 |     | 
           public PermissionService getPermissionService() { | 
  |  1029 |    0 |                    if ( permissionService == null ) { | 
  |  1030 |    0 |                            permissionService = KIMServiceLocator.getPermissionService();  | 
  |  1031 |     | 
                   }  | 
  |  1032 |    0 |                    return permissionService;  | 
  |  1033 |     | 
           }  | 
  |  1034 |     | 
     | 
  |  1035 |     | 
           public ResponsibilityService getResponsibilityService() { | 
  |  1036 |    0 |                    if ( responsibilityService == null ) { | 
  |  1037 |    0 |                            responsibilityService = KIMServiceLocator.getResponsibilityService();  | 
  |  1038 |     | 
                   }  | 
  |  1039 |    0 |                    return responsibilityService;  | 
  |  1040 |     | 
           }  | 
  |  1041 |     | 
     | 
  |  1042 |     | 
         | 
  |  1043 |     | 
         | 
  |  1044 |     | 
         | 
  |  1045 |     | 
     | 
  |  1046 |     | 
             | 
  |  1047 |     | 
     | 
  |  1048 |     | 
     | 
  |  1049 |     | 
           public KimResponsibilityInfo getResponsibility(String responsibilityId) { | 
  |  1050 |    0 |                    return getResponsibilityService().getResponsibility( responsibilityId );  | 
  |  1051 |     | 
           }  | 
  |  1052 |     | 
     | 
  |  1053 |     | 
             | 
  |  1054 |     | 
     | 
  |  1055 |     | 
     | 
  |  1056 |     | 
           public boolean hasResponsibility(String principalId, String namespaceCode,  | 
  |  1057 |     | 
                           String responsibilityName, AttributeSet qualification,  | 
  |  1058 |     | 
                           AttributeSet responsibilityDetails) { | 
  |  1059 |    0 |                    return getResponsibilityService().hasResponsibility( principalId, namespaceCode, responsibilityName, qualification, responsibilityDetails );  | 
  |  1060 |     | 
           }  | 
  |  1061 |     | 
     | 
  |  1062 |     | 
           public List<? extends KimResponsibilityInfo> getResponsibilitiesByName( String namespaceCode, String responsibilityName) { | 
  |  1063 |    0 |                    return getResponsibilityService().getResponsibilitiesByName( namespaceCode, responsibilityName );  | 
  |  1064 |     | 
           }  | 
  |  1065 |     | 
     | 
  |  1066 |     | 
           public List<ResponsibilityActionInfo> getResponsibilityActions( String namespaceCode, String responsibilityName,  | 
  |  1067 |     | 
                       AttributeSet qualification, AttributeSet responsibilityDetails) { | 
  |  1068 |    0 |                    return getResponsibilityService().getResponsibilityActions( namespaceCode, responsibilityName, qualification, responsibilityDetails );  | 
  |  1069 |     | 
           }  | 
  |  1070 |     | 
     | 
  |  1071 |     | 
             | 
  |  1072 |     | 
     | 
  |  1073 |     | 
     | 
  |  1074 |     | 
     | 
  |  1075 |     | 
     | 
  |  1076 |     | 
           public List<ResponsibilityActionInfo> getResponsibilityActionsByTemplateName(  | 
  |  1077 |     | 
                           String namespaceCode, String responsibilityTemplateName,  | 
  |  1078 |     | 
                           AttributeSet qualification, AttributeSet responsibilityDetails) { | 
  |  1079 |    0 |                    return getResponsibilityService().getResponsibilityActionsByTemplateName(namespaceCode, responsibilityTemplateName, qualification, responsibilityDetails);  | 
  |  1080 |     | 
           }  | 
  |  1081 |     | 
     | 
  |  1082 |     | 
             | 
  |  1083 |     | 
     | 
  |  1084 |     | 
     | 
  |  1085 |     | 
     | 
  |  1086 |     | 
     | 
  |  1087 |     | 
           public boolean hasResponsibilityByTemplateName(String principalId,  | 
  |  1088 |     | 
                           String namespaceCode, String responsibilityTemplateName,  | 
  |  1089 |     | 
                           AttributeSet qualification, AttributeSet responsibilityDetails) { | 
  |  1090 |    0 |                    return getResponsibilityService().hasResponsibilityByTemplateName(principalId, namespaceCode, responsibilityTemplateName, qualification, responsibilityDetails);  | 
  |  1091 |     | 
           }  | 
  |  1092 |     | 
     | 
  |  1093 |     | 
           public void setEntityPrincipalCacheMaxSize(int entityPrincipalCacheMaxSize) { | 
  |  1094 |    0 |                    this.entityPrincipalCacheMaxSize = entityPrincipalCacheMaxSize;  | 
  |  1095 |    0 |            }  | 
  |  1096 |     | 
     | 
  |  1097 |     | 
           public void setEntityPrincipalCacheMaxAgeSeconds(int entityPrincipalCacheMaxAge) { | 
  |  1098 |    0 |                    this.entityPrincipalCacheMaxAgeSeconds = entityPrincipalCacheMaxAge;  | 
  |  1099 |    0 |            }  | 
  |  1100 |     | 
     | 
  |  1101 |     | 
           public void setGroupCacheMaxSize(int groupCacheMaxSize) { | 
  |  1102 |    0 |                    this.groupCacheMaxSize = groupCacheMaxSize;  | 
  |  1103 |    0 |            }  | 
  |  1104 |     | 
     | 
  |  1105 |     | 
           public void setGroupCacheMaxAgeSeconds(int groupCacheMaxAge) { | 
  |  1106 |    0 |                    this.groupCacheMaxAgeSeconds = groupCacheMaxAge;  | 
  |  1107 |    0 |            }  | 
  |  1108 |     | 
     | 
  |  1109 |     | 
           public void setPermissionCacheMaxSize(int permissionCacheMaxSize) { | 
  |  1110 |    0 |                    this.permissionCacheMaxSize = permissionCacheMaxSize;  | 
  |  1111 |    0 |            }  | 
  |  1112 |     | 
     | 
  |  1113 |     | 
           public void setPermissionCacheMaxAgeSeconds(int permissionCacheMaxAge) { | 
  |  1114 |    0 |                    this.permissionCacheMaxAgeSeconds = permissionCacheMaxAge;  | 
  |  1115 |    0 |            }  | 
  |  1116 |     | 
     | 
  |  1117 |     | 
           public void setResponsibilityCacheMaxSize(int responsibilityCacheMaxSize) { | 
  |  1118 |    0 |                    this.responsibilityCacheMaxSize = responsibilityCacheMaxSize;  | 
  |  1119 |    0 |            }  | 
  |  1120 |     | 
     | 
  |  1121 |     | 
           public void setResponsibilityCacheMaxAgeSeconds(int responsibilityCacheMaxAge) { | 
  |  1122 |    0 |                    this.responsibilityCacheMaxAgeSeconds = responsibilityCacheMaxAge;  | 
  |  1123 |    0 |            }  | 
  |  1124 |     | 
     | 
  |  1125 |     | 
       protected void logAuthorizationCheck(String checkType, String principalId, String namespaceCode, String permissionName, AttributeSet permissionDetails, AttributeSet qualification ) { | 
  |  1126 |    0 |                    StringBuilder sb = new StringBuilder();  | 
  |  1127 |    0 |                    sb.append(  '\n' );  | 
  |  1128 |    0 |                    sb.append( "Is AuthZ for " ).append( checkType ).append( ": " ).append( namespaceCode ).append( "/" ).append( permissionName ).append( '\n' );  | 
  |  1129 |    0 |                    sb.append( "             Principal:  " ).append( principalId );  | 
  |  1130 |    0 |                    if ( principalId != null ) { | 
  |  1131 |    0 |                            KimPrincipalInfo principal = getPrincipal( principalId );  | 
  |  1132 |    0 |                            if ( principal != null ) { | 
  |  1133 |    0 |                                    sb.append( " (" ).append( principal.getPrincipalName() ).append( ')' ); | 
  |  1134 |     | 
                           }  | 
  |  1135 |     | 
                   }  | 
  |  1136 |    0 |                    sb.append( '\n' );  | 
  |  1137 |    0 |                    sb.append( "             Details:\n" );  | 
  |  1138 |    0 |                    if ( permissionDetails != null ) { | 
  |  1139 |    0 |                            sb.append( permissionDetails.formattedDump( 25 ) );  | 
  |  1140 |     | 
                   } else { | 
  |  1141 |    0 |                            sb.append( "                         [null]\n" );  | 
  |  1142 |     | 
                   }  | 
  |  1143 |    0 |                    sb.append( "             Qualifiers:\n" );  | 
  |  1144 |    0 |                    if ( qualification != null && !qualification.isEmpty() ) { | 
  |  1145 |    0 |                            sb.append( qualification.formattedDump( 25 ) );  | 
  |  1146 |     | 
                   } else { | 
  |  1147 |    0 |                            sb.append( "                         [null]\n" );  | 
  |  1148 |     | 
                   }  | 
  |  1149 |    0 |                    if (LOG.isTraceEnabled()) { | 
  |  1150 |    0 |                            LOG.trace( sb.append(ExceptionUtils.getStackTrace(new Throwable())));  | 
  |  1151 |     | 
                   } else { | 
  |  1152 |    0 |                            LOG.debug(sb.toString());  | 
  |  1153 |     | 
                   }  | 
  |  1154 |    0 |        }  | 
  |  1155 |     | 
     | 
  |  1156 |     | 
       protected void logHasPermissionCheck(String checkType, String principalId, String namespaceCode, String permissionName, AttributeSet permissionDetails ) { | 
  |  1157 |    0 |                    StringBuilder sb = new StringBuilder();  | 
  |  1158 |    0 |                    sb.append(  '\n' );  | 
  |  1159 |    0 |                    sb.append( "Has Perm for " ).append( checkType ).append( ": " ).append( namespaceCode ).append( "/" ).append( permissionName ).append( '\n' );  | 
  |  1160 |    0 |                    sb.append( "             Principal:  " ).append( principalId );  | 
  |  1161 |    0 |                    if ( principalId != null ) { | 
  |  1162 |    0 |                            KimPrincipalInfo principal = getPrincipal( principalId );  | 
  |  1163 |    0 |                            if ( principal != null ) { | 
  |  1164 |    0 |                                    sb.append( " (" ).append( principal.getPrincipalName() ).append( ')' ); | 
  |  1165 |     | 
                           }  | 
  |  1166 |     | 
                   }  | 
  |  1167 |    0 |                    sb.append(  '\n' );  | 
  |  1168 |    0 |                    sb.append( "             Details:\n" );  | 
  |  1169 |    0 |                    if ( permissionDetails != null ) { | 
  |  1170 |    0 |                            sb.append( permissionDetails.formattedDump( 25 ) );  | 
  |  1171 |     | 
                   } else { | 
  |  1172 |    0 |                            sb.append( "                         [null]\n" );  | 
  |  1173 |     | 
                   }  | 
  |  1174 |    0 |                    if (LOG.isTraceEnabled()) { | 
  |  1175 |    0 |                            LOG.trace( sb.append( ExceptionUtils.getStackTrace(new Throwable())) );  | 
  |  1176 |     | 
                   } else { | 
  |  1177 |    0 |                            LOG.debug(sb.toString());  | 
  |  1178 |     | 
                   }  | 
  |  1179 |    0 |        }  | 
  |  1180 |     | 
     | 
  |  1181 |     | 
           public GroupUpdateService getGroupUpdateService() { | 
  |  1182 |     | 
                   try { | 
  |  1183 |    0 |                            if ( groupUpdateService == null ) { | 
  |  1184 |    0 |                                    groupUpdateService = KIMServiceLocatorInternal.getGroupUpdateService();  | 
  |  1185 |    0 |                                    if ( groupUpdateService == null ) { | 
  |  1186 |    0 |                                            throw new UnsupportedOperationException( "null returned for GroupUpdateService, unable to update group data");  | 
  |  1187 |     | 
                                   }  | 
  |  1188 |     | 
                           }  | 
  |  1189 |    0 |                    } catch ( Exception ex ) { | 
  |  1190 |    0 |                            throw new UnsupportedOperationException( "unable to obtain a GroupUpdateService, unable to update group data", ex);  | 
  |  1191 |    0 |                    }  | 
  |  1192 |    0 |                    return groupUpdateService;  | 
  |  1193 |     | 
           }  | 
  |  1194 |     | 
     | 
  |  1195 |     | 
           public IdentityUpdateService getIdentityUpdateService() { | 
  |  1196 |     | 
                   try { | 
  |  1197 |    0 |                            if ( identityUpdateService == null ) { | 
  |  1198 |    0 |                                    identityUpdateService = KIMServiceLocatorInternal.getIdentityUpdateService();  | 
  |  1199 |    0 |                                    if ( identityUpdateService == null ) { | 
  |  1200 |    0 |                                            throw new UnsupportedOperationException( "null returned for IdentityUpdateService, unable to update identity data");  | 
  |  1201 |     | 
                                   }  | 
  |  1202 |     | 
                           }  | 
  |  1203 |    0 |                    } catch ( Exception ex ) { | 
  |  1204 |    0 |                            throw new UnsupportedOperationException( "unable to obtain an IdentityUpdateService, unable to update identity data", ex);  | 
  |  1205 |    0 |                    }  | 
  |  1206 |    0 |                    return identityUpdateService;  | 
  |  1207 |     | 
           }  | 
  |  1208 |     | 
   }  |