use of org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService in project carbon-identity-framework by wso2.
the class IdentityProviderManagementServiceTest method testGetAllLocalClaimUrisException.
@Test
public void testGetAllLocalClaimUrisException() throws Exception {
ClaimMetadataManagementServiceImpl claimMetadataManagementService = mock(ClaimMetadataManagementServiceImpl.class);
IdpMgtServiceComponentHolder.getInstance().setClaimMetadataManagementService(claimMetadataManagementService);
when(claimMetadataManagementService.getLocalClaims(anyString())).thenThrow(ClaimMetadataException.class);
assertThrows(IdentityProviderManagementException.class, () -> identityProviderManagementService.getAllLocalClaimUris());
}
use of org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService in project carbon-identity-framework by wso2.
the class SSOConsentServiceImplTest method testGetConsentRequiredClaimsWithExistingConsents.
@Test
public void testGetConsentRequiredClaimsWithExistingConsents() throws Exception {
ServiceProvider serviceProvider = new ServiceProvider();
serviceProvider.setApplicationName("Travelocity.com");
User user = new User();
user.setTenantDomain("carbon.super");
user.setUserStoreDomain("PRIMARY");
serviceProvider.setOwner(user);
ClaimConfig claimConfig = new ClaimConfig();
Claim tempClaim1 = new Claim();
tempClaim1.setClaimUri("http://wso2.org/claims/organization");
ClaimMapping tempClaimMapping1 = new ClaimMapping();
tempClaimMapping1.setRequested(true);
tempClaimMapping1.setMandatory(false);
tempClaimMapping1.setLocalClaim(tempClaim1);
tempClaimMapping1.setRemoteClaim(tempClaim1);
Claim tempClaim2 = new Claim();
tempClaim2.setClaimUri("http://wso2.org/claims/country");
ClaimMapping tempClaimMapping2 = new ClaimMapping();
tempClaimMapping2.setRequested(true);
tempClaimMapping2.setMandatory(true);
tempClaimMapping2.setLocalClaim(tempClaim2);
tempClaimMapping2.setRemoteClaim(tempClaim2);
claimConfig.setClaimMappings(new ClaimMapping[] { tempClaimMapping1, tempClaimMapping2 });
serviceProvider.setClaimConfig(claimConfig);
LocalAndOutboundAuthenticationConfig localAndOutboundAuthenticationConfig = new LocalAndOutboundAuthenticationConfig();
localAndOutboundAuthenticationConfig.setSubjectClaimUri(null);
serviceProvider.setLocalAndOutBoundAuthenticationConfig(localAndOutboundAuthenticationConfig);
AuthenticatedUser authenticatedUser = getAuthenticatedUser();
mockStatic(IdentityUtil.class);
when(IdentityUtil.getProperty("Consent.PromptSubjectClaimRequestedConsent")).thenReturn(null);
mockCarbonContextForTenant();
mockStatic(FrameworkServiceDataHolder.class);
when(FrameworkServiceDataHolder.getInstance()).thenReturn(frameworkServiceDataHolder);
setConsentManagerConfigurationHolder();
RealmService realmService = mock(RealmService.class);
configurationHolder.setRealmService(realmService);
ConsentManager consentManager = new ConsentManagerImpl(configurationHolder);
when(frameworkServiceDataHolder.getConsentManager()).thenReturn(consentManager);
mockStatic(ConsentUtils.class);
when(ConsentUtils.getTenantDomainFromCarbonContext()).thenReturn("carbon.super");
mockRealmService(realmService);
when(frameworkServiceDataHolder.getClaimMetadataManagementService()).thenReturn(claimMetadataManagementService);
List<LocalClaim> localClaims = new ArrayList<>();
LocalClaim localClaim = new LocalClaim("http://wso2.org/claims/country");
LocalClaim localClaim2 = new LocalClaim("http://wso2.org/claims/organization");
localClaims.add(localClaim);
localClaims.add(localClaim2);
when(claimMetadataManagementService.getLocalClaims(anyString())).thenReturn(localClaims);
ConsentClaimsData consentClaimsData = ssoConsentService.getConsentRequiredClaimsWithExistingConsents(serviceProvider, authenticatedUser);
assertEquals(consentClaimsData.getRequestedClaims().get(0).getClaimUri(), "http://wso2.org/claims/organization", "Incorrect requested claim URI");
assertEquals(consentClaimsData.getMandatoryClaims().get(0).getClaimUri(), "http://wso2.org/claims/country", "Incorrect mandatory claim URI");
assertNotNull(consentClaimsData.getMandatoryClaims().get(0).getClaimUri());
}
use of org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService in project identity-inbound-auth-oauth by wso2-extensions.
the class OpenIDConnectClaimFilterImplTest method setUp.
@BeforeClass
public void setUp() throws Exception {
openIDConnectClaimFilter = new OpenIDConnectClaimFilterImpl();
scopeClaimMappingDAO = new ScopeClaimMappingDAOImpl();
ServiceProvider serviceProvider = new ServiceProvider();
ssoConsentService = mock(SSOConsentServiceImpl.class);
ClaimMetadataManagementService claimMetadataManagementService = mock(ClaimMetadataManagementService.class);
applicationMgtService = mock(ApplicationManagementService.class);
OAuth2ServiceComponentHolder.setApplicationMgtService(applicationMgtService);
when(applicationMgtService.getServiceProviderByClientId(CLIENT_ID, IdentityApplicationConstants.OAuth2.NAME, SP_TENANT_DOMAIN)).thenReturn(serviceProvider);
OpenIDConnectServiceComponentHolder.getInstance().setClaimMetadataManagementService(claimMetadataManagementService);
OpenIDConnectServiceComponentHolder.getInstance().setSsoConsentService(ssoConsentService);
RegistryService registryService = mock(RegistryService.class);
UserRegistry userRegistry = mock(UserRegistry.class);
resource = new ResourceImpl();
OAuth2ServiceComponentHolder.setRegistryService(registryService);
when(registryService.getConfigSystemRegistry(anyInt())).thenReturn(userRegistry);
when(userRegistry.get(anyString())).thenReturn(resource);
List externalClaims = new ArrayList<>();
ExternalClaim externalClaim = new ExternalClaim("testUserClaimURI", "testUserClaimURI", "testUserClaimURI");
externalClaims.add(externalClaim);
when(claimMetadataManagementService.getExternalClaims(anyString(), anyString())).thenReturn(externalClaims);
List claimsWithConsent = getClaimsWithConsent();
when(ssoConsentService.getClaimsWithConsents(any(), any())).thenReturn(claimsWithConsent);
}
use of org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService in project carbon-identity-framework by wso2.
the class IdentityClaimManagementServiceComponent method activate.
@Activate
protected void activate(ComponentContext ctxt) {
try {
BundleContext bundleCtx = ctxt.getBundleContext();
IdentityClaimManagementServiceDataHolder.getInstance().setBundleContext(bundleCtx);
if (IdentityClaimManagementServiceDataHolder.getInstance().getClaimConfigInitDAO() == null) {
IdentityClaimManagementServiceDataHolder.getInstance().setClaimConfigInitDAO(new DefaultClaimConfigInitDAO());
}
ClaimMetadataStoreFactory claimMetadataStoreFactory = new ClaimMetadataStoreFactory();
bundleCtx.registerService(ClaimManagerFactory.class.getName(), claimMetadataStoreFactory, null);
ClaimMetadataManagementService claimManagementService = new ClaimMetadataManagementServiceImpl();
bundleCtx.registerService(ClaimMetadataManagementService.class.getName(), claimManagementService, null);
IdentityClaimManagementServiceDataHolder.getInstance().setClaimManagementService(claimManagementService);
bundleCtx.registerService(TenantMgtListener.class.getName(), new ClaimMetadataTenantMgtListener(), null);
registerClaimConfigListener(bundleCtx);
// Register claim operation event handler implementation.
bundleCtx.registerService(AbstractEventHandler.class.getName(), new ClaimMetadataManagementAuditLogger(), null);
if (log.isDebugEnabled()) {
log.debug("ClaimMetadataManagementAuditLogger is successfully registered.");
log.debug("Identity Claim Management Core bundle is activated");
}
} catch (Throwable e) {
log.error("Error occurred while activating Identity Claim Management Service Component", e);
}
}
use of org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService in project carbon-identity-framework by wso2.
the class IdentityProviderManagementServiceTest method testGetAllLocalClaimUris.
@Test
public void testGetAllLocalClaimUris() throws Exception {
ClaimMetadataManagementServiceImpl claimMetadataManagementService = mock(ClaimMetadataManagementServiceImpl.class);
IdpMgtServiceComponentHolder.getInstance().setClaimMetadataManagementService(claimMetadataManagementService);
LocalClaim localClaim1 = new LocalClaim("http://wso2.org/claims/test1");
List<LocalClaim> claimList = new ArrayList<>();
claimList.add(localClaim1);
when(claimMetadataManagementService.getLocalClaims(anyString())).thenReturn(claimList);
String[] allLocalClaimUris = identityProviderManagementService.getAllLocalClaimUris();
Assert.assertEquals(allLocalClaimUris.length, 1);
Assert.assertEquals(allLocalClaimUris[0], "http://wso2.org/claims/test1");
}
Aggregations