List of usage examples for org.apache.shiro.subject SimplePrincipalCollection getPrimaryPrincipal
public Object getPrimaryPrincipal()
From source file:com.dylan.shiro.infrastructure.shiro.CasRealm.java
License:Apache License
/** * Retrieves the AuthorizationInfo for the given principals (the CAS previously authenticated user : id + attributes). * // w w w . j a v a 2 s . c om * @param principals the primary identifying principals of the AuthorizationInfo that should be retrieved. * @return the AuthorizationInfo associated with this principals. */ @Override @SuppressWarnings("unchecked") protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { // retrieve user information SimplePrincipalCollection principalCollection = (SimplePrincipalCollection) principals; String userName = (String) principalCollection.getPrimaryPrincipal(); User user = getUserRepository().getByName(userName); Set<String> roles = user.getRolesName(); Set<String> permissions = user.getPermissions(); List<Object> listPrincipals = principalCollection.asList(); Map<String, String> attributes = (Map<String, String>) listPrincipals.get(1); // create simple authorization info SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo(); // add default roles simpleAuthorizationInfo.addRoles(roles); // add default permissions simpleAuthorizationInfo.addStringPermissions(permissions); // get roles from attributes List<String> attributeNames = split(roleAttributeNames); for (String attributeName : attributeNames) { String value = attributes.get(attributeName); addRoles(simpleAuthorizationInfo, split(value)); } // get permissions from attributes attributeNames = split(permissionAttributeNames); for (String attributeName : attributeNames) { String value = attributes.get(attributeName); addPermissions(simpleAuthorizationInfo, split(value)); } return simpleAuthorizationInfo; }
From source file:org.apache.usergrid.security.shiro.ShiroCache.java
License:Apache License
/** get cache for application scope */ private ScopedCache<String, V> getCacheScope(K key) { PrincipalIdentifier principal;/*from w w w . j a va2 s . c o m*/ if (key instanceof SimplePrincipalCollection) { SimplePrincipalCollection spc = (SimplePrincipalCollection) key; principal = (PrincipalIdentifier) spc.getPrimaryPrincipal(); } else { principal = (PrincipalIdentifier) key; } CacheScope scope = new CacheScope(new SimpleId(principal.getApplicationId(), "application")); ScopedCache<String, V> scopedCache = cacheFactory.getScopedCache(scope); return scopedCache; }
From source file:org.apache.usergrid.security.shiro.ShiroCache.java
License:Apache License
/** key is the user UUID in string form + class name of key */ private String getKeyString(K key) { if (key instanceof SimplePrincipalCollection) { SimplePrincipalCollection spc = (SimplePrincipalCollection) key; if (spc.getPrimaryPrincipal() instanceof UserPrincipal) { UserPrincipal p = (UserPrincipal) spc.getPrimaryPrincipal(); return p.getUser().getUuid().toString(); }//w ww . j a va2s . com } return key.toString() + "_" + key.getClass().getSimpleName(); }