use of org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig in project carbon-identity-framework by wso2.
the class IdPManagementDAO method getFederatedAuthenticatorConfigs.
/**
* @param dbConnection
* @param idPName
* @param tenantId
* @return
* @throws IdentityProviderManagementException
* @throws SQLException
*/
private FederatedAuthenticatorConfig[] getFederatedAuthenticatorConfigs(Connection dbConnection, String idPName, IdentityProvider federatedIdp, int tenantId) throws IdentityProviderManagementException, SQLException {
int idPId = getIdentityProviderIdentifier(dbConnection, idPName, tenantId);
PreparedStatement prepStmt1 = null;
PreparedStatement prepStmt2 = null;
ResultSet rs = null;
ResultSet proprs = null;
String defaultAuthName = null;
if (federatedIdp != null && federatedIdp.getDefaultAuthenticatorConfig() != null) {
defaultAuthName = federatedIdp.getDefaultAuthenticatorConfig().getName();
}
String sqlStmt = IdPManagementConstants.SQLQueries.GET_ALL_IDP_AUTH_SQL;
Set<FederatedAuthenticatorConfig> federatedAuthenticatorConfigs = new HashSet<FederatedAuthenticatorConfig>();
try {
prepStmt1 = dbConnection.prepareStatement(sqlStmt);
prepStmt1.setInt(1, idPId);
rs = prepStmt1.executeQuery();
while (rs.next()) {
FederatedAuthenticatorConfig authnConfig = new FederatedAuthenticatorConfig();
int authnId = rs.getInt("ID");
authnConfig.setName(rs.getString("NAME"));
if ((IdPManagementConstants.IS_TRUE_VALUE).equals(rs.getString("IS_ENABLED"))) {
authnConfig.setEnabled(true);
} else {
authnConfig.setEnabled(false);
}
authnConfig.setDisplayName(rs.getString("DISPLAY_NAME"));
if (defaultAuthName != null && authnConfig.getName().equals(defaultAuthName)) {
federatedIdp.getDefaultAuthenticatorConfig().setDisplayName(authnConfig.getDisplayName());
}
sqlStmt = IdPManagementConstants.SQLQueries.GET_IDP_AUTH_PROPS_SQL;
prepStmt2 = dbConnection.prepareStatement(sqlStmt);
prepStmt2.setInt(1, authnId);
proprs = prepStmt2.executeQuery();
Set<Property> properties = new HashSet<Property>();
while (proprs.next()) {
Property property = new Property();
property.setName(proprs.getString("PROPERTY_KEY"));
property.setValue(proprs.getString("PROPERTY_VALUE"));
if ((IdPManagementConstants.IS_TRUE_VALUE).equals(proprs.getString("IS_SECRET"))) {
property.setConfidential(true);
}
properties.add(property);
}
authnConfig.setProperties(properties.toArray(new Property[properties.size()]));
federatedAuthenticatorConfigs.add(authnConfig);
}
return federatedAuthenticatorConfigs.toArray(new FederatedAuthenticatorConfig[federatedAuthenticatorConfigs.size()]);
} finally {
IdentityDatabaseUtil.closeAllConnections(null, proprs, prepStmt2);
IdentityDatabaseUtil.closeAllConnections(null, rs, prepStmt1);
}
}
use of org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig in project carbon-identity-framework by wso2.
the class IdPManagementDAO method updateFederatedAuthenticatorConfigs.
/**
* @param newFederatedAuthenticatorConfigs
* @param oldFederatedAuthenticatorConfigs
* @param dbConnection
* @param idpId
* @param tenantId
* @throws IdentityProviderManagementException
* @throws SQLException
*/
private void updateFederatedAuthenticatorConfigs(FederatedAuthenticatorConfig[] newFederatedAuthenticatorConfigs, FederatedAuthenticatorConfig[] oldFederatedAuthenticatorConfigs, Connection dbConnection, int idpId, int tenantId, boolean isResidentIdP) throws IdentityProviderManagementException, SQLException {
Map<String, FederatedAuthenticatorConfig> oldFedAuthnConfigMap = new HashMap<>();
if (oldFederatedAuthenticatorConfigs != null && oldFederatedAuthenticatorConfigs.length > 0) {
for (FederatedAuthenticatorConfig fedAuthnConfig : oldFederatedAuthenticatorConfigs) {
oldFedAuthnConfigMap.put(fedAuthnConfig.getName(), fedAuthnConfig);
}
}
Map<String, FederatedAuthenticatorConfig> newFedAuthnConfigMap = new HashMap<>();
if (newFederatedAuthenticatorConfigs != null && newFederatedAuthenticatorConfigs.length > 0) {
for (FederatedAuthenticatorConfig fedAuthenticator : newFederatedAuthenticatorConfigs) {
newFedAuthnConfigMap.put(fedAuthenticator.getName(), fedAuthenticator);
if (fedAuthenticator.isValid()) {
if (oldFedAuthnConfigMap.containsKey(fedAuthenticator.getName())) {
updateFederatedAuthenticatorConfig(fedAuthenticator, oldFedAuthnConfigMap.get(fedAuthenticator.getName()), dbConnection, idpId, tenantId);
} else {
addFederatedAuthenticatorConfig(fedAuthenticator, dbConnection, idpId, tenantId);
}
}
}
}
if (!isResidentIdP) {
// Remove deleted federated authenticator configs.
for (String oldFedAuthenticator : oldFedAuthnConfigMap.keySet()) {
if (!newFedAuthnConfigMap.containsKey(oldFedAuthenticator)) {
deleteFederatedAuthenticatorConfig(oldFedAuthnConfigMap.get(oldFedAuthenticator), dbConnection, idpId, tenantId);
}
}
}
}
use of org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig 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.identity.application.common.model.FederatedAuthenticatorConfig 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.FederatedAuthenticatorConfig 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