Search in sources :

Example 91 with Property

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

Example 92 with Property

use of org.wso2.carbon.identity.application.common.model.xsd.Property in project carbon-identity-framework by wso2.

the class IdPManagementDAO method updateSingleValuedFederatedConfigProperties.

private void updateSingleValuedFederatedConfigProperties(Connection dbConnection, int authnId, int tenantId, List<Property> singleValuedProperties) throws SQLException {
    PreparedStatement prepStmt2 = null;
    PreparedStatement prepStmt3 = null;
    String sqlStmt;
    try {
        for (Property property : singleValuedProperties) {
            sqlStmt = IdPManagementConstants.SQLQueries.UPDATE_IDP_AUTH_PROP_SQL;
            prepStmt2 = dbConnection.prepareStatement(sqlStmt);
            prepStmt2.setString(1, property.getValue());
            if (property.isConfidential()) {
                prepStmt2.setString(2, IdPManagementConstants.IS_TRUE_VALUE);
            } else {
                prepStmt2.setString(2, IdPManagementConstants.IS_FALSE_VALUE);
            }
            prepStmt2.setInt(3, authnId);
            prepStmt2.setString(4, property.getName());
            int rows = prepStmt2.executeUpdate();
            if (rows == 0) {
                // this should be an insert.
                sqlStmt = IdPManagementConstants.SQLQueries.ADD_IDP_AUTH_PROP_SQL;
                prepStmt3 = dbConnection.prepareStatement(sqlStmt);
                prepStmt3.setInt(1, authnId);
                prepStmt3.setInt(2, tenantId);
                prepStmt3.setString(3, property.getName());
                prepStmt3.setString(4, property.getValue());
                if (property.isConfidential()) {
                    prepStmt3.setString(5, IdPManagementConstants.IS_TRUE_VALUE);
                } else {
                    prepStmt3.setString(5, IdPManagementConstants.IS_FALSE_VALUE);
                }
                prepStmt3.executeUpdate();
            }
        }
    } finally {
        IdentityDatabaseUtil.closeStatement(prepStmt3);
        IdentityDatabaseUtil.closeStatement(prepStmt2);
    }
}
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 93 with Property

use of org.wso2.carbon.identity.application.common.model.xsd.Property in project carbon-identity-framework by wso2.

the class IdPManagementDAO method getProvisioningConnectorConfigs.

/**
 * @param dbConnection
 * @param idPName
 * @param tenantId
 * @return
 * @throws IdentityProviderManagementException
 * @throws SQLException
 */
public ProvisioningConnectorConfig[] getProvisioningConnectorConfigs(Connection dbConnection, String idPName, int idPId, int tenantId) throws IdentityProviderManagementException, SQLException {
    PreparedStatement prepStmt = null;
    PreparedStatement prepBaseStmt = null;
    ResultSet rs1 = null;
    ResultSet rs2 = null;
    try {
        // SP_IDP_PROV_CONNECTOR_TYPE,SP_IDP_PROV_CONFIG_KEY,
        // SP_IDP_PROV_CONFIG_VALUE,SP_IDP_PROV_CONFIG_IS_SECRET
        String sqlBaseStmt = IdPManagementConstants.SQLQueries.GET_IDP_PROVISIONING_CONFIGS_SQL;
        prepBaseStmt = dbConnection.prepareStatement(sqlBaseStmt);
        prepBaseStmt.setInt(1, idPId);
        rs1 = prepBaseStmt.executeQuery();
        Map<String, ProvisioningConnectorConfig> provisioningConnectorMap = new HashMap<String, ProvisioningConnectorConfig>();
        while (rs1.next()) {
            ProvisioningConnectorConfig provisioningConnector;
            String type = rs1.getString("PROVISIONING_CONNECTOR_TYPE");
            if (!provisioningConnectorMap.containsKey(type)) {
                provisioningConnector = new ProvisioningConnectorConfig();
                provisioningConnector.setName(type);
                if ((IdPManagementConstants.IS_TRUE_VALUE).equals(rs1.getString("IS_ENABLED"))) {
                    provisioningConnector.setEnabled(true);
                } else {
                    provisioningConnector.setEnabled(false);
                }
                if ((IdPManagementConstants.IS_TRUE_VALUE).equals(rs1.getString("IS_BLOCKING"))) {
                    provisioningConnector.setBlocking(true);
                } else {
                    provisioningConnector.setBlocking(false);
                }
                if (provisioningConnector.getProvisioningProperties() == null || provisioningConnector.getProvisioningProperties().length == 0) {
                    String sqlStmt = IdPManagementConstants.SQLQueries.GET_IDP_PROVISIONING_PROPERTY_SQL;
                    prepStmt = dbConnection.prepareStatement(sqlStmt);
                    int configId = rs1.getInt("ID");
                    prepStmt.setInt(1, tenantId);
                    prepStmt.setInt(2, configId);
                    rs2 = prepStmt.executeQuery();
                    List<Property> provisioningProperties = new ArrayList<Property>();
                    while (rs2.next()) {
                        Property property = new Property();
                        String name = rs2.getString("PROPERTY_KEY");
                        String value = rs2.getString("PROPERTY_VALUE");
                        String blobValue = getBlobValue(rs2.getBinaryStream("PROPERTY_BLOB_VALUE"));
                        String propertyType = rs2.getString("PROPERTY_TYPE");
                        String isSecret = rs2.getString("IS_SECRET");
                        property.setName(name);
                        if (propertyType != null && IdentityApplicationConstants.ConfigElements.PROPERTY_TYPE_BLOB.equals(propertyType.trim())) {
                            property.setValue(blobValue);
                        } else {
                            property.setValue(value);
                        }
                        property.setType(propertyType);
                        if ((IdPManagementConstants.IS_TRUE_VALUE).equals(isSecret)) {
                            property.setConfidential(true);
                        } else {
                            property.setConfidential(false);
                        }
                        provisioningProperties.add(property);
                    }
                    provisioningConnector.setProvisioningProperties(provisioningProperties.toArray(new Property[provisioningProperties.size()]));
                }
                provisioningConnectorMap.put(type, provisioningConnector);
            }
        }
        return provisioningConnectorMap.values().toArray(new ProvisioningConnectorConfig[provisioningConnectorMap.size()]);
    } finally {
        IdentityDatabaseUtil.closeAllConnections(null, rs2, prepBaseStmt);
        IdentityDatabaseUtil.closeAllConnections(null, rs1, prepStmt);
    }
}
Also used : HashMap(java.util.HashMap) ResultSet(java.sql.ResultSet) 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) ProvisioningConnectorConfig(org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)

Example 94 with Property

use of org.wso2.carbon.identity.application.common.model.xsd.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 95 with Property

use of org.wso2.carbon.identity.application.common.model.xsd.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)

Aggregations

ArrayList (java.util.ArrayList)114 HashMap (java.util.HashMap)114 Property (org.wso2.carbon.identity.application.common.model.Property)103 Map (java.util.Map)62 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)50 Test (org.testng.annotations.Test)41 UserStoreException (org.wso2.carbon.user.api.UserStoreException)38 IOException (java.io.IOException)37 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)31 List (java.util.List)30 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)29 Resource (org.wso2.carbon.registry.core.Resource)29 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)27 OMElement (org.apache.axiom.om.OMElement)24 PreparedStatement (java.sql.PreparedStatement)23 ProvisioningConnectorConfig (org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)23 Property (org.wso2.carbon.identity.application.common.model.xsd.Property)23