Search in sources :

Example 41 with IdentityProvider

use of org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider in project carbon-identity-framework by wso2.

the class JsGraphBuilderTest method filterOptionsDataProvider.

@DataProvider
public Object[][] filterOptionsDataProvider() {
    ApplicationAuthenticatorService.getInstance().getLocalAuthenticators().clear();
    LocalAuthenticatorConfig basic = new LocalAuthenticatorConfig();
    basic.setName("BasicAuthenticator");
    basic.setDisplayName("basic");
    LocalAuthenticatorConfig totp = new LocalAuthenticatorConfig();
    totp.setName("TOTPAuthenticator");
    totp.setDisplayName("totp");
    ApplicationAuthenticatorService.getInstance().getLocalAuthenticators().add(basic);
    ApplicationAuthenticatorService.getInstance().getLocalAuthenticators().add(totp);
    IdentityProvider localIdp = new IdentityProvider();
    localIdp.setId("LOCAL");
    localIdp.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[0]);
    FederatedAuthenticatorConfig samlFederated = new FederatedAuthenticatorConfig();
    samlFederated.setDisplayName("samlsso");
    samlFederated.setName("SAMLAuthenticator");
    FederatedAuthenticatorConfig oidcFederated = new FederatedAuthenticatorConfig();
    oidcFederated.setDisplayName("oidc");
    oidcFederated.setName("OIDCAuthenticator");
    FederatedAuthenticatorConfig twitterFederated = new FederatedAuthenticatorConfig();
    twitterFederated.setDisplayName("twitter");
    twitterFederated.setName("TwitterAuthenticator");
    IdentityProvider customIdp1 = new IdentityProvider();
    customIdp1.setId("customIdp1");
    customIdp1.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { samlFederated, oidcFederated });
    customIdp1.setDefaultAuthenticatorConfig(samlFederated);
    IdentityProvider customIdp2 = new IdentityProvider();
    customIdp2.setId("customIdp2");
    customIdp2.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { twitterFederated });
    customIdp2.setDefaultAuthenticatorConfig(twitterFederated);
    AuthenticatorConfig basicAuthConfig = new AuthenticatorConfig();
    basicAuthConfig.setName("BasicAuthenticator");
    basicAuthConfig.setEnabled(true);
    basicAuthConfig.getIdps().put("LOCAL", localIdp);
    AuthenticatorConfig totpAuthConfig = new AuthenticatorConfig();
    totpAuthConfig.setName("TOTPAuthenticator");
    totpAuthConfig.setEnabled(true);
    totpAuthConfig.getIdps().put("LOCAL", localIdp);
    AuthenticatorConfig samlAuthConfig = new AuthenticatorConfig();
    samlAuthConfig.setName("SAMLAuthenticator");
    samlAuthConfig.setEnabled(true);
    samlAuthConfig.getIdps().put("customIdp1", customIdp1);
    AuthenticatorConfig oidcAuthConfig = new AuthenticatorConfig();
    oidcAuthConfig.setName("OIDCAuthenticator");
    oidcAuthConfig.setEnabled(true);
    oidcAuthConfig.getIdps().put("customIdp1", customIdp1);
    AuthenticatorConfig twitterAuthConfig = new AuthenticatorConfig();
    twitterAuthConfig.setName("TwitterAuthenticator");
    twitterAuthConfig.setEnabled(true);
    twitterAuthConfig.getIdps().put("customIdp2", customIdp2);
    StepConfig stepWithSingleOption = new StepConfig();
    stepWithSingleOption.setAuthenticatorList(Collections.singletonList(basicAuthConfig));
    Map<String, Map<String, String>> singleOptionConfig = new HashMap<>();
    singleOptionConfig.put("0", Collections.singletonMap("authenticator", "basic"));
    StepConfig stepWithMultipleOptions = new StepConfig();
    stepWithMultipleOptions.setAuthenticatorList(new ArrayList<>(Arrays.asList(basicAuthConfig, totpAuthConfig, oidcAuthConfig, twitterAuthConfig)));
    Map<String, String> oidcOption = new HashMap<>();
    oidcOption.put("idp", "customIdp1");
    oidcOption.put("authenticator", "oidc");
    Map<String, String> twitterOption = new HashMap<>();
    twitterOption.put("idp", "customIdp2");
    twitterOption.put("authenticator", "twitter");
    Map<String, String> invalidOption = new HashMap<>();
    invalidOption.put("idp", "customIdp1");
    invalidOption.put("authenticator", "twitter");
    Map<String, Map<String, String>> multipleOptionConfig = new HashMap<>();
    multipleOptionConfig.put("0", Collections.singletonMap("authenticator", "basic"));
    multipleOptionConfig.put("1", oidcOption);
    multipleOptionConfig.put("2", twitterOption);
    Map<String, Map<String, String>> multipleAndInvalidOptionConfig = new HashMap<>();
    multipleAndInvalidOptionConfig.put("0", Collections.singletonMap("authenticator", "basic"));
    multipleAndInvalidOptionConfig.put("1", oidcOption);
    multipleAndInvalidOptionConfig.put("2", invalidOption);
    Map<String, Map<String, String>> idpOnlyOptionConfig = new HashMap<>();
    idpOnlyOptionConfig.put("0", Collections.singletonMap("authenticator", "basic"));
    idpOnlyOptionConfig.put("1", Collections.singletonMap("idp", "customIdp1"));
    Map<String, Map<String, String>> singleInvalidOptionConfig = new HashMap<>();
    singleInvalidOptionConfig.put("0", invalidOption);
    return new Object[][] { { singleOptionConfig, duplicateStepConfig(stepWithSingleOption), 1 }, { singleOptionConfig, duplicateStepConfig(stepWithMultipleOptions), 1 }, { multipleOptionConfig, duplicateStepConfig(stepWithMultipleOptions), 3 }, { multipleAndInvalidOptionConfig, duplicateStepConfig(stepWithMultipleOptions), 2 }, { singleInvalidOptionConfig, duplicateStepConfig(stepWithMultipleOptions), 4 }, { idpOnlyOptionConfig, duplicateStepConfig(stepWithMultipleOptions), 2 } };
}
Also used : AuthenticatorConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig) FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) LocalAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig) FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) HashMap(java.util.HashMap) LocalAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig) StepConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) HashMap(java.util.HashMap) Map(java.util.Map) DataProvider(org.testng.annotations.DataProvider)

Example 42 with IdentityProvider

use of org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider 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 43 with IdentityProvider

use of org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider in project carbon-identity-framework by wso2.

the class IdentityProviderManagementService method getPaginatedIdpInfo.

/**
 * Retrieves Identity providers list of array for the logged-in tenant.
 *
 * @param filter     searching value.
 * @param pageNumber page number.
 * @return Identity providers list of array.
 * @throws IdentityProviderManagementException Error when getting list of Identity Providers.
 */
public IdentityProvider[] getPaginatedIdpInfo(String filter, int pageNumber) throws IdentityProviderManagementException {
    validateRequestedPageNumber(pageNumber);
    Integer limit = IdentityUtil.getDefaultItemsPerPage();
    Integer offset = getIdpPageOffset(pageNumber, limit);
    String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    IdpSearchResult idpSearchResult = IdentityProviderManager.getInstance().getIdPs(limit, offset, filter, IdPManagementConstants.DEFAULT_SORT_ORDER, IdPManagementConstants.DEFAULT_SORT_BY, tenantDomain, new ArrayList<>());
    return idpSearchResult.getIdPs().toArray(new IdentityProvider[0]);
}
Also used : IdpSearchResult(org.wso2.carbon.idp.mgt.model.IdpSearchResult)

Example 44 with IdentityProvider

use of org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider in project carbon-identity-framework by wso2.

the class IdentityProviderManager method deleteIdPs.

/**
 * Delete all Identity Providers from a given tenant.
 *
 * @param tenantDomain Domain of the tenant
 * @throws IdentityProviderManagementException
 */
@Override
public void deleteIdPs(String tenantDomain) throws IdentityProviderManagementException {
    // Invoking the pre listeners.
    Collection<IdentityProviderMgtListener> listeners = IdPManagementServiceComponent.getIdpMgtListeners();
    for (IdentityProviderMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPreDeleteIdPs(tenantDomain)) {
            return;
        }
    }
    // Delete metadata strings of each IDP
    int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
    List<IdentityProvider> identityProviders = getIdPs(tenantDomain);
    for (IdentityProvider identityProvider : identityProviders) {
        deleteMetadataStrings(identityProvider.getIdentityProviderName(), tenantId);
    }
    dao.deleteIdPs(tenantId);
    // Invoking the post listeners.
    for (IdentityProviderMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPostDeleteIdPs(tenantDomain)) {
            return;
        }
    }
}
Also used : IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderMgtListener(org.wso2.carbon.idp.mgt.listener.IdentityProviderMgtListener)

Example 45 with IdentityProvider

use of org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider in project carbon-identity-framework by wso2.

the class IdentityProviderManager method getIdPById.

@Override
public IdentityProvider getIdPById(String id, String tenantDomain, boolean ignoreFileBasedIdps) throws IdentityProviderManagementException {
    if (StringUtils.isEmpty(id)) {
        String msg = "Invalid argument: Identity Provider ID value is empty";
        throw new IdentityProviderManagementException(msg);
    }
    int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
    Integer intId;
    IdentityProvider identityProvider = null;
    try {
        intId = Integer.parseInt(id);
        identityProvider = dao.getIdPById(null, intId, tenantId, tenantDomain);
    } catch (NumberFormatException e) {
    // Ignore this.
    }
    if (!ignoreFileBasedIdps) {
        if (identityProvider == null) {
            identityProvider = new FileBasedIdPMgtDAO().getIdPByName(id, tenantDomain);
        }
        if (identityProvider == null) {
            identityProvider = IdPManagementServiceComponent.getFileBasedIdPs().get(IdentityApplicationConstants.DEFAULT_IDP_CONFIG);
        }
    }
    return identityProvider;
}
Also used : FileBasedIdPMgtDAO(org.wso2.carbon.idp.mgt.dao.FileBasedIdPMgtDAO) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider)

Aggregations

IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)190 Test (org.testng.annotations.Test)103 IdentityProviderManagementException (org.wso2.carbon.idp.mgt.IdentityProviderManagementException)65 ArrayList (java.util.ArrayList)64 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)54 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)53 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)47 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)47 API (org.wso2.carbon.apimgt.core.models.API)43 IdentityProvider (org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider)37 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)35 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)34 Property (org.wso2.carbon.identity.application.common.model.Property)29 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.idp.xsd.FederatedAuthenticatorConfig)29 ProvisioningConnectorConfig (org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)27 Connection (java.sql.Connection)25 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProviderProperty)22 Property (org.wso2.carbon.identity.application.common.model.idp.xsd.Property)22 HashMap (java.util.HashMap)20 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)20