Search in sources :

Example 6 with IdentityProviderMgtListener

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

the class IdentityProviderNameResolverListener method doPreDeleteIdPByResourceId.

public boolean doPreDeleteIdPByResourceId(String resourceId, String tenantDomain) throws IdentityProviderManagementException {
    // Get IDP by resourceId.
    IdentityProvider idp = dao.getIdPByResourceId(resourceId, IdentityTenantUtil.getTenantId(tenantDomain), tenantDomain);
    if (idp != null) {
        String idpName = idp.getIdentityProviderName();
        // Invoking the pre-delete listeners.
        Collection<IdentityProviderMgtListener> listeners = IdPManagementServiceComponent.getIdpMgtListeners();
        for (IdentityProviderMgtListener listener : listeners) {
            if (listener.isEnable() && !listener.doPreDeleteIdP(idpName, tenantDomain)) {
                return false;
            }
        }
    }
    return true;
}
Also used : IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider)

Example 7 with IdentityProviderMgtListener

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

the class IdentityProviderNameResolverListener method doPreUpdateIdPByResourceId.

public boolean doPreUpdateIdPByResourceId(String resourceId, IdentityProvider identityProvider, String tenantDomain) throws IdentityProviderManagementException {
    int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
    IdentityProvider idp = dao.getIdPByResourceId(resourceId, tenantId, tenantDomain);
    if (idp != null) {
        String oldIdPName = idp.getIdentityProviderName();
        // invoking the pre listeners
        Collection<IdentityProviderMgtListener> listeners = IdPManagementServiceComponent.getIdpMgtListeners();
        for (IdentityProviderMgtListener listener : listeners) {
            if (listener.isEnable() && !listener.doPreUpdateIdP(oldIdPName, identityProvider, tenantDomain)) {
                return false;
            }
        }
    }
    return true;
}
Also used : IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider)

Example 8 with IdentityProviderMgtListener

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

the class IdentityProviderManager method updateResidentIdP.

/**
 * Update 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 updating Resident Identity Provider
 */
@Override
public void updateResidentIdP(IdentityProvider identityProvider, String tenantDomain) throws IdentityProviderManagementException {
    IdentityProvider residentIdp = dao.getIdPByName(null, IdentityApplicationConstants.RESIDENT_IDP_RESERVED_NAME, IdentityTenantUtil.getTenantId(tenantDomain), tenantDomain);
    Map<String, String> configurationDetails = new HashMap<>();
    for (IdentityProviderProperty property : identityProvider.getIdpProperties()) {
        configurationDetails.put(property.getName(), property.getValue());
    }
    IdentityProviderProperty[] identityMgtProperties = residentIdp.getIdpProperties();
    List<IdentityProviderProperty> newProperties = new ArrayList<>();
    for (IdentityProviderProperty identityMgtProperty : identityMgtProperties) {
        IdentityProviderProperty prop = new IdentityProviderProperty();
        String key = identityMgtProperty.getName();
        prop.setName(key);
        if (configurationDetails.containsKey(key)) {
            prop.setValue(configurationDetails.get(key));
        } else {
            prop.setValue(identityMgtProperty.getValue());
        }
        newProperties.add(prop);
        configurationDetails.remove(key);
    }
    for (Map.Entry<String, String> entry : configurationDetails.entrySet()) {
        IdentityProviderProperty prop = new IdentityProviderProperty();
        prop.setName(entry.getKey());
        prop.setValue(entry.getValue());
        newProperties.add(prop);
    }
    identityProvider.setIdpProperties(newProperties.toArray(new IdentityProviderProperty[newProperties.size()]));
    for (IdentityProviderProperty idpProp : identityProvider.getIdpProperties()) {
        if (StringUtils.equals(idpProp.getName(), IdentityApplicationConstants.SESSION_IDLE_TIME_OUT)) {
            if (StringUtils.isBlank(idpProp.getValue()) || !StringUtils.isNumeric(idpProp.getValue()) || Integer.parseInt(idpProp.getValue().trim()) <= 0) {
                throw new IdentityProviderManagementException(IdentityApplicationConstants.SESSION_IDLE_TIME_OUT + " of ResidentIdP should be a numeric value greater than 0 ");
            }
        } else if (StringUtils.equals(idpProp.getName(), IdentityApplicationConstants.REMEMBER_ME_TIME_OUT)) {
            if (StringUtils.isBlank(idpProp.getValue()) || !StringUtils.isNumeric(idpProp.getValue()) || Integer.parseInt(idpProp.getValue().trim()) <= 0) {
                throw new IdentityProviderManagementException(IdentityApplicationConstants.REMEMBER_ME_TIME_OUT + " of ResidentIdP should be a numeric value greater than 0 ");
            }
        } else if (StringUtils.equals(idpProp.getName(), IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_VALIDITY_PERIOD)) {
            if (StringUtils.isBlank(idpProp.getValue()) || !StringUtils.isNumeric(idpProp.getValue()) || Integer.parseInt(idpProp.getValue().trim()) <= 0) {
                throw new IdentityProviderManagementException(IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_VALIDITY_PERIOD + " of ResidentIdP should be a numeric value greater than 0 ");
            }
        } else if (StringUtils.equals(idpProp.getName(), IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_SIGNING_ENABLED)) {
            if (StringUtils.isBlank(idpProp.getValue())) {
                throw new IdentityProviderManagementException(IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_SIGNING_ENABLED + " of ResidentIdP should be a boolean value ");
            } else if (StringUtils.equals(idpProp.getName(), IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_AUTHN_REQUESTS_SIGNING_ENABLED)) {
                if (StringUtils.isBlank(idpProp.getValue())) {
                    throw new IdentityProviderManagementException(IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_AUTHN_REQUESTS_SIGNING_ENABLED + " of ResidentIdP should be a boolean value ");
                }
            }
        }
    }
    // invoking the pre listeners
    Collection<IdentityProviderMgtListener> listeners = IdPManagementServiceComponent.getIdpMgtListeners();
    for (IdentityProviderMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPreUpdateResidentIdP(identityProvider, tenantDomain)) {
            return;
        }
    }
    if (identityProvider.getFederatedAuthenticatorConfigs() == null) {
        identityProvider.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[0]);
    }
    IdentityProvider currentIdP = IdentityProviderManager.getInstance().getIdPByName(IdentityApplicationConstants.RESIDENT_IDP_RESERVED_NAME, tenantDomain, true);
    int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
    validateUpdateOfIdPEntityId(currentIdP.getFederatedAuthenticatorConfigs(), identityProvider.getFederatedAuthenticatorConfigs(), tenantId, tenantDomain);
    dao.updateIdP(identityProvider, currentIdP, tenantId, tenantDomain);
    // invoking the post listeners
    for (IdentityProviderMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPostUpdateResidentIdP(identityProvider, tenantDomain)) {
            return;
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderMgtListener(org.wso2.carbon.idp.mgt.listener.IdentityProviderMgtListener) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) Map(java.util.Map) HashMap(java.util.HashMap)

Example 9 with IdentityProviderMgtListener

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

the class IdentityProviderManager method forceDeleteIdpByResourceId.

/**
 * Force delete an Identity Provider from a given tenant. This will remove any associations this Identity
 * Provider has with any Service Providers in authentication steps or provisioning.
 *
 * @param resourceId   resource ID of IDP to be deleted
 * @param tenantDomain tenantDomain to which the IDP belongs to
 */
public void forceDeleteIdpByResourceId(String resourceId, String tenantDomain) throws IdentityProviderManagementException {
    // Invoking the pre listeners
    Collection<IdentityProviderMgtListener> listeners = IdPManagementServiceComponent.getIdpMgtListeners();
    for (IdentityProviderMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPreDeleteIdPByResourceId(resourceId, tenantDomain)) {
            return;
        }
    }
    IdentityProvider identityProvider = getIdPByResourceId(resourceId, tenantDomain, true);
    if (identityProvider == null) {
        throw IdPManagementUtil.handleClientException(IdPManagementConstants.ErrorMessage.ERROR_CODE_IDP_DOES_NOT_EXIST, resourceId);
    }
    forceDeleteIDP(resourceId, identityProvider.getIdentityProviderName(), tenantDomain);
    // Invoking the post listeners
    for (IdentityProviderMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPostDeleteIdPByResourceId(resourceId, identityProvider, tenantDomain)) {
            return;
        }
    }
}
Also used : IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderMgtListener(org.wso2.carbon.idp.mgt.listener.IdentityProviderMgtListener)

Example 10 with IdentityProviderMgtListener

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

the class IdentityProviderManager method addIdPWithResourceId.

/**
 * Adds an Identity Provider to the given tenant
 *
 * @param identityProvider new Identity Provider information
 * @throws IdentityProviderManagementException Error when adding Identity Provider
 *                                             information
 */
@Override
public IdentityProvider addIdPWithResourceId(IdentityProvider identityProvider, String tenantDomain) throws IdentityProviderManagementException {
    validateAddIdPInputValues(identityProvider.getIdentityProviderName(), tenantDomain);
    validateOutboundProvisioningRoles(identityProvider, tenantDomain);
    // Invoking the pre listeners.
    Collection<IdentityProviderMgtListener> listeners = IdPManagementServiceComponent.getIdpMgtListeners();
    for (IdentityProviderMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPreAddIdP(identityProvider, tenantDomain)) {
            return null;
        }
    }
    int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
    if (isPermissionAndRoleConfigExist(identityProvider)) {
        verifyAndUpdateRoleConfiguration(tenantDomain, tenantId, identityProvider.getPermissionAndRoleConfig());
    }
    validateIdPEntityId(identityProvider.getFederatedAuthenticatorConfigs(), tenantId, tenantDomain);
    validateIdPIssuerName(identityProvider, tenantId, tenantDomain);
    handleMetadata(tenantId, identityProvider);
    String resourceId = dao.addIdP(identityProvider, tenantId, tenantDomain);
    identityProvider = dao.getIdPByResourceId(resourceId, tenantId, tenantDomain);
    // invoking the post listeners
    for (IdentityProviderMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPostAddIdP(identityProvider, tenantDomain)) {
            return null;
        }
    }
    return identityProvider;
}
Also used : IdentityProviderMgtListener(org.wso2.carbon.idp.mgt.listener.IdentityProviderMgtListener)

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