Search in sources :

Example 66 with Property

use of org.wso2.carbon.user.api.Property in project carbon-identity-framework by wso2.

the class IdentityProviderManager method buildSAMLProperties.

private FederatedAuthenticatorConfig buildSAMLProperties(IdentityProvider identityProvider, String tenantDomain) throws IdentityProviderManagementException {
    String samlSSOUrl = buildSAMLUrl(IdentityUtil.getProperty(IdentityConstants.ServerConfig.SSO_IDP_URL), tenantDomain, IdPManagementConstants.SAMLSSO, true);
    String samlLogoutUrl = buildSAMLUrl(IdentityUtil.getProperty(IdentityConstants.ServerConfig.SSO_IDP_URL), tenantDomain, IdPManagementConstants.SAMLSSO, true);
    String samlECPUrl = buildSAMLUrl(IdentityUtil.getProperty(IdentityConstants.ServerConfig.SAML_ECP_URL), tenantDomain, IdPManagementConstants.SAML_ECP_URL, true);
    String samlArtifactUrl = buildSAMLUrl(IdentityUtil.getProperty(IdentityConstants.ServerConfig.SSO_ARTIFACT_URL), tenantDomain, IdPManagementConstants.SSO_ARTIFACT_URL, false);
    FederatedAuthenticatorConfig samlFederatedAuthConfig = IdentityApplicationManagementUtil.getFederatedAuthenticator(identityProvider.getFederatedAuthenticatorConfigs(), IdentityApplicationConstants.Authenticator.SAML2SSO.NAME);
    if (samlFederatedAuthConfig == null) {
        samlFederatedAuthConfig = new FederatedAuthenticatorConfig();
        samlFederatedAuthConfig.setName(IdentityApplicationConstants.Authenticator.SAML2SSO.NAME);
    }
    List<Property> propertiesList = new ArrayList<>();
    Property samlSSOUrlProperty = resolveFedAuthnProperty(samlSSOUrl, samlFederatedAuthConfig, IdentityApplicationConstants.Authenticator.SAML2SSO.SSO_URL);
    propertiesList.add(samlSSOUrlProperty);
    Property samlLogoutUrlProperty = resolveFedAuthnProperty(samlLogoutUrl, samlFederatedAuthConfig, IdentityApplicationConstants.Authenticator.SAML2SSO.LOGOUT_REQ_URL);
    propertiesList.add(samlLogoutUrlProperty);
    Property samlECPUrlProperty = resolveFedAuthnProperty(samlECPUrl, samlFederatedAuthConfig, IdentityApplicationConstants.Authenticator.SAML2SSO.ECP_URL);
    propertiesList.add(samlECPUrlProperty);
    Property samlArtifactUrlProperty = resolveFedAuthnProperty(samlArtifactUrl, samlFederatedAuthConfig, IdentityApplicationConstants.Authenticator.SAML2SSO.ARTIFACT_RESOLVE_URL);
    propertiesList.add(samlArtifactUrlProperty);
    Property idPEntityIdProperty = IdentityApplicationManagementUtil.getProperty(samlFederatedAuthConfig.getProperties(), IdentityApplicationConstants.Authenticator.SAML2SSO.IDP_ENTITY_ID);
    if (idPEntityIdProperty == null) {
        idPEntityIdProperty = new Property();
        idPEntityIdProperty.setName(IdentityApplicationConstants.Authenticator.SAML2SSO.IDP_ENTITY_ID);
        idPEntityIdProperty.setValue(IdPManagementUtil.getResidentIdPEntityId());
    }
    propertiesList.add(idPEntityIdProperty);
    if (IdentityTenantUtil.isTenantQualifiedUrlsEnabled()) {
        // Add SSO URL as a destination URL if not already available.
        addSSOUrlAsDestinationUrl(samlFederatedAuthConfig, samlSSOUrl, propertiesList);
    }
    for (Property property : samlFederatedAuthConfig.getProperties()) {
        if (property != null && !IdentityApplicationConstants.Authenticator.SAML2SSO.SSO_URL.equals(property.getName()) && !IdentityApplicationConstants.Authenticator.SAML2SSO.LOGOUT_REQ_URL.equals(property.getName()) && !IdentityApplicationConstants.Authenticator.SAML2SSO.ECP_URL.equals(property.getName()) && !IdentityApplicationConstants.Authenticator.SAML2SSO.IDP_ENTITY_ID.equals(property.getName())) {
            propertiesList.add(property);
        }
    }
    Property samlMetadataValidityPeriodProperty = IdentityApplicationManagementUtil.getProperty(samlFederatedAuthConfig.getProperties(), IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_VALIDITY_PERIOD);
    if (samlMetadataValidityPeriodProperty == null) {
        samlMetadataValidityPeriodProperty = new Property();
        samlMetadataValidityPeriodProperty.setName(IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_VALIDITY_PERIOD);
        samlMetadataValidityPeriodProperty.setValue(IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_VALIDITY_PERIOD_DEFAULT);
    }
    propertiesList.add(samlMetadataValidityPeriodProperty);
    Property samlMetadataSigningEnabledProperty = IdentityApplicationManagementUtil.getProperty(samlFederatedAuthConfig.getProperties(), IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_SIGNING_ENABLED);
    if (samlMetadataSigningEnabledProperty == null) {
        samlMetadataSigningEnabledProperty = new Property();
        samlMetadataSigningEnabledProperty.setName(IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_SIGNING_ENABLED);
        samlMetadataSigningEnabledProperty.setValue(IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_SIGNING_ENABLED_DEFAULT);
    }
    propertiesList.add(samlMetadataSigningEnabledProperty);
    Property samlAuthnRequestSigningProperty = IdentityApplicationManagementUtil.getProperty(samlFederatedAuthConfig.getProperties(), IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_AUTHN_REQUESTS_SIGNING_ENABLED);
    if (samlAuthnRequestSigningProperty == null) {
        samlAuthnRequestSigningProperty = new Property();
        samlAuthnRequestSigningProperty.setName(IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_AUTHN_REQUESTS_SIGNING_ENABLED);
        samlAuthnRequestSigningProperty.setValue(IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_AUTHN_REQUESTS_SIGNING_DEFAULT);
    }
    propertiesList.add(samlAuthnRequestSigningProperty);
    samlFederatedAuthConfig.setProperties(propertiesList.toArray(new Property[propertiesList.size()]));
    return samlFederatedAuthConfig;
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) ArrayList(java.util.ArrayList) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) Property(org.wso2.carbon.identity.application.common.model.Property)

Example 67 with Property

use of org.wso2.carbon.user.api.Property in project carbon-identity-framework by wso2.

the class IdentityProviderManager method handleMetadata.

/**
 * If metadata file is available, creates a new FederatedAuthenticatorConfig from that
 *
 * @param identityProvider
 * @throws IdentityProviderManagementException
 */
private void handleMetadata(int tenantId, IdentityProvider identityProvider) throws IdentityProviderManagementException {
    if (IdpMgtServiceComponentHolder.getInstance().getMetadataConverters().isEmpty()) {
        throw new IdentityProviderManagementException("Metadata Converter is not set");
    }
    FederatedAuthenticatorConfig[] federatedAuthenticatorConfigs = identityProvider.getFederatedAuthenticatorConfigs();
    for (FederatedAuthenticatorConfig federatedAuthenticatorConfig : federatedAuthenticatorConfigs) {
        Property[] properties = federatedAuthenticatorConfig.getProperties();
        if (ArrayUtils.isNotEmpty(properties)) {
            for (Property property : properties) {
                if (property != null) {
                    if (StringUtils.isNotBlank(property.getName()) && property.getName().contains(IdPManagementConstants.META_DATA)) {
                        for (MetadataConverter metadataConverter : IdpMgtServiceComponentHolder.getInstance().getMetadataConverters()) {
                            if (metadataConverter.canHandle(property)) {
                                try {
                                    if (isMetadataFileExist(identityProvider.getIdentityProviderName(), property.getValue())) {
                                        try {
                                            metadataConverter.saveMetadataString(tenantId, identityProvider.getIdentityProviderName(), federatedAuthenticatorConfig.getName(), property.getValue());
                                        } catch (IdentityProviderManagementException e) {
                                            String data = "Couldn't save metadata in registry.SAML2SSOMetadataConverter" + " is not set. ";
                                            throw IdPManagementUtil.handleServerException(IdPManagementConstants.ErrorMessage.ERROR_CODE_ADD_IDP, data);
                                        }
                                    }
                                    StringBuilder certificate = new StringBuilder();
                                    try {
                                        FederatedAuthenticatorConfig metaFederated = metadataConverter.getFederatedAuthenticatorConfig(properties, certificate);
                                        String spName = "";
                                        for (Property value : properties) {
                                            if (value != null && IdentityApplicationConstants.Authenticator.SAML2SSO.SP_ENTITY_ID.equals(value.getName())) {
                                                spName = value.getValue();
                                            }
                                        }
                                        if (spName.equals("")) {
                                            throw new IdentityProviderManagementException("SP name can't be empty");
                                        }
                                        if (metaFederated != null && ArrayUtils.isNotEmpty(metaFederated.getProperties())) {
                                            for (int y = 0; y < metaFederated.getProperties().length; y++) {
                                                if (metaFederated.getProperties()[y] != null && IdentityApplicationConstants.Authenticator.SAML2SSO.SP_ENTITY_ID.equals(metaFederated.getProperties()[y].getName())) {
                                                    metaFederated.getProperties()[y].setValue(spName);
                                                    break;
                                                }
                                            }
                                        }
                                        if (metaFederated != null && ArrayUtils.isNotEmpty(metaFederated.getProperties())) {
                                            federatedAuthenticatorConfig.setProperties(metaFederated.getProperties());
                                        } else {
                                            throw new IdentityProviderManagementException("Error setting metadata using file");
                                        }
                                    } catch (IdentityProviderManagementException ex) {
                                        throw new IdentityProviderManagementException("Error converting metadata", ex);
                                    }
                                    if (certificate.toString().length() > 0) {
                                        identityProvider.setCertificate(certificate.toString());
                                    }
                                } catch (XMLStreamException e) {
                                    throw new IdentityProviderManagementException("Error while configuring metadata", e);
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) MetadataConverter(org.wso2.carbon.idp.mgt.util.MetadataConverter) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) Property(org.wso2.carbon.identity.application.common.model.Property)

Example 68 with Property

use of org.wso2.carbon.user.api.Property in project carbon-identity-framework by wso2.

the class FileBasedIdPMgtDAO method getIdPByAuthenticatorPropertyValue.

public IdentityProvider getIdPByAuthenticatorPropertyValue(String property, String value, String tenantDomain, String authenticatorName) {
    Map<String, IdentityProvider> identityProviders = IdPManagementServiceComponent.getFileBasedIdPs();
    for (Entry<String, IdentityProvider> entry : identityProviders.entrySet()) {
        FederatedAuthenticatorConfig[] federatedAuthenticatorConfigs = entry.getValue().getFederatedAuthenticatorConfigs();
        // Get SAML2 Web SSO authenticator
        FederatedAuthenticatorConfig samlAuthenticatorConfig = IdentityApplicationManagementUtil.getFederatedAuthenticator(federatedAuthenticatorConfigs, authenticatorName);
        if (samlAuthenticatorConfig != null) {
            Property samlProperty = IdentityApplicationManagementUtil.getProperty(samlAuthenticatorConfig.getProperties(), property);
            if (samlProperty != null) {
                if (value.equalsIgnoreCase(samlProperty.getValue())) {
                    return entry.getValue();
                }
            }
        }
    }
    return null;
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) Property(org.wso2.carbon.identity.application.common.model.Property) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)

Example 69 with Property

use of org.wso2.carbon.user.api.Property in project carbon-identity-framework by wso2.

the class IdPManagementDAO method buildTemplateIdProperty.

/**
 * Build templateId property for the IDP.
 *
 * @param identityProvider Identity provider.
 * @return templateId IdentityProviderProperty.
 */
private IdentityProviderProperty buildTemplateIdProperty(IdentityProvider identityProvider) {
    IdentityProviderProperty templateIdProperty = new IdentityProviderProperty();
    templateIdProperty.setName(TEMPLATE_ID_IDP_PROPERTY_NAME);
    templateIdProperty.setDisplayName(TEMPLATE_ID_IDP_PROPERTY_DISPLAY_NAME);
    templateIdProperty.setValue(StringUtils.isNotBlank(identityProvider.getTemplateId()) ? identityProvider.getTemplateId() : StringUtils.EMPTY);
    return templateIdProperty;
}
Also used : IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)

Example 70 with Property

use of org.wso2.carbon.user.api.Property in project carbon-identity-framework by wso2.

the class IdPManagementDAO method updateProvisioningConfigProperty.

private void updateProvisioningConfigProperty(ProvisioningConnectorConfig[] provisioningConnectors, Connection dbConnection, int idpId, int tenantId) throws IdentityProviderManagementException, SQLException {
    String sqlStmt = IdPManagementConstants.SQLQueries.UPDATE_IDP_PROVISIONING_CONFIG_PROPERTY_SQL;
    try (PreparedStatement prepStmt = dbConnection.prepareStatement(sqlStmt)) {
        for (ProvisioningConnectorConfig connector : provisioningConnectors) {
            if (isProvisioningConfigAvailableToUpdate(connector, dbConnection, idpId, tenantId)) {
                updateProvisioningConfig(connector, dbConnection, idpId, tenantId);
                Property[] connectorProperties = connector.getProvisioningProperties();
                if (connectorProperties != null && connectorProperties.length > 0) {
                    for (Property config : connectorProperties) {
                        if (config == null) {
                            continue;
                        }
                        prepStmt.setString(1, config.getName());
                        if (IdentityApplicationConstants.ConfigElements.PROPERTY_TYPE_BLOB.equals(config.getType())) {
                            prepStmt.setString(2, null);
                            setBlobValue(config.getValue(), prepStmt, 3);
                            prepStmt.setString(4, config.getType());
                        } else {
                            prepStmt.setString(2, config.getValue());
                            setBlobValue(null, prepStmt, 3);
                            prepStmt.setString(4, IdentityApplicationConstants.ConfigElements.PROPERTY_TYPE_STRING);
                        }
                        if (config.isConfidential()) {
                            prepStmt.setString(5, IdPManagementConstants.IS_TRUE_VALUE);
                        } else {
                            prepStmt.setString(5, IdPManagementConstants.IS_FALSE_VALUE);
                        }
                        prepStmt.setInt(6, idpId);
                        prepStmt.setInt(7, tenantId);
                        prepStmt.setString(8, connector.getName());
                        prepStmt.setInt(9, tenantId);
                        prepStmt.setString(10, config.getName());
                        prepStmt.executeUpdate();
                    }
                }
            } else {
                addProvisioningConnectorConfigs(new ProvisioningConnectorConfig[] { connector }, dbConnection, idpId, tenantId);
            }
        }
    } catch (IOException e) {
        throw new IdentityProviderManagementException("An error occurred when processing content stream while " + "updating provisioning config properties of Identity Provider : " + idpId, e);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) Property(org.wso2.carbon.identity.application.common.model.Property) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException) ProvisioningConnectorConfig(org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)

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