Skip to content

Commit

Permalink
Update APIs to support custom authentication management.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Nov 20, 2024
1 parent 3da9303 commit a0dad0a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ public enum ErrorMessage {
"Unable to decode the provided authenticator ID %s."),
ERROR_CODE_NO_SYSTEM_AUTHENTICATOR_FOUND("60043", "No system authenticator found.",
"No system authenticator found for the provided authenticator Id %s."),
ERROR_COED_MULTIPLE_USER_DEFINED_AUTHENTICATORS_FOUND("60044", "Multiple authenticators found.",
"Multiple user defined authenticators are not allowed."),

// Server Error starting from 650xx.
ERROR_CODE_ERROR_ADDING_IDP("65002",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1779,6 +1779,10 @@ private void updateFederatedAuthenticatorConfig(IdentityProvider idp, FederatedA
} else {
definedByType = resolveDefinedByTypeToUpdateFederatedAuthenticator(authenticatorName);
}
if (definedByType == DefinedByType.USER && federatedAuthenticators.size() > 1) {
throw handleException(Response.Status.BAD_REQUEST,
Constants.ErrorMessage.ERROR_COED_MULTIPLE_USER_DEFINED_AUTHENTICATORS_FOUND, null);
}
FederatedAuthenticatorConfig authConfig = FederatedAuthenticatorConfigBuilderFactory.build(
authenticator, authenticatorName, definedByType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@
import org.wso2.carbon.idp.mgt.IdentityProviderManagementServerException;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Base64;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -184,17 +180,22 @@ private static UserDefinedFederatedAuthenticatorConfig createUserDefinedFederate

validateUserDefinedFederatedAuthenticatorModel(config);

UserDefinedFederatedAuthenticatorConfig authConfig = new UserDefinedFederatedAuthenticatorConfig();
UserDefinedAuthenticatorEndpointConfig.UserDefinedAuthenticatorEndpointConfigBuilder endpointConfigBuilder =
new UserDefinedAuthenticatorEndpointConfig.UserDefinedAuthenticatorEndpointConfigBuilder();
endpointConfigBuilder.uri(config.endpoint.getUri());
endpointConfigBuilder.authenticationType(config.endpoint.getAuthentication().getType().toString());
endpointConfigBuilder.authenticationProperties(config.endpoint.getAuthentication().getProperties()
.entrySet().stream().collect(Collectors.toMap(
Map.Entry::getKey, entry -> entry.getValue().toString())));
authConfig.setEndpointConfig(endpointConfigBuilder.build());

return authConfig;
try {
UserDefinedFederatedAuthenticatorConfig authConfig = new UserDefinedFederatedAuthenticatorConfig();
UserDefinedAuthenticatorEndpointConfig.UserDefinedAuthenticatorEndpointConfigBuilder endpointConfigBuilder =
new UserDefinedAuthenticatorEndpointConfig.UserDefinedAuthenticatorEndpointConfigBuilder();
endpointConfigBuilder.uri(config.endpoint.getUri());
endpointConfigBuilder.authenticationType(config.endpoint.getAuthentication().getType().toString());
endpointConfigBuilder.authenticationProperties(config.endpoint.getAuthentication().getProperties()
.entrySet().stream().collect(Collectors.toMap(
Map.Entry::getKey, entry -> entry.getValue().toString())));
authConfig.setEndpointConfig(endpointConfigBuilder.build());

return authConfig;
} catch (NoSuchElementException e) {
throw new IdentityProviderManagementClientException(Constants.ErrorMessage
.ERROR_CODE_INVALID_INPUT.getCode(), e.getMessage());
}
}

private static void validateUserDefinedFederatedAuthenticatorModel(Config config)
Expand Down

0 comments on commit a0dad0a

Please sign in to comment.