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;
}
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");
}
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");
}
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);
}
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");
}
Aggregations