Skip to content

Commit

Permalink
Address comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Jan 26, 2025
1 parent c92c750 commit 30bddd8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,21 @@ private AuthenticationStep buildAuthenticationStep(AuthenticationStepModel stepM
List<LocalAuthenticatorConfig> localAuthOptions = new ArrayList<>();
List<IdentityProvider> federatedAuthOptions = new ArrayList<>();

/* The defined type of the authenticator (USER or SYSTEM) will not be resolved here. Since this is flow of
the authenticator is being configured for application authentication flows, only the type of the authenticator
local or federated) is relevant. Therefore, resolving by the defined type is not necessary.
*/
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.setDefinedByType(resolveDefinedByType(option));
localAuthOption.setName(option.getAuthenticator());
localAuthOptions.add(localAuthOption);
} else {
FederatedAuthenticatorConfig federatedAuthConfig = new FederatedAuthenticatorConfig();
federatedAuthConfig.setEnabled(true);
federatedAuthConfig.setName(option.getAuthenticator());
federatedAuthConfig.setDefinedByType(resolveDefinedByType(option));
IdentityProvider federatedIdp = new IdentityProvider();
federatedIdp.setIdentityProviderName(option.getIdp());
federatedIdp.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[]{federatedAuthConfig});
Expand All @@ -184,25 +186,6 @@ private AuthenticationStep buildAuthenticationStep(AuthenticationStepModel stepM
return authenticationStep;
}

private DefinedByType resolveDefinedByType(Authenticator authenticator) {

if (FrameworkConstants.LOCAL_IDP_NAME.equals(authenticator.getIdp())) {
LocalAuthenticatorConfig localAuthConfig = ApplicationAuthenticatorService.getInstance()
.getLocalAuthenticatorByName(authenticator.getAuthenticator());
if (localAuthConfig != null) {
return localAuthConfig.getDefinedByType();
}
} else {
FederatedAuthenticatorConfig federatedAuthConfig = ApplicationAuthenticatorService.getInstance()
.getFederatedAuthenticatorByName(authenticator.getAuthenticator());
if (federatedAuthConfig != null) {
return federatedAuthConfig.getDefinedByType();
}
}

return DefinedByType.USER;
}

private int getSubjectStepId(Integer subjectStepId, int numSteps) {

return subjectStepId != null && subjectStepId <= numSteps ? subjectStepId : 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ private Authenticator buildAuthenticatorResponse(LocalAuthenticatorConfig config
UserDefinedLocalAuthenticatorConfig userDefinedConfig = castToUserDefinedConfig(config);
authenticator.setImage(userDefinedConfig.getImageUrl());
authenticator.setDescription(userDefinedConfig.getDescription());
resolveEndpointConfiguration(authenticator, userDefinedConfig);
resolveEndpointConfigurationForAuthenticatorFromConfig(authenticator, userDefinedConfig);
} else {
authenticator.setDefinedBy(Authenticator.DefinedByEnum.SYSTEM);
setAuthenticatorProperties(config, authenticator);
Expand All @@ -839,8 +839,12 @@ private UserDefinedLocalAuthenticatorConfig castToUserDefinedConfig(LocalAuthent
}
}

private void resolveEndpointConfiguration(Authenticator authenticator, UserDefinedLocalAuthenticatorConfig config) {
private void resolveEndpointConfigurationForAuthenticatorFromConfig(
Authenticator authenticator, UserDefinedLocalAuthenticatorConfig config) {

/* Only the endpoint URI of the endpoint configurations of the user-defined authenticator is set to the
authenticator. The authentication properties in the config are aliases for secrets and must not be included
in the response body.*/
UserDefinedAuthenticatorEndpointConfig endpointConfig = config.getEndpointConfig();
Endpoint endpoint = new Endpoint();
endpoint.setUri(endpointConfig.getAuthenticatorEndpointUri());
Expand Down

0 comments on commit 30bddd8

Please sign in to comment.