use of org.wso2.carbon.identity.oauth2.authz.OAuthAuthzReqMessageContext in project carbon-apimgt by wso2.
the class SystemScopesIssuer method getScopes.
public List<String> getScopes(OAuthAuthzReqMessageContext oAuthAuthzReqMessageContext) {
List<String> authorizedScopes = null;
List<String> requestedScopes = new ArrayList<>();
if (oAuthAuthzReqMessageContext.getApprovedScope() != null) {
requestedScopes = Arrays.asList(oAuthAuthzReqMessageContext.getApprovedScope());
}
String clientId = oAuthAuthzReqMessageContext.getAuthorizationReqDTO().getConsumerKey();
AuthenticatedUser authenticatedUser = oAuthAuthzReqMessageContext.getAuthorizationReqDTO().getUser();
Map<String, String> appScopes = getAppScopes(clientId, authenticatedUser, requestedScopes);
if (appScopes != null) {
// If no scopes can be found in the context of the application
if (isAppScopesEmpty(appScopes, clientId)) {
return getAllowedScopes(requestedScopes);
}
String[] userRoles = getUserRoles(authenticatedUser);
authorizedScopes = getAuthorizedScopes(userRoles, requestedScopes, appScopes);
}
return authorizedScopes;
}
use of org.wso2.carbon.identity.oauth2.authz.OAuthAuthzReqMessageContext in project carbon-apimgt by wso2.
the class SystemScopeIssuerImplTest method init.
@Before
public void init() throws IdentityOAuth2Exception {
systemScopesIssuer = Mockito.mock(SystemScopesIssuer.class);
oAuth2AuthorizeReqDTO = new OAuth2AuthorizeReqDTO();
String[] scopes = { "test", "test1" };
restAPIScopes.put("test", "test");
authenticatedUser = Mockito.mock(AuthenticatedUser.class);
Mockito.when(systemScopesIssuer.getAppScopes(Mockito.anyString(), Mockito.anyObject(), Mockito.anyList())).thenReturn(restAPIScopes);
Mockito.when(systemScopesIssuer.validateScope((OAuthAuthzReqMessageContext) Mockito.anyObject())).thenReturn(true);
oAuth2AuthorizeReqDTO.setScopes(scopes);
oAuth2AuthorizeReqDTO.setUser(authenticatedUser);
oAuthAuthzReqMessageContext = new OAuthAuthzReqMessageContext(oAuth2AuthorizeReqDTO);
oAuth2AccessTokenReqDTO = new OAuth2AccessTokenReqDTO();
oAuth2AccessTokenReqDTO.setScope(scopes);
oAuthTokenReqMessageContext = new OAuthTokenReqMessageContext(oAuth2AccessTokenReqDTO);
Mockito.when(systemScopesIssuer.validateScope((OAuthTokenReqMessageContext) Mockito.anyObject())).thenReturn(true);
oAuth2TokenValidationRequestDTO = new OAuth2TokenValidationRequestDTO();
oAuth2TokenValidationResponseDTO = new OAuth2TokenValidationResponseDTO();
oAuth2TokenValidationMessageContext = new OAuth2TokenValidationMessageContext(oAuth2TokenValidationRequestDTO, oAuth2TokenValidationResponseDTO);
Mockito.when(systemScopesIssuer.validateScope((OAuth2TokenValidationMessageContext) Mockito.anyObject())).thenReturn(true);
}
Aggregations