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/core/ServerIdpManagementService.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/core/ServerIdpManagementService.java index 4a08eb348c..0653ab737c 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/core/ServerIdpManagementService.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/core/ServerIdpManagementService.java @@ -2428,30 +2428,8 @@ private FederatedAuthenticatorListResponse createFederatedAuthenticatorResponse( FederatedAuthenticatorConfig[] fedAuthConfigs = idp.getFederatedAuthenticatorConfigs(); FederatedAuthenticatorListResponse fedAuthIDPResponse = new FederatedAuthenticatorListResponse(); - List authenticators = new ArrayList<>(); - for (FederatedAuthenticatorConfig fedAuthConfig : fedAuthConfigs) { - FederatedAuthenticatorListItem fedAuthListItem = new FederatedAuthenticatorListItem(); - fedAuthListItem.setAuthenticatorId(base64URLEncode(fedAuthConfig.getName())); - fedAuthListItem.setName(fedAuthConfig.getName()); - fedAuthListItem.setIsEnabled(fedAuthConfig.isEnabled()); - fedAuthListItem.setDefinedBy(FederatedAuthenticatorListItem.DefinedByEnum.valueOf( - fedAuthConfig.getDefinedByType().toString())); - FederatedAuthenticatorConfig federatedAuthenticatorConfig = - ApplicationAuthenticatorService.getInstance().getFederatedAuthenticatorByName( - fedAuthConfig.getName()); - if (federatedAuthenticatorConfig != null) { - String[] tags = federatedAuthenticatorConfig.getTags(); - if (ArrayUtils.isNotEmpty(tags)) { - fedAuthListItem.setTags(Arrays.asList(tags)); - } - } - fedAuthListItem.setSelf( - ContextLoader.buildURIForBody(String.format(V1_API_PATH_COMPONENT + IDP_PATH_COMPONENT + - "/%s/federated-authenticators/%s", idp.getResourceId(), - base64URLEncode(fedAuthConfig.getName()))) - .toString()); - authenticators.add(fedAuthListItem); - } + List authenticators = + FederatedAuthenticatorConfigBuilderFactory.build(fedAuthConfigs); fedAuthIDPResponse.setDefaultAuthenticatorId(idp.getDefaultAuthenticatorConfig() != null ? base64URLEncode(idp .getDefaultAuthenticatorConfig().getName()) : null); fedAuthIDPResponse.setAuthenticators(authenticators); 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 2223458692..eea2376d46 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 @@ -25,6 +25,7 @@ import org.wso2.carbon.identity.api.server.idp.v1.model.AuthenticationType; import org.wso2.carbon.identity.api.server.idp.v1.model.Endpoint; import org.wso2.carbon.identity.api.server.idp.v1.model.FederatedAuthenticator; +import org.wso2.carbon.identity.api.server.idp.v1.model.FederatedAuthenticatorListItem; import org.wso2.carbon.identity.api.server.idp.v1.model.FederatedAuthenticatorPUTRequest; import org.wso2.carbon.identity.application.common.ApplicationAuthenticatorService; import org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig; @@ -38,6 +39,7 @@ import org.wso2.carbon.idp.mgt.IdentityProviderManagementServerException; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; import java.util.Arrays; import java.util.Base64; import java.util.List; @@ -118,17 +120,10 @@ public static FederatedAuthenticator build(FederatedAuthenticatorConfig config) federatedAuthenticator.setName(config.getName()); federatedAuthenticator.setIsEnabled(config.isEnabled()); - - FederatedAuthenticatorConfig federatedAuthenticatorConfig = - ApplicationAuthenticatorService.getInstance().getFederatedAuthenticatorByName( - config.getName()); - if (federatedAuthenticatorConfig != null) { - String[] tags = federatedAuthenticatorConfig.getTags(); - if (ArrayUtils.isNotEmpty(tags)) { - federatedAuthenticator.setTags(Arrays.asList(tags)); - } + String[] tags = resolveAuthenticatorTags(config); + if (ArrayUtils.isNotEmpty(tags)) { + federatedAuthenticator.setTags(Arrays.asList(tags)); } - if (DefinedByType.SYSTEM == config.getDefinedByType()) { federatedAuthenticator.setDefinedBy(FederatedAuthenticator.DefinedByEnum.SYSTEM); List properties = @@ -141,6 +136,32 @@ public static FederatedAuthenticator build(FederatedAuthenticatorConfig config) return federatedAuthenticator; } + + /** + * Builds a list of FederatedAuthenticatorListItem instances based on the given array of + * FederatedAuthenticatorConfig. + * + * @param fedAuthConfigs Array of FederatedAuthenticatorConfig instances. + * @return List of FederatedAuthenticatorListItem instances. + */ + public static List build(FederatedAuthenticatorConfig[] fedAuthConfigs) { + + List authenticators = new ArrayList<>(); + for (FederatedAuthenticatorConfig config : fedAuthConfigs) { + FederatedAuthenticatorListItem authenticatorListItem = new FederatedAuthenticatorListItem(); + authenticatorListItem.setName(config.getName()); + 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)); + } + authenticators.add(authenticatorListItem); + } + + return authenticators; + } private static FederatedAuthenticatorConfig createFederatedAuthenticatorConfig(Config config) throws IdentityProviderManagementClientException { @@ -435,6 +456,20 @@ private static void resolveEndpointConfiguration(FederatedAuthenticator authenti } } + private static String[] resolveAuthenticatorTags(FederatedAuthenticatorConfig config) { + + if (DefinedByType.USER == config.getDefinedByType()) { + return config.getTags(); + + } + FederatedAuthenticatorConfig federatedAuthenticatorConfig = + ApplicationAuthenticatorService.getInstance().getFederatedAuthenticatorByName(config.getName()); + if (federatedAuthenticatorConfig != null) { + return federatedAuthenticatorConfig.getTags(); + } + return new String[0]; + } + /** * Config class to build FederatedAuthenticatorConfig. */