use of org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementServiceImpl 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.ClaimMetadataManagementServiceImpl in project carbon-identity-framework by wso2.
the class ClaimMetadataHandler method getMappingsFromOtherDialectToCarbon.
/**
* @param otherDialectURI
* @param otherClaimURIs
* @param tenantDomain
* @return
* @throws ClaimMetadataException
*/
public Set<ExternalClaim> getMappingsFromOtherDialectToCarbon(String otherDialectURI, Set<String> otherClaimURIs, String tenantDomain) throws ClaimMetadataException {
Set<ExternalClaim> returnSet = new HashSet<ExternalClaim>();
if (otherDialectURI == null) {
String message = "Invalid argument: \'otherDialectURI\' is \'NULL\'";
log.error(message);
throw new ClaimMetadataException(message);
}
try {
ClaimMetadataManagementServiceImpl claimMetadataService = new ClaimMetadataManagementServiceImpl();
if (otherDialectURI.equals(UserCoreConstants.DEFAULT_CARBON_DIALECT)) {
List<LocalClaim> localClaims = claimMetadataService.getLocalClaims(tenantDomain);
if (otherClaimURIs == null || otherClaimURIs.isEmpty()) {
for (LocalClaim localClaim : localClaims) {
ExternalClaim claimMapping = new ExternalClaim(localClaim.getClaimDialectURI(), localClaim.getClaimURI(), localClaim.getClaimURI());
returnSet.add(claimMapping);
}
return returnSet;
} else {
for (LocalClaim localClaim : localClaims) {
if (otherClaimURIs.contains(localClaim.getClaimURI())) {
ExternalClaim claimMapping = new ExternalClaim(otherDialectURI, localClaim.getClaimURI(), localClaim.getClaimURI());
returnSet.add(claimMapping);
}
}
return returnSet;
}
} else {
List<ExternalClaim> externalClaims = claimMetadataService.getExternalClaims(otherDialectURI, tenantDomain);
if (otherClaimURIs == null || otherClaimURIs.isEmpty()) {
returnSet = new HashSet<ExternalClaim>(externalClaims);
} else {
for (ExternalClaim externalClaim : externalClaims) {
if (otherClaimURIs.contains(externalClaim.getClaimURI())) {
returnSet.add(externalClaim);
}
}
}
return returnSet;
}
} catch (ClaimMetadataException e) {
throw new ClaimMetadataException(e.getMessage(), e);
}
}
use of org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementServiceImpl in project carbon-identity-framework by wso2.
the class DefaultApplicationValidator method validateClaimsConfigs.
/**
* Validate claim related configurations and append to the validation msg list.
*
* @param validationMsg validation error messages
* @param claimConfig claim config
* @param subjectClaimUri Subject claim Uri
* @param tenantDomain tenant domain
* @throws IdentityApplicationManagementException Identity Application Management Exception
*/
private void validateClaimsConfigs(List<String> validationMsg, ClaimConfig claimConfig, String subjectClaimUri, String tenantDomain, String serviceProviderName) throws IdentityApplicationManagementException {
if (claimConfig == null) {
return;
}
ApplicationManagementService applicationMgtService = ApplicationManagementService.getInstance();
String[] allLocalClaimUris = applicationMgtService.getAllLocalClaimUris(tenantDomain);
ArrayList<String> remoteClaimUris = new ArrayList<>();
ClaimMapping[] claimMappings = claimConfig.getClaimMappings();
if (claimMappings != null) {
for (ClaimMapping claimMapping : claimMappings) {
String claimUri = claimMapping.getLocalClaim().getClaimUri();
remoteClaimUris.add(claimMapping.getRemoteClaim().getClaimUri());
if (!Arrays.asList(allLocalClaimUris).contains(claimUri)) {
validationMsg.add(String.format(CLAIM_NOT_AVAILABLE, claimUri, tenantDomain));
}
}
}
String roleClaimUri = claimConfig.getRoleClaimURI();
String userClaimUri = claimConfig.getUserClaimURI();
if (claimConfig.isLocalClaimDialect()) {
if (StringUtils.isNotBlank(roleClaimUri) && !Arrays.asList(allLocalClaimUris).contains(roleClaimUri)) {
validationMsg.add(String.format(CLAIM_NOT_AVAILABLE, roleClaimUri, tenantDomain));
}
if (StringUtils.isNotBlank(userClaimUri) && !Arrays.asList(allLocalClaimUris).contains(userClaimUri)) {
validationMsg.add(String.format(CLAIM_NOT_AVAILABLE, userClaimUri, tenantDomain));
}
if (StringUtils.isNotBlank(subjectClaimUri) && !Arrays.asList(allLocalClaimUris).contains(subjectClaimUri)) {
validationMsg.add(String.format(CLAIM_NOT_AVAILABLE, subjectClaimUri, tenantDomain));
}
} else {
if (StringUtils.isNotBlank(roleClaimUri) && !(remoteClaimUris).contains(roleClaimUri)) {
validationMsg.add(String.format(SP_CLAIM_NOT_AVAILABLE, roleClaimUri, serviceProviderName));
}
if (StringUtils.isNotBlank(userClaimUri) && !(remoteClaimUris).contains(userClaimUri)) {
validationMsg.add(String.format(SP_CLAIM_NOT_AVAILABLE, userClaimUri, serviceProviderName));
}
if (StringUtils.isNotBlank(subjectClaimUri) && !(remoteClaimUris).contains(subjectClaimUri)) {
validationMsg.add(String.format(SP_CLAIM_NOT_AVAILABLE, subjectClaimUri, serviceProviderName));
}
}
String[] spClaimDialects = claimConfig.getSpClaimDialects();
if (spClaimDialects != null) {
try {
ClaimMetadataManagementServiceImpl claimAdminService = new ClaimMetadataManagementServiceImpl();
List<ClaimDialect> serverClaimMapping = claimAdminService.getClaimDialects(tenantDomain);
if (serverClaimMapping != null) {
List<String> serverDialectURIS = serverClaimMapping.stream().map(ClaimDialect::getClaimDialectURI).collect(Collectors.toList());
for (String spClaimDialect : spClaimDialects) {
if (!serverDialectURIS.contains(spClaimDialect)) {
validationMsg.add(String.format(CLAIM_DIALECT_NOT_AVAILABLE, spClaimDialect, tenantDomain));
}
}
}
} catch (ClaimMetadataException e) {
validationMsg.add(String.format("Error in getting claim dialect for %s. ", tenantDomain));
}
}
}
use of org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementServiceImpl 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.ClaimMetadataManagementServiceImpl 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