use of org.wso2.carbon.identity.oauth.user.UserInfoEndpointException in project identity-inbound-auth-oauth by wso2-extensions.
the class ClaimUtil method getUserRealm.
private static UserRealm getUserRealm(String username, String userTenantDomain) throws IdentityException, UserInfoEndpointException {
UserRealm realm;
realm = IdentityTenantUtil.getRealm(userTenantDomain, username);
if (realm == null) {
throw new UserInfoEndpointException("Invalid User Domain provided: " + userTenantDomain + "Cannot retrieve user claims for user: " + username);
}
return realm;
}
use of org.wso2.carbon.identity.oauth.user.UserInfoEndpointException in project identity-inbound-auth-oauth by wso2-extensions.
the class ClaimUtil method getUserAttributesFromCache.
private static Map<ClaimMapping, String> getUserAttributesFromCache(OAuth2TokenValidationResponseDTO tokenResponse) throws UserInfoEndpointException {
AuthorizationGrantCacheKey cacheKey = new AuthorizationGrantCacheKey(OAuth2Util.getAccessTokenIdentifier(tokenResponse));
AuthorizationGrantCacheEntry cacheEntry = AuthorizationGrantCache.getInstance().getValueFromCacheByToken(cacheKey);
if (cacheEntry == null) {
return new HashMap<>();
}
return cacheEntry.getUserAttributes();
}
use of org.wso2.carbon.identity.oauth.user.UserInfoEndpointException in project identity-inbound-auth-oauth by wso2-extensions.
the class ClaimUtilTest method testGetClaimsFromUserStore.
@Test(dataProvider = "provideDataForGetClaimsFromUser")
public void testGetClaimsFromUserStore(boolean mockRealm, boolean mockAccessTokenDO, boolean mockServiceProvider, Object claimMappingObject, Map<String, String> spToLocalClaimMappings, Map<String, String> userClaimsMap, String clientId, String subjectClaimUri, String userStoreDomain, String claimSeparator, boolean isFederated, boolean mapFedUsersToLocal, int expectedMapSize) throws Exception {
ClaimMapping[] claimMappings = (ClaimMapping[]) claimMappingObject;
mockStatic(IdentityTenantUtil.class);
if (mockRealm) {
when(IdentityTenantUtil.getRealm(anyString(), anyString())).thenReturn(mockedUserRealm);
} else {
when(IdentityTenantUtil.getRealm(anyString(), anyString())).thenReturn(null);
}
mockStatic(OAuthServerConfiguration.class);
when(OAuthServerConfiguration.getInstance()).thenReturn(mockedOAuthServerConfiguration);
when(mockedOAuthServerConfiguration.isMapFederatedUsersToLocal()).thenReturn(mapFedUsersToLocal);
mockOAuth2Util();
AuthenticatedUser authenticatedUser = getAuthenticatedUser("carbon.super", userStoreDomain, "test-user", isFederated, "4b4414e1-916b-4475-aaee-6b0751c29f11");
mockStatic(FrameworkUtils.class);
when(FrameworkUtils.resolveUserIdFromUsername(anyInt(), anyString(), anyString())).thenReturn("4b4414e1-916b-4475-aaee-6b0751c29f11");
AccessTokenDO accessTokenDO = getAccessTokenDO(clientId, authenticatedUser);
if (mockAccessTokenDO) {
when(OAuth2Util.getAccessTokenDOfromTokenIdentifier(anyString())).thenReturn(accessTokenDO);
}
mockStatic(OAuth2ServiceComponentHolder.class);
when(OAuth2ServiceComponentHolder.getApplicationMgtService()).thenReturn(mockedApplicationManagementService);
when(mockedApplicationManagementService.getServiceProviderNameByClientId(anyString(), anyString(), anyString())).thenReturn("SP1");
if (mockServiceProvider) {
when(mockedApplicationManagementService.getApplicationExcludingFileBasedSPs(anyString(), anyString())).thenReturn(mockedServiceProvider);
}
when(mockedValidationTokenResponseDTO.getAuthorizedUser()).thenReturn(AUTHORIZED_USER);
when(mockedValidationTokenResponseDTO.getAuthorizationContextToken()).thenReturn(mockedAuthzContextToken);
mockedUserStoreManager = mock(AbstractUserStoreManager.class);
when(mockedUserRealm.getUserStoreManager()).thenReturn(mockedUserStoreManager);
when(mockedServiceProvider.getClaimConfig()).thenReturn(mockedClaimConfig);
when(mockedClaimConfig.getClaimMappings()).thenReturn(claimMappings);
when(mockedServiceProvider.getLocalAndOutBoundAuthenticationConfig()).thenReturn(mockedLocalAndOutboundConfig);
when(mockedLocalAndOutboundConfig.getSubjectClaimUri()).thenReturn(subjectClaimUri);
mockStatic(ClaimMetadataHandler.class);
when(ClaimMetadataHandler.getInstance()).thenReturn(mockedClaimMetadataHandler);
when(mockedClaimMetadataHandler.getMappingsMapFromOtherDialectToCarbon(anyString(), isNull(Set.class), anyString(), anyBoolean())).thenReturn(spToLocalClaimMappings);
if (userClaimsMap != null) {
when(mockedUserStoreManager.getUserClaimValuesWithID(anyString(), any(String[].class), anyString())).thenReturn(userClaimsMap);
} else {
when(mockedUserStoreManager.getUserClaimValuesWithID(anyString(), any(String[].class), anyString())).thenThrow(new UserStoreException("UserNotFound"));
}
mockStatic(IdentityUtil.class);
when(IdentityUtil.extractDomainFromName(anyString())).thenReturn(userStoreDomain);
when(mockedUserRealm.getUserStoreManager()).thenReturn(mockedUserStoreManager);
when(mockedUserStoreManager.getSecondaryUserStoreManager(anyString())).thenReturn(mockedUserStoreManager);
when(mockedUserStoreManager.getRealmConfiguration()).thenReturn(mockedRealmConfiguration);
when(mockedRealmConfiguration.getUserStoreProperty(IdentityCoreConstants.MULTI_ATTRIBUTE_SEPARATOR)).thenReturn(claimSeparator);
when(mockedServiceProvider.getPermissionAndRoleConfig()).thenReturn(mockedPermissionAndRoleConfig);
when(mockedPermissionAndRoleConfig.getRoleMappings()).thenReturn(roleMappings);
Map<String, Object> claimsMap;
try {
claimsMap = ClaimUtil.getClaimsFromUserStore(mockedValidationTokenResponseDTO);
Assert.assertEquals(claimsMap.size(), expectedMapSize);
} catch (UserInfoEndpointException e) {
Assert.assertEquals(expectedMapSize, -1, "Unexpected exception thrown");
}
}
use of org.wso2.carbon.identity.oauth.user.UserInfoEndpointException in project identity-inbound-auth-oauth by wso2-extensions.
the class AbstractUserInfoResponseBuilder method getServiceProvider.
private ServiceProvider getServiceProvider(String tenantDomain, String clientId) throws UserInfoEndpointException {
ApplicationManagementService applicationMgtService = OAuth2ServiceComponentHolder.getApplicationMgtService();
ServiceProvider serviceProvider;
try {
// Get the Service Provider.
serviceProvider = applicationMgtService.getServiceProviderByClientId(clientId, IdentityApplicationConstants.OAuth2.NAME, tenantDomain);
} catch (IdentityApplicationManagementException e) {
throw new UserInfoEndpointException("Error while obtaining the service provider for client_id: " + clientId + " of tenantDomain: " + tenantDomain, e);
}
return serviceProvider;
}
use of org.wso2.carbon.identity.oauth.user.UserInfoEndpointException in project identity-inbound-auth-oauth by wso2-extensions.
the class AbstractUserInfoResponseBuilder method getServiceProviderTenantDomain.
private String getServiceProviderTenantDomain(OAuth2TokenValidationResponseDTO tokenResponse) throws UserInfoEndpointException {
String clientId = null;
OAuthAppDO oAuthAppDO;
try {
clientId = getClientId(OAuth2Util.getAccessTokenIdentifier(tokenResponse));
oAuthAppDO = OAuth2Util.getAppInformationByClientId(clientId);
} catch (IdentityOAuth2Exception | InvalidOAuthClientException e) {
throw new UserInfoEndpointException("Error while retrieving OAuth app information for clientId: " + clientId);
}
return OAuth2Util.getTenantDomainOfOauthApp(oAuthAppDO);
}
Aggregations