use of org.wso2.carbon.user.api.Property in project carbon-identity-framework by wso2.
the class IdPManagementDAO method deleteFederatedConfigProperties.
private void deleteFederatedConfigProperties(Connection dbConnection, int authnId, int tenantId, List<Property> properties) throws SQLException {
if (CollectionUtils.isEmpty(properties)) {
return;
}
PreparedStatement deletePrepStmt = null;
String sqlStmt = IdPManagementConstants.SQLQueries.DELETE_IDP_AUTH_PROP_WITH_KEY_SQL;
try {
deletePrepStmt = dbConnection.prepareStatement(sqlStmt);
for (Property property : properties) {
deletePrepStmt.setString(1, property.getName());
deletePrepStmt.setInt(2, tenantId);
deletePrepStmt.setInt(3, authnId);
deletePrepStmt.addBatch();
}
deletePrepStmt.executeBatch();
} finally {
IdentityDatabaseUtil.closeStatement(deletePrepStmt);
}
}
use of org.wso2.carbon.user.api.Property in project carbon-identity-framework by wso2.
the class IdPManagementDAO method updateFederatedAuthenticatorConfig.
/**
* @param newFederatedAuthenticatorConfig
* @param oldFederatedAuthenticatorConfig
* @param dbConnection
* @param idpId
* @throws IdentityProviderManagementException
* @throws SQLException
*/
private void updateFederatedAuthenticatorConfig(FederatedAuthenticatorConfig newFederatedAuthenticatorConfig, FederatedAuthenticatorConfig oldFederatedAuthenticatorConfig, Connection dbConnection, int idpId, int tenantId) throws IdentityProviderManagementException, SQLException {
PreparedStatement prepStmt1 = null;
try {
String sqlStmt = IdPManagementConstants.SQLQueries.UPDATE_IDP_AUTH_SQL;
prepStmt1 = dbConnection.prepareStatement(sqlStmt);
if (newFederatedAuthenticatorConfig.isEnabled()) {
prepStmt1.setString(1, IdPManagementConstants.IS_TRUE_VALUE);
} else {
prepStmt1.setString(1, IdPManagementConstants.IS_FALSE_VALUE);
}
prepStmt1.setInt(2, idpId);
prepStmt1.setString(3, newFederatedAuthenticatorConfig.getName());
prepStmt1.executeUpdate();
int authnId = getAuthenticatorIdentifier(dbConnection, idpId, newFederatedAuthenticatorConfig.getName());
List<Property> unUpdatedProperties = new ArrayList<>();
List<Property> singleValuedProperties = new ArrayList<>();
List<Property> multiValuedProperties = new ArrayList<>();
// Checking for old fed auth config properties that are not updated so we can delete them.
if (ArrayUtils.isNotEmpty(oldFederatedAuthenticatorConfig.getProperties())) {
if (ArrayUtils.isNotEmpty(newFederatedAuthenticatorConfig.getProperties())) {
for (Property propertyOld : oldFederatedAuthenticatorConfig.getProperties()) {
boolean hasProp = false;
for (Property propertyNew : newFederatedAuthenticatorConfig.getProperties()) {
if (StringUtils.equals(propertyOld.getName(), propertyNew.getName())) {
hasProp = true;
break;
}
}
if (!hasProp) {
unUpdatedProperties.add(propertyOld);
}
}
} else {
unUpdatedProperties = new ArrayList<>(Arrays.asList(oldFederatedAuthenticatorConfig.getProperties()));
}
}
for (Property property : newFederatedAuthenticatorConfig.getProperties()) {
if (Pattern.matches(IdPManagementConstants.MULTI_VALUED_PROPERT_IDENTIFIER_PATTERN, property.getName())) {
multiValuedProperties.add(property);
} else {
singleValuedProperties.add(property);
}
}
if (CollectionUtils.isNotEmpty(unUpdatedProperties)) {
deleteFederatedConfigProperties(dbConnection, authnId, tenantId, unUpdatedProperties);
}
if (CollectionUtils.isNotEmpty(singleValuedProperties)) {
updateSingleValuedFederatedConfigProperties(dbConnection, authnId, tenantId, singleValuedProperties);
}
if (CollectionUtils.isNotEmpty(multiValuedProperties)) {
updateMultiValuedFederatedConfigProperties(dbConnection, oldFederatedAuthenticatorConfig.getProperties(), authnId, tenantId, multiValuedProperties);
}
} finally {
IdentityDatabaseUtil.closeStatement(prepStmt1);
}
}
use of org.wso2.carbon.user.api.Property in project carbon-identity-framework by wso2.
the class IdPManagementDAO method updateMultiValuedFederatedConfigProperties.
private void updateMultiValuedFederatedConfigProperties(Connection dbConnection, Property[] oldFederatedAuthenticatorConfigProperties, int authnId, int tenantId, List<Property> multiValuedProperties) throws SQLException {
PreparedStatement deleteOldValuePrepStmt = null;
PreparedStatement addNewPropsPrepStmt = null;
String sqlStmt;
try {
for (Property property : oldFederatedAuthenticatorConfigProperties) {
if (Pattern.matches(IdPManagementConstants.MULTI_VALUED_PROPERT_IDENTIFIER_PATTERN, property.getName())) {
sqlStmt = IdPManagementConstants.SQLQueries.DELETE_IDP_AUTH_PROP_WITH_KEY_SQL;
deleteOldValuePrepStmt = dbConnection.prepareStatement(sqlStmt);
deleteOldValuePrepStmt.setString(1, property.getName());
deleteOldValuePrepStmt.setInt(2, tenantId);
deleteOldValuePrepStmt.setInt(3, authnId);
deleteOldValuePrepStmt.executeUpdate();
}
}
for (Property property : multiValuedProperties) {
sqlStmt = IdPManagementConstants.SQLQueries.ADD_IDP_AUTH_PROP_SQL;
addNewPropsPrepStmt = dbConnection.prepareStatement(sqlStmt);
addNewPropsPrepStmt.setInt(1, authnId);
addNewPropsPrepStmt.setInt(2, tenantId);
addNewPropsPrepStmt.setString(3, property.getName());
addNewPropsPrepStmt.setString(4, property.getValue());
if (property.isConfidential()) {
addNewPropsPrepStmt.setString(5, IdPManagementConstants.IS_TRUE_VALUE);
} else {
addNewPropsPrepStmt.setString(5, IdPManagementConstants.IS_FALSE_VALUE);
}
addNewPropsPrepStmt.executeUpdate();
}
} finally {
IdentityDatabaseUtil.closeStatement(deleteOldValuePrepStmt);
IdentityDatabaseUtil.closeStatement(addNewPropsPrepStmt);
}
}
use of org.wso2.carbon.user.api.Property 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.user.api.Property 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 } };
}
Aggregations