From 97b733472ae101946928210f25037b568a46dab5 Mon Sep 17 00:00:00 2001 From: Thisara-Welmilla Date: Tue, 17 Dec 2024 21:51:45 +0530 Subject: [PATCH] Address comments. --- ...atedAuthenticatorConfigBuilderFactory.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/impl/FederatedAuthenticatorConfigBuilderFactory.java b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/impl/FederatedAuthenticatorConfigBuilderFactory.java index ef6c99e585..2b891823e2 100644 --- a/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/impl/FederatedAuthenticatorConfigBuilderFactory.java +++ b/components/org.wso2.carbon.identity.api.server.idp/org.wso2.carbon.identity.api.server.idp.v1/src/main/java/org/wso2/carbon/identity/api/server/idp/v1/impl/FederatedAuthenticatorConfigBuilderFactory.java @@ -18,7 +18,6 @@ package org.wso2.carbon.identity.api.server.idp.v1.impl; -import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.wso2.carbon.identity.api.server.common.ContextLoader; import org.wso2.carbon.identity.api.server.idp.common.Constants; @@ -124,9 +123,9 @@ public static FederatedAuthenticator build(FederatedAuthenticatorConfig config) federatedAuthenticator.setName(config.getName()); federatedAuthenticator.setIsEnabled(config.isEnabled()); - String[] tags = resolveAuthenticatorTags(config); - if (ArrayUtils.isNotEmpty(tags)) { - federatedAuthenticator.setTags(Arrays.asList(tags)); + List tags = resolveAuthenticatorTags(config); + if (tags.isEmpty()) { + federatedAuthenticator.setTags(tags); } if (DefinedByType.SYSTEM == config.getDefinedByType()) { @@ -147,6 +146,7 @@ public static FederatedAuthenticator build(FederatedAuthenticatorConfig config) * FederatedAuthenticatorConfig. * * @param fedAuthConfigs Array of FederatedAuthenticatorConfig instances. + * @param idpResourceId Identity provider resource ID. * @return List of FederatedAuthenticatorListItem instances. */ public static List build(FederatedAuthenticatorConfig[] fedAuthConfigs, @@ -160,9 +160,9 @@ public static List build(FederatedAuthenticatorC authenticatorListItem.setIsEnabled(config.isEnabled()); authenticatorListItem.definedBy(FederatedAuthenticatorListItem.DefinedByEnum.valueOf( config.getDefinedByType().toString())); - String[] tags = resolveAuthenticatorTags(config); - if (ArrayUtils.isNotEmpty(tags)) { - authenticatorListItem.setTags(Arrays.asList(tags)); + List tags = resolveAuthenticatorTags(config); + if (tags.isEmpty()) { + authenticatorListItem.setTags(tags); } authenticatorListItem.setSelf(ContextLoader.buildURIForBody(String.format(V1_API_PATH_COMPONENT + IDP_PATH_COMPONENT + "/%s/federated-authenticators/%s", idpResourceId, @@ -466,21 +466,19 @@ private static void resolveEndpointConfiguration(FederatedAuthenticator authenti } } - private static String[] resolveAuthenticatorTags(FederatedAuthenticatorConfig config) { + private static List resolveAuthenticatorTags(FederatedAuthenticatorConfig config) { /* If the authenticator is defined by the user, return the tags of the authenticator config. Otherwise, return the tags of the system registered federated authenticator template. */ if (DefinedByType.USER == config.getDefinedByType()) { - return config.getTags(); - + return Arrays.asList(config.getTags()); } + FederatedAuthenticatorConfig federatedAuthenticatorConfig = ApplicationAuthenticatorService.getInstance().getFederatedAuthenticatorByName(config.getName()); - if (federatedAuthenticatorConfig != null) { - return federatedAuthenticatorConfig.getTags(); - } - return new String[0]; + return federatedAuthenticatorConfig != null ? Arrays.asList(federatedAuthenticatorConfig.getTags()) + : new ArrayList<>(); } /**