Search in sources :

Example 1 with OIDCScopeClaimCacheEntry

use of org.wso2.carbon.identity.openidconnect.cache.OIDCScopeClaimCacheEntry in project identity-inbound-auth-oauth by wso2-extensions.

the class OpenIDConnectClaimFilterImplTest method testGetClaimsFilteredByOIDCScopes.

@Test(dataProvider = "testGetClaimsFilteredByOIDCScopes")
public void testGetClaimsFilteredByOIDCScopes(String requestedScope, int numberOfClaims, String claim) throws Exception {
    requestedScopes = new HashSet<>();
    requestedScopes.add(requestedScope);
    OIDCScopeClaimCacheEntry oidcScopeClaimCacheEntry = new OIDCScopeClaimCacheEntry();
    oidcScopeClaimCacheEntry.setScopeClaimMapping(getScopeDTOList());
    OIDCScopeClaimCache.getInstance().addScopeClaimMap(-1234, oidcScopeClaimCacheEntry);
    List claims = openIDConnectClaimFilter.getClaimsFilteredByOIDCScopes(requestedScopes, SP_TENANT_DOMAIN);
    Assert.assertEquals(claims.size(), numberOfClaims);
    Assert.assertEquals(claims.get(0), claim);
}
Also used : OIDCScopeClaimCacheEntry(org.wso2.carbon.identity.openidconnect.cache.OIDCScopeClaimCacheEntry) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.testng.annotations.Test)

Example 2 with OIDCScopeClaimCacheEntry

use of org.wso2.carbon.identity.openidconnect.cache.OIDCScopeClaimCacheEntry in project identity-inbound-auth-oauth by wso2-extensions.

the class CacheBackedScopeClaimMappingDAOImpl method initScopeClaimMapping.

@Override
public void initScopeClaimMapping(int tenantId, List<ScopeDTO> scopeClaims) throws IdentityOAuth2Exception {
    scopeClaimMappingDAOImpl.initScopeClaimMapping(tenantId, scopeClaims);
    OIDCScopeClaimCacheEntry oidcScopeClaimCacheEntry = new OIDCScopeClaimCacheEntry();
    oidcScopeClaimCacheEntry.setScopeClaimMapping(scopeClaims);
    oidcScopeClaimCache.addScopeClaimMap(tenantId, oidcScopeClaimCacheEntry);
    if (log.isDebugEnabled()) {
        log.debug("The cache oidcScopeClaimCache is initialized for the tenant : " + tenantId);
    }
}
Also used : OIDCScopeClaimCacheEntry(org.wso2.carbon.identity.openidconnect.cache.OIDCScopeClaimCacheEntry)

Example 3 with OIDCScopeClaimCacheEntry

use of org.wso2.carbon.identity.openidconnect.cache.OIDCScopeClaimCacheEntry in project identity-inbound-auth-oauth by wso2-extensions.

the class CacheBackedScopeClaimMappingDAOImpl method getClaims.

@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;
}
Also used : OIDCScopeClaimCacheEntry(org.wso2.carbon.identity.openidconnect.cache.OIDCScopeClaimCacheEntry) ScopeDTO(org.wso2.carbon.identity.oauth.dto.ScopeDTO)

Example 4 with OIDCScopeClaimCacheEntry

use of org.wso2.carbon.identity.openidconnect.cache.OIDCScopeClaimCacheEntry in project identity-inbound-auth-oauth by wso2-extensions.

the class CacheBackedScopeClaimMappingDAOImpl method addScopes.

@Override
public void addScopes(int tenantId, List<ScopeDTO> scopeClaimsMap) throws IdentityOAuth2Exception {
    scopeClaimMappingDAOImpl.addScopes(tenantId, scopeClaimsMap);
    OIDCScopeClaimCacheEntry oidcScopeClaimCacheEntry = new OIDCScopeClaimCacheEntry();
    oidcScopeClaimCacheEntry.setScopeClaimMapping(scopeClaimsMap);
    oidcScopeClaimCache.addScopeClaimMap(tenantId, oidcScopeClaimCacheEntry);
    if (log.isDebugEnabled()) {
        log.debug("The cache oidcScopeClaimCache is added for the tenant : " + tenantId);
    }
}
Also used : OIDCScopeClaimCacheEntry(org.wso2.carbon.identity.openidconnect.cache.OIDCScopeClaimCacheEntry)

Example 5 with OIDCScopeClaimCacheEntry

use of org.wso2.carbon.identity.openidconnect.cache.OIDCScopeClaimCacheEntry in project identity-inbound-auth-oauth by wso2-extensions.

the class OpenIDConnectClaimFilterImplTest method testHandleUpdatedAtClaim.

@Test
public void testHandleUpdatedAtClaim() {
    String date = "2021-10-27T11:34:13.791Z";
    claims = new HashMap<>();
    claims.put("updated_at", date);
    String[] requestedScopes = { "profile" };
    OIDCScopeClaimCacheEntry oidcScopeClaimCacheEntry = new OIDCScopeClaimCacheEntry();
    oidcScopeClaimCacheEntry.setScopeClaimMapping(getScopeDTOList());
    OIDCScopeClaimCache.getInstance().addScopeClaimMap(-1234, oidcScopeClaimCacheEntry);
    Map<String, Object> filteredClaims = openIDConnectClaimFilter.getClaimsFilteredByOIDCScopes(claims, requestedScopes, CLIENT_ID, SP_TENANT_DOMAIN);
    // Due to the effect of time zone during time conversion, considering only the seconds during comparison
    // Check is to ensure this claim is in seconds not milliseconds
    String filteredDate = String.valueOf(filteredClaims.get("updated_at"));
    Assert.assertEquals(filteredDate.substring(8), "53");
}
Also used : OIDCScopeClaimCacheEntry(org.wso2.carbon.identity.openidconnect.cache.OIDCScopeClaimCacheEntry) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Aggregations

OIDCScopeClaimCacheEntry (org.wso2.carbon.identity.openidconnect.cache.OIDCScopeClaimCacheEntry)8 ScopeDTO (org.wso2.carbon.identity.oauth.dto.ScopeDTO)3 ArrayList (java.util.ArrayList)2 Test (org.testng.annotations.Test)2 List (java.util.List)1 Matchers.anyString (org.mockito.Matchers.anyString)1