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;
}
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;
}
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;
}
Aggregations