Search in sources :

Example 51 with FederatedAuthenticatorConfig

use of org.wso2.carbon.identity.application.common.model.xsd.FederatedAuthenticatorConfig in project identity-api-server by wso2.

the class UpdateAuthenticationSequence method buildAuthenticationStep.

private AuthenticationStep buildAuthenticationStep(AuthenticationStepModel stepModel) {
    AuthenticationStep authenticationStep = new AuthenticationStep();
    // iteration the options, divide in to federated and local and add the configs
    if (CollectionUtils.isEmpty(stepModel.getOptions())) {
        throw Utils.buildBadRequestError("Authentication Step options cannot be empty.");
    }
    List<LocalAuthenticatorConfig> localAuthOptions = new ArrayList<>();
    List<IdentityProvider> federatedAuthOptions = new ArrayList<>();
    stepModel.getOptions().forEach(option -> {
        // TODO : add validations to swagger so that we don't need to check inputs here.
        if (FrameworkConstants.LOCAL_IDP_NAME.equals(option.getIdp())) {
            LocalAuthenticatorConfig localAuthOption = new LocalAuthenticatorConfig();
            localAuthOption.setEnabled(true);
            localAuthOption.setName(option.getAuthenticator());
            localAuthOptions.add(localAuthOption);
        } else {
            FederatedAuthenticatorConfig federatedAuthConfig = new FederatedAuthenticatorConfig();
            federatedAuthConfig.setEnabled(true);
            federatedAuthConfig.setName(option.getAuthenticator());
            IdentityProvider federatedIdp = new IdentityProvider();
            federatedIdp.setIdentityProviderName(option.getIdp());
            federatedIdp.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { federatedAuthConfig });
            federatedIdp.setDefaultAuthenticatorConfig(federatedAuthConfig);
            federatedAuthOptions.add(federatedIdp);
        }
    });
    authenticationStep.setLocalAuthenticatorConfigs(localAuthOptions.toArray(new LocalAuthenticatorConfig[0]));
    authenticationStep.setFederatedIdentityProviders(federatedAuthOptions.toArray(new IdentityProvider[0]));
    return authenticationStep;
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) LocalAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig) ArrayList(java.util.ArrayList) AuthenticationStep(org.wso2.carbon.identity.application.common.model.AuthenticationStep) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider)

Example 52 with FederatedAuthenticatorConfig

use of org.wso2.carbon.identity.application.common.model.xsd.FederatedAuthenticatorConfig in project identity-api-server by wso2.

the class ServerAuthenticatorManagementService method getDistinctTags.

/**
 * Retrieves a distinct list of tags defined for the federated authenticators of an identity provider.
 *
 * @param identityProvider The identity provider.
 * @return A distinct list of tags defined for the federated authenticators of an identity provider.
 */
private List<String> getDistinctTags(IdentityProvider identityProvider) {
    ArrayList<String> tagsList = new ArrayList<>();
    FederatedAuthenticatorConfig[] fedAuthConfigs = identityProvider.getFederatedAuthenticatorConfigs();
    if (fedAuthConfigs != null) {
        for (FederatedAuthenticatorConfig config : fedAuthConfigs) {
            if (config.isEnabled()) {
                FederatedAuthenticatorConfig federatedAuthenticatorConfig = ApplicationAuthenticatorService.getInstance().getFederatedAuthenticatorByName(config.getName());
                if (federatedAuthenticatorConfig != null) {
                    String[] tags = federatedAuthenticatorConfig.getTags();
                    if (ArrayUtils.isNotEmpty(tags)) {
                        tagsList.addAll(Arrays.asList(tags));
                    }
                }
            }
        }
        return tagsList.stream().distinct().collect(Collectors.toList());
    }
    return null;
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) ArrayList(java.util.ArrayList)

Example 53 with FederatedAuthenticatorConfig

use of org.wso2.carbon.identity.application.common.model.xsd.FederatedAuthenticatorConfig in project carbon-apimgt by wso2.

the class SystemScopesIssuer method getResidentIDPForIssuer.

private IdentityProvider getResidentIDPForIssuer(String tenantDomain, String jwtIssuer) throws IdentityOAuth2Exception {
    String issuer = "";
    IdentityProvider residentIdentityProvider;
    try {
        residentIdentityProvider = IdentityProviderManager.getInstance().getResidentIdP(tenantDomain);
    } catch (IdentityProviderManagementException var7) {
        String errorMsg = String.format("Error while getting Resident Identity Provider of '%s' tenant.", tenantDomain);
        throw new IdentityOAuth2Exception(errorMsg, var7);
    }
    FederatedAuthenticatorConfig[] fedAuthnConfigs = residentIdentityProvider.getFederatedAuthenticatorConfigs();
    FederatedAuthenticatorConfig oauthAuthenticatorConfig = IdentityApplicationManagementUtil.getFederatedAuthenticator(fedAuthnConfigs, "openidconnect");
    if (oauthAuthenticatorConfig != null) {
        issuer = IdentityApplicationManagementUtil.getProperty(oauthAuthenticatorConfig.getProperties(), "IdPEntityId").getValue();
    }
    return jwtIssuer.equals(issuer) ? residentIdentityProvider : null;
}
Also used : IdentityOAuth2Exception(org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException)

Example 54 with FederatedAuthenticatorConfig

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

the class ApplicationDAOImpl method getLocalAndOutboundAuthenticationConfig.

/**
 * @param applicationId
 * @param connection
 * @param propertyList
 * @return
 * @throws SQLException
 */
private LocalAndOutboundAuthenticationConfig getLocalAndOutboundAuthenticationConfig(int applicationId, Connection connection, int tenantId, List<ServiceProviderProperty> propertyList) throws SQLException, IdentityApplicationManagementException {
    PreparedStatement getStepInfoPrepStmt = null;
    ResultSet stepInfoResultSet = null;
    if (log.isDebugEnabled()) {
        log.debug("Reading Steps of Application " + applicationId);
    }
    try {
        getStepInfoPrepStmt = connection.prepareStatement(LOAD_STEPS_INFO_BY_APP_ID);
        // STEP_ORDER, AUTHENTICATOR_ID, IS_SUBJECT_STEP, IS_ATTRIBUTE_STEP
        getStepInfoPrepStmt.setInt(1, applicationId);
        stepInfoResultSet = getStepInfoPrepStmt.executeQuery();
        Map<String, AuthenticationStep> authSteps = new HashMap<>();
        Map<String, Map<String, List<FederatedAuthenticatorConfig>>> stepFedIdPAuthenticators = new HashMap<>();
        Map<String, List<LocalAuthenticatorConfig>> stepLocalAuth = new HashMap<>();
        while (stepInfoResultSet.next()) {
            String step = String.valueOf(stepInfoResultSet.getInt(1));
            AuthenticationStep authStep;
            if (authSteps.containsKey(step)) {
                authStep = authSteps.get(step);
            } else {
                authStep = new AuthenticationStep();
                authStep.setStepOrder(stepInfoResultSet.getInt(1));
                stepLocalAuth.put(step, new ArrayList<LocalAuthenticatorConfig>());
                stepFedIdPAuthenticators.put(step, new HashMap<String, List<FederatedAuthenticatorConfig>>());
            }
            int authenticatorId = stepInfoResultSet.getInt(2);
            Map<String, String> authenticatorInfo = getAuthenticatorInfo(connection, tenantId, authenticatorId);
            if (authenticatorInfo != null && authenticatorInfo.get(ApplicationConstants.IDP_NAME) != null && ApplicationConstants.LOCAL_IDP_NAME.equals(authenticatorInfo.get("idpName"))) {
                LocalAuthenticatorConfig localAuthenticator = new LocalAuthenticatorConfig();
                localAuthenticator.setName(authenticatorInfo.get(ApplicationConstants.IDP_AUTHENTICATOR_NAME));
                localAuthenticator.setDisplayName(authenticatorInfo.get(ApplicationConstants.IDP_AUTHENTICATOR_DISPLAY_NAME));
                stepLocalAuth.get(step).add(localAuthenticator);
            } else {
                Map<String, List<FederatedAuthenticatorConfig>> stepFedIdps = stepFedIdPAuthenticators.get(step);
                if (!stepFedIdps.containsKey(authenticatorInfo.get(ApplicationConstants.IDP_NAME))) {
                    stepFedIdps.put(authenticatorInfo.get(ApplicationConstants.IDP_NAME), new ArrayList<FederatedAuthenticatorConfig>());
                }
                List<FederatedAuthenticatorConfig> idpAuths = stepFedIdps.get(authenticatorInfo.get(ApplicationConstants.IDP_NAME));
                FederatedAuthenticatorConfig fedAuthenticator = new FederatedAuthenticatorConfig();
                fedAuthenticator.setName(authenticatorInfo.get(ApplicationConstants.IDP_AUTHENTICATOR_NAME));
                fedAuthenticator.setDisplayName(authenticatorInfo.get(ApplicationConstants.IDP_AUTHENTICATOR_DISPLAY_NAME));
                idpAuths.add(fedAuthenticator);
            }
            authStep.setSubjectStep("1".equals(stepInfoResultSet.getString(3)));
            authStep.setAttributeStep("1".equals(stepInfoResultSet.getString(4)));
            authSteps.put(step, authStep);
        }
        LocalAndOutboundAuthenticationConfig localAndOutboundConfiguration = new LocalAndOutboundAuthenticationConfig();
        AuthenticationStep[] authenticationSteps = new AuthenticationStep[authSteps.size()];
        int authStepCount = 0;
        for (Entry<String, AuthenticationStep> entry : authSteps.entrySet()) {
            AuthenticationStep authStep = entry.getValue();
            String stepId = entry.getKey();
            List<LocalAuthenticatorConfig> localAuthenticatorList = stepLocalAuth.get(stepId);
            if (localAuthenticatorList != null && localAuthenticatorList.size() > 0) {
                authStep.setLocalAuthenticatorConfigs(localAuthenticatorList.toArray(new LocalAuthenticatorConfig[localAuthenticatorList.size()]));
            }
            Map<String, List<FederatedAuthenticatorConfig>> idpList = stepFedIdPAuthenticators.get(stepId);
            if (idpList != null && idpList.size() > 0) {
                IdentityProvider[] fedIdpList = new IdentityProvider[idpList.size()];
                int idpCount = 0;
                for (Entry<String, List<FederatedAuthenticatorConfig>> idpEntry : idpList.entrySet()) {
                    String idpName = idpEntry.getKey();
                    List<FederatedAuthenticatorConfig> fedAuthenticators = idpEntry.getValue();
                    IdentityProvider idp = new IdentityProvider();
                    idp.setIdentityProviderName(idpName);
                    idp.setFederationHub(isFederationHubIdP(idpName, connection, tenantId));
                    idp.setFederatedAuthenticatorConfigs(fedAuthenticators.toArray(new FederatedAuthenticatorConfig[fedAuthenticators.size()]));
                    idp.setDefaultAuthenticatorConfig(idp.getFederatedAuthenticatorConfigs()[0]);
                    fedIdpList[idpCount++] = idp;
                }
                authStep.setFederatedIdentityProviders(fedIdpList);
            }
            authenticationSteps[authStepCount++] = authStep;
        }
        Arrays.sort(authenticationSteps, Comparator.comparingInt(AuthenticationStep::getStepOrder));
        int numSteps = authenticationSteps.length;
        // We check if the steps have consecutive step numbers.
        if (numSteps > 0 && authenticationSteps[numSteps - 1].getStepOrder() != numSteps) {
            if (log.isDebugEnabled()) {
                log.debug("Authentication steps of Application with id: " + applicationId + "  do not have " + "consecutive numbers. This was possibility due to a IDP force deletion. Fixing the step " + "order.");
            }
            // Iterate through the steps and fix step order.
            int count = 1;
            for (AuthenticationStep step : authenticationSteps) {
                step.setStepOrder(count++);
            }
        }
        localAndOutboundConfiguration.setAuthenticationSteps(authenticationSteps);
        String authType = getAuthenticationType(applicationId, connection);
        if (StringUtils.equalsIgnoreCase(authType, ApplicationConstants.AUTH_TYPE_FEDERATED) || StringUtils.equalsIgnoreCase(authType, ApplicationConstants.AUTH_TYPE_FLOW)) {
            if (ArrayUtils.isEmpty(authenticationSteps)) {
                // the authType to 'default'.
                if (log.isDebugEnabled()) {
                    log.debug("Authentication type is '" + authType + "' eventhough the application with id: " + applicationId + " has zero authentication step. This was possibility due to a IDP force deletion. " + " Defaulting authentication type to " + ApplicationConstants.AUTH_TYPE_DEFAULT);
                }
                authType = ApplicationConstants.AUTH_TYPE_DEFAULT;
            }
        }
        localAndOutboundConfiguration.setAuthenticationType(authType);
        AuthenticationScriptConfig authenticationScriptConfig = getScriptConfiguration(applicationId, connection);
        if (authenticationScriptConfig != null) {
            localAndOutboundConfiguration.setAuthenticationScriptConfig(authenticationScriptConfig);
        }
        PreparedStatement localAndOutboundConfigPrepStmt = null;
        ResultSet localAndOutboundConfigResultSet = null;
        try {
            localAndOutboundConfigPrepStmt = connection.prepareStatement(LOAD_LOCAL_AND_OUTBOUND_CONFIG_BY_APP_ID);
            localAndOutboundConfigPrepStmt.setInt(1, tenantId);
            localAndOutboundConfigPrepStmt.setInt(2, applicationId);
            localAndOutboundConfigResultSet = localAndOutboundConfigPrepStmt.executeQuery();
            if (localAndOutboundConfigResultSet.next()) {
                localAndOutboundConfiguration.setUseTenantDomainInLocalSubjectIdentifier("1".equals(localAndOutboundConfigResultSet.getString(1)));
                localAndOutboundConfiguration.setUseUserstoreDomainInLocalSubjectIdentifier("1".equals(localAndOutboundConfigResultSet.getString(2)));
                localAndOutboundConfiguration.setEnableAuthorization("1".equals(localAndOutboundConfigResultSet.getString(3)));
                localAndOutboundConfiguration.setAlwaysSendBackAuthenticatedListOfIdPs("1".equals(localAndOutboundConfigResultSet.getString(4)));
                localAndOutboundConfiguration.setSubjectClaimUri(localAndOutboundConfigResultSet.getString(5));
                readAndSetConfigurationsFromProperties(propertyList, localAndOutboundConfiguration);
            }
        } finally {
            IdentityApplicationManagementUtil.closeStatement(localAndOutboundConfigPrepStmt);
            IdentityApplicationManagementUtil.closeResultSet(localAndOutboundConfigResultSet);
        }
        return localAndOutboundConfiguration;
    } finally {
        IdentityApplicationManagementUtil.closeStatement(getStepInfoPrepStmt);
        IdentityApplicationManagementUtil.closeResultSet(stepInfoResultSet);
    }
}
Also used : HashMap(java.util.HashMap) FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) LocalAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig) LocalAndOutboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig) AuthenticationScriptConfig(org.wso2.carbon.identity.application.common.model.script.AuthenticationScriptConfig) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) AuthenticationStep(org.wso2.carbon.identity.application.common.model.AuthenticationStep) PreparedStatement(java.sql.PreparedStatement) NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) Map(java.util.Map) HashMap(java.util.HashMap)

Example 55 with FederatedAuthenticatorConfig

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

the class JsGraphBuilderTest method filterParamsDataProvider.

@DataProvider
public Object[][] filterParamsDataProvider() {
    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);
    FederatedAuthenticatorConfig twitterFederated = new FederatedAuthenticatorConfig();
    twitterFederated.setDisplayName("twitter");
    twitterFederated.setName("TwitterAuthenticator");
    IdentityProvider localIdp = new IdentityProvider();
    localIdp.setId("local");
    localIdp.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[0]);
    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);
    when(localApplicationAuthenticator.getName()).thenReturn("BasicAuthenticator");
    when(localApplicationAuthenticator.getFriendlyName()).thenReturn("basic");
    basicAuthConfig.setApplicationAuthenticator(localApplicationAuthenticator);
    basicAuthConfig.getIdps().put("local", localIdp);
    AuthenticatorConfig totpAuthConfig = new AuthenticatorConfig();
    totpAuthConfig.setName("TOTPAuthenticator");
    totpAuthConfig.setEnabled(true);
    when(totpApplicationAuthenticator.getName()).thenReturn("TOTPAuthenticator");
    when(totpApplicationAuthenticator.getFriendlyName()).thenReturn("totp");
    totpAuthConfig.setApplicationAuthenticator(totpApplicationAuthenticator);
    totpAuthConfig.getIdps().put("local", localIdp);
    AuthenticatorConfig twitterAuthConfig = new AuthenticatorConfig();
    twitterAuthConfig.setName("TwitterAuthenticator");
    twitterAuthConfig.setEnabled(true);
    when(federatedApplicationAuthenticator.getName()).thenReturn("TwitterAuthenticator");
    when(federatedApplicationAuthenticator.getFriendlyName()).thenReturn("twitter");
    twitterAuthConfig.setApplicationAuthenticator(federatedApplicationAuthenticator);
    twitterAuthConfig.getIdps().put("customIdp2", customIdp2);
    StepConfig stepWithSingleOption = new StepConfig();
    stepWithSingleOption.setAuthenticatorList(Collections.singletonList(basicAuthConfig));
    Map<String, Object> singleParamConfig = new HashMap<>();
    Map<String, Object> params = new HashMap<>();
    params.put("BasicAuthenticator", Collections.singletonMap("foo", "xyz"));
    singleParamConfig.put("local", params);
    StepConfig stepWithMultipleOptions = new StepConfig();
    stepWithMultipleOptions.setAuthenticatorList(new ArrayList<>(Arrays.asList(basicAuthConfig, totpAuthConfig, twitterAuthConfig)));
    Map<String, Object> localParams = new HashMap<>();
    localParams.put("BasicAuthenticator", Collections.singletonMap("foo", "xyz"));
    localParams.put("TOTPAuthenticator", Collections.singletonMap("domain", "localhost"));
    Map<String, Object> federatedParams = new HashMap<>();
    federatedParams.put("customIdp2", Collections.singletonMap("foo", "user"));
    Map<String, Object> multiParamConfig = new HashMap<>();
    multiParamConfig.put("local", localParams);
    multiParamConfig.put("federated", federatedParams);
    return new Object[][] { { singleParamConfig, duplicateStepConfig(stepWithSingleOption), "BasicAuthenticator", "foo", "xyz" }, { singleParamConfig, duplicateStepConfig(stepWithSingleOption), "BasicAuthenticator", "foos", null }, { singleParamConfig, duplicateStepConfig(stepWithMultipleOptions), "BasicAuthenticator", "foo", "xyz" }, { multiParamConfig, duplicateStepConfig(stepWithMultipleOptions), "BasicAuthenticator", "domain", null }, { multiParamConfig, duplicateStepConfig(stepWithMultipleOptions), "TwitterAuthenticator", "foo", "user" }, { multiParamConfig, duplicateStepConfig(stepWithMultipleOptions), "TOTPAuthenticator", "domain", "localhost" } };
}
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) DataProvider(org.testng.annotations.DataProvider)

Aggregations

FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)60 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)36 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.idp.xsd.FederatedAuthenticatorConfig)29 Property (org.wso2.carbon.identity.application.common.model.Property)28 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)25 ArrayList (java.util.ArrayList)21 IdentityProviderManagementException (org.wso2.carbon.idp.mgt.IdentityProviderManagementException)17 IdentityProvider (org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider)16 Test (org.testng.annotations.Test)14 Property (org.wso2.carbon.identity.application.common.model.idp.xsd.Property)14 HashMap (java.util.HashMap)12 ProvisioningConnectorConfig (org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)11 LocalAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig)10 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProviderProperty)10 ClaimConfig (org.wso2.carbon.identity.application.common.model.ClaimConfig)9 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)8 LocalRole (org.wso2.carbon.identity.application.common.model.LocalRole)8 PermissionsAndRoleConfig (org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig)8 Map (java.util.Map)7 DataProvider (org.testng.annotations.DataProvider)7