From 90972411ca3ab37f14288b77fd1358d6505e91ed Mon Sep 17 00:00:00 2001 From: Thisara-Welmilla Date: Mon, 2 Dec 2024 15:17:02 +0530 Subject: [PATCH] Update APIs to support custom authentication management. --- .../core/ServerAuthenticatorManagementService.java | 14 +++++++++++--- .../LocalAuthenticatorConfigBuilderFactory.java | 4 ++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/core/ServerAuthenticatorManagementService.java b/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/core/ServerAuthenticatorManagementService.java index 1bb986ba81..0c0eb7f8b6 100644 --- a/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/core/ServerAuthenticatorManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/core/ServerAuthenticatorManagementService.java @@ -115,7 +115,13 @@ public List getAuthenticators(String filter, Integer limit, Integ LocalAuthenticatorConfig[] localAuthenticatorConfigs = AuthenticatorsServiceHolder.getInstance() .getApplicationManagementService().getAllLocalAuthenticators(ContextLoader .getTenantDomainFromContext()); - + List userDefinedLocalAuthConfigs = + AuthenticatorsServiceHolder.getInstance().getApplicationAuthenticatorService() + .getUserDefinedLocalAuthenticators(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]; @@ -155,6 +161,8 @@ public List 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 new RuntimeException(e); } } @@ -1002,7 +1010,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) { @@ -1012,7 +1020,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; diff --git a/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/impl/LocalAuthenticatorConfigBuilderFactory.java b/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/impl/LocalAuthenticatorConfigBuilderFactory.java index f3c27fcb67..ba7221227b 100644 --- a/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/impl/LocalAuthenticatorConfigBuilderFactory.java +++ b/components/org.wso2.carbon.identity.api.server.authenticators/org.wso2.carbon.identity.api.server.authenticators.v1/src/main/java/org/wso2/carbon/identity/api/server/authenticators/v1/impl/LocalAuthenticatorConfigBuilderFactory.java @@ -123,9 +123,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()); } }