Search in sources :

Example 81 with Property

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);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) Property(org.wso2.carbon.identity.application.common.model.Property)

Example 82 with Property

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);
    }
}
Also used : ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) Property(org.wso2.carbon.identity.application.common.model.Property)

Example 83 with Property

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);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) Property(org.wso2.carbon.identity.application.common.model.Property)

Example 84 with Property

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);
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) PermissionsAndRoleConfig(org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig) FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) ClaimConfig(org.wso2.carbon.identity.application.common.model.ClaimConfig) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) LocalRole(org.wso2.carbon.identity.application.common.model.LocalRole) RoleMapping(org.wso2.carbon.identity.application.common.model.RoleMapping) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) Property(org.wso2.carbon.identity.application.common.model.Property) ProvisioningConnectorConfig(org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig) Claim(org.wso2.carbon.identity.application.common.model.Claim) LocalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim)

Example 85 with Property

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 } };
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) PermissionsAndRoleConfig(org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig) FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) ClaimConfig(org.wso2.carbon.identity.application.common.model.ClaimConfig) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) LocalRole(org.wso2.carbon.identity.application.common.model.LocalRole) Matchers.anyObject(org.mockito.Matchers.anyObject) RoleMapping(org.wso2.carbon.identity.application.common.model.RoleMapping) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) Property(org.wso2.carbon.identity.application.common.model.Property) ProvisioningConnectorConfig(org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig) Claim(org.wso2.carbon.identity.application.common.model.Claim) LocalClaim(org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim) DataProvider(org.testng.annotations.DataProvider)

Aggregations

ArrayList (java.util.ArrayList)118 HashMap (java.util.HashMap)114 Property (org.wso2.carbon.identity.application.common.model.Property)105 Map (java.util.Map)62 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)50 Test (org.testng.annotations.Test)42 IOException (java.io.IOException)38 UserStoreException (org.wso2.carbon.user.api.UserStoreException)38 Property (org.wso2.carbon.identity.application.common.model.idp.xsd.Property)36 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationRequestConfig)33 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)32 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)32 List (java.util.List)31 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)29 Resource (org.wso2.carbon.registry.core.Resource)29 OMElement (org.apache.axiom.om.OMElement)27 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)27 PreparedStatement (java.sql.PreparedStatement)23 QName (javax.xml.namespace.QName)23 ProvisioningConnectorConfig (org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)23