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 Dec 4, 2024
1 parent 660f2fd commit 942975c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ public List<Authenticator> getAuthenticators(String filter, Integer limit, Integ
LocalAuthenticatorConfig[] localAuthenticatorConfigs = AuthenticatorsServiceHolder.getInstance()
.getApplicationManagementService().getAllLocalAuthenticators(ContextLoader
.getTenantDomainFromContext());

List<UserDefinedLocalAuthenticatorConfig> userDefinedLocalAuthConfigs =
AuthenticatorsServiceHolder.getInstance().getApplicationAuthenticatorService()
.getAllUserDefinedLocalAuthenticators(ContextLoader.getTenantDomainFromContext());
if (CollectionUtils.isNotEmpty(userDefinedLocalAuthConfigs)) {
localAuthenticatorConfigs = (LocalAuthenticatorConfig[]) ArrayUtils.addAll(localAuthenticatorConfigs,
userDefinedLocalAuthConfigs.toArray(new LocalAuthenticatorConfig[0]));
}
int localAuthenticatorsCount = localAuthenticatorConfigs.length;
RequestPathAuthenticatorConfig[] requestPathAuthenticatorConfigs = new RequestPathAuthenticatorConfig[0];

Expand Down Expand Up @@ -155,6 +161,8 @@ public List<Authenticator> getAuthenticators(String filter, Integer limit, Integ
null);
} catch (IdentityProviderManagementException e) {
throw handleIdPException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_LISTING_IDPS, null);
} catch (AuthenticatorMgtException e) {
throw handleAuthenticatorException(e);
}
}

Expand Down Expand Up @@ -207,8 +215,7 @@ public ConnectedApps getConnectedAppsOfLocalAuthenticator(String authenticatorId
* @param config The user defined local authenticator update request.
* @return The created authenticator.
*/
public Authenticator addUserDefinedLocalAuthenticator(
UserDefinedLocalAuthenticatorCreation config) {
public Authenticator addUserDefinedLocalAuthenticator(UserDefinedLocalAuthenticatorCreation config) {

try {
UserDefinedLocalAuthenticatorConfig createdConfig = AuthenticatorsServiceHolder.getInstance()
Expand Down Expand Up @@ -1002,7 +1009,7 @@ private APIError handleAuthenticatorException(AuthenticatorMgtException e) {
errorCode : Constants.AUTHENTICATOR_ERROR_PREFIX + errorCode;
errorResponse.setCode(errorCode);
}
errorResponse.setDescription(e.getMessage());
errorResponse.setDescription(e.getDescription());
status = Response.Status.BAD_REQUEST;
} else if (e instanceof AuthenticatorMgtServerException) {
if (e.getErrorCode() != null) {
Expand All @@ -1012,7 +1019,7 @@ private APIError handleAuthenticatorException(AuthenticatorMgtException e) {
errorCode : Constants.AUTHENTICATOR_ERROR_PREFIX + errorCode;
errorResponse.setCode(errorCode);
}
errorResponse.setDescription(e.getMessage());
errorResponse.setDescription(e.getDescription());
status = Response.Status.INTERNAL_SERVER_ERROR;
} else {
status = Response.Status.INTERNAL_SERVER_ERROR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ public static Authenticator build(UserDefinedLocalAuthenticatorConfig config) {
public static UserDefinedLocalAuthenticatorConfig build(UserDefinedLocalAuthenticatorCreation config)
throws AuthenticatorMgtClientException {

String authenticationType = AuthenticatorPropertyConstants.AuthenticationType.IDENTIFICATION.toString();
if (config.getAuthenticationType() != null) {
authenticationType = config.getAuthenticationType().toString();
}
UserDefinedLocalAuthenticatorConfig authConfig = new UserDefinedLocalAuthenticatorConfig(
AuthenticatorPropertyConstants.AuthenticationType.valueOf(
config.getAuthenticationType().toString()));
authConfig.setAuthenticationType(AuthenticatorPropertyConstants.AuthenticationType.valueOf(
config.getAuthenticationType().toString()));
AuthenticatorPropertyConstants.AuthenticationType.valueOf(authenticationType));
authConfig.setName(config.getName());
authConfig.setDisplayName(config.getDisplayName());
authConfig.setEnabled(config.getIsEnabled());
Expand Down Expand Up @@ -123,9 +124,9 @@ private static UserDefinedAuthenticatorEndpointConfig buildEndpointConfig(Endpoi
.entrySet().stream().collect(Collectors.toMap(
Map.Entry::getKey, entry -> entry.getValue().toString())));
return endpointConfigBuilder.build();
} catch (NoSuchElementException e) {
} catch (NoSuchElementException | IllegalArgumentException e) {
Constants.ErrorMessage error = ERROR_CODE_INVALID_ENDPOINT_CONFIG;
throw new AuthenticatorMgtClientException(error.getCode(), error.getMessage(), error.getMessage());
throw new AuthenticatorMgtClientException(error.getCode(), error.getMessage(), e.getMessage());
}
}

Expand Down

0 comments on commit 942975c

Please sign in to comment.