Search in sources :

Example 16 with ScopeDTO

use of org.wso2.carbon.identity.oauth.scope.endpoint.dto.ScopeDTO 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 17 with ScopeDTO

use of org.wso2.carbon.identity.oauth.scope.endpoint.dto.ScopeDTO 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 18 with ScopeDTO

use of org.wso2.carbon.identity.oauth.scope.endpoint.dto.ScopeDTO 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 19 with ScopeDTO

use of org.wso2.carbon.identity.oauth.scope.endpoint.dto.ScopeDTO in project identity-inbound-auth-oauth by wso2-extensions.

the class OAuth2Util method getOIDCScopes.

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;
}
Also used : IdentityOAuth2Exception(org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception) ScopeDTO(org.wso2.carbon.identity.oauth.dto.ScopeDTO) ArrayList(java.util.ArrayList) UserStoreException(org.wso2.carbon.user.api.UserStoreException)

Example 20 with ScopeDTO

use of org.wso2.carbon.identity.oauth.scope.endpoint.dto.ScopeDTO in project carbon-apimgt by wso2.

the class MappingUtil method scopeDto.

/**
 * used to convert {@link Scope} to {@link ScopeDTO}
 * @param scope scope Object
 * @param scopeBindingType type of bindings
 * @return ScopeDTO object
 */
public static ScopeDTO scopeDto(Scope scope, String scopeBindingType) {
    ScopeDTO scopeDTO = new ScopeDTO();
    scopeDTO.setName(scope.getName());
    scopeDTO.setDescription(scope.getDescription());
    Scope_bindingsDTO scopeBindingsDTO = new Scope_bindingsDTO();
    scopeBindingsDTO.setType(scopeBindingType);
    if (scope.getBindings() != null) {
        scopeBindingsDTO.setValues(scope.getBindings());
    } else {
        scopeBindingsDTO.setValues(Collections.emptyList());
    }
    scopeDTO.setBindings(scopeBindingsDTO);
    return scopeDTO;
}
Also used : Scope_bindingsDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.Scope_bindingsDTO) ScopeDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.ScopeDTO)

Aggregations

ArrayList (java.util.ArrayList)23 ScopeDTO (org.wso2.carbon.identity.oauth.dto.ScopeDTO)18 HashMap (java.util.HashMap)13 Scope (org.wso2.carbon.apimgt.api.model.Scope)11 ScopeDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ScopeDTO)11 Test (org.testng.annotations.Test)8 APIScopeDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIScopeDTO)8 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)8 Scope (org.wso2.carbon.identity.oauth2.bean.Scope)8 HashSet (java.util.HashSet)7 List (java.util.List)7 ScopeDTO (org.wso2.carbon.identity.oauth.scope.endpoint.dto.ScopeDTO)7 Map (java.util.Map)6 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)6 JdbcTemplate (org.wso2.carbon.database.utils.jdbc.JdbcTemplate)6 DataAccessException (org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)6 OIDCScopeClaimCacheEntry (org.wso2.carbon.identity.openidconnect.cache.OIDCScopeClaimCacheEntry)6 Matchers.anyString (org.mockito.Matchers.anyString)5 SQLIntegrityConstraintViolationException (java.sql.SQLIntegrityConstraintViolationException)4 Arrays (java.util.Arrays)4