Search in sources :

Example 6 with ScopeDTO

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

the class ScopeUtils method getScope.

public static Scope getScope(ScopeToUpdateDTO scopeDTO, String scopeName) {
    Scope scope = new Scope(scopeName, scopeDTO.getDisplayName(), getScopeBindings(scopeDTO.getScopeBindings()), scopeDTO.getDescription());
    scope.addScopeBindings(DEFAULT_SCOPE_BINDING, scopeDTO.getBindings());
    return scope;
}
Also used : Scope(org.wso2.carbon.identity.oauth2.bean.Scope)

Example 7 with ScopeDTO

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

the class ScopeUtilsTest method testGetScope.

@Test(description = "Testing getScope")
public void testGetScope() throws Exception {
    ScopeDTO scopeDTO = new ScopeDTO();
    scopeDTO.setName(CLIENT_NAME);
    scopeDTO.setDisplayName(CLIENT_NAME);
    scopeDTO.setDescription(SCOPE_DESCRIPTION);
    ArrayList binding = new ArrayList();
    Scope scope1 = ScopeUtils.getScope(scopeDTO);
    assertEquals(scope1.getName(), CLIENT_NAME, "Actual name is not match for expected name");
    assertEquals(scope1.getDisplayName(), CLIENT_NAME, "Actual display name is not match for expected display name");
    assertEquals(scope1.getDescription(), SCOPE_DESCRIPTION, "Actual description is not match for expected description");
    assertEquals(scope1.getBindings(), binding, "Actual binding is not match for expected binding");
}
Also used : Scope(org.wso2.carbon.identity.oauth2.bean.Scope) ScopeDTO(org.wso2.carbon.identity.oauth.scope.endpoint.dto.ScopeDTO) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 8 with ScopeDTO

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

the class ScopeUtilsTest method testGetScopeDTOs.

@Test(description = "Testing getScopeDTO")
public void testGetScopeDTOs() throws Exception {
    int scopeName;
    int scopeSize = 15;
    Set<Scope> scopes = new HashSet<>();
    ArrayList<String> bindings = new ArrayList<>(Arrays.asList("scope1", "scope2"));
    for (int i = 0; i < scopeSize; i++) {
        Scope scope1 = new Scope(CLIENT_NAME + "" + i, CLIENT_NAME + "" + i, SCOPE_DESCRIPTION, bindings);
        scopes.add(scope1);
    }
    Set<ScopeDTO> scopeDTOs = ScopeUtils.getScopeDTOs(scopes);
    assertNotNull(scopeDTOs);
    assertEquals(scopeDTOs.size(), scopeSize, "Invalid Scopes size");
}
Also used : Scope(org.wso2.carbon.identity.oauth2.bean.Scope) ScopeDTO(org.wso2.carbon.identity.oauth.scope.endpoint.dto.ScopeDTO) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 9 with ScopeDTO

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

the class OAuth2ServiceComponent method loadScopeConfigFile.

private static void loadScopeConfigFile() {
    List<ScopeDTO> listOIDCScopesClaims = new ArrayList<>();
    String configDirPath = CarbonUtils.getCarbonConfigDirPath();
    String confXml = Paths.get(configDirPath, IDENTITY_PATH, OAuthConstants.OIDC_SCOPE_CONFIG_PATH).toString();
    File configFile = new File(confXml);
    if (!configFile.exists()) {
        log.warn("OIDC scope-claim Configuration File is not present at: " + confXml);
        return;
    }
    XMLStreamReader parser = null;
    try (InputStream stream = new FileInputStream(configFile)) {
        parser = XMLInputFactory.newInstance().createXMLStreamReader(stream);
        StAXOMBuilder builder = new StAXOMBuilder(parser);
        OMElement documentElement = builder.getDocumentElement();
        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);
            String displayName = omElement.getAttributeValue(new QName(DISPLAY_NAME));
            if (StringUtils.isNotEmpty(displayName)) {
                scope.setDisplayName(displayName);
            } else {
                scope.setDisplayName(configType);
            }
            String description = omElement.getAttributeValue(new QName(DESCRIPTION));
            if (StringUtils.isNotEmpty(description)) {
                scope.setDescription(description);
            }
            scope.setClaim(loadClaimConfig(omElement));
            listOIDCScopesClaims.add(scope);
        }
    } catch (XMLStreamException e) {
        log.warn("Error while streaming OIDC scope config.", e);
    } catch (IOException e) {
        log.warn("Error while loading OIDC scope config.", e);
    } finally {
        try {
            if (parser != null) {
                parser.close();
            }
        } catch (XMLStreamException e) {
            log.error("Error while closing XML stream", e);
        }
    }
    OAuth2ServiceComponentHolder.getInstance().setOIDCScopesClaims(listOIDCScopesClaims);
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) ScopeDTO(org.wso2.carbon.identity.oauth.dto.ScopeDTO) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) OMElement(org.apache.axiom.om.OMElement) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) XMLStreamException(javax.xml.stream.XMLStreamException) Iterator(java.util.Iterator) StAXOMBuilder(org.apache.axiom.om.impl.builder.StAXOMBuilder) File(java.io.File)

Example 10 with ScopeDTO

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

the class OpenIDConnectClaimFilterImplTest method testGetClaimsFilteredByUserConsentWithException.

@Test
public void testGetClaimsFilteredByUserConsentWithException() throws Exception {
    claims = getClaims();
    AuthenticatedUser user = getDefaultAuthenticatedLocalUser();
    when(ssoConsentService.isSSOConsentManagementEnabled(any())).thenReturn(false);
    Mockito.doThrow(new IdentityApplicationManagementException("")).when(applicationMgtService).getServiceProviderByClientId("dummy", IdentityApplicationConstants.OAuth2.NAME, SP_TENANT_DOMAIN);
    Map<String, Object> claimFilter = openIDConnectClaimFilter.getClaimsFilteredByUserConsent(claims, user, "dummy", SP_TENANT_DOMAIN);
    Assert.assertEquals(((ScopeDTO) claimFilter.get("testUserClaimURI")).getName(), "email");
    Assert.assertEquals(((ScopeDTO) claimFilter.get("testUserClaimURI")).getDescription(), "emailDescription");
    Assert.assertEquals(((ScopeDTO) claimFilter.get("testUserClaimURI2")).getName(), "address");
    Assert.assertEquals(((ScopeDTO) claimFilter.get("testUserClaimURI2")).getDescription(), "addressDescription");
}
Also used : IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) Matchers.anyString(org.mockito.Matchers.anyString) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) Test(org.testng.annotations.Test)

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