Search in sources :

Example 1 with IdentityProviderManager

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

the class ConfigurationFacade method getIdPConfigByName.

public ExternalIdPConfig getIdPConfigByName(String idpName, String tenantDomain) throws IdentityProviderManagementException {
    ExternalIdPConfig externalIdPConfig = null;
    IdentityProvider idpDO = null;
    if (log.isDebugEnabled()) {
        log.debug("Trying to find the IdP for name: " + idpName);
    }
    try {
        IdentityProviderManager idpManager = IdentityProviderManager.getInstance();
        idpDO = idpManager.getEnabledIdPByName(idpName, tenantDomain);
        if (idpDO != null) {
            if (log.isDebugEnabled()) {
                log.debug("A registered IdP was found");
            }
            externalIdPConfig = new ExternalIdPConfig(idpDO);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("A registered IdP was not found the given name");
            }
        }
    } catch (IdentityProviderManagementException e) {
        throw new IdentityProviderManagementException("Exception while getting IdP by name", e);
    }
    return externalIdPConfig;
}
Also used : IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) ExternalIdPConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.ExternalIdPConfig) IdentityProviderManager(org.wso2.carbon.idp.mgt.IdentityProviderManager) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException)

Example 2 with IdentityProviderManager

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

the class FrameworkUtils method getResidentIdpConfiguration.

/**
 * Get the configurations of a tenant from cache or database.
 *
 * @param tenantDomain Domain name of the tenant
 * @return Configurations belong to the tenant
 */
private static Property[] getResidentIdpConfiguration(String tenantDomain) throws FrameworkException {
    IdpManager identityProviderManager = IdentityProviderManager.getInstance();
    IdentityProvider residentIdp = null;
    try {
        residentIdp = identityProviderManager.getResidentIdP(tenantDomain);
    } catch (IdentityProviderManagementException e) {
        String errorMsg = String.format("Error while retrieving resident Idp for %s tenant.", tenantDomain);
        throw new FrameworkException(errorMsg, e);
    }
    IdentityProviderProperty[] identityMgtProperties = residentIdp.getIdpProperties();
    Property[] configMap = new Property[identityMgtProperties.length];
    int index = 0;
    for (IdentityProviderProperty identityMgtProperty : identityMgtProperties) {
        if (ALREADY_WRITTEN_PROPERTY.equals(identityMgtProperty.getName())) {
            continue;
        }
        Property property = new Property();
        property.setName(identityMgtProperty.getName());
        property.setValue(identityMgtProperty.getValue());
        configMap[index] = property;
        index++;
    }
    return configMap;
}
Also used : FrameworkException(org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) IdpManager(org.wso2.carbon.idp.mgt.IdpManager) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException) IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) Property(org.wso2.carbon.identity.application.common.model.Property)

Example 3 with IdentityProviderManager

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

the class IdentityProviderManager method deleteIdP.

/**
 * Deletes an Identity Provider from a given tenant
 *
 * @param idPName Name of the IdP to be deleted
 * @throws IdentityProviderManagementException Error when deleting Identity Provider
 *                                             information
 * @deprecated use {@link IdentityProviderManager#deleteIdPByResourceId(String, String)} instead.
 */
@Deprecated
@Override
public void deleteIdP(String idPName, String tenantDomain) throws IdentityProviderManagementException {
    // Invoking the pre listeners.
    Collection<IdentityProviderMgtListener> listeners = IdPManagementServiceComponent.getIdpMgtListeners();
    for (IdentityProviderMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPreDeleteIdP(idPName, tenantDomain)) {
            return;
        }
    }
    if (StringUtils.isEmpty(idPName)) {
        String data = "IdP name is empty.";
        throw IdPManagementUtil.handleClientException(IdPManagementConstants.ErrorMessage.ERROR_CODE_IDP_NAME_INVALID, data);
    }
    IdentityProvider identityProvider = this.getIdPByName(idPName, tenantDomain, true);
    if (identityProvider == null) {
        return;
    }
    deleteIDP(identityProvider.getResourceId(), idPName, tenantDomain);
    // Invoking the post listeners.
    for (IdentityProviderMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPostDeleteIdP(idPName, tenantDomain)) {
            return;
        }
    }
}
Also used : IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderMgtListener(org.wso2.carbon.idp.mgt.listener.IdentityProviderMgtListener)

Example 4 with IdentityProviderManager

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

the class IdentityProviderManager method forceDeleteIdp.

/**
 * 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 idpName      name of IDP to be deleted
 * @param tenantDomain tenantDomain to which the IDP belongs to
 * @deprecated use {@link IdentityProviderManager#forceDeleteIdpByResourceId(String, String)} instead.
 */
@Deprecated
public void forceDeleteIdp(String idpName, String tenantDomain) throws IdentityProviderManagementException {
    // Invoking the pre listeners.
    Collection<IdentityProviderMgtListener> listeners = IdPManagementServiceComponent.getIdpMgtListeners();
    for (IdentityProviderMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPreDeleteIdP(idpName, tenantDomain)) {
            return;
        }
    }
    IdentityProvider identityProvider = this.getIdPByName(idpName, tenantDomain, true);
    if (identityProvider == null) {
        throw IdPManagementUtil.handleClientException(IdPManagementConstants.ErrorMessage.ERROR_CODE_IDP_NAME_DOES_NOT_EXIST, idpName);
    }
    forceDeleteIDP(identityProvider.getResourceId(), idpName, tenantDomain);
    // Invoking the post listeners.
    for (IdentityProviderMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPostDeleteIdP(idpName, tenantDomain)) {
            return;
        }
    }
}
Also used : IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderMgtListener(org.wso2.carbon.idp.mgt.listener.IdentityProviderMgtListener)

Example 5 with IdentityProviderManager

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

the class IdPManagementServiceComponent method cleanUpRemovedIdps.

private void cleanUpRemovedIdps() {
    IdentityProviderManager idpManager = IdentityProviderManager.getInstance();
    String superTenantDN = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
    List<IdentityProvider> idPs;
    try {
        idPs = idpManager.getIdPs(superTenantDN);
    } catch (IdentityProviderManagementException e) {
        log.error("Error loading IDPs", e);
        return;
    }
    for (IdentityProvider idp : idPs) {
        if (isSharedIdP(idp) && !sharedIdps.contains(idp.getIdentityProviderName())) {
            // IDP config file has been deleted from filesystem
            try {
                idpManager.deleteIdP(idp.getIdentityProviderName(), superTenantDN);
                if (log.isDebugEnabled()) {
                    log.debug("Deleted shared IdP with the name : " + idp.getIdentityProviderName());
                }
            } catch (IdentityProviderManagementException e) {
                log.error("Error when deleting IdP " + idp.getIdentityProviderName(), e);
            }
        }
    }
}
Also used : IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderManager(org.wso2.carbon.idp.mgt.IdentityProviderManager) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException)

Aggregations

IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)27 IdentityProviderManagementException (org.wso2.carbon.idp.mgt.IdentityProviderManagementException)15 IdentityProviderManager (org.wso2.carbon.idp.mgt.IdentityProviderManager)13 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)11 ArrayList (java.util.ArrayList)7 Test (org.testng.annotations.Test)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)5 PostAuthnHandlerFlowStatus (org.wso2.carbon.identity.application.authentication.framework.handler.request.PostAuthnHandlerFlowStatus)5 HashMap (java.util.HashMap)4 SequenceConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)4 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)4 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)4 IdpManager (org.wso2.carbon.idp.mgt.IdpManager)4 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)3 IdentityProviderMgtListener (org.wso2.carbon.idp.mgt.listener.IdentityProviderMgtListener)3 UserRealm (org.wso2.carbon.user.core.UserRealm)3 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)3 RealmService (org.wso2.carbon.user.core.service.RealmService)3 ExternalIdPConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.ExternalIdPConfig)2