use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class IdPManagementDAO method isClaimReferredByAnyIdp.
/**
* Method that checks whether a claim is associated with any identity provider.
*
* @param dbConnection Optional DB connection.
* @param claimUri Claim URI.
* @param tenantId ID of the tenant.
* @return True if claim is referred by an identity provider.
* @throws IdentityProviderManagementException Error when obtaining claim references.
*/
public boolean isClaimReferredByAnyIdp(Connection dbConnection, String claimUri, int tenantId) throws IdentityProviderManagementException {
boolean dbConnInitialized = true;
PreparedStatement prepStmt = null;
ResultSet rs = null;
boolean isClaimReferred = false;
if (dbConnection == null) {
dbConnection = IdentityDatabaseUtil.getDBConnection(false);
} else {
dbConnInitialized = false;
}
try {
String sqlStmt = IdPManagementConstants.SQLQueries.GET_TOTAL_IDP_CLAIM_USAGES;
prepStmt = dbConnection.prepareStatement(sqlStmt);
prepStmt.setInt(1, tenantId);
prepStmt.setString(2, claimUri);
rs = prepStmt.executeQuery();
if (rs.next()) {
isClaimReferred = rs.getInt(1) > 0;
}
return isClaimReferred;
} catch (SQLException e) {
throw new IdentityProviderManagementException("Error occurred while retrieving IDP usages of the claim " + claimUri, e);
} finally {
if (dbConnInitialized) {
IdentityDatabaseUtil.closeAllConnections(dbConnection, rs, prepStmt);
} else {
IdentityDatabaseUtil.closeAllConnections(null, rs, prepStmt);
}
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class IdentityProviderManagementServiceTest method addTestIdps.
private void addTestIdps() throws IdentityProviderManagementException {
// Initialize Test Identity Provider 1.
IdentityProvider idp1 = new IdentityProvider();
idp1.setIdentityProviderName("testIdP1");
idp1.setIdentityProviderDescription("Test Idp 1");
idp1.setHomeRealmId("1");
idp1.setEnable(true);
idp1.setPrimary(true);
idp1.setFederationHub(true);
idp1.setCertificate("");
RoleMapping roleMapping1 = new RoleMapping();
roleMapping1.setRemoteRole("Role1");
roleMapping1.setLocalRole(new LocalRole("1", "LocalRole1"));
RoleMapping roleMapping2 = new RoleMapping();
roleMapping2.setRemoteRole("Role2");
roleMapping2.setLocalRole(new LocalRole("2", "LocalRole2"));
PermissionsAndRoleConfig permissionsAndRoleConfig = new PermissionsAndRoleConfig();
permissionsAndRoleConfig.setIdpRoles(new String[] { "Role1", "Role2" });
permissionsAndRoleConfig.setRoleMappings(new RoleMapping[] { roleMapping1, roleMapping2 });
idp1.setPermissionAndRoleConfig(permissionsAndRoleConfig);
FederatedAuthenticatorConfig federatedAuthenticatorConfig = new FederatedAuthenticatorConfig();
federatedAuthenticatorConfig.setDisplayName("DisplayName1");
federatedAuthenticatorConfig.setName("Name");
federatedAuthenticatorConfig.setEnabled(true);
Property property1 = new Property();
property1.setName("Property1");
property1.setValue("value1");
property1.setConfidential(true);
Property property2 = new Property();
property2.setName("Property2");
property2.setValue("value2");
property2.setConfidential(false);
federatedAuthenticatorConfig.setProperties(new Property[] { property1, property2 });
idp1.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { federatedAuthenticatorConfig });
ProvisioningConnectorConfig provisioningConnectorConfig1 = new ProvisioningConnectorConfig();
provisioningConnectorConfig1.setName("ProvisiningConfig1");
provisioningConnectorConfig1.setProvisioningProperties(new Property[] { property1 });
ProvisioningConnectorConfig provisioningConnectorConfig2 = new ProvisioningConnectorConfig();
provisioningConnectorConfig2.setName("ProvisiningConfig2");
provisioningConnectorConfig2.setProvisioningProperties(new Property[] { property2 });
provisioningConnectorConfig2.setEnabled(true);
provisioningConnectorConfig2.setBlocking(true);
idp1.setProvisioningConnectorConfigs(new ProvisioningConnectorConfig[] { provisioningConnectorConfig1, provisioningConnectorConfig2 });
IdentityProviderProperty identityProviderProperty = new IdentityProviderProperty();
identityProviderProperty.setDisplayName("idpDisplayName");
identityProviderProperty.setName("idpPropertyName");
identityProviderProperty.setValue("idpPropertyValue");
idp1.setIdpProperties(new IdentityProviderProperty[] { identityProviderProperty });
ClaimConfig claimConfig = new ClaimConfig();
claimConfig.setLocalClaimDialect(false);
claimConfig.setRoleClaimURI("Country");
claimConfig.setUserClaimURI("Country");
ClaimMapping claimMapping = ClaimMapping.build("http://wso2.org/claims/country", "Country", "", true);
Claim remoteClaim = new Claim();
remoteClaim.setClaimId(0);
remoteClaim.setClaimUri("Country");
claimConfig.setClaimMappings(new ClaimMapping[] { claimMapping });
claimConfig.setIdpClaims(new Claim[] { remoteClaim });
idp1.setClaimConfig(claimConfig);
// Initialize Test Identity Provider 2.
IdentityProvider idp2 = new IdentityProvider();
idp2.setIdentityProviderName("testIdP2");
idp2.setHomeRealmId("2");
ClaimConfig claimConfig2 = new ClaimConfig();
claimConfig2.setLocalClaimDialect(true);
claimConfig2.setRoleClaimURI("http://wso2.org/claims/role");
claimConfig2.setUserClaimURI("http://wso2.org/claims/fullname");
ClaimMapping claimMapping2 = new ClaimMapping();
Claim localClaim2 = new Claim();
localClaim2.setClaimId(0);
localClaim2.setClaimUri("http://wso2.org/claims/fullname");
claimMapping2.setLocalClaim(localClaim2);
claimConfig2.setClaimMappings(new ClaimMapping[] { claimMapping2 });
idp2.setClaimConfig(claimConfig2);
// Initialize Test Identity Provider 3.
IdentityProvider idp3 = new IdentityProvider();
idp3.setIdentityProviderName("testIdP3");
idp3.setHomeRealmId("3");
// IDP with PermissionsAndRoleConfig, FederatedAuthenticatorConfigs, ProvisioningConnectorConfigs, ClaimConfigs.
identityProviderManagementService.addIdP(idp1);
// IDP with Local Cliam Dialect ClaimConfigs.
identityProviderManagementService.addIdP(idp2);
// IDP with Only name.
identityProviderManagementService.addIdP(idp3);
}
use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class IdentityProviderManagementServiceTest method addIdPData.
@DataProvider
public Object[][] addIdPData() {
// Initialize Test Identity Provider 1.
IdentityProvider idp1 = new IdentityProvider();
idp1.setIdentityProviderName("testIdP1");
idp1.setEnable(true);
idp1.setPrimary(true);
idp1.setFederationHub(true);
idp1.setCertificate("");
RoleMapping roleMapping1 = new RoleMapping(new LocalRole("1", "LocalRole1"), "Role1");
RoleMapping roleMapping2 = new RoleMapping(new LocalRole("2", "LocalRole2"), "Role2");
PermissionsAndRoleConfig permissionsAndRoleConfig = new PermissionsAndRoleConfig();
permissionsAndRoleConfig.setIdpRoles(new String[] { "Role1", "Role2" });
permissionsAndRoleConfig.setRoleMappings(new RoleMapping[] { roleMapping1, roleMapping2 });
idp1.setPermissionAndRoleConfig(permissionsAndRoleConfig);
FederatedAuthenticatorConfig federatedAuthenticatorConfig = new FederatedAuthenticatorConfig();
federatedAuthenticatorConfig.setDisplayName("DisplayName1");
federatedAuthenticatorConfig.setName("Name");
federatedAuthenticatorConfig.setEnabled(true);
Property property1 = new Property();
property1.setName("Property1");
property1.setValue("value1");
property1.setConfidential(false);
Property property2 = new Property();
property2.setName("Property2");
property2.setValue("value2");
property2.setConfidential(true);
federatedAuthenticatorConfig.setProperties(new Property[] { property1, property2 });
idp1.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { federatedAuthenticatorConfig });
ProvisioningConnectorConfig provisioningConnectorConfig1 = new ProvisioningConnectorConfig();
provisioningConnectorConfig1.setName("ProvisiningConfig1");
provisioningConnectorConfig1.setProvisioningProperties(new Property[] { property1 });
ProvisioningConnectorConfig provisioningConnectorConfig2 = new ProvisioningConnectorConfig();
provisioningConnectorConfig2.setName("ProvisiningConfig2");
provisioningConnectorConfig2.setProvisioningProperties(new Property[] { property2 });
provisioningConnectorConfig2.setEnabled(true);
provisioningConnectorConfig2.setBlocking(true);
idp1.setProvisioningConnectorConfigs(new ProvisioningConnectorConfig[] { provisioningConnectorConfig1, provisioningConnectorConfig2 });
ClaimConfig claimConfig = new ClaimConfig();
claimConfig.setLocalClaimDialect(false);
claimConfig.setRoleClaimURI("Country");
claimConfig.setUserClaimURI("Country");
ClaimMapping claimMapping = ClaimMapping.build("http://wso2.org/claims/country", "Country", "", true);
claimConfig.setClaimMappings(new ClaimMapping[] { claimMapping });
Claim remoteClaim = new Claim();
remoteClaim.setClaimId(0);
remoteClaim.setClaimUri("Country");
claimConfig.setIdpClaims(new Claim[] { remoteClaim });
idp1.setClaimConfig(claimConfig);
// Initialize Test Identity Provider 2.
IdentityProvider idp2 = new IdentityProvider();
idp2.setIdentityProviderName("testIdP2");
ClaimConfig claimConfig2 = new ClaimConfig();
claimConfig2.setLocalClaimDialect(true);
claimConfig2.setRoleClaimURI("http://wso2.org/claims/role");
claimConfig2.setUserClaimURI("http://wso2.org/claims/fullname");
ClaimMapping claimMapping2 = new ClaimMapping();
Claim localClaim2 = new Claim();
localClaim2.setClaimId(0);
localClaim2.setClaimUri("http://wso2.org/claims/fullname");
claimMapping2.setLocalClaim(localClaim2);
claimConfig2.setClaimMappings(new ClaimMapping[] { claimMapping2 });
idp2.setClaimConfig(claimConfig2);
// Initialize Test Identity Provider 3.
IdentityProvider idp3 = new IdentityProvider();
idp3.setIdentityProviderName("testIdP3");
return new Object[][] { // IDP with PermissionsAndRoleConfig,FederatedAuthenticatorConfigs,ProvisioningConnectorConfigs,Claims.
{ idp1 }, // IDP with Local Cliam Dialect ClaimConfigs.
{ idp2 }, // IDP with only the name.
{ idp3 } };
}
use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class IdPManagementDAOTest method updateIdPData.
@DataProvider
public Object[][] updateIdPData() {
// Initialize Test Identity Provider 1.
IdentityProvider idp1 = new IdentityProvider();
idp1.setIdentityProviderName("testIdP1");
idp1.setHomeRealmId("1");
idp1.setEnable(true);
idp1.setPrimary(true);
idp1.setFederationHub(true);
idp1.setCertificate("");
FederatedAuthenticatorConfig federatedAuthenticatorConfig = new FederatedAuthenticatorConfig();
federatedAuthenticatorConfig.setDisplayName("DisplayName1");
federatedAuthenticatorConfig.setName("Name");
federatedAuthenticatorConfig.setEnabled(true);
Property property1 = new Property();
property1.setName("Property1");
property1.setValue("value1");
property1.setConfidential(true);
federatedAuthenticatorConfig.setProperties(new Property[] { property1 });
idp1.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { federatedAuthenticatorConfig });
ProvisioningConnectorConfig provisioningConnectorConfig = new ProvisioningConnectorConfig();
provisioningConnectorConfig.setName("ProvisiningConfig1");
provisioningConnectorConfig.setProvisioningProperties(new Property[] { property1 });
idp1.setProvisioningConnectorConfigs(new ProvisioningConnectorConfig[] { provisioningConnectorConfig });
// Initialize Test Identity Provider 2.
IdentityProvider idp2 = new IdentityProvider();
idp2.setIdentityProviderName("testIdP2");
idp2.setHomeRealmId("2");
ClaimConfig claimConfig2 = new ClaimConfig();
claimConfig2.setLocalClaimDialect(true);
claimConfig2.setRoleClaimURI("http://wso2.org/claims/role");
claimConfig2.setUserClaimURI("http://wso2.org/claims/fullname");
ClaimMapping claimMapping2 = new ClaimMapping();
Claim localClaim2 = new Claim();
localClaim2.setClaimId(0);
localClaim2.setClaimUri("http://wso2.org/claims/fullname");
claimMapping2.setLocalClaim(localClaim2);
claimConfig2.setClaimMappings(new ClaimMapping[] { claimMapping2 });
idp2.setClaimConfig(claimConfig2);
// Initialize Test Identity Provider 3.
IdentityProvider idp3 = new IdentityProvider();
idp3.setIdentityProviderName("testIdP3");
// Initialize New Test Identity Provider 1.
IdentityProvider idp1New = new IdentityProvider();
idp1New.setIdentityProviderName("testIdP1New");
idp1New.setEnable(true);
idp1New.setPrimary(true);
idp1New.setFederationHub(true);
idp1New.setCertificate("");
RoleMapping newRoleMapping1 = new RoleMapping();
newRoleMapping1.setRemoteRole("Role1New");
newRoleMapping1.setLocalRole(new LocalRole("1", "LocalRole1"));
RoleMapping newRoleMapping2 = new RoleMapping();
newRoleMapping2.setRemoteRole("Role2New");
newRoleMapping2.setLocalRole(new LocalRole("2", "LocalRole2"));
PermissionsAndRoleConfig newPermissionsAndRoleConfig = new PermissionsAndRoleConfig();
newPermissionsAndRoleConfig.setIdpRoles(new String[] { "Role1New", "Role2New" });
newPermissionsAndRoleConfig.setRoleMappings(new RoleMapping[] { newRoleMapping1, newRoleMapping2 });
idp1New.setPermissionAndRoleConfig(newPermissionsAndRoleConfig);
FederatedAuthenticatorConfig newFederatedAuthenticatorConfig = new FederatedAuthenticatorConfig();
newFederatedAuthenticatorConfig.setDisplayName("DisplayName1New");
newFederatedAuthenticatorConfig.setName("Name");
newFederatedAuthenticatorConfig.setEnabled(true);
Property property1New = new Property();
property1New.setName("Property1New");
property1New.setValue("value1New");
property1New.setConfidential(false);
Property property2New = new Property();
property2New.setName("Property2New");
property2New.setValue("value2New");
property2New.setConfidential(false);
newFederatedAuthenticatorConfig.setProperties(new Property[] { property1New, property2New });
idp1New.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { newFederatedAuthenticatorConfig });
ProvisioningConnectorConfig newProvisioningConnectorConfig1 = new ProvisioningConnectorConfig();
newProvisioningConnectorConfig1.setName("ProvisiningConfig1");
newProvisioningConnectorConfig1.setProvisioningProperties(new Property[] { property1New });
ProvisioningConnectorConfig newProvisioningConnectorConfig2 = new ProvisioningConnectorConfig();
newProvisioningConnectorConfig2.setName("ProvisiningConfig2");
newProvisioningConnectorConfig2.setProvisioningProperties(new Property[] { property2New });
newProvisioningConnectorConfig2.setEnabled(true);
newProvisioningConnectorConfig2.setBlocking(true);
idp1New.setProvisioningConnectorConfigs(new ProvisioningConnectorConfig[] { newProvisioningConnectorConfig1, newProvisioningConnectorConfig2 });
ClaimConfig newClaimConfig = new ClaimConfig();
newClaimConfig.setLocalClaimDialect(false);
newClaimConfig.setRoleClaimURI("Country");
newClaimConfig.setUserClaimURI("Country");
ClaimMapping claimMapping = ClaimMapping.build("http://wso2.org/claims/country", "Country", "", true);
Claim remoteClaim = new Claim();
remoteClaim.setClaimId(0);
remoteClaim.setClaimUri("Country");
newClaimConfig.setClaimMappings(new ClaimMapping[] { claimMapping });
newClaimConfig.setIdpClaims(new Claim[] { remoteClaim });
idp1New.setClaimConfig(newClaimConfig);
// Initialize New Test Identity Provider 2.
IdentityProvider idp2New = new IdentityProvider();
idp2New.setIdentityProviderName("testIdP2New");
// Initialize New Test Identity Provider 3.
IdentityProvider idp3New = new IdentityProvider();
idp3New.setIdentityProviderName("testIdP3New");
return new Object[][] { // Update PermissionsAndRoleConfig,FederatedAuthenticatorConfig,ProvisioningConnectorConfig,ClaimConfig.
{ idp1, idp1New, SAMPLE_TENANT_ID }, // Update name, LocalClaimDialect, ClaimConfig.
{ idp2, idp2New, SAMPLE_TENANT_ID }, // Update name.
{ idp3, idp3New, SAMPLE_TENANT_ID2 } };
}
use of org.wso2.carbon.identity.application.common.model.xsd.Claim in project carbon-identity-framework by wso2.
the class UniqueClaimUserOperationEventListener method checkClaimUniqueness.
private void checkClaimUniqueness(String username, Map<String, String> claims, String profile, UserStoreManager userStoreManager, Object credential) throws UserStoreException {
String errorMessage = StringUtils.EMPTY;
String tenantDomain = getTenantDomain(userStoreManager);
List<String> duplicateClaim = new ArrayList<>();
Claim claimObject = null;
for (Map.Entry<String, String> claim : claims.entrySet()) {
try {
if (isUniqueClaim(claim.getKey(), tenantDomain)) {
try {
claimObject = userStoreManager.getClaimManager().getClaim(claim.getKey());
} catch (org.wso2.carbon.user.api.UserStoreException e) {
log.error("Error while getting claim from claimUri: " + claim.getKey() + ".", e);
}
if (claimObject == null) {
continue;
}
// checks whether allowed login identifiers are equal to the password
if (credential != null && (credential.toString()).equals(claim.getValue())) {
errorMessage = "Password can not be equal to the value defined for " + claimObject.getDisplayTag() + "!";
throw new UserStoreException(errorMessage, new PolicyViolationException(errorMessage));
}
if (isClaimDuplicated(username, claim.getKey(), claim.getValue(), profile, userStoreManager)) {
String displayTag = claimObject.getDisplayTag();
if (StringUtils.isBlank(displayTag)) {
displayTag = claim.getKey();
}
duplicateClaim.add(displayTag);
}
}
} catch (ClaimMetadataException e) {
log.error("Error while getting claim metadata for claimUri : " + claim.getKey() + ".", e);
}
}
if (StringUtils.isNotBlank(errorMessage)) {
throw new UserStoreException(errorMessage, new PolicyViolationException(errorMessage));
}
if (duplicateClaim.size() == 0) {
return;
} else if (duplicateClaim.size() == 1) {
errorMessage = "The value defined for " + duplicateClaim.get(0) + " is already in use by different user!";
} else {
String claimList = String.join(", ", duplicateClaim);
errorMessage = "The values defined for " + claimList + " are already in use by a different users!";
}
throw new UserStoreException(errorMessage, new PolicyViolationException(errorMessage));
}
Aggregations