Search in sources :

Example 11 with IdentityProviderMgtListener

use of org.wso2.carbon.idp.mgt.listener.IdentityProviderMgtListener in project carbon-identity-framework by wso2.

the class IdentityProviderManager method updateIdP.

/**
 * Updates a given Identity Provider information
 *
 * @param oldIdPName          existing Identity Provider name
 * @param newIdentityProvider new IdP information
 * @throws IdentityProviderManagementException Error when updating Identity Provider
 *                                             information
 * @deprecated use {@link IdentityProviderManager#updateIdPByResourceId(String, IdentityProvider, String)} instead.
 */
@Deprecated
@Override
public void updateIdP(String oldIdPName, IdentityProvider newIdentityProvider, String tenantDomain) throws IdentityProviderManagementException {
    // Invoking the pre listeners.
    Collection<IdentityProviderMgtListener> listeners = IdPManagementServiceComponent.getIdpMgtListeners();
    for (IdentityProviderMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPreUpdateIdP(oldIdPName, newIdentityProvider, tenantDomain)) {
            return;
        }
    }
    IdentityProvider currentIdentityProvider = this.getIdPByName(oldIdPName, tenantDomain, true);
    if (currentIdentityProvider == null) {
        throw IdPManagementUtil.handleClientException(IdPManagementConstants.ErrorMessage.ERROR_CODE_IDP_NAME_DOES_NOT_EXIST, oldIdPName);
    }
    updateIDP(currentIdentityProvider, newIdentityProvider, IdentityTenantUtil.getTenantId(tenantDomain), tenantDomain);
    // Invoking the post listeners.
    for (IdentityProviderMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPostUpdateIdP(oldIdPName, newIdentityProvider, tenantDomain)) {
            return;
        }
    }
}
Also used : IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderMgtListener(org.wso2.carbon.idp.mgt.listener.IdentityProviderMgtListener)

Example 12 with IdentityProviderMgtListener

use of org.wso2.carbon.idp.mgt.listener.IdentityProviderMgtListener in project carbon-identity-framework by wso2.

the class IdentityProviderManager method addResidentIdP.

/**
 * Add Resident Identity provider for a given tenant.
 *
 * @param identityProvider <code>IdentityProvider</code>
 * @param tenantDomain     Tenant domain whose resident IdP is requested
 * @throws IdentityProviderManagementException Error when adding Resident Identity Provider
 */
@Override
public void addResidentIdP(IdentityProvider identityProvider, String tenantDomain) throws IdentityProviderManagementException {
    // invoking the pre listeners
    Collection<IdentityProviderMgtListener> listeners = IdPManagementServiceComponent.getIdpMgtListeners();
    for (IdentityProviderMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPreAddResidentIdP(identityProvider, tenantDomain)) {
            return;
        }
    }
    if (identityProvider.getFederatedAuthenticatorConfigs() == null) {
        identityProvider.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[0]);
    }
    FederatedAuthenticatorConfig saml2SSOResidentAuthenticatorConfig = IdentityApplicationManagementUtil.getFederatedAuthenticator(identityProvider.getFederatedAuthenticatorConfigs(), IdentityApplicationConstants.Authenticator.SAML2SSO.NAME);
    if (saml2SSOResidentAuthenticatorConfig == null) {
        saml2SSOResidentAuthenticatorConfig = new FederatedAuthenticatorConfig();
        saml2SSOResidentAuthenticatorConfig.setName(IdentityApplicationConstants.Authenticator.SAML2SSO.NAME);
    }
    if (saml2SSOResidentAuthenticatorConfig.getProperties() == null) {
        saml2SSOResidentAuthenticatorConfig.setProperties(new Property[0]);
    }
    boolean idPEntityIdAvailable = false;
    for (Property property : saml2SSOResidentAuthenticatorConfig.getProperties()) {
        if (IdentityApplicationConstants.Authenticator.SAML2SSO.IDP_ENTITY_ID.equals(property.getName())) {
            idPEntityIdAvailable = true;
        }
    }
    if (!idPEntityIdAvailable) {
        Property property = new Property();
        property.setName(IdentityApplicationConstants.Authenticator.SAML2SSO.IDP_ENTITY_ID);
        int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
        if (tenantId != MultitenantConstants.SUPER_TENANT_ID && IdentityTenantUtil.isTenantQualifiedUrlsEnabled()) {
            property.setValue(IdPManagementUtil.getResidentIdPEntityId() + "/t/" + tenantDomain);
        } else {
            property.setValue(IdPManagementUtil.getResidentIdPEntityId());
        }
        if (saml2SSOResidentAuthenticatorConfig.getProperties().length > 0) {
            List<Property> properties = Arrays.asList(saml2SSOResidentAuthenticatorConfig.getProperties());
            properties.add(property);
            saml2SSOResidentAuthenticatorConfig.setProperties((Property[]) properties.toArray());
        } else {
            saml2SSOResidentAuthenticatorConfig.setProperties(new Property[] { property });
        }
    }
    Property samlMetadataValidityPeriodProperty = new Property();
    String samlMetadataValidityPeriod = IdentityUtil.getProperty(IdentityConstants.ServerConfig.SAML_METADATA_VALIDITY_PERIOD);
    if (StringUtils.isBlank(samlMetadataValidityPeriod)) {
        samlMetadataValidityPeriod = IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_VALIDITY_PERIOD_DEFAULT;
    } else if (!StringUtils.isNumeric(samlMetadataValidityPeriod) || Integer.parseInt(samlMetadataValidityPeriod) <= 0) {
        log.warn("SAMLMetadataValidityPeriod in identity.xml should be a numeric value " + "hence defaulting to value: " + IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_VALIDITY_PERIOD_DEFAULT + "m");
        samlMetadataValidityPeriod = IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_VALIDITY_PERIOD_DEFAULT;
    }
    samlMetadataValidityPeriodProperty.setName(IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_VALIDITY_PERIOD);
    samlMetadataValidityPeriodProperty.setValue(samlMetadataValidityPeriod);
    Property samlMetadataSigningEnabledProperty = new Property();
    String samlMetadataSigningEnabled = IdentityUtil.getProperty(IdentityConstants.ServerConfig.SAML_METADATA_SIGNING_ENABLED);
    if (StringUtils.isBlank(samlMetadataSigningEnabled)) {
        log.warn("SAMLMetadataSigningEnabled in identity.xml should be a boolean value");
        samlMetadataSigningEnabled = IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_SIGNING_ENABLED_DEFAULT;
    }
    samlMetadataSigningEnabledProperty.setName(IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_SIGNING_ENABLED);
    samlMetadataSigningEnabledProperty.setValue(samlMetadataSigningEnabled);
    Property samlAuthnRequestSigningProperty = new Property();
    String samlAuthnRequestSigningEnabled = IdentityUtil.getProperty(IdentityConstants.ServerConfig.SAML_METADATA_AUTHN_REQUESTS_SIGNING_ENABLED);
    if (StringUtils.isBlank(samlAuthnRequestSigningEnabled)) {
        log.warn("samlAuthnRequestSigningEnabled in identity.xml should be a boolean value");
        samlAuthnRequestSigningEnabled = IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_AUTHN_REQUESTS_SIGNING_DEFAULT;
    }
    samlAuthnRequestSigningProperty.setName(IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_AUTHN_REQUESTS_SIGNING_ENABLED);
    samlAuthnRequestSigningProperty.setValue(samlAuthnRequestSigningEnabled);
    List<Property> propertyList = new ArrayList<>(Arrays.asList(saml2SSOResidentAuthenticatorConfig.getProperties()));
    propertyList.add(samlMetadataValidityPeriodProperty);
    propertyList.add(samlMetadataSigningEnabledProperty);
    propertyList.add(samlAuthnRequestSigningProperty);
    Property[] properties = new Property[propertyList.size()];
    properties = propertyList.toArray(properties);
    saml2SSOResidentAuthenticatorConfig.setProperties(properties);
    Property oidcProperty = new Property();
    oidcProperty.setName(OPENID_IDP_ENTITY_ID);
    oidcProperty.setValue(getOIDCResidentIdPEntityId());
    FederatedAuthenticatorConfig oidcAuthenticationConfig = new FederatedAuthenticatorConfig();
    oidcAuthenticationConfig.setProperties(new Property[] { oidcProperty });
    oidcAuthenticationConfig.setName(IdentityApplicationConstants.Authenticator.OIDC.NAME);
    Property passiveStsProperty = new Property();
    passiveStsProperty.setName(IdentityApplicationConstants.Authenticator.PassiveSTS.IDENTITY_PROVIDER_ENTITY_ID);
    passiveStsProperty.setValue(IdPManagementUtil.getResidentIdPEntityId());
    FederatedAuthenticatorConfig passiveStsAuthenticationConfig = new FederatedAuthenticatorConfig();
    passiveStsAuthenticationConfig.setProperties(new Property[] { passiveStsProperty });
    passiveStsAuthenticationConfig.setName(IdentityApplicationConstants.Authenticator.PassiveSTS.NAME);
    FederatedAuthenticatorConfig[] federatedAuthenticatorConfigs = { saml2SSOResidentAuthenticatorConfig, passiveStsAuthenticationConfig, oidcAuthenticationConfig };
    identityProvider.setFederatedAuthenticatorConfigs(IdentityApplicationManagementUtil.concatArrays(identityProvider.getFederatedAuthenticatorConfigs(), federatedAuthenticatorConfigs));
    IdentityProviderProperty[] idpProperties = new IdentityProviderProperty[2];
    IdentityProviderProperty rememberMeTimeoutProperty = new IdentityProviderProperty();
    String rememberMeTimeout = IdentityUtil.getProperty(IdentityConstants.ServerConfig.REMEMBER_ME_TIME_OUT);
    if (StringUtils.isBlank(rememberMeTimeout) || !StringUtils.isNumeric(rememberMeTimeout) || Integer.parseInt(rememberMeTimeout) <= 0) {
        log.warn("RememberMeTimeout in identity.xml should be a numeric value");
        rememberMeTimeout = IdentityApplicationConstants.REMEMBER_ME_TIME_OUT_DEFAULT;
    }
    rememberMeTimeoutProperty.setName(IdentityApplicationConstants.REMEMBER_ME_TIME_OUT);
    rememberMeTimeoutProperty.setValue(rememberMeTimeout);
    IdentityProviderProperty sessionIdletimeOutProperty = new IdentityProviderProperty();
    String idleTimeout = IdentityUtil.getProperty(IdentityConstants.ServerConfig.SESSION_IDLE_TIMEOUT);
    if (StringUtils.isBlank(idleTimeout) || !StringUtils.isNumeric(idleTimeout) || Integer.parseInt(idleTimeout) <= 0) {
        log.warn("SessionIdleTimeout in identity.xml should be a numeric value");
        idleTimeout = IdentityApplicationConstants.SESSION_IDLE_TIME_OUT_DEFAULT;
    }
    sessionIdletimeOutProperty.setName(IdentityApplicationConstants.SESSION_IDLE_TIME_OUT);
    sessionIdletimeOutProperty.setValue(idleTimeout);
    idpProperties[0] = rememberMeTimeoutProperty;
    idpProperties[1] = sessionIdletimeOutProperty;
    identityProvider.setIdpProperties(idpProperties);
    dao.addIdP(identityProvider, IdentityTenantUtil.getTenantId(tenantDomain), tenantDomain);
    // invoking the post listeners
    for (IdentityProviderMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPostAddResidentIdP(identityProvider, tenantDomain)) {
            return;
        }
    }
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) ArrayList(java.util.ArrayList) IdentityProviderMgtListener(org.wso2.carbon.idp.mgt.listener.IdentityProviderMgtListener) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) Property(org.wso2.carbon.identity.application.common.model.Property)

Aggregations

IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)10 IdentityProviderMgtListener (org.wso2.carbon.idp.mgt.listener.IdentityProviderMgtListener)10 ArrayList (java.util.ArrayList)2 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)1 Property (org.wso2.carbon.identity.application.common.model.Property)1