Search in sources :

Example 41 with ProvisioningConnectorConfig

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

the class OutboundProvisioningManager method getOutboundProvisioningConnector.

/**
 * @param fIdP
 * @param registeredConnectorFactories
 * @param tenantDomainName
 * @param enableJitProvisioning
 * @return
 * @throws IdentityProviderManagementException
 * @throws UserStoreException
 */
private AbstractOutboundProvisioningConnector getOutboundProvisioningConnector(IdentityProvider fIdP, Map<String, AbstractProvisioningConnectorFactory> registeredConnectorFactories, String tenantDomainName, boolean enableJitProvisioning) throws IdentityProviderManagementException, IdentityProvisioningException {
    String idpName = fIdP.getIdentityProviderName();
    // name of the default provisioning connector.
    String connectorType = fIdP.getDefaultProvisioningConnectorConfig().getName();
    // get identity provider configuration.
    fIdP = IdentityProviderManager.getInstance().getEnabledIdPByName(idpName, tenantDomainName);
    if (fIdP == null) {
        // If not its an exception.
        throw new IdentityProvisioningException("Provisioning identity provider not available in the system. Idp Name : " + idpName);
    }
    // get a list of provisioning connectors associated with the provisioning
    // identity provider.
    ProvisioningConnectorConfig[] provisioningConfigs = fIdP.getProvisioningConnectorConfigs();
    if (provisioningConfigs != null && provisioningConfigs.length > 0) {
        for (ProvisioningConnectorConfig defaultProvisioningConfig : provisioningConfigs) {
            if (!connectorType.equals(defaultProvisioningConfig.getName()) || !defaultProvisioningConfig.isEnabled()) {
                // we need to find the provisioning connector selected by the service provider.
                continue;
            }
            // this is how we match the configuration to the runtime. the provisioning
            // connector factory should be registered with the system, with the exact
            // name available in the corresponding configuration.
            AbstractProvisioningConnectorFactory factory = registeredConnectorFactories.get(connectorType);
            // get the provisioning properties associated with a given provisioning
            // connector.
            Property[] provisioningProperties = defaultProvisioningConfig.getProvisioningProperties();
            if (enableJitProvisioning) {
                Property jitEnabled = new Property();
                jitEnabled.setName(IdentityProvisioningConstants.JIT_PROVISIONING_ENABLED);
                jitEnabled.setValue("1");
                provisioningProperties = IdentityApplicationManagementUtil.concatArrays(provisioningProperties, new Property[] { jitEnabled });
            }
            Property userIdClaimURL = new Property();
            userIdClaimURL.setName("userIdClaimUri");
            if (fIdP.getClaimConfig() != null && fIdP.getClaimConfig().getUserClaimURI() != null) {
                userIdClaimURL.setValue(fIdP.getClaimConfig().getUserClaimURI());
            } else {
                userIdClaimURL.setValue("");
            }
            List<Property> provisioningPropertiesList = new ArrayList<>(Arrays.asList(provisioningProperties));
            provisioningPropertiesList.add(userIdClaimURL);
            provisioningProperties = new Property[provisioningPropertiesList.size()];
            provisioningProperties = provisioningPropertiesList.toArray(provisioningProperties);
            // can only be associated with a single provisioning connector.
            return factory.getConnector(idpName, provisioningProperties, tenantDomainName);
        }
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) Property(org.wso2.carbon.identity.application.common.model.Property) ProvisioningConnectorConfig(org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)

Example 42 with ProvisioningConnectorConfig

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

the class IdentityProvider method build.

public static IdentityProvider build(OMElement identityProviderOM) {
    IdentityProvider identityProvider = new IdentityProvider();
    Iterator<?> iter = identityProviderOM.getChildElements();
    String defaultAuthenticatorConfigName = null;
    String defaultProvisioningConfigName = null;
    ArrayList<IdentityProviderProperty> idpProperties = new ArrayList();
    while (iter.hasNext()) {
        OMElement element = (OMElement) (iter.next());
        String elementName = element.getLocalName();
        if (elementName.equals(FILE_ELEMENT_IDENTITY_PROVIDER_NAME)) {
            if (element.getText() != null) {
                identityProvider.setIdentityProviderName(element.getText());
            } else {
                log.error("Identity provider not loaded from the file system. Identity provider name must be " + "not null.");
                return null;
            }
        } else if (FILE_ELEMENT_IDENTITY_PROVIDER_DESCRIPTION.equals(elementName)) {
            identityProvider.setIdentityProviderDescription(element.getText());
        } else if (FILE_ELEMENT_ALIAS.equals(elementName)) {
            identityProvider.setAlias(element.getText());
        } else if (FILE_ELEMENT_DISPLAY_NAME.equals(elementName)) {
            identityProvider.setDisplayName(element.getText());
        } else if (FILE_ELEMENT_IS_PRIMARY.equals(elementName)) {
            if (element.getText() != null && element.getText().trim().length() > 0) {
                identityProvider.setPrimary(Boolean.parseBoolean(element.getText()));
            }
        } else if (FILE_ELEMENT_IS_ENABLED.equals(elementName)) {
            if (element.getText() != null && element.getText().trim().length() > 0) {
                identityProvider.setEnable((Boolean.parseBoolean(element.getText())));
            }
        } else if (FILE_ELEMENT_IS_FEDERATION_HUB.equals(elementName)) {
            if (element.getText() != null && element.getText().trim().length() > 0) {
                identityProvider.setFederationHub(Boolean.parseBoolean(element.getText()));
            }
        } else if (FILE_ELEMENT_HOME_REALM_ID.equals(elementName)) {
            identityProvider.setHomeRealmId(element.getText());
        } else if (FILE_ELEMENT_PROVISIONING_ROLE.equals(elementName)) {
            identityProvider.setProvisioningRole(element.getText());
        } else if (FILE_ELEMENT_ISSUER.equals(elementName)) {
            IdentityProviderProperty idpIssuer = new IdentityProviderProperty();
            idpIssuer.setName(IDP_ISSUER_NAME);
            idpIssuer.setValue(element.getText());
            idpProperties.add(idpIssuer);
        } else if (FILE_ELEMENT_JWKS_ENDPOINT.equals(elementName)) {
            IdentityProviderProperty jwksEndpoint = new IdentityProviderProperty();
            jwksEndpoint.setName(JWKS_URI);
            jwksEndpoint.setValue(element.getText());
            jwksEndpoint.setDisplayName(JWKS_DISPLAYNAME);
            idpProperties.add(jwksEndpoint);
        } else if (FILE_ELEMENT_FEDERATED_AUTHENTICATOR_CONFIGS.equals(elementName)) {
            Iterator<?> federatedAuthenticatorConfigsIter = element.getChildElements();
            if (federatedAuthenticatorConfigsIter == null) {
                continue;
            }
            List<FederatedAuthenticatorConfig> federatedAuthenticatorConfigsArrList;
            federatedAuthenticatorConfigsArrList = new ArrayList<FederatedAuthenticatorConfig>();
            while (federatedAuthenticatorConfigsIter.hasNext()) {
                OMElement federatedAuthenticatorConfigsElement = (OMElement) (federatedAuthenticatorConfigsIter.next());
                FederatedAuthenticatorConfig fedAuthConfig;
                fedAuthConfig = FederatedAuthenticatorConfig.build(federatedAuthenticatorConfigsElement);
                if (fedAuthConfig != null) {
                    federatedAuthenticatorConfigsArrList.add(fedAuthConfig);
                }
            }
            if (federatedAuthenticatorConfigsArrList.size() > 0) {
                FederatedAuthenticatorConfig[] federatedAuthenticatorConfigsArr;
                federatedAuthenticatorConfigsArr = federatedAuthenticatorConfigsArrList.toArray(new FederatedAuthenticatorConfig[0]);
                identityProvider.setFederatedAuthenticatorConfigs(federatedAuthenticatorConfigsArr);
            }
        } else if (FILE_ELEMENT_DEFAULT_AUTHENTICATOR_CONFIG.equals(elementName)) {
            if (element.getText().trim().isEmpty()) {
                FederatedAuthenticatorConfig defaultAuthenticatorConfig = FederatedAuthenticatorConfig.build(element);
                if (defaultAuthenticatorConfig != null) {
                    defaultAuthenticatorConfigName = defaultAuthenticatorConfig.getName();
                }
            } else {
                defaultAuthenticatorConfigName = element.getText();
            }
        } else if (FILE_ELEMENT_PROVISIONING_CONNECTOR_CONFIGS.equals(elementName)) {
            Iterator<?> provisioningConnectorConfigsIter = element.getChildElements();
            if (provisioningConnectorConfigsIter == null) {
                continue;
            }
            List<ProvisioningConnectorConfig> provisioningConnectorConfigsArrList;
            provisioningConnectorConfigsArrList = new ArrayList<ProvisioningConnectorConfig>();
            while (provisioningConnectorConfigsIter.hasNext()) {
                OMElement provisioningConnectorConfigsElement = (OMElement) (provisioningConnectorConfigsIter.next());
                ProvisioningConnectorConfig proConConfig = null;
                try {
                    proConConfig = ProvisioningConnectorConfig.build(provisioningConnectorConfigsElement);
                } catch (IdentityApplicationManagementException e) {
                    log.error("Error while building provisioningConnectorConfig for IDP " + identityProvider.getIdentityProviderName() + ". Cause : " + e.getMessage() + ". Building rest of the " + "IDP configs", e);
                }
                if (proConConfig != null) {
                    provisioningConnectorConfigsArrList.add(proConConfig);
                }
            }
            if (CollectionUtils.isNotEmpty(provisioningConnectorConfigsArrList)) {
                ProvisioningConnectorConfig[] provisioningConnectorConfigsArr;
                provisioningConnectorConfigsArr = provisioningConnectorConfigsArrList.toArray(new ProvisioningConnectorConfig[0]);
                identityProvider.setProvisioningConnectorConfigs(provisioningConnectorConfigsArr);
            }
        } else if (FILE_ELEMENT_DEFAULT_PROVISIONING_CONNECTOR_CONFIG.equals(elementName)) {
            if (element.getText().trim().isEmpty()) {
                try {
                    ProvisioningConnectorConfig proConConfig = ProvisioningConnectorConfig.build(element);
                    if (proConConfig != null) {
                        defaultProvisioningConfigName = proConConfig.getName();
                    }
                } catch (IdentityApplicationManagementException e) {
                    log.error(String.format("Error while building default provisioning connector config for IDP %s" + ". Cause : %s Building rest of the IDP configs", identityProvider.getIdentityProviderName(), e.getMessage()));
                }
            } else {
                defaultProvisioningConfigName = element.getText();
            }
        } else if (FILE_ELEMENT_CLAIM_CONFIG.equals(elementName)) {
            identityProvider.setClaimConfig(ClaimConfig.build(element));
        } else if (FILE_ELEMENT_CERTIFICATE.equals(elementName)) {
            identityProvider.setCertificate(element.getText());
        } else if (FILE_ELEMENT_PERMISSION_AND_ROLE_CONFIG.equals(elementName)) {
            identityProvider.setPermissionAndRoleConfig(PermissionsAndRoleConfig.build(element));
        } else if (FILE_ELEMENT_JUST_IN_TIME_PROVISIONING_CONFIG.equals(elementName)) {
            identityProvider.setJustInTimeProvisioningConfig(JustInTimeProvisioningConfig.build(element));
        } else if (FILE_ELEMENT_IMAGE_URL.equals(elementName)) {
            identityProvider.setImageUrl(element.getText());
        } else if (TEMPLATE_ID.equals(elementName)) {
            identityProvider.setTemplateId(element.getText());
        }
    }
    FederatedAuthenticatorConfig[] federatedAuthenticatorConfigs = identityProvider.getFederatedAuthenticatorConfigs();
    boolean foundDefaultAuthenticator = false;
    for (int i = 0; i < federatedAuthenticatorConfigs.length; i++) {
        if (StringUtils.equals(defaultAuthenticatorConfigName, federatedAuthenticatorConfigs[i].getName())) {
            identityProvider.setDefaultAuthenticatorConfig(federatedAuthenticatorConfigs[i]);
            foundDefaultAuthenticator = true;
            break;
        }
    }
    if ((!foundDefaultAuthenticator && federatedAuthenticatorConfigs.length > 0) || (federatedAuthenticatorConfigs.length == 0 && StringUtils.isNotBlank(defaultAuthenticatorConfigName))) {
        log.warn("No matching federated authentication config found with default authentication config name :  " + defaultAuthenticatorConfigName + " in identity provider : " + identityProvider.displayName + ".");
        return null;
    }
    ProvisioningConnectorConfig[] provisioningConnectorConfigs = identityProvider.getProvisioningConnectorConfigs();
    boolean foundDefaultProvisioningConfig = false;
    for (int i = 0; i < provisioningConnectorConfigs.length; i++) {
        if (StringUtils.equals(defaultProvisioningConfigName, provisioningConnectorConfigs[i].getName())) {
            identityProvider.setDefaultProvisioningConnectorConfig(provisioningConnectorConfigs[i]);
            foundDefaultProvisioningConfig = true;
            break;
        }
    }
    if ((!foundDefaultProvisioningConfig && provisioningConnectorConfigs.length > 0) || (provisioningConnectorConfigs.length == 0 && StringUtils.isNotBlank(defaultProvisioningConfigName))) {
        log.warn("No matching provisioning config found with default provisioning config name :  " + defaultProvisioningConfigName + " in identity provider : " + identityProvider.displayName + ".");
        identityProvider = null;
    }
    if (CollectionUtils.size(idpProperties) > 0) {
        identityProvider.setIdpProperties(idpProperties.toArray(new IdentityProviderProperty[0]));
    }
    return identityProvider;
}
Also used : IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) ArrayList(java.util.ArrayList) OMElement(org.apache.axiom.om.OMElement) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 43 with ProvisioningConnectorConfig

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

the class ProvisioningConnectorConfig method build.

/**
 * <ProvisioningConnectorConfig> <Name></Name> <ProvisioningProperties></ProvisioningProperties>
 * </ProvisioningConnectorConfig>
 */
public static ProvisioningConnectorConfig build(OMElement provisioningConnectorConfigOM) throws IdentityApplicationManagementException {
    ProvisioningConnectorConfig provisioningConnectorConfig = new ProvisioningConnectorConfig();
    Iterator<?> iter = provisioningConnectorConfigOM.getChildElements();
    while (iter.hasNext()) {
        OMElement element = (OMElement) (iter.next());
        String elementName = element.getLocalName();
        if ("ProvisioningProperties".equals(elementName)) {
            Iterator<?> propertiesIter = element.getChildElements();
            List<Property> propertiesArrList = new ArrayList<>();
            if (propertiesIter != null) {
                while (propertiesIter.hasNext()) {
                    OMElement propertiesElement = (OMElement) (propertiesIter.next());
                    propertiesArrList.add(Property.build(propertiesElement));
                }
            }
            if (CollectionUtils.isNotEmpty(propertiesArrList)) {
                Property[] propertiesArr = propertiesArrList.toArray(new Property[0]);
                provisioningConnectorConfig.setProvisioningProperties(propertiesArr);
            }
        } else if ("Name".equals(elementName)) {
            provisioningConnectorConfig.setName(element.getText());
        } else if ("IsEnabled".equals(elementName)) {
            provisioningConnectorConfig.setEnabled(Boolean.parseBoolean(element.getText()));
        } else if ("IsBlocking".equals(elementName)) {
            provisioningConnectorConfig.setBlocking(Boolean.parseBoolean(element.getText()));
        } else if ("IsRulesEnabled".equals(elementName)) {
            provisioningConnectorConfig.setRulesEnabled(Boolean.parseBoolean(element.getText()));
        }
    }
    if (StringUtils.isBlank(provisioningConnectorConfig.getName())) {
        throw new IdentityApplicationManagementException("No configured name found for " + "ProvisioningConnectorConfig");
    }
    return provisioningConnectorConfig;
}
Also used : IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) ArrayList(java.util.ArrayList) OMElement(org.apache.axiom.om.OMElement)

Example 44 with ProvisioningConnectorConfig

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

the class IdPManagementDAO method getIdPByAuthenticatorPropertyValue.

/**
 * @param dbConnection
 * @param property     Property which has a unique value like EntityID to specifically identify a IdentityProvider
 *                     Unless it will return first matched IdentityProvider
 * @param value
 * @param tenantId
 * @param tenantDomain
 * @return
 * @throws IdentityProviderManagementException
 */
public IdentityProvider getIdPByAuthenticatorPropertyValue(Connection dbConnection, String property, String value, int tenantId, String tenantDomain) throws IdentityProviderManagementException {
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    IdentityProvider federatedIdp = null;
    boolean dbConnectionInitialized = true;
    if (dbConnection == null) {
        dbConnection = IdentityDatabaseUtil.getDBConnection(false);
    } else {
        dbConnectionInitialized = false;
    }
    try {
        // SP_IDP_ID, SP_IDP_NAME, SP_IDP_PRIMARY, SP_IDP_HOME_REALM_ID,SP_IDP_CERTIFICATE,
        // SP_IDP_TOKEN_EP_ALIAS,
        // SP_IDP_INBOUND_PROVISIONING_ENABLED,SP_IDP_INBOUND_PROVISIONING_USER_STORE_ID,
        // SP_IDP_USER_CLAIM_URI,
        // SP_IDP_ROLE_CLAIM_URI,SP_IDP_DEFAULT_AUTHENTICATOR_NAME,SP_IDP_DEFAULT_PRO_CONNECTOR_NAME
        String sqlStmt = IdPManagementConstants.SQLQueries.GET_IDP_BY_AUTHENTICATOR_PROPERTY;
        prepStmt = dbConnection.prepareStatement(sqlStmt);
        prepStmt.setString(1, property);
        prepStmt.setString(2, value);
        prepStmt.setInt(3, tenantId);
        rs = prepStmt.executeQuery();
        int idpId = -1;
        String idPName = "";
        if (rs.next()) {
            federatedIdp = new IdentityProvider();
            idpId = rs.getInt("ID");
            idPName = rs.getString("NAME");
            federatedIdp.setIdentityProviderName(idPName);
            if ((IdPManagementConstants.IS_TRUE_VALUE).equals(rs.getString("IS_PRIMARY"))) {
                federatedIdp.setPrimary(true);
            } else {
                federatedIdp.setPrimary(false);
            }
            federatedIdp.setHomeRealmId(rs.getString("HOME_REALM_ID"));
            federatedIdp.setCertificate(getBlobValue(rs.getBinaryStream("CERTIFICATE")));
            federatedIdp.setAlias(rs.getString("ALIAS"));
            JustInTimeProvisioningConfig jitProConfig = new JustInTimeProvisioningConfig();
            if (IdPManagementConstants.IS_TRUE_VALUE.equals(rs.getString("INBOUND_PROV_ENABLED"))) {
                jitProConfig.setProvisioningEnabled(true);
            } else {
                jitProConfig.setProvisioningEnabled(false);
            }
            jitProConfig.setProvisioningUserStore(rs.getString("INBOUND_PROV_USER_STORE_ID"));
            federatedIdp.setJustInTimeProvisioningConfig(jitProConfig);
            String userClaimUri = rs.getString("USER_CLAIM_URI");
            String roleClaimUri = rs.getString("ROLE_CLAIM_URI");
            String defaultAuthenticatorName = rs.getString("DEFAULT_AUTHENTICATOR_NAME");
            String defaultProvisioningConnectorConfigName = rs.getString("DEFAULT_PRO_CONNECTOR_NAME");
            federatedIdp.setIdentityProviderDescription(rs.getString("DESCRIPTION"));
            // IS_FEDERATION_HUB_IDP
            if (IdPManagementConstants.IS_TRUE_VALUE.equals(rs.getString("IS_FEDERATION_HUB"))) {
                federatedIdp.setFederationHub(true);
            } else {
                federatedIdp.setFederationHub(false);
            }
            if (federatedIdp.getClaimConfig() == null) {
                federatedIdp.setClaimConfig(new ClaimConfig());
            }
            // IS_LOCAL_CLAIM_DIALECT
            if (IdPManagementConstants.IS_TRUE_VALUE.equals(rs.getString("IS_LOCAL_CLAIM_DIALECT"))) {
                federatedIdp.getClaimConfig().setLocalClaimDialect(true);
            } else {
                federatedIdp.getClaimConfig().setLocalClaimDialect(false);
            }
            federatedIdp.setProvisioningRole(rs.getString("PROVISIONING_ROLE"));
            if (IdPManagementConstants.IS_TRUE_VALUE.equals(rs.getString("IS_ENABLED"))) {
                federatedIdp.setEnable(true);
            } else {
                federatedIdp.setEnable(false);
            }
            federatedIdp.setDisplayName(rs.getString("DISPLAY_NAME"));
            if (defaultAuthenticatorName != null) {
                FederatedAuthenticatorConfig defaultAuthenticator = new FederatedAuthenticatorConfig();
                defaultAuthenticator.setName(defaultAuthenticatorName);
                federatedIdp.setDefaultAuthenticatorConfig(defaultAuthenticator);
            }
            if (defaultProvisioningConnectorConfigName != null) {
                ProvisioningConnectorConfig defaultProConnector = new ProvisioningConnectorConfig();
                defaultProConnector.setName(defaultProvisioningConnectorConfigName);
                federatedIdp.setDefaultProvisioningConnectorConfig(defaultProConnector);
            }
            // get federated authenticators.
            federatedIdp.setFederatedAuthenticatorConfigs(getFederatedAuthenticatorConfigs(dbConnection, idPName, federatedIdp, tenantId));
            if (federatedIdp.getClaimConfig().isLocalClaimDialect()) {
                federatedIdp.setClaimConfig(getLocalIdPDefaultClaimValues(dbConnection, idPName, userClaimUri, roleClaimUri, idpId, tenantId));
            } else {
                // get claim configuration.
                federatedIdp.setClaimConfig(getIdPClaimConfiguration(dbConnection, idPName, userClaimUri, roleClaimUri, idpId, tenantId));
            }
            // get provisioning connectors.
            federatedIdp.setProvisioningConnectorConfigs(getProvisioningConnectorConfigs(dbConnection, idPName, idpId, tenantId));
            // get permission and role configuration.
            federatedIdp.setPermissionAndRoleConfig(getPermissionsAndRoleConfiguration(dbConnection, idPName, idpId, tenantId));
            List<IdentityProviderProperty> propertyList = filterIdenityProperties(federatedIdp, getIdentityPropertiesByIdpId(dbConnection, Integer.parseInt(rs.getString("ID"))));
            if (IdentityApplicationConstants.RESIDENT_IDP_RESERVED_NAME.equals(idPName)) {
                propertyList = resolveConnectorProperties(propertyList, tenantDomain);
            }
            federatedIdp.setIdpProperties(propertyList.toArray(new IdentityProviderProperty[0]));
        }
        return federatedIdp;
    } catch (SQLException e) {
        throw new IdentityProviderManagementException("Error occurred while retrieving Identity Provider " + "information for Authenticator Property : " + property + " and value : " + value, e);
    } catch (ConnectorException e) {
        throw new IdentityProviderManagementException("Error occurred while retrieving the identity connector " + "configurations.", e);
    } finally {
        if (dbConnectionInitialized) {
            IdentityDatabaseUtil.closeAllConnections(dbConnection, rs, prepStmt);
        } else {
            IdentityDatabaseUtil.closeAllConnections(null, rs, prepStmt);
        }
    }
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) ClaimConfig(org.wso2.carbon.identity.application.common.model.ClaimConfig) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) JustInTimeProvisioningConfig(org.wso2.carbon.identity.application.common.model.JustInTimeProvisioningConfig) ConnectorException(org.wso2.carbon.identity.core.ConnectorException) ResultSet(java.sql.ResultSet) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException) ProvisioningConnectorConfig(org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)

Example 45 with ProvisioningConnectorConfig

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

the class IdPManagementDAO method getIDP.

/**
 * @param dbConnection
 * @param idPName
 * @param idpId
 * @param tenantId
 * @param tenantDomain
 * @return
 * @throws IdentityProviderManagementException
 */
private IdentityProvider getIDP(Connection dbConnection, String idPName, int idpId, String resourceId, int tenantId, String tenantDomain) throws IdentityProviderManagementException {
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    IdentityProvider federatedIdp = null;
    boolean dbConnectionInitialized = true;
    if (dbConnection == null) {
        dbConnection = IdentityDatabaseUtil.getDBConnection(false);
    } else {
        dbConnectionInitialized = false;
    }
    try {
        // SP_IDP_ID, SP_IDP_PRIMARY, SP_IDP_HOME_REALM_ID,SP_IDP_CERTIFICATE,
        // SP_IDP_TOKEN_EP_ALIAS,
        // SP_IDP_INBOUND_PROVISIONING_ENABLED,SP_IDP_INBOUND_PROVISIONING_USER_STORE_ID,
        // SP_IDP_USER_CLAIM_URI,
        // SP_IDP_ROLE_CLAIM_URI,SP_IDP_DEFAULT_AUTHENTICATOR_NAME,SP_IDP_DEFAULT_PRO_CONNECTOR_NAME
        String sqlStmt = IdPManagementConstants.SQLQueries.GET_IDP_BY_RESOURCE_ID_SQL;
        if (StringUtils.isBlank(resourceId)) {
            sqlStmt = IdPManagementConstants.SQLQueries.GET_IDP_BY_NAME_SQL;
            if (StringUtils.isEmpty(idPName)) {
                sqlStmt = IdPManagementConstants.SQLQueries.GET_IDP_BY_ID_SQL;
            }
        }
        prepStmt = dbConnection.prepareStatement(sqlStmt);
        prepStmt.setInt(1, tenantId);
        prepStmt.setInt(2, MultitenantConstants.SUPER_TENANT_ID);
        if (StringUtils.isNotEmpty(resourceId)) {
            prepStmt.setString(3, resourceId);
        } else if (StringUtils.isNotEmpty(idPName)) {
            prepStmt.setString(3, idPName);
        } else {
            prepStmt.setInt(3, idpId);
        }
        rs = prepStmt.executeQuery();
        if (rs.next()) {
            federatedIdp = new IdentityProvider();
            idpId = rs.getInt("ID");
            federatedIdp.setId(Integer.toString(idpId));
            idPName = rs.getString("NAME");
            federatedIdp.setIdentityProviderName(idPName);
            resourceId = rs.getString("UUID");
            federatedIdp.setResourceId(resourceId);
            federatedIdp.setImageUrl(rs.getString("IMAGE_URL"));
            if ((IdPManagementConstants.IS_TRUE_VALUE).equals(rs.getString("IS_PRIMARY"))) {
                federatedIdp.setPrimary(true);
            } else {
                federatedIdp.setPrimary(false);
            }
            federatedIdp.setHomeRealmId(rs.getString("HOME_REALM_ID"));
            federatedIdp.setCertificate(getBlobValue(rs.getBinaryStream("CERTIFICATE")));
            federatedIdp.setAlias(rs.getString("ALIAS"));
            JustInTimeProvisioningConfig jitProConfig = new JustInTimeProvisioningConfig();
            if ((IdPManagementConstants.IS_TRUE_VALUE).equals(rs.getString("INBOUND_PROV_ENABLED"))) {
                jitProConfig.setProvisioningEnabled(true);
            } else {
                jitProConfig.setProvisioningEnabled(false);
            }
            jitProConfig.setProvisioningUserStore(rs.getString("INBOUND_PROV_USER_STORE_ID"));
            federatedIdp.setJustInTimeProvisioningConfig(jitProConfig);
            String userClaimUri = rs.getString("USER_CLAIM_URI");
            String roleClaimUri = rs.getString("ROLE_CLAIM_URI");
            String defaultAuthenticatorName = rs.getString("DEFAULT_AUTHENTICATOR_NAME");
            String defaultProvisioningConnectorConfigName = rs.getString("DEFAULT_PRO_CONNECTOR_NAME");
            federatedIdp.setIdentityProviderDescription(rs.getString("DESCRIPTION"));
            // IS_FEDERATION_HUB_IDP
            if (IdPManagementConstants.IS_TRUE_VALUE.equals(rs.getString("IS_FEDERATION_HUB"))) {
                federatedIdp.setFederationHub(true);
            } else {
                federatedIdp.setFederationHub(false);
            }
            if (federatedIdp.getClaimConfig() == null) {
                federatedIdp.setClaimConfig(new ClaimConfig());
            }
            // IS_LOCAL_CLAIM_DIALECT
            if (IdPManagementConstants.IS_TRUE_VALUE.equals(rs.getString("IS_LOCAL_CLAIM_DIALECT"))) {
                federatedIdp.getClaimConfig().setLocalClaimDialect(true);
            } else {
                federatedIdp.getClaimConfig().setLocalClaimDialect(false);
            }
            federatedIdp.setProvisioningRole(rs.getString("PROVISIONING_ROLE"));
            if (IdPManagementConstants.IS_TRUE_VALUE.equals(rs.getString("IS_ENABLED"))) {
                federatedIdp.setEnable(true);
            } else {
                federatedIdp.setEnable(false);
            }
            federatedIdp.setDisplayName(rs.getString("DISPLAY_NAME"));
            if (defaultProvisioningConnectorConfigName != null) {
                ProvisioningConnectorConfig defaultProConnector = new ProvisioningConnectorConfig();
                defaultProConnector.setName(defaultProvisioningConnectorConfigName);
                federatedIdp.setDefaultProvisioningConnectorConfig(defaultProConnector);
            }
            // get federated authenticators.
            federatedIdp.setFederatedAuthenticatorConfigs(getFederatedAuthenticatorConfigs(dbConnection, idPName, federatedIdp, tenantId));
            if (defaultAuthenticatorName != null && federatedIdp.getFederatedAuthenticatorConfigs() != null) {
                federatedIdp.setDefaultAuthenticatorConfig(IdentityApplicationManagementUtil.getFederatedAuthenticator(federatedIdp.getFederatedAuthenticatorConfigs(), defaultAuthenticatorName));
            }
            if (federatedIdp.getClaimConfig().isLocalClaimDialect()) {
                federatedIdp.setClaimConfig(getLocalIdPDefaultClaimValues(dbConnection, idPName, userClaimUri, roleClaimUri, idpId, tenantId));
            } else {
                // get claim configuration.
                federatedIdp.setClaimConfig(getIdPClaimConfiguration(dbConnection, idPName, userClaimUri, roleClaimUri, idpId, tenantId));
            }
            // get provisioning connectors.
            federatedIdp.setProvisioningConnectorConfigs(getProvisioningConnectorConfigs(dbConnection, idPName, idpId, tenantId));
            // get permission and role configuration.
            federatedIdp.setPermissionAndRoleConfig(getPermissionsAndRoleConfiguration(dbConnection, idPName, idpId, tenantId));
            List<IdentityProviderProperty> propertyList = filterIdenityProperties(federatedIdp, getIdentityPropertiesByIdpId(dbConnection, idpId));
            if (IdentityApplicationConstants.RESIDENT_IDP_RESERVED_NAME.equals(idPName)) {
                propertyList = resolveConnectorProperties(propertyList, tenantDomain);
            }
            federatedIdp.setIdpProperties(propertyList.toArray(new IdentityProviderProperty[0]));
        }
        return federatedIdp;
    } catch (SQLException e) {
        throw new IdentityProviderManagementException("Error occurred while retrieving Identity Provider " + "information for tenant : " + tenantDomain + " and Identity Provider name : " + idPName, e);
    } catch (ConnectorException e) {
        throw new IdentityProviderManagementException("Error occurred while retrieving the identity connector " + "configurations.", e);
    } finally {
        if (dbConnectionInitialized) {
            IdentityDatabaseUtil.closeAllConnections(dbConnection, rs, prepStmt);
        } else {
            IdentityDatabaseUtil.closeAllConnections(null, rs, prepStmt);
        }
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) ClaimConfig(org.wso2.carbon.identity.application.common.model.ClaimConfig) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) JustInTimeProvisioningConfig(org.wso2.carbon.identity.application.common.model.JustInTimeProvisioningConfig) ConnectorException(org.wso2.carbon.identity.core.ConnectorException) ResultSet(java.sql.ResultSet) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException) ProvisioningConnectorConfig(org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)

Aggregations

ProvisioningConnectorConfig (org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)39 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)19 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)19 Property (org.wso2.carbon.identity.application.common.model.Property)19 ArrayList (java.util.ArrayList)17 IdentityProviderManagementException (org.wso2.carbon.idp.mgt.IdentityProviderManagementException)14 ClaimConfig (org.wso2.carbon.identity.application.common.model.ClaimConfig)10 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)10 ProvisioningConnectorConfig (org.wso2.carbon.identity.application.common.model.idp.xsd.ProvisioningConnectorConfig)10 PreparedStatement (java.sql.PreparedStatement)9 Property (org.wso2.carbon.identity.application.common.model.idp.xsd.Property)9 Test (org.testng.annotations.Test)8 Claim (org.wso2.carbon.identity.application.common.model.Claim)7 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)7 LocalRole (org.wso2.carbon.identity.application.common.model.LocalRole)7 PermissionsAndRoleConfig (org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig)7 RoleMapping (org.wso2.carbon.identity.application.common.model.RoleMapping)7 ResultSet (java.sql.ResultSet)6 HashMap (java.util.HashMap)6 JustInTimeProvisioningConfig (org.wso2.carbon.identity.application.common.model.JustInTimeProvisioningConfig)6