private List<ScopeDTO> buildScopeDTO(Map<String, List<String>> scopeClaimMap, int tenantId) { List<ScopeDTO> oidcScopeClaimList = new ArrayList<>(); for (Map.Entry<String, List<String>> scopeClaimEntry : scopeClaimMap.entrySet()) { ScopeDTO scopeDTO = new ScopeDTO(); String scopeName = scopeClaimEntry.getKey(); List<String> claimsList = scopeClaimEntry.getValue(); scopeDTO.setName(scopeClaimEntry.getKey()); if (CollectionUtils.isNotEmpty(claimsList)) { scopeDTO.setClaim(claimsList.toArray(new String[claimsList.size()])); } oidcScopeClaimList.add(scopeDTO); if (log.isDebugEnabled()) { log.debug("The scope: " + scopeName + " and the claims: " + String.join(",", claimsList) + "are successfully" + " loaded for the tenant: " + tenantId); } } return oidcScopeClaimList; } }
@Override public ScopeDTO getClaims(String scope, int tenantId) throws IdentityOAuth2Exception { OIDCScopeClaimCacheEntry oidcScopeClaimCacheEntry = oidcScopeClaimCache.getScopeClaimMap(tenantId); oidcScopeClaimCacheEntry = loadOIDCScopeClaims(tenantId, oidcScopeClaimCacheEntry); ScopeDTO scopeDTO = new ScopeDTO(); for (ScopeDTO scopeObj : oidcScopeClaimCacheEntry.getScopeClaimMapping()) { if (scope.equals(scopeObj.getName()) && scopeObj.getClaim() != null) { scopeDTO = scopeObj; } } return scopeDTO; }
@Override public List<String> getScopeNames(int tenantId) throws IdentityOAuth2Exception { OIDCScopeClaimCacheEntry oidcScopeClaimCacheEntry = oidcScopeClaimCache.getScopeClaimMap(tenantId); oidcScopeClaimCacheEntry = loadOIDCScopeClaims(tenantId, oidcScopeClaimCacheEntry); List<String> scopes = new ArrayList<>(); for (ScopeDTO scopeDTO : oidcScopeClaimCacheEntry.getScopeClaimMapping()) { scopes.add(scopeDTO.getName()); } return scopes; }
/** * To retrieve oidc claims mapped to an oidc scope. * * @param scope scope * @return list of claims which are mapped to the oidc scope. * @throws IdentityOAuth2Exception if an error occurs when lading oidc claims. */ public String[] getClaims(String scope) throws IdentityOAuthAdminException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); try { ScopeDTO scopeDTO = OAuthTokenPersistenceFactory.getInstance().getScopeClaimMappingDAO(). getClaims(scope, tenantId); if (scopeDTO != null && ArrayUtils.isNotEmpty(scopeDTO.getClaim())) { return scopeDTO.getClaim(); } else { if (log.isDebugEnabled()) { log.debug("Could not load oidc claims. Hence returning an empty array."); } return new String[0]; } } catch (IdentityOAuth2Exception e) { throw handleError("Error while loading OIDC claims for the scope: " + scope + " in tenant: " + tenantId, e); } }
public static List<String> getOIDCScopes(String tenantDomain) { List<String> scopes = new ArrayList<>(); try { int tenantId = OAuthComponentServiceHolder.getInstance().getRealmService().getTenantManager() .getTenantId(tenantDomain); // Get the scopes from the cache or the db List<ScopeDTO> scopesDTOList = OAuthTokenPersistenceFactory.getInstance().getScopeClaimMappingDAO(). getScopes(tenantId); if (CollectionUtils.isNotEmpty(scopesDTOList)) { for (ScopeDTO scope : scopesDTOList) { scopes.add(scope.getName()); } } } catch (UserStoreException | IdentityOAuth2Exception e) { log.error("Error while retrieving OIDC scopes.", e); } return scopes; }
@Override public ScopeDTO getClaims(String scope, int tenantId) throws IdentityOAuth2Exception { String sql = SQLQueries.GET_IDN_OIDC_CLAIMS; JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate(); ScopeDTO scopeDTO = new ScopeDTO(); try { List<String> claimsList = jdbcTemplate.executeQuery(sql, (resultSet, i) -> resultSet.getString(1) , preparedStatement -> { preparedStatement.setString(1, scope); preparedStatement.setInt(2, tenantId); }); scopeDTO.setName(scope); String[] claimsArr = new String[claimsList.size()]; scopeDTO.setClaim(claimsList.toArray(claimsArr)); } catch (DataAccessException e) { String errorMessage = "Error while loading OIDC claims for the scope: " + scope; throw new IdentityOAuth2Exception(errorMessage, e); } return scopeDTO; }
Iterator iterator = documentElement.getChildElements(); while (iterator.hasNext()) { ScopeDTO scope = new ScopeDTO(); OMElement omElement = (OMElement) iterator.next(); String configType = omElement.getAttributeValue(new QName( "id")); scope.setName(configType); scope.setClaim(loadClaimConfig(omElement)); listOIDCScopesClaims.add(scope);