/** * Reads the DialectURI of the ClaimURIs to be retrieved from identity.xml -> OAuth -> * TokenGeneration -> ConsumerDialectURI. If not configured it uses http://wso2.org/claims as * default */ @Override public void init() { dialectURI = OAuthServerConfiguration.getInstance().getConsumerDialectURI(); if (dialectURI == null) { dialectURI = DEFAULT_DIALECT_URI; } claimsLocalCache = ClaimCache.getInstance(); }
@Override public SortedMap<String, String> getClaims(String endUserName, String[] requestedClaims) throws IdentityOAuth2Exception { SortedMap<String, String> claimValues; try { int tenantId = JWTTokenGenerator.getTenantId(endUserName); // check in local cache String key = endUserName + ":" + tenantId; CacheKey cacheKey = new ClaimCacheKey(key); Object result = claimsLocalCache.getValueFromCache(cacheKey); if (result != null) { claimValues = ((UserClaims) result).getClaimValues(); } else { // if no claims were requested, return all if (requestedClaims == null) { log.debug("No claims set requested. Returning all claims in the dialect"); ClaimManager claimManager = OAuthComponentServiceHolder.getRealmService() .getTenantUserRealm(tenantId) .getClaimManager(); ClaimMapping[] claims = claimManager.getAllClaimMappings(dialectURI); requestedClaims = claimToString(claims); } UserStoreManager userStoreManager = OAuthComponentServiceHolder.getRealmService() .getTenantUserRealm(tenantId) .getUserStoreManager(); claimValues = new TreeMap(userStoreManager.getUserClaimValues(endUserName, requestedClaims, null)); UserClaims userClaims = new UserClaims(claimValues); claimsLocalCache.addToCache(cacheKey, userClaims); } } catch (UserStoreException e) { log.debug("Error while reading user claims ", e); throw new IdentityOAuth2Exception( "Error while retrieving user claim values from " + "user store: " + e.getMessage()); } return claimValues; }