diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/ApplicationAuthenticationService.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/ApplicationAuthenticationService.java index 2175d265017a..9682499f099e 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/ApplicationAuthenticationService.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/ApplicationAuthenticationService.java @@ -21,7 +21,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.identity.application.authentication.framework.exception.ApplicationAuthenticationException; -import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceComponent; +import org.wso2.carbon.identity.application.authentication.framework.internal.core.ApplicationAuthenticatorManager; import java.util.ArrayList; import java.util.List; @@ -33,6 +33,7 @@ public class ApplicationAuthenticationService { private static final Log log = LogFactory.getLog(ApplicationAuthenticationService.class); + @Deprecated public ApplicationAuthenticator getAuthenticator(String name) throws ApplicationAuthenticationException { if (name == null) { @@ -43,7 +44,8 @@ public ApplicationAuthenticator getAuthenticator(String name) throws Application ApplicationAuthenticator appAuthenticator = null; - for (ApplicationAuthenticator authenticator : FrameworkServiceComponent.getAuthenticators()) { + for (ApplicationAuthenticator authenticator : + ApplicationAuthenticatorManager.getInstance().getSystemDefinedAuthenticators()) { if (authenticator.getName().equals(name)) { appAuthenticator = authenticator; @@ -53,15 +55,41 @@ public ApplicationAuthenticator getAuthenticator(String name) throws Application return appAuthenticator; } - public List getAllAuthenticators() throws ApplicationAuthenticationException { - return FrameworkServiceComponent.getAuthenticators(); + @Deprecated + public ApplicationAuthenticator getAllAuthenticator( + String name, String tenantDomain) throws ApplicationAuthenticationException { + + if (name == null) { + String errMsg = "Authenticator name cannot be null"; + log.error(errMsg); + throw new ApplicationAuthenticationException(errMsg); + } + + ApplicationAuthenticator appAuthenticator = null; + + for (ApplicationAuthenticator authenticator : + ApplicationAuthenticatorManager.getInstance().getSystemDefinedAuthenticators()) { + + if (authenticator.getName().equals(name)) { + appAuthenticator = authenticator; + } + } + + return appAuthenticator; + } + + @Deprecated + public List getAllSystemAuthenticators() throws ApplicationAuthenticationException { + + return ApplicationAuthenticatorManager.getInstance().getSystemDefinedAuthenticators(); } public List getLocalAuthenticators() throws ApplicationAuthenticationException { List localAuthenticators = new ArrayList(); - for (ApplicationAuthenticator authenticator : FrameworkServiceComponent.getAuthenticators()) { + for (ApplicationAuthenticator authenticator : + ApplicationAuthenticatorManager.getInstance().getSystemDefinedAuthenticators()) { if (authenticator instanceof LocalApplicationAuthenticator) { localAuthenticators.add(authenticator); @@ -75,7 +103,8 @@ public List getFederatedAuthenticators() throws Applic List federatedAuthenticators = new ArrayList(); - for (ApplicationAuthenticator authenticator : FrameworkServiceComponent.getAuthenticators()) { + for (ApplicationAuthenticator authenticator : + ApplicationAuthenticatorManager.getInstance().getSystemDefinedAuthenticators()) { if (authenticator instanceof FederatedApplicationAuthenticator) { federatedAuthenticators.add(authenticator); @@ -89,7 +118,8 @@ public List getRequestPathAuthenticators() throws Appl List reqPathAuthenticators = new ArrayList(); - for (ApplicationAuthenticator authenticator : FrameworkServiceComponent.getAuthenticators()) { + for (ApplicationAuthenticator authenticator : + ApplicationAuthenticatorManager.getInstance().getSystemDefinedAuthenticators()) { if (authenticator instanceof RequestPathApplicationAuthenticator) { reqPathAuthenticators.add(authenticator); diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/AuthenticationService.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/AuthenticationService.java index 5a3abe96f378..366fa560594e 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/AuthenticationService.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/AuthenticationService.java @@ -25,6 +25,7 @@ import org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationResultCacheEntry; import org.wso2.carbon.identity.application.authentication.framework.exception.auth.service.AuthServiceClientException; import org.wso2.carbon.identity.application.authentication.framework.exception.auth.service.AuthServiceException; +import org.wso2.carbon.identity.application.authentication.framework.internal.core.ApplicationAuthenticatorManager; import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationResult; import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatorData; import org.wso2.carbon.identity.application.authentication.framework.model.auth.service.AuthServiceErrorInfo; @@ -140,7 +141,7 @@ private void handleIntermediateAuthResponse(AuthServiceRequestWrapper request, A List authenticatorDataList; if (isMultiOptionsResponse) { responseData.setAuthenticatorSelectionRequired(true); - authenticatorDataList = getAuthenticatorBasicData(response.getAuthenticators(), + authenticatorDataList = getAuthenticatorBasicData(request, response.getAuthenticators(), request.getAuthInitiationData()); } else { authenticatorDataList = request.getAuthInitiationData(); @@ -274,9 +275,8 @@ private String getErrorMessage(AuthServiceResponseWrapper response) throws AuthS return queryParams.get(AuthServiceConstants.AUTH_FAILURE_MSG_PARAM); } - private List getAuthenticatorBasicData(String authenticatorList, - List authInitiationData) - throws AuthServiceException { + private List getAuthenticatorBasicData(AuthServiceRequestWrapper request, + String authenticatorList, List authInitiationData) throws AuthServiceException { List authenticatorDataList = new ArrayList<>(); String[] authenticatorAndIdpsArr = StringUtils.split(authenticatorList, @@ -293,7 +293,8 @@ private List getAuthenticatorBasicData(String authenticatorLi continue; } - ApplicationAuthenticator authenticator = FrameworkUtils.getAppAuthenticatorByName(name); + ApplicationAuthenticator authenticator = ApplicationAuthenticatorManager.getInstance() + .getAppAuthenticatorByName(name, getTenantDomain((HttpServletRequest) request.getRequest())); if (authenticator == null) { throw new AuthServiceException(AuthServiceConstants.ErrorMessage.ERROR_AUTHENTICATOR_NOT_FOUND.code(), String.format(AuthServiceConstants.ErrorMessage.ERROR_AUTHENTICATOR_NOT_FOUND.description(), @@ -413,7 +414,7 @@ private void validateRequest(AuthServiceRequest authServiceRequest) throws AuthS } // Validate all configured authenticators support API based authentication. - Set authenticators = getConfiguredAuthenticators(serviceProvider); + Set authenticators = getConfiguredAuthenticators(serviceProvider, tenantDomain); for (ApplicationAuthenticator authenticator : authenticators) { if (!authenticator.isAPIBasedAuthenticationSupported()) { throw new AuthServiceClientException( @@ -425,7 +426,8 @@ private void validateRequest(AuthServiceRequest authServiceRequest) throws AuthS } - private Set getConfiguredAuthenticators(ServiceProvider serviceProvider) { + private Set getConfiguredAuthenticators(ServiceProvider serviceProvider, + String tenantDomain) { LocalAndOutboundAuthenticationConfig authenticationConfig = serviceProvider .getLocalAndOutBoundAuthenticationConfig(); @@ -435,40 +437,42 @@ private Set getConfiguredAuthenticators(ServiceProvide Set authenticators = new HashSet<>(); for (AuthenticationStep authenticationStep : authenticationConfig.getAuthenticationSteps()) { - processLocalAuthenticators(authenticationStep, authenticators); - processFederatedAuthenticators(authenticationStep, authenticators); + processLocalAuthenticators(authenticationStep, authenticators, tenantDomain); + processFederatedAuthenticators(authenticationStep, authenticators, tenantDomain); } return authenticators; } private void processLocalAuthenticators(AuthenticationStep authenticationStep, - Set authenticators) { + Set authenticators, String tenantDomain) { if (authenticationStep.getLocalAuthenticatorConfigs() != null) { for (LocalAuthenticatorConfig localAuthenticatorConfig : authenticationStep.getLocalAuthenticatorConfigs()) { - addAuthenticator(authenticators, localAuthenticatorConfig.getName()); + addAuthenticator(authenticators, localAuthenticatorConfig.getName(), tenantDomain); } } } private void processFederatedAuthenticators(AuthenticationStep authenticationStep, - Set authenticators) { + Set authenticators, String tenantDomain) { if (authenticationStep.getFederatedIdentityProviders() != null) { for (IdentityProvider federatedIdP : authenticationStep.getFederatedIdentityProviders()) { FederatedAuthenticatorConfig fedAuthenticatorConfig = federatedIdP.getDefaultAuthenticatorConfig(); if (fedAuthenticatorConfig != null) { - addAuthenticator(authenticators, fedAuthenticatorConfig.getName()); + addAuthenticator(authenticators, fedAuthenticatorConfig.getName(), tenantDomain); } } } } - private void addAuthenticator(Set authenticators, String authenticatorName) { + private void addAuthenticator(Set authenticators, String authenticatorName, + String tenantDomain) { - ApplicationAuthenticator authenticator = FrameworkUtils.getAppAuthenticatorByName(authenticatorName); + ApplicationAuthenticator authenticator = ApplicationAuthenticatorManager.getInstance() + .getAppAuthenticatorByName(authenticatorName, tenantDomain); if (authenticator != null) { authenticators.add(authenticator); } diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/cache/AuthenticationContextLoader.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/cache/AuthenticationContextLoader.java index fd4426586df6..36f527f8f8d5 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/cache/AuthenticationContextLoader.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/cache/AuthenticationContextLoader.java @@ -32,7 +32,7 @@ import org.wso2.carbon.identity.application.authentication.framework.exception.session.storage.SessionDataStorageOptimizationException; import org.wso2.carbon.identity.application.authentication.framework.exception.session.storage.SessionDataStorageOptimizationServerException; import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder; -import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils; +import org.wso2.carbon.identity.application.authentication.framework.internal.core.ApplicationAuthenticatorManager; import org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException; import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException; import org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException; @@ -175,8 +175,8 @@ private void loadAuthenticatorConfig(AuthenticationContext context) StepConfig stepConfig = entry.getValue(); for (AuthenticatorConfig authenticatorConfig : stepConfig.getAuthenticatorList()) { if (authenticatorConfig.getApplicationAuthenticator() == null) { - authenticatorConfig.setApplicationAuthenticator(FrameworkUtils. - getAppAuthenticatorByName(authenticatorConfig.getName())); + authenticatorConfig.setApplicationAuthenticator(ApplicationAuthenticatorManager.getInstance() + .getAppAuthenticatorByName(authenticatorConfig.getName(), context.getTenantDomain())); } if (authenticatorConfig.getIdps() == null && authenticatorConfig.getIdpNames() == null) { authenticatorConfig.setIdPs(Collections.emptyMap()); diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/builder/FileBasedConfigurationBuilder.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/builder/FileBasedConfigurationBuilder.java index 8883e1e606f8..8dee064505b5 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/builder/FileBasedConfigurationBuilder.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/builder/FileBasedConfigurationBuilder.java @@ -28,8 +28,8 @@ import org.wso2.carbon.identity.application.authentication.framework.config.model.ExternalIdPConfig; import org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig; import org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig; +import org.wso2.carbon.identity.application.authentication.framework.internal.core.ApplicationAuthenticatorManager; import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants; -import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils; import org.wso2.carbon.identity.application.common.model.IdentityProvider; import org.wso2.carbon.identity.application.common.util.IdentityApplicationConstants; import org.wso2.carbon.identity.application.common.util.IdentityApplicationManagementUtil; @@ -901,7 +901,8 @@ private AuthenticatorConfig processAuthenticatorConfigElement(OMElement authenti } AuthenticatorConfig authenticatorConfig = new AuthenticatorConfig(authenticatorName, enabled, parameterMap); - authenticatorConfig.setApplicationAuthenticator(FrameworkUtils.getAppAuthenticatorByName(authenticatorName)); + authenticatorConfig.setApplicationAuthenticator(ApplicationAuthenticatorManager.getInstance() + .getSystemDefinedAuthenticatorByName(authenticatorName)); return authenticatorConfig; } diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/loader/UIBasedConfigurationLoader.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/loader/UIBasedConfigurationLoader.java index e4556a87159c..b0c11d6e6933 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/loader/UIBasedConfigurationLoader.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/loader/UIBasedConfigurationLoader.java @@ -31,8 +31,8 @@ import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGenericGraphBuilderFactory; import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; import org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException; -import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceComponent; import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder; +import org.wso2.carbon.identity.application.authentication.framework.internal.core.ApplicationAuthenticatorManager; import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants; import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils; import org.wso2.carbon.identity.application.common.ApplicationAuthenticatorService; @@ -228,7 +228,8 @@ protected void loadRequestPathAuthenticators(SequenceConfig sequenceConfig, Serv authConfig.setEnabled(true); // iterate through each system authentication config - for (ApplicationAuthenticator appAuthenticator : FrameworkServiceComponent.getAuthenticators()) { + for (ApplicationAuthenticator appAuthenticator : + ApplicationAuthenticatorManager.getInstance().getSystemDefinedAuthenticators()) { if (authenticatorName.equalsIgnoreCase(appAuthenticator.getName())) { authConfig.setApplicationAuthenticator(appAuthenticator); @@ -308,7 +309,8 @@ private void loadStepAuthenticator(StepConfig stepConfig, IdentityProvider idp, authenticatorConfig.setName(authenticatorName); ApplicationAuthenticator appAuthenticatorForConfig = null; - for (ApplicationAuthenticator appAuthenticator : FrameworkServiceComponent.getAuthenticators()) { + for (ApplicationAuthenticator appAuthenticator : + ApplicationAuthenticatorManager.getInstance().getSystemDefinedAuthenticators()) { if (authenticatorName.equalsIgnoreCase(appAuthenticator.getName())) { appAuthenticatorForConfig = appAuthenticator; diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/OptimizedAuthenticatorConfig.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/OptimizedAuthenticatorConfig.java index 95adf0590bfb..31e42716420f 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/OptimizedAuthenticatorConfig.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/OptimizedAuthenticatorConfig.java @@ -26,7 +26,7 @@ import org.wso2.carbon.identity.application.authentication.framework.exception.session.storage.SessionDataStorageOptimizationException; import org.wso2.carbon.identity.application.authentication.framework.exception.session.storage.SessionDataStorageOptimizationServerException; import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder; -import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils; +import org.wso2.carbon.identity.application.authentication.framework.internal.core.ApplicationAuthenticatorManager; import org.wso2.carbon.identity.application.common.model.IdentityProvider; import org.wso2.carbon.idp.mgt.IdentityProviderManagementClientException; import org.wso2.carbon.idp.mgt.IdentityProviderManagementException; @@ -80,7 +80,8 @@ public AuthenticatorConfig getAuthenticatorConfig() throws AuthenticatorConfig authenticatorConfig = new AuthenticatorConfig(); authenticatorConfig.setName(this.name); authenticatorConfig.setEnabled(this.enabled); - authenticatorConfig.setApplicationAuthenticator(FrameworkUtils.getAppAuthenticatorByName(this.name)); + authenticatorConfig.setApplicationAuthenticator(ApplicationAuthenticatorManager.getInstance() + .getAppAuthenticatorByName(this.name, tenantDomain)); authenticatorConfig.setAuthenticatorStateInfo(this.authenticatorStateInfo); authenticatorConfig.setParameterMap(this.parameterMap); Map idps = new HashMap<>(); diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/internal/FrameworkServiceComponent.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/internal/FrameworkServiceComponent.java index d500ce7ea9f5..947d8a622c8f 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/internal/FrameworkServiceComponent.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/internal/FrameworkServiceComponent.java @@ -75,6 +75,7 @@ import org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityResponseFactory; import org.wso2.carbon.identity.application.authentication.framework.inbound.IdentityProcessor; import org.wso2.carbon.identity.application.authentication.framework.inbound.IdentityServlet; +import org.wso2.carbon.identity.application.authentication.framework.internal.core.ApplicationAuthenticatorManager; import org.wso2.carbon.identity.application.authentication.framework.internal.impl.AuthenticationMethodNameTranslatorImpl; import org.wso2.carbon.identity.application.authentication.framework.internal.impl.ServerSessionManagementServiceImpl; import org.wso2.carbon.identity.application.authentication.framework.internal.impl.UserSessionManagementServiceImpl; @@ -193,11 +194,6 @@ public static BundleContext getBundleContext() throws FrameworkException { return bundleContext; } - public static List getAuthenticators() { - - return FrameworkServiceDataHolder.getInstance().getAuthenticators(); - } - @SuppressWarnings("unchecked") @Activate protected void activate(ComponentContext ctxt) { @@ -483,7 +479,7 @@ protected void unsetRealmService(RealmService realmService) { ) protected void setAuthenticator(ApplicationAuthenticator authenticator) { - FrameworkServiceDataHolder.getInstance().getAuthenticators().add(authenticator); + ApplicationAuthenticatorManager.getInstance().addSystemDefinedAuthenticator(authenticator); Property[] configProperties = null; @@ -583,7 +579,7 @@ protected void unsetSessionSerializer(SessionSerializer sessionSerializer) { protected void unsetAuthenticator(ApplicationAuthenticator authenticator) { - FrameworkServiceDataHolder.getInstance().getAuthenticators().remove(authenticator); + ApplicationAuthenticatorManager.getInstance().removeSystemDefinedAuthenticator(authenticator); String authenticatorName = authenticator.getName(); ApplicationAuthenticatorService appAuthenticatorService = ApplicationAuthenticatorService.getInstance(); @@ -1116,7 +1112,7 @@ protected void unsetRoleManagementServiceV2(RoleManagementService roleManagement @Reference( name = "org.wso2.carbon.identity.application.authentication.framework.AuthenticatorAdapterService", service = org.wso2.carbon.identity.application.authentication.framework.AuthenticatorAdapterService.class, - cardinality = ReferenceCardinality.OPTIONAL, + cardinality = ReferenceCardinality.MANDATORY, policy = ReferencePolicy.DYNAMIC, unbind = "unsetAuthenticatorAdapterService") protected void setAuthenticatorAdapterService(AuthenticatorAdapterService adapterService) { diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/internal/FrameworkServiceDataHolder.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/internal/FrameworkServiceDataHolder.java index f4f6566f2ffb..b445447c5c52 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/internal/FrameworkServiceDataHolder.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/internal/FrameworkServiceDataHolder.java @@ -23,7 +23,6 @@ import org.apache.commons.logging.LogFactory; import org.osgi.framework.BundleContext; import org.wso2.carbon.consent.mgt.core.ConsentManager; -import org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticator; import org.wso2.carbon.identity.application.authentication.framework.AuthenticationDataPublisher; import org.wso2.carbon.identity.application.authentication.framework.AuthenticationMethodNameTranslator; import org.wso2.carbon.identity.application.authentication.framework.AuthenticatorAdapterService; @@ -78,7 +77,6 @@ public class FrameworkServiceDataHolder { private static FrameworkServiceDataHolder instance = new FrameworkServiceDataHolder(); private BundleContext bundleContext = null; private RealmService realmService = null; - private List authenticators = new ArrayList<>(); private List applicationRolesResolvers = new ArrayList<>(); private long nanoTimeReference = 0; private long unixTimeReference = 0; @@ -166,11 +164,6 @@ public void setBundleContext(BundleContext bundleContext) { this.bundleContext = bundleContext; } - public List getAuthenticators() { - - return authenticators; - } - /** * Add an application role resolver to the list of application role resolvers. * diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/internal/core/ApplicationAuthenticatorManager.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/internal/core/ApplicationAuthenticatorManager.java new file mode 100644 index 000000000000..ebf89e9a67c4 --- /dev/null +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/internal/core/ApplicationAuthenticatorManager.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.identity.application.authentication.framework.internal.core; + +import org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticator; +import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder; +import org.wso2.carbon.identity.application.common.ApplicationAuthenticatorService; +import org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig; +import org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig; +import org.wso2.carbon.idp.mgt.IdentityProviderManager; + +import java.util.ArrayList; +import java.util.List; + +/** + * This class is used to manage the authenticator adapters for user defined authenticators. + */ +public class ApplicationAuthenticatorManager { + + private static final ApplicationAuthenticatorManager instance = new ApplicationAuthenticatorManager(); + private final List systemDefinedAuthenticators = new ArrayList<>(); + + public static ApplicationAuthenticatorManager getInstance() { + + return instance; + } + + public void addSystemDefinedAuthenticator(ApplicationAuthenticator authenticator) { + + systemDefinedAuthenticators.add(authenticator); + } + + public void removeSystemDefinedAuthenticator(ApplicationAuthenticator authenticator) { + + systemDefinedAuthenticators.remove(authenticator); + } + + public List getSystemDefinedAuthenticators() { + + return systemDefinedAuthenticators; + } + + public ApplicationAuthenticator getSystemDefinedAuthenticatorByName(String authenticatorName) { + + for (ApplicationAuthenticator authenticator : systemDefinedAuthenticators) { + if (authenticator.getName().equals(authenticatorName)) { + return authenticator; + } + } + return null; + } + + public ApplicationAuthenticator getAppAuthenticatorByName(String authenticatorName, String tenantDomain) { + + for (ApplicationAuthenticator authenticator : systemDefinedAuthenticators) { + if (authenticator.getName().equals(authenticatorName)) { + return authenticator; + } + } + + try { + LocalAuthenticatorConfig localConfig = ApplicationAuthenticatorService.getInstance() + .getUserDefinedLocalAuthenticator(tenantDomain, authenticatorName); + if (localConfig != null) { + return FrameworkServiceDataHolder.getInstance().getAuthenticatorAdapterService() + .getLocalAuthenticatorAdapter(localConfig); + } + + FederatedAuthenticatorConfig[] fedConfig = IdentityProviderManager.getInstance() + .getAllFederatedAuthenticators(tenantDomain); + for (FederatedAuthenticatorConfig fedAuth : fedConfig) { + if (fedAuth.getName().equals(authenticatorName)) { + return FrameworkServiceDataHolder.getInstance().getAuthenticatorAdapterService() + .getFederatedAuthenticatorAdapter(fedAuth); + } + } + return null; + } catch (Exception e) { + throw new RuntimeException("Error while getting the authenticator for the name: " + authenticatorName, e); + } + } +} diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/util/FrameworkUtils.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/util/FrameworkUtils.java index e346a3c25f52..4c3e65f58b36 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/util/FrameworkUtils.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/util/FrameworkUtils.java @@ -99,6 +99,7 @@ import org.wso2.carbon.identity.application.authentication.framework.handler.step.impl.GraphBasedStepHandler; import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceComponent; import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder; +import org.wso2.carbon.identity.application.authentication.framework.internal.core.ApplicationAuthenticatorManager; import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedIdPData; import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser; import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationError; @@ -260,6 +261,9 @@ public class FrameworkUtils { private static final String JDK_SCRIPTER_CLASS_NAME = "jdk.nashorn.api.scripting.ScriptObjectMirror"; private static final String GRAALJS_SCRIPTER_CLASS_NAME = "org.graalvm.polyglot.Context"; + private static final ApplicationAuthenticatorManager applicationAuthenticatorManager = + ApplicationAuthenticatorManager.getInstance(); + private FrameworkUtils() { } @@ -371,13 +375,16 @@ public static HttpServletRequest getCommonAuthReqWithParams(HttpServletRequest r } /** - * @param name - * @return + * Get system defined application authenticator by name. + * + * @param name Name of the authenticator. + * @return ApplicationAuthenticator. */ + @Deprecated public static ApplicationAuthenticator getAppAuthenticatorByName(String name) { - for (ApplicationAuthenticator authenticator : FrameworkServiceComponent.getAuthenticators()) { - + for (ApplicationAuthenticator authenticator : + applicationAuthenticatorManager.getSystemDefinedAuthenticators()) { if (name.equals(authenticator.getName())) { return authenticator; } @@ -401,7 +408,8 @@ public static AuthenticationContext getContextData(HttpServletRequest request) { return context; } } - for (ApplicationAuthenticator authenticator : FrameworkServiceComponent.getAuthenticators()) { + for (ApplicationAuthenticator authenticator : ApplicationAuthenticatorManager.getInstance() + .getSystemDefinedAuthenticators()) { try { String contextIdentifier = authenticator.getContextIdentifier(request); @@ -411,6 +419,8 @@ public static AuthenticationContext getContextData(HttpServletRequest request) { break; } } + contextIdentifier = request.getParameter("sessionDataKey"); + context = FrameworkUtils.getAuthenticationContextFromCache(contextIdentifier); } catch (UnsupportedOperationException e) { if (log.isDebugEnabled()) { log.debug("Ignore UnsupportedOperationException.", e);