Search in sources :

Example 1 with AuthenticationStepModel

use of org.wso2.carbon.identity.api.server.application.management.v1.AuthenticationStepModel in project identity-api-server by wso2.

the class ServiceProviderToApiModel method buildAuthStep.

private AuthenticationStepModel buildAuthStep(AuthenticationStep authenticationStep) {
    AuthenticationStepModel authStep = new AuthenticationStepModel();
    authStep.setId(authenticationStep.getStepOrder());
    arrayToStream(authenticationStep.getFederatedIdentityProviders()).forEach(y -> authStep.addOptionsItem(new Authenticator().idp(y.getIdentityProviderName()).authenticator(y.getDefaultAuthenticatorConfig().getName())));
    arrayToStream(authenticationStep.getLocalAuthenticatorConfigs()).forEach(y -> authStep.addOptionsItem(new Authenticator().idp(FrameworkConstants.LOCAL_IDP_NAME).authenticator(y.getName())));
    return authStep;
}
Also used : AuthenticationStepModel(org.wso2.carbon.identity.api.server.application.management.v1.AuthenticationStepModel) Authenticator(org.wso2.carbon.identity.api.server.application.management.v1.Authenticator)

Example 2 with AuthenticationStepModel

use of org.wso2.carbon.identity.api.server.application.management.v1.AuthenticationStepModel in project identity-api-server by wso2.

the class UpdateAuthenticationSequence method getAuthenticationSteps.

private AuthenticationStep[] getAuthenticationSteps(AuthenticationSequence authSequenceApiModel) {
    if (CollectionUtils.isEmpty(authSequenceApiModel.getSteps())) {
        throw Utils.buildBadRequestError("Authentication steps cannot be empty for user defined " + "authentication type: " + AuthenticationSequence.TypeEnum.USER_DEFINED);
    }
    // Sort the authentication steps.
    List<AuthenticationStepModel> sortedStepModelList = Optional.of(authSequenceApiModel.getSteps()).map(steps -> {
        steps.sort(Comparator.comparingInt(AuthenticationStepModel::getId));
        return steps;
    }).orElse(Collections.emptyList());
    int numSteps = sortedStepModelList.size();
    if (numSteps != sortedStepModelList.get(numSteps - 1).getId()) {
        // to be equal to number of steps.
        throw Utils.buildBadRequestError("Step ids need to be consecutive in the authentication sequence steps.");
    }
    int subjectStepId = getSubjectStepId(authSequenceApiModel.getSubjectStepId(), numSteps);
    int attributeStepId = getSubjectStepId(authSequenceApiModel.getAttributeStepId(), numSteps);
    // We create a array of size (numSteps + 1) since step order starts from 1.
    AuthenticationStep[] authenticationSteps = new AuthenticationStep[numSteps];
    int stepOrder = 1;
    for (AuthenticationStepModel stepModel : sortedStepModelList) {
        AuthenticationStep authenticationStep = buildAuthenticationStep(stepModel);
        authenticationStep.setStepOrder(stepOrder);
        if (subjectStepId == stepOrder) {
            authenticationStep.setSubjectStep(true);
        }
        if (attributeStepId == stepOrder) {
            authenticationStep.setAttributeStep(true);
        }
        authenticationSteps[stepOrder - 1] = authenticationStep;
        stepOrder++;
    }
    return authenticationSteps;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) AuthenticationSequence(org.wso2.carbon.identity.api.server.application.management.v1.AuthenticationSequence) Utils(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.Utils) FrameworkConstants(org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants) RequestPathAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) AuthenticationStep(org.wso2.carbon.identity.application.common.model.AuthenticationStep) FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) ArrayList(java.util.ArrayList) AuthenticationStepModel(org.wso2.carbon.identity.api.server.application.management.v1.AuthenticationStepModel) AuthenticationScriptConfig(org.wso2.carbon.identity.application.common.model.script.AuthenticationScriptConfig) ApplicationConstants(org.wso2.carbon.identity.application.mgt.ApplicationConstants) List(java.util.List) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) LocalAndOutboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig) CollectionUtils(org.apache.commons.collections.CollectionUtils) UpdateFunction(org.wso2.carbon.identity.api.server.application.management.v1.core.functions.UpdateFunction) Optional(java.util.Optional) LocalAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig) Comparator(java.util.Comparator) Collections(java.util.Collections) AuthenticationStepModel(org.wso2.carbon.identity.api.server.application.management.v1.AuthenticationStepModel) AuthenticationStep(org.wso2.carbon.identity.application.common.model.AuthenticationStep)

Example 3 with AuthenticationStepModel

use of org.wso2.carbon.identity.api.server.application.management.v1.AuthenticationStepModel 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)

Aggregations

ArrayList (java.util.ArrayList)2 AuthenticationStepModel (org.wso2.carbon.identity.api.server.application.management.v1.AuthenticationStepModel)2 AuthenticationStep (org.wso2.carbon.identity.application.common.model.AuthenticationStep)2 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)2 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)2 LocalAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig)2 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Optional (java.util.Optional)1 CollectionUtils (org.apache.commons.collections.CollectionUtils)1 StringUtils (org.apache.commons.lang.StringUtils)1 AuthenticationSequence (org.wso2.carbon.identity.api.server.application.management.v1.AuthenticationSequence)1 Authenticator (org.wso2.carbon.identity.api.server.application.management.v1.Authenticator)1 UpdateFunction (org.wso2.carbon.identity.api.server.application.management.v1.core.functions.UpdateFunction)1 Utils (org.wso2.carbon.identity.api.server.application.management.v1.core.functions.Utils)1 FrameworkConstants (org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants)1 LocalAndOutboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig)1 RequestPathAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.RequestPathAuthenticatorConfig)1 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)1