Search in sources :

Example 21 with IdentityProviderManager

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

the class ApplicationIdentityProviderMgtListener method doPreUpdateIdP.

@Override
public boolean doPreUpdateIdP(String oldIdPName, IdentityProvider identityProvider, String tenantDomain) throws IdentityProviderManagementException {
    try {
        IdentityServiceProviderCache.getInstance().clear(tenantDomain);
        IdentityProviderManager identityProviderManager = IdentityProviderManager.getInstance();
        ConnectedAppsResult connectedApplications;
        String idpId = identityProviderManager.getIdPByName(oldIdPName, tenantDomain).getResourceId();
        if (identityProvider.getResourceId() == null && idpId != null) {
            identityProvider.setResourceId(idpId);
        }
        int offset = 0;
        do {
            connectedApplications = identityProviderManager.getConnectedApplications(idpId, null, offset, tenantDomain);
            List<ServiceProvider> serviceProvidersList = new ArrayList<>();
            for (String appResourceId : connectedApplications.getApps()) {
                ServiceProvider serviceProvider = ApplicationMgtSystemConfig.getInstance().getApplicationDAO().getApplicationByResourceId(appResourceId, tenantDomain);
                serviceProvidersList.add(serviceProvider);
            }
            for (ServiceProvider serviceProvider : serviceProvidersList) {
                LocalAndOutboundAuthenticationConfig localAndOutboundAuthConfig = serviceProvider.getLocalAndOutBoundAuthenticationConfig();
                AuthenticationStep[] authSteps = localAndOutboundAuthConfig.getAuthenticationSteps();
                OutboundProvisioningConfig outboundProvisioningConfig = serviceProvider.getOutboundProvisioningConfig();
                IdentityProvider[] provisioningIdps = outboundProvisioningConfig.getProvisioningIdentityProviders();
                // Check whether the identity provider is referred in a service provider
                validateIdpDisable(identityProvider, authSteps, provisioningIdps);
                // Validating Applications with Federated Authenticators configured.
                updateApplicationWithFederatedAuthenticators(identityProvider, tenantDomain, serviceProvider, localAndOutboundAuthConfig, authSteps);
                // Validating Applications with Outbound Provisioning Connectors configured.
                updateApplicationWithProvisioningConnectors(identityProvider, provisioningIdps);
                // Clear application caches if IDP name is updated.
                if (!StringUtils.equals(oldIdPName, identityProvider.getIdentityProviderName())) {
                    CacheBackedApplicationDAO.clearAllAppCache(serviceProvider, tenantDomain);
                }
            }
            offset = connectedApplications.getOffSet() + connectedApplications.getLimit();
        } while (connectedApplications.getTotalAppCount() > offset);
    } catch (IdentityApplicationManagementException e) {
        throw new IdentityProviderManagementException("Error when updating default authenticator of service providers", e);
    }
    return true;
}
Also used : ConnectedAppsResult(org.wso2.carbon.idp.mgt.model.ConnectedAppsResult) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) ArrayList(java.util.ArrayList) AuthenticationStep(org.wso2.carbon.identity.application.common.model.AuthenticationStep) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) OutboundProvisioningConfig(org.wso2.carbon.identity.application.common.model.OutboundProvisioningConfig) LocalAndOutboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) IdentityProviderManager(org.wso2.carbon.idp.mgt.IdentityProviderManager) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException)

Example 22 with IdentityProviderManager

use of org.wso2.carbon.idp.mgt.IdentityProviderManager 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 23 with IdentityProviderManager

use of org.wso2.carbon.idp.mgt.IdentityProviderManager in project identity-inbound-auth-oauth by wso2-extensions.

the class SAML2BearerGrantHandlerTest method prepareForGetIssuer.

private void prepareForGetIssuer() throws Exception {
    when(tenantManager.getTenantId(anyString())).thenReturn(-1234);
    when(realmService.getTenantManager()).thenReturn(tenantManager);
    SAMLSSOUtil.setRealmService(realmService);
    federatedAuthenticatorConfig.setProperties(new Property[] { getProperty(IdentityApplicationConstants.Authenticator.SAML2SSO.IDP_ENTITY_ID, TestConstants.LOACALHOST_DOMAIN) });
    federatedAuthenticatorConfig.setName(IdentityApplicationConstants.Authenticator.SAML2SSO.NAME);
    FederatedAuthenticatorConfig[] fedAuthConfs = { federatedAuthenticatorConfig };
    IdentityProvider identityProvider = getIdentityProvider("LOCAL", TestConstants.OAUTH2_TOKEN_EP);
    identityProvider.setFederatedAuthenticatorConfigs(fedAuthConfs);
    mockStatic(IdentityProviderManager.class);
    when(IdentityProviderManager.getInstance()).thenReturn(identityProviderManager);
    when(identityProviderManager.getResidentIdP(anyString())).thenReturn(identityProvider);
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider)

Example 24 with IdentityProviderManager

use of org.wso2.carbon.idp.mgt.IdentityProviderManager in project identity-inbound-auth-oauth by wso2-extensions.

the class RequestObjectValidatorImplTest method mockIdentityProviderManager.

private void mockIdentityProviderManager() throws Exception {
    IdentityProvider idp = new IdentityProvider();
    idp.setIdentityProviderName("LOCAL");
    idp.setEnable(true);
    PowerMockito.mockStatic(IdentityProviderManager.class);
    IdentityProviderManager identityProviderManager = mock(IdentityProviderManager.class);
    when(IdentityProviderManager.getInstance()).thenReturn(identityProviderManager);
    when(identityProviderManager.getResidentIdP(anyString())).thenReturn(idp);
}
Also used : IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderManager(org.wso2.carbon.idp.mgt.IdentityProviderManager)

Example 25 with IdentityProviderManager

use of org.wso2.carbon.idp.mgt.IdentityProviderManager in project identity-inbound-auth-oauth by wso2-extensions.

the class SAML2BearerGrantHandlerTest method initIdentityProviderManager.

private IdentityProvider initIdentityProviderManager(String idpName, String alias) throws Exception {
    mockStatic(IdentityApplicationManagementUtil.class);
    IdentityProvider identityProviderIns = getIdentityProvider(idpName, alias);
    when(IdentityProviderManager.getInstance()).thenReturn(identityProviderManager);
    when(identityProviderManager.getIdPByAuthenticatorPropertyValue(anyString(), anyString(), anyString(), anyString(), anyBoolean())).thenReturn(identityProviderIns);
    if (IdentityApplicationConstants.RESIDENT_IDP_RESERVED_NAME.equals(idpName)) {
        when(identityProviderManager.getResidentIdP(anyString())).thenReturn(identityProviderIns);
    }
    return identityProviderIns;
}
Also used : IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider)

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