diff --git a/components/action-mgt/org.wso2.carbon.identity.action.execution/src/main/java/org/wso2/carbon/identity/action/execution/internal/service/impl/ActionExecutorServiceImpl.java b/components/action-mgt/org.wso2.carbon.identity.action.execution/src/main/java/org/wso2/carbon/identity/action/execution/internal/service/impl/ActionExecutorServiceImpl.java index 97471a8f9510..0def0a166348 100644 --- a/components/action-mgt/org.wso2.carbon.identity.action.execution/src/main/java/org/wso2/carbon/identity/action/execution/internal/service/impl/ActionExecutorServiceImpl.java +++ b/components/action-mgt/org.wso2.carbon.identity.action.execution/src/main/java/org/wso2/carbon/identity/action/execution/internal/service/impl/ActionExecutorServiceImpl.java @@ -25,6 +25,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.osgi.annotation.bundle.Capability; import org.wso2.carbon.identity.action.execution.api.exception.ActionExecutionException; import org.wso2.carbon.identity.action.execution.api.exception.ActionExecutionRequestBuilderException; import org.wso2.carbon.identity.action.execution.api.exception.ActionExecutionResponseProcessorException; @@ -83,6 +84,13 @@ * It is responsible for building the request payload, calling the API, processing the response and * returning the status of the action execution. */ +@Capability( + namespace = "osgi.service", + attribute = { + "objectClass=org.wso2.carbon.identity.action.execution.api.service.ActionExecutorService", + "service.scope=singleton" + } +) public class ActionExecutorServiceImpl implements ActionExecutorService { private static final Log LOG = LogFactory.getLog(ActionExecutorServiceImpl.class); diff --git a/components/action-mgt/org.wso2.carbon.identity.action.management/src/main/java/org/wso2/carbon/identity/action/management/internal/service/impl/CacheBackedActionManagementService.java b/components/action-mgt/org.wso2.carbon.identity.action.management/src/main/java/org/wso2/carbon/identity/action/management/internal/service/impl/CacheBackedActionManagementService.java index 992d96eb825f..7a25bcf82415 100644 --- a/components/action-mgt/org.wso2.carbon.identity.action.management/src/main/java/org/wso2/carbon/identity/action/management/internal/service/impl/CacheBackedActionManagementService.java +++ b/components/action-mgt/org.wso2.carbon.identity.action.management/src/main/java/org/wso2/carbon/identity/action/management/internal/service/impl/CacheBackedActionManagementService.java @@ -21,6 +21,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.osgi.annotation.bundle.Capability; import org.wso2.carbon.identity.action.management.api.exception.ActionMgtException; import org.wso2.carbon.identity.action.management.api.model.Action; import org.wso2.carbon.identity.action.management.api.model.Authentication; @@ -35,6 +36,13 @@ /** * CacheBackedActionManagementService act as the caching layer for the Action Management Service. */ +@Capability( + namespace = "osgi.service", + attribute = { + "objectClass=org.wso2.carbon.identity.action.management.api.service.ActionManagementService", + "service.scope=singleton" + } +) public class CacheBackedActionManagementService implements ActionManagementService { private static final CacheBackedActionManagementService INSTANCE = new CacheBackedActionManagementService(); diff --git a/components/api-resource-mgt/org.wso2.carbon.identity.api.resource.mgt/src/main/java/org/wso2/carbon/identity/api/resource/mgt/APIResourceManagerImpl.java b/components/api-resource-mgt/org.wso2.carbon.identity.api.resource.mgt/src/main/java/org/wso2/carbon/identity/api/resource/mgt/APIResourceManagerImpl.java index a6f67d65c3c9..390463e01c3e 100644 --- a/components/api-resource-mgt/org.wso2.carbon.identity.api.resource.mgt/src/main/java/org/wso2/carbon/identity/api/resource/mgt/APIResourceManagerImpl.java +++ b/components/api-resource-mgt/org.wso2.carbon.identity.api.resource.mgt/src/main/java/org/wso2/carbon/identity/api/resource/mgt/APIResourceManagerImpl.java @@ -19,6 +19,7 @@ package org.wso2.carbon.identity.api.resource.mgt; import org.apache.commons.lang.StringUtils; +import org.osgi.annotation.bundle.Capability; import org.wso2.carbon.identity.api.resource.mgt.constant.APIResourceManagementConstants; import org.wso2.carbon.identity.api.resource.mgt.dao.impl.APIResourceManagementDAOImpl; import org.wso2.carbon.identity.api.resource.mgt.dao.impl.CacheBackedAPIResourceMgtDAO; @@ -38,6 +39,13 @@ /** * API resource management service. */ +@Capability( + namespace = "osgi.service", + attribute = { + "objectClass=org.wso2.carbon.identity.api.resource.mgt.APIResourceManager", + "service.scope=singleton" + } +) public class APIResourceManagerImpl implements APIResourceManager { private static final APIResourceManager INSTANCE = new APIResourceManagerImpl(); diff --git a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ApplicationManagementServiceImpl.java b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ApplicationManagementServiceImpl.java index c132355d58a6..7f1af7dee0a3 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ApplicationManagementServiceImpl.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ApplicationManagementServiceImpl.java @@ -25,6 +25,7 @@ import org.apache.commons.lang3.SerializationUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.osgi.annotation.bundle.Capability; import org.w3c.dom.Document; import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.context.CarbonContext; @@ -194,6 +195,13 @@ /** * Application management service implementation. */ +@Capability( + namespace = "osgi.service", + attribute = { + "objectClass=org.wso2.carbon.identity.application.mgt.ApplicationManagementService", + "service.scope=singleton" + } +) public class ApplicationManagementServiceImpl extends ApplicationManagementService { private static final Log log = LogFactory.getLog(ApplicationManagementServiceImpl.class); diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/pom.xml b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/pom.xml index 883b979c7520..ca1e5edcc3b6 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/pom.xml +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/pom.xml @@ -119,7 +119,7 @@ org.wso2.carbon.identity.user.profile - org.wso2.eclipse.osgi + org.eclipse.platform org.eclipse.osgi.services @@ -265,7 +265,6 @@ javax.xml.namespace, javax.xml.stream, - org.eclipse.equinox.http.helper, javax.servlet.*; version="${imp.pkg.version.javax.servlet}", org.apache.axiom.*; version="${axiom.osgi.version.range}", 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/graph/JsGraphBuilderFactory.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/JsGraphBuilderFactory.java deleted file mode 100644 index 0d4d806a97bf..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/JsGraphBuilderFactory.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (c) 2017, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph; - -import jdk.nashorn.api.scripting.ClassFilter; -import jdk.nashorn.api.scripting.NashornScriptEngineFactory; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.AbstractJSObjectWrapper; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsLogger; -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.handler.sequence.impl.SelectAcrFromFunction; -import org.wso2.carbon.identity.application.authentication.framework.handler.sequence.impl.SelectOneFunction; -import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants; -import org.wso2.carbon.identity.base.IdentityRuntimeException; -import org.wso2.carbon.identity.core.util.IdentityUtil; - -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - -import javax.script.Bindings; -import javax.script.ScriptContext; -import javax.script.ScriptEngine; - -/** - * Factory to create a Javascript based sequence builder. - * This factory is there to reuse of Nashorn engine and any related expnsive objects. - */ -public class JsGraphBuilderFactory implements JsBaseGraphBuilderFactory { - - private static final Log LOG = LogFactory.getLog(JsGraphBuilderFactory.class); - private static final String JS_BINDING_CURRENT_CONTEXT = "JS_BINDING_CURRENT_CONTEXT"; - private static final String[] NASHORN_ARGS = {"--no-java", "--no-deprecation-warning"}; - - private ClassFilter classFilter; - - // Suppress the Nashorn deprecation warnings in jdk 11 - @SuppressWarnings("removal") - private NashornScriptEngineFactory factory; - - private static boolean useThreadLocalScriptEngine = false; - - public void init() { - - factory = new NashornScriptEngineFactory(); - classFilter = new RestrictedClassFilter(); - setUseThreadLocalScriptEngine(); - } - - public static void restoreCurrentContext(AuthenticationContext context, ScriptEngine engine) - throws FrameworkException { - - Map map = (Map) context.getProperty(JS_BINDING_CURRENT_CONTEXT); - Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE); - if (map != null) { - for (Map.Entry entry : map.entrySet()) { - Object deserializedValue = JsNashornSerializer.fromJsSerializableInternal(entry.getValue(), engine); - if (deserializedValue instanceof AbstractJSObjectWrapper) { - ((AbstractJSObjectWrapper) deserializedValue).initializeContext(context); - } - bindings.put(entry.getKey(), deserializedValue); - } - } - } - - public static void persistCurrentContext(AuthenticationContext context, ScriptEngine engine) { - - Bindings engineBindings = engine.getBindings(ScriptContext.ENGINE_SCOPE); - Map persistableMap = new HashMap<>(); - engineBindings.forEach((key, value) -> persistableMap.put(key, - JsNashornSerializer.toJsSerializableInternal(value))); - context.setProperty(JS_BINDING_CURRENT_CONTEXT, persistableMap); - } - - public ScriptEngine createEngine(AuthenticationContext authenticationContext) { - - ScriptEngine engine; - Bindings globalBindings; - if (useThreadLocalScriptEngine) { - Optional optionalScriptEngine = new ThreadLocalScriptEngineHolder().getScriptEngine(); - engine = optionalScriptEngine.orElseThrow( - () -> new IdentityRuntimeException("Failed to create a script engine")); - globalBindings = engine.getBindings(ScriptContext.GLOBAL_SCOPE); - } else { - engine = factory.getScriptEngine(NASHORN_ARGS, getClassLoader(), classFilter); - globalBindings = engine.createBindings(); - engine.setBindings(globalBindings, ScriptContext.GLOBAL_SCOPE); - engine.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE); - } - SelectAcrFromFunction selectAcrFromFunction = new SelectAcrFromFunction(); -// todo move to functions registry - globalBindings.put(FrameworkConstants.JSAttributes.JS_FUNC_SELECT_ACR_FROM, - (SelectOneFunction) selectAcrFromFunction::evaluate); - - JsLogger jsLogger = new JsLogger(); - globalBindings.put(FrameworkConstants.JSAttributes.JS_LOG, jsLogger); - return engine; - } - - @Override - public JsSerializer getJsUtil() { - - return JsNashornSerializer.getInstance(); - } - - @Override - public JsBaseGraphBuilder getCurrentBuilder() { - - return JsNashornGraphBuilder.getCurrentBuilder(); - } - - private ClassLoader getClassLoader() { - - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - return classLoader == null ? NashornScriptEngineFactory.class.getClassLoader() : classLoader; - } - - public JsNashornGraphBuilder createBuilder(AuthenticationContext authenticationContext, - Map stepConfigMap) { - - return new JsNashornGraphBuilder(authenticationContext, stepConfigMap, createEngine(authenticationContext)); - } - - public JsNashornGraphBuilder createBuilder(AuthenticationContext authenticationContext, - Map stepConfigMap, AuthGraphNode currentNode) { - - return new JsNashornGraphBuilder(authenticationContext, stepConfigMap, - createEngine(authenticationContext), currentNode); - } - - private void setUseThreadLocalScriptEngine() { - - useThreadLocalScriptEngine = - Boolean.parseBoolean(IdentityUtil.getProperty(FrameworkConstants.THREAD_LOCAL_SCRIPT_ENGINE_CONFIG)); - } - -} 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/graph/JsNashornGraphBuilder.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/JsNashornGraphBuilder.java deleted file mode 100644 index 177e04fdb099..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/JsNashornGraphBuilder.java +++ /dev/null @@ -1,1216 +0,0 @@ -/* - * Copyright (c) 2017, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph; - -import jdk.nashorn.api.scripting.ScriptObjectMirror; -import org.apache.commons.collections.MapUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.context.CarbonContext; -import org.wso2.carbon.identity.application.authentication.framework.AsyncProcess; -import org.wso2.carbon.identity.application.authentication.framework.AuthenticationDecisionEvaluator; -import org.wso2.carbon.identity.application.authentication.framework.JsFunctionRegistry; -import org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig; -import org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.nashorn.JsNashornAuthenticationContext; -import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; -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.util.FrameworkConstants; -import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils; -import org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig; -import org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig; -import org.wso2.carbon.identity.central.log.mgt.utils.LogConstants; -import org.wso2.carbon.identity.central.log.mgt.utils.LoggerUtils; -import org.wso2.carbon.identity.functions.library.mgt.FunctionLibraryManagementService; -import org.wso2.carbon.identity.functions.library.mgt.exception.FunctionLibraryManagementException; -import org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary; -import org.wso2.carbon.utils.DiagnosticLog; - -import java.io.Serializable; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.function.BiConsumer; -import java.util.stream.Collectors; - -import javax.script.Bindings; -import javax.script.Invocable; -import javax.script.ScriptContext; -import javax.script.ScriptEngine; -import javax.script.ScriptException; - -/** - * Translate the authentication graph config to runtime model. - * This is not thread safe. Should be discarded after each build. - */ -public class JsNashornGraphBuilder extends JsGraphBuilder { - - private static final Log log = LogFactory.getLog(JsNashornGraphBuilder.class); - private Map stepNamedMap; - private AuthenticationGraph result = new AuthenticationGraph(); - private AuthGraphNode currentNode = null; - private AuthenticationContext authenticationContext; - private ScriptEngine engine; - private static ThreadLocal contextForJs = new ThreadLocal<>(); - private static ThreadLocal dynamicallyBuiltBaseNode = new ThreadLocal<>(); - private static ThreadLocal currentBuilder = new ThreadLocal<>(); - private static final String REMOVE_FUNCTIONS = "var quit=function(){Log.error('quit function is restricted.')};" + - "var exit=function(){Log.error('exit function is restricted.')};" + - "var print=function(){Log.error('print function is restricted.')};" + - "var echo=function(){Log.error('echo function is restricted.')};" + - "var readFully=function(){Log.error('readFully function is restricted.')};" + - "var readLine=function(){Log.error('readLine function is restricted.')};" + - "var load=function(){Log.error('load function is restricted.')};" + - "var loadWithNewGlobal=function(){Log.error('loadWithNewGlobal function is restricted.')};" + - "var $ARG=null;var $ENV=null;var $EXEC=null;" + - "var $OPTIONS=null;var $OUT=null;var $ERR=null;var $EXIT=null;" + - "Object.defineProperty(this, 'engine', {});"; - - /** - * Constructs the builder with the given authentication context. - * - * @param authenticationContext current authentication context. - * @param stepConfigMap The Step map from the service provider configuration. - * @param scriptEngine Script engine. - */ - public JsNashornGraphBuilder(AuthenticationContext authenticationContext, Map stepConfigMap, - ScriptEngine scriptEngine) { - - this.engine = scriptEngine; - this.authenticationContext = authenticationContext; - stepNamedMap = stepConfigMap.entrySet().stream() - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - } - - /** - * Constructs the builder with the given authentication context. - * - * @param authenticationContext current authentication context. - * @param stepConfigMap The Step map from the service provider configuration. - * @param scriptEngine Script engine. - * @param currentNode Current authentication graph node. - */ - public JsNashornGraphBuilder(AuthenticationContext authenticationContext, Map stepConfigMap, - ScriptEngine scriptEngine, AuthGraphNode currentNode) { - - this.engine = scriptEngine; - this.authenticationContext = authenticationContext; - this.currentNode = currentNode; - stepNamedMap = stepConfigMap.entrySet().stream() - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - } - - /** - * Returns the built graph. - * - * @return AuthenticationGraph built from JsGraphBuilder - */ - public AuthenticationGraph build() { - - if (result.isBuildSuccessful()) { - if (currentNode != null && !(currentNode instanceof EndStep)) { - attachToLeaf(currentNode, new EndStep()); - } - } else { - //no need to do anything - if (log.isDebugEnabled()) { - log.debug("Not building the graph as the initialization was unsuccessful."); - } - } - return result; - } - - @Override - public AuthenticationDecisionEvaluator getScriptEvaluator(GenericSerializableJsFunction fn) { - - return new JsBasedEvaluator((SerializableJsFunction) fn); - } - - /** - * Creates the graph with the given Script and step map. - * - * @param script the Dynamic authentication script. - */ - public JsNashornGraphBuilder createWith(String script) { - - try { - currentBuilder.set(this); - Bindings globalBindings = engine.getBindings(ScriptContext.GLOBAL_SCOPE); - globalBindings.put(FrameworkConstants.JSAttributes.JS_FUNC_EXECUTE_STEP, (StepExecutor) this::executeStep); - globalBindings.put(FrameworkConstants.JSAttributes.JS_FUNC_SEND_ERROR, (BiConsumer) - this::sendError); - globalBindings.put(FrameworkConstants.JSAttributes.JS_AUTH_FAILURE, - (FailAuthenticationFunction) this::fail); - globalBindings.put(FrameworkConstants.JSAttributes.JS_FUNC_SHOW_PROMPT, - (PromptExecutor) this::addShowPrompt); - globalBindings.put(FrameworkConstants.JSAttributes.JS_FUNC_LOAD_FUNC_LIB, - (LoadExecutor) this::loadLocalLibrary); - JsFunctionRegistry jsFunctionRegistrar = FrameworkServiceDataHolder.getInstance().getJsFunctionRegistry(); - if (jsFunctionRegistrar != null) { - Map functionMap = jsFunctionRegistrar - .getSubsystemFunctionsMap(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER); - functionMap.forEach(globalBindings::put); - } - Invocable invocable = (Invocable) engine; - engine.eval(FrameworkServiceDataHolder.getInstance().getCodeForRequireFunction()); - removeDefaultFunctions(engine); - - String identifier = UUID.randomUUID().toString(); - JSExecutionMonitorData scriptExecutionData; - try { - startScriptExecutionMonitor(identifier, authenticationContext); - engine.eval(script); - invocable.invokeFunction(FrameworkConstants.JSAttributes.JS_FUNC_ON_LOGIN_REQUEST, - new JsNashornAuthenticationContext(authenticationContext)); - } finally { - scriptExecutionData = endScriptExecutionMonitor(identifier); - } - if (scriptExecutionData != null) { - storeAuthScriptExecutionMonitorData(authenticationContext, scriptExecutionData); - } - JsGraphBuilderFactory.persistCurrentContext(authenticationContext, engine); - } catch (ScriptException e) { - result.setBuildSuccessful(false); - result.setErrorReason("Error in executing the Javascript. Nested exception is: " + e.getMessage()); - if (log.isDebugEnabled()) { - log.debug("Error in executing the Javascript.", e); - } - } catch (NoSuchMethodException e) { - result.setBuildSuccessful(false); - result.setErrorReason("Error in executing the Javascript. " + FrameworkConstants.JSAttributes - .JS_FUNC_ON_LOGIN_REQUEST + " function is not defined."); - if (log.isDebugEnabled()) { - log.debug("Error in executing the Javascript.", e); - } - } finally { - clearCurrentBuilder(); - } - return this; - } - - public static void clearCurrentBuilder() { - - currentBuilder.remove(); - } - - public static JsNashornGraphBuilder getCurrentBuilder() { - - return currentBuilder.get(); - } - - /** - * Add authentication fail node to the authentication graph during subsequent requests. - * - * @param parameterMap Parameters needed to send the error. - */ - public static void sendErrorAsync(String url, Map parameterMap) { - - FailNode newNode = createFailNode(url, parameterMap, true); - - AuthGraphNode currentNode = dynamicallyBuiltBaseNode.get(); - if (currentNode == null) { - dynamicallyBuiltBaseNode.set(newNode); - } else { - attachToLeaf(currentNode, newNode); - } - } - - private static FailNode createFailNode(String url, Map parameterMap, boolean isShowErrorPage) { - - FailNode failNode = new FailNode(); - if (isShowErrorPage && StringUtils.isNotBlank(url)) { - failNode.setErrorPageUri(url); - } - // setShowErrorPage is set to true as sendError function redirects to a specific error page. - failNode.setShowErrorPage(isShowErrorPage); - - parameterMap.forEach((key, value) -> failNode.getFailureData().put(key, String.valueOf(value))); - return failNode; - } - - /** - * Add authentication fail node to the authentication graph in the initial request. - * - * @param parameterMap Parameters needed to send the error. - */ - public void sendError(String url, Map parameterMap) { - - FailNode newNode = createFailNode(url, parameterMap, true); - if (currentNode == null) { - result.setStartNode(newNode); - } else { - attachToLeaf(currentNode, newNode); - } - } - - @SuppressWarnings("unchecked") - public void fail(Object... parameters) { - - Map parameterMap; - - if (parameters.length == 1) { - parameterMap = (Map) parameters[0]; - } else { - parameterMap = Collections.EMPTY_MAP; - } - - FailNode newNode = createFailNode(StringUtils.EMPTY, parameterMap, false); - - if (currentNode == null) { - result.setStartNode(newNode); - } else { - attachToLeaf(currentNode, newNode); - } - } - - @SuppressWarnings("unchecked") - public static void failAsync(Object... parameters) { - - Map parameterMap; - - if (parameters.length == 1) { - parameterMap = (Map) parameters[0]; - } else { - parameterMap = Collections.EMPTY_MAP; - } - - FailNode newNode = createFailNode(StringUtils.EMPTY, parameterMap, false); - - AuthGraphNode currentNode = dynamicallyBuiltBaseNode.get(); - if (currentNode == null) { - dynamicallyBuiltBaseNode.set(newNode); - } else { - attachToLeaf(currentNode, newNode); - } - } - - /** - * Adds the step given by step ID tp the authentication graph. - * - * @param stepId Step Id - * @param params params - */ - @SuppressWarnings("unchecked") - public void executeStep(int stepId, Object... params) { - - StepConfig stepConfig; - stepConfig = stepNamedMap.get(stepId); - - if (stepConfig == null) { - log.error("Given Authentication Step :" + stepId + " is not in Environment"); - return; - } - StepConfigGraphNode newNode = wrap(stepConfig); - if (currentNode == null) { - result.setStartNode(newNode); - } else { - attachToLeaf(currentNode, newNode); - } - currentNode = newNode; - if (params.length > 0) { - // if there are any params provided, last one is assumed to be the event listeners - if (params[params.length - 1] instanceof Map) { - attachEventListeners((Map) params[params.length - 1]); - } else { - log.error("Invalid argument and hence ignored. Last argument should be a Map of event listeners."); - } - } - if (params.length == 2) { - // There is an argument with options present - if (params[0] instanceof Map) { - Map options = (Map) params[0]; - handleOptions(options, stepConfig); - } - } - } - - /** - * Handle options within executeStep function. This method will update step configs through stepNamedMap. - * - * @param options Map of authenticator options. - * @param stepConfig Current stepConfig. - */ - @Override - @SuppressWarnings("unchecked") - protected void handleOptions(Map options, StepConfig stepConfig) { - - handleOptionsAsyncEvent(options, stepConfig, stepNamedMap); - } - - /** - * Handle options within executeStepInAsyncEvent function. This method will update step configs through context. - * - * @param options Map of authenticator options. - * @param stepConfig Current stepConfig. - * @param stepConfigMap Map of stepConfigs get from the context object. - */ - @Override - @SuppressWarnings("unchecked") - protected void handleOptionsAsyncEvent(Map options, StepConfig stepConfig, - Map stepConfigMap) { - - Object authenticationOptionsObj = options.get(FrameworkConstants.JSAttributes.AUTHENTICATION_OPTIONS); - if (authenticationOptionsObj instanceof Map) { - filterOptions((Map>) authenticationOptionsObj, stepConfig); - } else { - if (log.isDebugEnabled()) { - log.debug("Authenticator options not provided or invalid, hence proceeding without filtering"); - } - } - - Object authenticatorParams = options.get(FrameworkConstants.JSAttributes.AUTHENTICATOR_PARAMS); - if (authenticatorParams instanceof Map) { - authenticatorParamsOptions((Map) authenticatorParams, stepConfig); - } else { - if (log.isDebugEnabled()) { - log.debug("Authenticator params not provided or invalid, hence proceeding without setting params"); - } - } - - Object stepOptions = options.get(FrameworkConstants.JSAttributes.STEP_OPTIONS); - if (stepOptions instanceof Map) { - handleStepOptions(stepConfig, (Map) stepOptions, stepConfigMap); - } else { - if (log.isDebugEnabled()) { - log.debug("Step options not provided or invalid, hence proceeding without handling"); - } - } - } - - /** - * Handle step options provided for the step from the authentication script. - * - * @param stepConfig Config of the step. - * @param stepOptions Options provided from the script for the step. - * @param stepConfigMap StepConfigs of each step as a map. - */ - protected void handleStepOptions(StepConfig stepConfig, Map stepOptions, - Map stepConfigMap) { - - stepConfig.setForced(Boolean.parseBoolean(stepOptions.get(FrameworkConstants.JSAttributes.FORCE_AUTH_PARAM))); - if (Boolean.parseBoolean(stepOptions.get(FrameworkConstants.JSAttributes.SUBJECT_IDENTIFIER_PARAM))) { - setCurrentStepAsSubjectIdentifier(stepConfig, stepConfigMap); - } - if (Boolean.parseBoolean(stepOptions.get(FrameworkConstants.JSAttributes.SUBJECT_ATTRIBUTE_PARAM))) { - setCurrentStepAsSubjectAttribute(stepConfig, stepConfigMap); - } - stepConfig.setSkipPrompt(Boolean.parseBoolean(stepOptions.get( - FrameworkConstants.JSAttributes.SKIP_PROMPT))); - } - - /** - * Filter out options in the step config to retain only the options provided in authentication options - * - * @param authenticationOptions Authentication options to keep - * @param stepConfig The step config to be modified - */ - protected void filterOptions(Map> authenticationOptions, StepConfig stepConfig) { - - Map> filteredOptions = new HashMap<>(); - authenticationOptions.forEach((id, option) -> { - String idp = option.get(FrameworkConstants.JSAttributes.IDP); - String authenticator = option.get(FrameworkConstants.JSAttributes.AUTHENTICATOR); - if (StringUtils.isNotBlank(authenticator) && StringUtils.isBlank(idp)) { - // If Idp is not set, but authenticator is set, idp is assumed as local - idp = FrameworkConstants.LOCAL_IDP_NAME; - } - if (StringUtils.isNotBlank(idp)) { - filteredOptions.putIfAbsent(idp, new HashSet<>()); - if (StringUtils.isNotBlank(authenticator)) { - if (FrameworkUtils.isAuthenticatorNameInAuthConfigEnabled()) { - filteredOptions.get(idp).add(authenticator); - } else { - filteredOptions.get(idp).add(authenticator.toLowerCase()); - } - } - } - }); - if (log.isDebugEnabled()) { - StringBuilder sb = new StringBuilder(); - for (Map.Entry> entry : filteredOptions.entrySet()) { - sb.append('\n').append(entry.getKey()).append(" : "); - sb.append(StringUtils.join(entry.getValue(), ",")); - } - log.debug("Authenticator options: " + sb.toString()); - } - Set authenticatorsToRemove = new HashSet<>(); - Map idpsToRemove = new HashMap<>(); - stepConfig.getAuthenticatorList().forEach(authenticatorConfig -> authenticatorConfig.getIdps() - .forEach((idpName, idp) -> { - Set authenticators = filteredOptions.get(idpName); - boolean removeOption = false; - if (authenticators == null) { - if (log.isDebugEnabled()) { - log.debug(String.format("Authentication options didn't include idp: %s. Hence excluding from " + - "options list", idpName)); - } - removeOption = true; - } else if (!authenticators.isEmpty()) { - // Both idp and authenticator present, but authenticator is given by display name due to the fact - // that it is the one available at UI. Should translate the display name to actual name, and - // keep/remove option - removeOption = true; - - if (FrameworkConstants.LOCAL_IDP_NAME.equals(idpName)) { - for (LocalAuthenticatorConfig localAuthenticatorConfig : getLocalAuthenticatorConfigsList()) { - if (FrameworkUtils.isAuthenticatorNameInAuthConfigEnabled()) { - if (authenticatorConfig.getName().equals(localAuthenticatorConfig.getName()) && - authenticators.contains(localAuthenticatorConfig.getName())) { - removeOption = false; - break; - } - } else { - if (authenticatorConfig.getName().equals(localAuthenticatorConfig.getName()) && - authenticators.contains(localAuthenticatorConfig.getDisplayName() - .toLowerCase())) { - removeOption = false; - break; - } - } - } - if (log.isDebugEnabled()) { - if (removeOption) { - log.debug(String.format("Authenticator options don't match any entry for local" + - "authenticator: %s. Hence removing the option", authenticatorConfig.getName())); - } else { - log.debug(String.format("Authenticator options contained a match for local " + - "authenticator: %s. Hence keeping the option", authenticatorConfig.getName())); - } - } - } else { - for (FederatedAuthenticatorConfig federatedAuthConfig - : idp.getFederatedAuthenticatorConfigs()) { - if (FrameworkUtils.isAuthenticatorNameInAuthConfigEnabled()) { - if (authenticatorConfig.getName().equals(federatedAuthConfig.getName()) && - authenticators.contains(federatedAuthConfig.getName())) { - removeOption = false; - break; - } - } else { - if (authenticatorConfig.getName().equals(federatedAuthConfig.getName()) && - authenticators.contains(federatedAuthConfig.getDisplayName().toLowerCase())) { - removeOption = false; - break; - } - } - } - if (log.isDebugEnabled()) { - if (removeOption) { - log.debug(String.format("Authenticator options don't match any entry for idp: %s, " + - "authenticator: %s. Hence removing the option", idpName, authenticatorConfig - .getName())); - } else { - log.debug(String.format("Authenticator options contained a match for idp: %s, " + - "authenticator: %s. Hence keeping the option", idpName, authenticatorConfig - .getName())); - } - } - } - } else { - if (log.isDebugEnabled()) { - log.debug(String.format("No authenticator filters for idp %s, hence keeping it as an option", - idpName)); - } - } - if (removeOption) { - if (authenticatorConfig.getIdps().size() > 1) { - idpsToRemove.put(idpName, authenticatorConfig); - } else { - authenticatorsToRemove.add(authenticatorConfig); - } - } - })); - if (stepConfig.getAuthenticatorList().size() > authenticatorsToRemove.size()) { - idpsToRemove.forEach((idp, authenticatorConfig) -> { - int index = stepConfig.getAuthenticatorList().indexOf(authenticatorConfig); - stepConfig.getAuthenticatorList().get(index).getIdps().remove(idp); - stepConfig.getAuthenticatorList().get(index).getIdpNames().remove(idp); - if (log.isDebugEnabled()) { - log.debug("Removed " + idp + " option from " + authenticatorConfig.getName() + " as it " + - "doesn't match the provided authenticator options"); - } - }); - // If all idps are removed from the authenticator the authenticator should be removed. - stepConfig.getAuthenticatorList().forEach(authenticatorConfig -> { - if (authenticatorConfig.getIdps().isEmpty()) { - authenticatorsToRemove.add(authenticatorConfig); - } - }); - stepConfig.getAuthenticatorList().removeAll(authenticatorsToRemove); - if (log.isDebugEnabled()) { - log.debug("Removed " + authenticatorsToRemove.size() + " options which doesn't match the " + - "provided authenticator options"); - } - } else { - log.warn("The filtered authenticator list is empty, hence proceeding without filtering"); - } - } - - /** - * Add authenticator params in the message context. - * - * @param options Authentication options - */ - protected void authenticatorParamsOptions(Map options, StepConfig stepConfig) { - - Map> authenticatorParams = new HashMap<>(); - - Object localOptions = options.get(FrameworkConstants.JSAttributes.JS_LOCAL_IDP); - if (localOptions instanceof Map) { - ((Map) localOptions).forEach((authenticatorName, params) -> { - if (params instanceof Map) { - authenticatorParams.put(authenticatorName, new HashMap<>((Map) params)); - } - }); - } - - Object federatedOptionsObj = options.get(FrameworkConstants.JSAttributes.JS_FEDERATED_IDP); - if (federatedOptionsObj instanceof Map) { - Map> federatedOptions = (Map>) federatedOptionsObj; - stepConfig.getAuthenticatorList().forEach(authenticatorConfig -> authenticatorConfig.getIdps() - .forEach((idpName, idp) -> { - if (!FrameworkConstants.LOCAL_IDP_NAME.equals(idpName) - && federatedOptions.containsKey(idpName)) { - for (FederatedAuthenticatorConfig federatedAuthConfig - : idp.getFederatedAuthenticatorConfigs()) { - String authenticatorName = authenticatorConfig.getApplicationAuthenticator().getName(); - if (authenticatorConfig.getName().equals(federatedAuthConfig.getName())) { - authenticatorParams.put(authenticatorName, - new HashMap<>(federatedOptions.get(idpName))); - } - } - } - })); - } - - Object commonOptions = options.get(FrameworkConstants.JSAttributes.JS_COMMON_OPTIONS); - if (commonOptions instanceof Map) { - authenticatorParams.put(FrameworkConstants.JSAttributes.JS_COMMON_OPTIONS, - new HashMap<>((Map) commonOptions)); - - } - - if (!authenticatorParams.isEmpty()) { - authenticationContext.addAuthenticatorParams(authenticatorParams); - } - } - - /** - * Adds the step given by step ID tp the authentication graph. - * - * @param params params - */ - @SuppressWarnings("unchecked") - public void executeStepInAsyncEvent(int stepId, Object... params) { - - AuthenticationContext context = contextForJs.get(); - AuthGraphNode currentNode = dynamicallyBuiltBaseNode.get(); - - if (log.isDebugEnabled()) { - log.debug("Execute Step on async event. Step ID : " + stepId); - } - AuthenticationGraph graph = context.getSequenceConfig().getAuthenticationGraph(); - if (graph == null) { - log.error("The graph happens to be null on the sequence config. Can not execute step : " + stepId); - return; - } - - StepConfig stepConfig = graph.getStepMap().get(stepId); - if (stepConfig == null) { - if (log.isDebugEnabled()) { - log.debug("The stepConfig of the step ID : " + stepId + " is null"); - } - return; - } - // Inorder to keep original stepConfig as a backup in AuthenticationGraph. - StepConfig clonedStepConfig = new StepConfig(stepConfig); - StepConfig stepConfigFromContext = null; - if (MapUtils.isNotEmpty(context.getSequenceConfig().getStepMap())) { - stepConfigFromContext = context.getSequenceConfig().getStepMap().values().stream() - .filter(contextStepConfig -> (stepConfig.getOrder() == contextStepConfig.getOrder())) - .findFirst().orElse(null); - } - clonedStepConfig.applyStateChangesToNewObjectFromContextStepMap(stepConfigFromContext); - if (log.isDebugEnabled()) { - log.debug("Found step for the Step ID : " + stepId + ", Step Config " + clonedStepConfig); - } - StepConfigGraphNode newNode = wrap(clonedStepConfig); - if (currentNode == null) { - if (log.isDebugEnabled()) { - log.debug("Setting a new node at the first time. Node : " + newNode.getName()); - } - dynamicallyBuiltBaseNode.set(newNode); - } else { - attachToLeaf(currentNode, newNode); - } - - if (params.length > 0) { - // if there is only one param, it is assumed to be the event listeners - if (params[params.length - 1] instanceof Map) { - attachEventListeners((Map) params[params.length - 1], newNode); - } else { - log.error("Invalid argument and hence ignored. Last argument should be a Map of event listeners."); - } - } - - if (params.length == 2) { - // There is an argument with options present - if (params[0] instanceof Map) { - Map options = (Map) params[0]; - handleOptionsAsyncEvent(options, clonedStepConfig, context.getSequenceConfig().getStepMap()); - } - } - } - - /** - * Adds a function to show a prompt in Javascript code. - * - * @param templateId Identifier of the template - * @param parameters parameters - */ - @SuppressWarnings("unchecked") - public void addShowPrompt(String templateId, Object... parameters) { - - ShowPromptNode newNode = new ShowPromptNode(); - newNode.setTemplateId(templateId); - - if (parameters.length == 2) { - newNode.setData((Map) - JsNashornSerializer.toJsSerializableInternal(parameters[0])); - } - if (currentNode == null) { - result.setStartNode(newNode); - } else { - attachToLeaf(currentNode, newNode); - } - - currentNode = newNode; - if (parameters.length > 0) { - if (parameters[parameters.length - 1] instanceof Map) { - addEventListeners(newNode, (Map) parameters[parameters.length - 1]); - } else { - log.error("Invalid argument and hence ignored. Last argument should be a Map of event listeners."); - } - - } - } - - /** - * @param templateId Identifier of the template. - * @param parameters Parameters. - * @param handlers Handlers to run before and after the prompt. - * @param callbacks Callbacks to run after the prompt. - */ - @SuppressWarnings("unchecked") - @Override - public void addPromptInternal(String templateId, Map parameters, Map handlers, - Map callbacks) { - - ShowPromptNode newNode = new ShowPromptNode(); - newNode.setTemplateId(templateId); - newNode.setParameters(parameters); - - JsNashornGraphBuilder currentBuilder = getCurrentBuilder(); - if (currentBuilder.currentNode == null) { - currentBuilder.result.setStartNode(newNode); - } else { - attachToLeaf(currentBuilder.currentNode, newNode); - } - - currentBuilder.currentNode = newNode; - addEventListeners(newNode, callbacks); - addHandlers(newNode, handlers); - } - - /** - * @param templateId Identifier of the template. - * @param parameters Parameters. - * @param handlers Handlers to run before and after the prompt. - * @param callbacks Callbacks to run after the prompt. - */ - @SuppressWarnings("unchecked") - public static void addPrompt(String templateId, Map parameters, Map handlers, - Map callbacks) { - - ShowPromptNode newNode = new ShowPromptNode(); - newNode.setTemplateId(templateId); - newNode.setParameters(parameters); - - JsNashornGraphBuilder currentBuilder = getCurrentBuilder(); - if (currentBuilder.currentNode == null) { - currentBuilder.result.setStartNode(newNode); - } else { - attachToLeaf(currentBuilder.currentNode, newNode); - } - - currentBuilder.currentNode = newNode; - addEventListeners(newNode, callbacks); - addHandlers(newNode, handlers); - } - - /** - * Loads the required function library from the database. - * - * @param functionLibraryName functionLibraryName - * @return functionLibraryScript - * @throws FunctionLibraryManagementException - */ - public String loadLocalLibrary(String functionLibraryName) throws FunctionLibraryManagementException { - - FunctionLibraryManagementService functionLibMgtService = FrameworkServiceComponent. - getFunctionLibraryManagementService(); - FunctionLibrary functionLibrary; - String libraryScript = null; - - functionLibrary = functionLibMgtService.getFunctionLibrary(functionLibraryName, - CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); - - if (functionLibrary != null) { - libraryScript = functionLibrary.getFunctionLibraryScript(); - } else { - log.error("No function library available with " + functionLibraryName + "name."); - } - return libraryScript; - } - - /** - * Adds a function to show a prompt in Javascript code. - * - * @param parameterMap parameterMap - */ - public static void addLongWaitProcess(AsyncProcess asyncProcess, - Map parameterMap) { - - getCurrentBuilder().addLongWaitProcessInternal(asyncProcess, parameterMap); - } - - - @Override - public void addLongWaitProcessInternal(AsyncProcess asyncProcess, Map parameterMap) { - - LongWaitNode newNode = new LongWaitNode(asyncProcess); - - if (parameterMap != null) { - addEventListeners(newNode, parameterMap); - } - if (this.currentNode == null) { - this.result.setStartNode(newNode); - } else { - attachToLeaf(this.currentNode, newNode); - } - - this.currentNode = newNode; - } - - private static void addLongWaitProcess(JsNashornGraphBuilder jsGraphBuilder, AsyncProcess asyncProcess, - Map parameterMap) { - - LongWaitNode newNode = new LongWaitNode(asyncProcess); - - if (parameterMap != null) { - addEventListeners(newNode, parameterMap); - } - if (jsGraphBuilder.currentNode == null) { - jsGraphBuilder.result.setStartNode(newNode); - } else { - attachToLeaf(jsGraphBuilder.currentNode, newNode); - } - - jsGraphBuilder.currentNode = newNode; - } - - private static void attachEventListeners(Map eventsMap, AuthGraphNode currentNode) { - - if (eventsMap == null) { - return; - } - DynamicDecisionNode decisionNode = new DynamicDecisionNode(); - addEventListeners(decisionNode, eventsMap); - if (!decisionNode.getGenericFunctionMap().isEmpty()) { - attachToLeaf(currentNode, decisionNode); - } - } - - private void attachEventListeners(Map eventsMap) { - - if (eventsMap == null) { - return; - } - DynamicDecisionNode decisionNode = new DynamicDecisionNode(); - addEventListeners(decisionNode, eventsMap); - if (!decisionNode.getGenericFunctionMap().isEmpty()) { - attachToLeaf(currentNode, decisionNode); - currentNode = decisionNode; - } - } - - /** - * Adds all the event listeners to the decision node. - * - * @param eventsMap Map of events and event handler functions, which is handled by this execution. - * @return created Dynamic Decision node. - */ - private static void addEventListeners(DynamicDecisionNode decisionNode, - Map eventsMap) { - - if (eventsMap == null) { - return; - } - eventsMap.forEach((key, value) -> { - if (value instanceof ScriptObjectMirror) { - SerializableJsFunction jsFunction = SerializableJsFunction - .toSerializableForm((ScriptObjectMirror) value); - if (jsFunction != null) { - decisionNode.addFunction(key, jsFunction); - } else { - log.error("Event handler : " + key + " is not a function : " + value); - } - } else if (value instanceof SerializableJsFunction) { - decisionNode.addFunction(key, (SerializableJsFunction) value); - } - }); - } - - private static void addHandlers(ShowPromptNode showPromptNode, Map handlersMap) { - - if (handlersMap == null) { - return; - } - handlersMap.forEach((key, value) -> { - if (value instanceof ScriptObjectMirror) { - SerializableJsFunction jsFunction = SerializableJsFunction - .toSerializableForm((ScriptObjectMirror) value); - if (jsFunction != null) { - showPromptNode.addGenericHandler(key, jsFunction); - } else { - log.error("Event handler : " + key + " is not a function : " + value); - } - } else if (value instanceof SerializableJsFunction) { - showPromptNode.addGenericHandler(key, (SerializableJsFunction) value); - } - }); - } - - /** - * Attach the new node to the destination node. - * Any immediate branches available in the destination will be re-attached to the new node. - * New node may be cloned if needed to attach on multiple branches. - * - * @param destination Current node. - * @param newNode New node to attach. - */ - protected static void infuse(AuthGraphNode destination, AuthGraphNode newNode) { - - if (destination instanceof StepConfigGraphNode) { - StepConfigGraphNode stepConfigGraphNode = ((StepConfigGraphNode) destination); - attachToLeaf(newNode, stepConfigGraphNode.getNext()); - newNode.setParent(destination); - stepConfigGraphNode.setNext(newNode); - } else if (destination instanceof DynamicDecisionNode) { - DynamicDecisionNode dynamicDecisionNode = (DynamicDecisionNode) destination; - newNode.setParent(destination); - attachToLeaf(newNode, dynamicDecisionNode.getDefaultEdge()); - dynamicDecisionNode.setDefaultEdge(newNode); - } else { - log.error("Can not infuse nodes in node type : " + destination); - } - - } - - /** - * Creates the StepConfigGraphNode with given StepConfig. - * - * @param stepConfig Step Config Object. - * @return built and wrapped new StepConfigGraphNode. - */ - protected static StepConfigGraphNode wrap(StepConfig stepConfig) { - - return new StepConfigGraphNode(stepConfig); - } - - /** - * Functional interface for authentication failed callback. - */ - @FunctionalInterface - public interface FailAuthenticationFunction { - - void fail(Object... parameterMap); - } - - /** - * Functional interface for executeStep function. - */ - @FunctionalInterface - public interface StepExecutor { - - void executeStep(Integer stepId, Object... parameterMap); - } - - /** - * Functional interface for prompt in the authentication. - */ - @FunctionalInterface - public interface PromptExecutor { - - void prompt(String template, Object... parameterMap); - } - - /** - * Functional interface for restricted functions in authentication script. - */ - @Deprecated - @FunctionalInterface - public interface RestrictedFunction { - - void exit(Object... arg); - } - - /** - * Functional interface to load authentication library. - */ - @FunctionalInterface - public interface LoadExecutor { - - String loadLocalLibrary(String libraryName) throws FunctionLibraryManagementException; - } - - @Deprecated - public void exitFunction(Object... arg) { - - log.error("Exit function is restricted."); - } - - @Deprecated - public void quitFunction(Object... arg) { - - log.error("Quit function is restricted."); - } - - private void removeDefaultFunctions(ScriptEngine engine) throws ScriptException { - - engine.eval(REMOVE_FUNCTIONS); - } - - private JSExecutionSupervisor getJSExecutionSupervisor() { - - return FrameworkServiceDataHolder.getInstance().getJsExecutionSupervisor(); - } - - private void storeAuthScriptExecutionMonitorData(AuthenticationContext context, - JSExecutionMonitorData jsExecutionMonitorData) { - - context.setProperty(FrameworkConstants.AdaptiveAuthentication.PROP_EXECUTION_SUPERVISOR_RESULT, - jsExecutionMonitorData); - } - - private JSExecutionMonitorData retrieveAuthScriptExecutionMonitorData(AuthenticationContext context) { - - JSExecutionMonitorData jsExecutionMonitorData; - Object storedResult = context.getProperty( - FrameworkConstants.AdaptiveAuthentication.PROP_EXECUTION_SUPERVISOR_RESULT); - if (storedResult != null) { - jsExecutionMonitorData = (JSExecutionMonitorData) storedResult; - } else { - jsExecutionMonitorData = new JSExecutionMonitorData(0L, 0L); - } - return jsExecutionMonitorData; - } - - private void startScriptExecutionMonitor(String identifier, AuthenticationContext context, - JSExecutionMonitorData previousExecutionResult) { - - JSExecutionSupervisor jsExecutionSupervisor = getJSExecutionSupervisor(); - if (jsExecutionSupervisor == null) { - return; - } - getJSExecutionSupervisor().monitor(identifier, context.getServiceProviderName() - , context.getTenantDomain(), previousExecutionResult.getElapsedTime(), - previousExecutionResult.getConsumedMemory()); - } - - private void startScriptExecutionMonitor(String identifier, AuthenticationContext context) { - - startScriptExecutionMonitor(identifier, context, new JSExecutionMonitorData(0L, 0L)); - } - - private JSExecutionMonitorData endScriptExecutionMonitor(String identifier) { - - JSExecutionSupervisor executionSupervisor = getJSExecutionSupervisor(); - if (executionSupervisor == null) { - return null; - } - return getJSExecutionSupervisor().completed(identifier); - } - - private void setCurrentStepAsSubjectIdentifier(StepConfig stepConfig, Map stepConfigMap) { - - stepConfigMap.forEach((integer, config) -> { // Remove existing subject identifier step. - if (config.isSubjectIdentifierStep()) { - config.setSubjectIdentifierStep(false); - } - }); - stepConfig.setSubjectIdentifierStep(true); - } - - private void setCurrentStepAsSubjectAttribute(StepConfig stepConfig, Map stepConfigMap) { - - stepConfigMap.forEach((integer, config) -> { // Remove existing subject attribute step. - if (config.isSubjectAttributeStep()) { - config.setSubjectAttributeStep(false); - } - }); - stepConfig.setSubjectAttributeStep(true); - } - - public AuthenticationDecisionEvaluator getScriptEvaluator(BaseSerializableJsFunction fn) { - - return new JsBasedEvaluator((SerializableJsFunction) fn); - } - - /** - * Javascript based Decision Evaluator implementation. - * This is used to create the Authentication Graph structure dynamically on the fly while the authentication flow - * is happening. - * The graph is re-organized based on last execution of the decision. - */ - public class JsBasedEvaluator implements AuthenticationDecisionEvaluator { - - private static final long serialVersionUID = 6853505881096840344L; - private SerializableJsFunction jsFunction; - - public JsBasedEvaluator(SerializableJsFunction jsFunction) { - - this.jsFunction = jsFunction; - } - - @Override - public Object evaluate(AuthenticationContext authenticationContext, Object... params) { - - JsNashornGraphBuilder graphBuilder = JsNashornGraphBuilder.this; - Object result = null; - if (jsFunction == null) { - return null; - } - if (jsFunction.isFunction()) { - ScriptEngine scriptEngine = getEngine(authenticationContext); - try { - currentBuilder.set(graphBuilder); - JsGraphBuilderFactory.restoreCurrentContext(authenticationContext, scriptEngine); - Bindings globalBindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE); - //Now re-assign the executeStep function to dynamic evaluation - globalBindings.put(FrameworkConstants.JSAttributes.JS_FUNC_EXECUTE_STEP, - (StepExecutor) graphBuilder::executeStepInAsyncEvent); - globalBindings.put(FrameworkConstants.JSAttributes.JS_FUNC_SEND_ERROR, - (BiConsumer) JsNashornGraphBuilder::sendErrorAsync); - globalBindings.put(FrameworkConstants.JSAttributes.JS_AUTH_FAILURE, - (FailAuthenticationFunction) JsNashornGraphBuilder::failAsync); - globalBindings.put(FrameworkConstants.JSAttributes.JS_FUNC_SHOW_PROMPT, (PromptExecutor) - graphBuilder::addShowPrompt); - globalBindings.put(FrameworkConstants.JSAttributes.JS_FUNC_LOAD_FUNC_LIB, (LoadExecutor) - graphBuilder::loadLocalLibrary); - JsFunctionRegistry jsFunctionRegistry = FrameworkServiceDataHolder.getInstance() - .getJsFunctionRegistry(); - if (jsFunctionRegistry != null) { - Map functionMap = jsFunctionRegistry - .getSubsystemFunctionsMap(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER); - functionMap.forEach(globalBindings::put); - } - removeDefaultFunctions(scriptEngine); - JsNashornGraphBuilder.contextForJs.set(authenticationContext); - - String identifier = UUID.randomUUID().toString(); - JSExecutionMonitorData scriptExecutionData = - retrieveAuthScriptExecutionMonitorData(authenticationContext); - try { - startScriptExecutionMonitor(identifier, authenticationContext, scriptExecutionData); - result = jsFunction.apply(scriptEngine, params); - } finally { - scriptExecutionData = endScriptExecutionMonitor(identifier); - } - if (scriptExecutionData != null) { - storeAuthScriptExecutionMonitorData(authenticationContext, scriptExecutionData); - } - JsGraphBuilderFactory.persistCurrentContext(authenticationContext, scriptEngine); - - AuthGraphNode executingNode = (AuthGraphNode) authenticationContext - .getProperty(FrameworkConstants.JSAttributes.PROP_CURRENT_NODE); - if (canInfuse(executingNode)) { - infuse(executingNode, dynamicallyBuiltBaseNode.get()); - } - - } catch (Throwable e) { - // We need to catch all the javascript errors here, then log and handle. - if (LoggerUtils.isDiagnosticLogsEnabled()) { - DiagnosticLog.DiagnosticLogBuilder diagnosticLogBuilder = new DiagnosticLog - .DiagnosticLogBuilder(FrameworkConstants.LogConstants.AUTHENTICATION_FRAMEWORK, - FrameworkConstants.LogConstants.ActionIDs.EXECUTE_ADAPTIVE_SCRIPT); - diagnosticLogBuilder.resultMessage("Error in executing the adaptive authentication script : " + - e.getMessage()) - .logDetailLevel(DiagnosticLog.LogDetailLevel.APPLICATION) - .resultStatus(DiagnosticLog.ResultStatus.FAILED); - // Adding application related details to diagnostic log. - FrameworkUtils.getApplicationResourceId(authenticationContext).ifPresent(applicationId -> - diagnosticLogBuilder.inputParam(LogConstants.InputKeys.APPLICATION_ID, applicationId)); - FrameworkUtils.getApplicationName(authenticationContext).ifPresent(applicationName -> - diagnosticLogBuilder.inputParam(LogConstants.InputKeys.APPLICATION_NAME, - applicationName)); - LoggerUtils.triggerDiagnosticLogEvent(diagnosticLogBuilder); - } - log.error("Error in executing the javascript for service provider : " + authenticationContext - .getServiceProviderName() + ", Javascript Fragment : \n" + jsFunction.getSource(), e); - AuthGraphNode executingNode = (AuthGraphNode) authenticationContext - .getProperty(FrameworkConstants.JSAttributes.PROP_CURRENT_NODE); - FailNode failNode = new FailNode(); - attachToLeaf(executingNode, failNode); - } finally { - contextForJs.remove(); - dynamicallyBuiltBaseNode.remove(); - clearCurrentBuilder(); - } - - } else { - result = jsFunction.getSource(); - } - return result; - } - - @Deprecated - public Object evaluate(AuthenticationContext authenticationContext) { - - return this.evaluate(authenticationContext, new JsNashornAuthenticationContext(authenticationContext)); - - } - - private boolean canInfuse(AuthGraphNode executingNode) { - - return executingNode instanceof DynamicDecisionNode && dynamicallyBuiltBaseNode.get() != null; - } - - private ScriptEngine getEngine(AuthenticationContext authenticationContext) { - - return (ScriptEngine) FrameworkServiceDataHolder.getInstance().getJsGenericGraphBuilderFactory() - .createEngine(authenticationContext); - } - } -} 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/graph/JsNashornSerializer.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/JsNashornSerializer.java deleted file mode 100644 index a633b934ba81..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/JsNashornSerializer.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (c) 2022, 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.config.model.graph; - -import jdk.nashorn.api.scripting.ScriptObjectMirror; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.script.ScriptEngine; -import javax.script.ScriptException; - -/** - * Serializer class supports JDK Nashorn Engine. - */ -public class JsNashornSerializer implements JsSerializer { - - private static final Log log = LogFactory.getLog(JsNashornSerializer.class); - - private static JsNashornSerializer jsNashornSerializer = new JsNashornSerializer(); - - public static JsNashornSerializer getInstance() { - - return jsNashornSerializer; - } - - /** - * Serialize the object using selected serializable function. - * @param value Object to evaluate. - * @return Serialized Object. - */ - @Override - public Object toJsSerializable(Object value) { - - return toJsSerializableInternal(value); - } - - /** - * Serialize the object using selected serializable function. - * @param value Object to evaluate. - * @return Serialized Object. - */ - public static Object toJsSerializableInternal(Object value) { - - if (value instanceof Serializable) { - if (value instanceof HashMap) { - Map map = new HashMap<>(); - ((HashMap) value).forEach((k, v) -> map.put((String) k, toJsSerializableInternal(v))); - return map; - } else { - return value; - } - } else if (value instanceof ScriptObjectMirror) { - ScriptObjectMirror scriptObjectMirror = (ScriptObjectMirror) value; - if (scriptObjectMirror.isFunction()) { - return SerializableJsFunction.toSerializableForm(scriptObjectMirror); - } else if (scriptObjectMirror.isArray()) { - List arrayItems = new ArrayList<>(scriptObjectMirror.size()); - scriptObjectMirror.values().forEach(v -> { - Object serializedObj = toJsSerializableInternal(v); - if (serializedObj instanceof Serializable) { - arrayItems.add((Serializable) serializedObj); - if (log.isDebugEnabled()) { - log.debug("Serialized the value of array item as : " + serializedObj); - } - } else { - log.warn(String.format("Non serializable array item: %s. and will not be persisted.", - serializedObj)); - } - }); - return arrayItems; - } else if (!scriptObjectMirror.isEmpty()) { - Map serializedMap = new HashMap<>(); - scriptObjectMirror.forEach((k, v) -> { - Object serializedObj = toJsSerializableInternal(v); - if (serializedObj instanceof Serializable) { - serializedMap.put(k, (Serializable) serializedObj); - if (log.isDebugEnabled()) { - log.debug("Serialized the value for key : " + k); - } - } else { - log.warn(String.format("Non serializable object for key : %s, and will not be persisted.", k)); - } - - }); - return serializedMap; - } else { - return Collections.EMPTY_MAP; - } - } - return value; - } - - /** - * De-Serialize the object using selected serializable function. - * @param value Serialized Object. - * @param engine Js Engine. - * @return De-Serialize object. - * @throws FrameworkException FrameworkException. - */ - @Override - public Object fromJsSerializable(Object value, ScriptEngine engine) throws FrameworkException { - - return fromJsSerializableInternal(value, engine); - } - - /** - * De-Serialize the object using selected serializable function. - * @param value Serialized Object. - * @param engine Js Engine. - * @return De-Serialize object. - * @throws FrameworkException FrameworkException. - */ - public static Object fromJsSerializableInternal(Object value, ScriptEngine engine) throws FrameworkException { - - if (value instanceof SerializableJsFunction) { - SerializableJsFunction serializableJsFunction = (SerializableJsFunction) value; - try { - return engine.eval(serializableJsFunction.getSource()); - } catch (ScriptException e) { - throw new FrameworkException("Error in resurrecting a Javascript Function : " + serializableJsFunction); - } - - } else if (value instanceof Map) { - Map deserializedMap = new HashMap<>(); - for (Map.Entry entry : ((Map) value).entrySet()) { - Object deserializedObj = fromJsSerializableInternal(entry.getValue(), engine); - deserializedMap.put(entry.getKey(), deserializedObj); - } - return deserializedMap; - } - return value; - } -} 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/graph/JsWrapperFactory.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/JsWrapperFactory.java deleted file mode 100644 index e6a672b3a192..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/JsWrapperFactory.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (c) 2022, 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.config.model.graph; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.nashorn.JsHeaders; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.nashorn.JsNashornAuthenticatedUser; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.nashorn.JsNashornAuthenticationContext; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.nashorn.JsNashornClaims; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.nashorn.JsNashornCookie; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.nashorn.JsNashornParameters; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.nashorn.JsNashornRuntimeClaims; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.nashorn.JsNashornServletRequest; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.nashorn.JsNashornServletResponse; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.nashorn.JsNashornStep; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.nashorn.JsNashornSteps; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.nashorn.JsNashornWritableParameters; -import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; -import org.wso2.carbon.identity.application.authentication.framework.context.TransientObjectWrapper; -import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser; - -import java.util.Map; - -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * Factory to create a Javascript Object Wrappers for Nashorn execution. - */ -public class JsWrapperFactory implements JsWrapperBaseFactory { - - @Override - public JsNashornAuthenticatedUser createJsAuthenticatedUser(AuthenticatedUser authenticatedUser) { - - return new JsNashornAuthenticatedUser(authenticatedUser); - } - - @Override - public JsNashornAuthenticatedUser createJsAuthenticatedUser(AuthenticationContext authenticationContext, - AuthenticatedUser authenticatedUser) { - - return new JsNashornAuthenticatedUser(authenticationContext, authenticatedUser); - } - - @Override - public JsNashornAuthenticatedUser createJsAuthenticatedUser(AuthenticationContext context, - AuthenticatedUser wrappedUser, int step, String idp) { - - return new JsNashornAuthenticatedUser(context, wrappedUser, step, idp); - } - - @Override - public JsNashornAuthenticationContext createJsAuthenticationContext(AuthenticationContext authenticationContext) { - - return new JsNashornAuthenticationContext(authenticationContext); - } - - @Override - public JsNashornCookie createJsCookie(Cookie cookie) { - - return new JsNashornCookie(cookie); - } - - @Override - public JsNashornParameters createJsParameters(Map parameters) { - - return new JsNashornParameters(parameters); - } - - @Override - public JsNashornWritableParameters createJsWritableParameters(Map data) { - - return new JsNashornWritableParameters(data); - } - - @Override - public JsNashornServletRequest createJsServletRequest(TransientObjectWrapper wrapped) { - - return new JsNashornServletRequest(wrapped); - } - - @Override - public JsNashornServletResponse createJsServletResponse(TransientObjectWrapper wrapped) { - - return new JsNashornServletResponse(wrapped); - } - - @Override - public JsNashornClaims createJsClaims(AuthenticationContext context, int step, String idp, - boolean isRemoteClaimRequest) { - - return new JsNashornClaims(context, step, idp, isRemoteClaimRequest); - } - - @Override - public JsNashornClaims createJsClaims(AuthenticationContext context, AuthenticatedUser user, - boolean isRemoteClaimRequest) { - - return new JsNashornClaims(context, user, isRemoteClaimRequest); - } - - @Override - public JsNashornRuntimeClaims createJsRuntimeClaims(AuthenticationContext context, int step, String idp) { - - return new JsNashornRuntimeClaims(context, step, idp); - } - - @Override - public JsNashornRuntimeClaims createJsRuntimeClaims(AuthenticationContext context, AuthenticatedUser user) { - - return new JsNashornRuntimeClaims(context, user); - } - - @Override - public JsNashornStep createJsStep(AuthenticationContext context, int step, String authenticatedIdp, - String authenticatedAuthenticator) { - - return new JsNashornStep(context, step, authenticatedIdp, authenticatedAuthenticator); - } - - @Override - public JsHeaders createJsHeaders(Map wrapped, HttpServletResponse response) { - - return new JsHeaders(wrapped, response); - } - - @Override - public JsNashornSteps createJsSteps(AuthenticationContext context) { - - return new JsNashornSteps(context); - } -} 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/graph/JsWrapperFactoryProvider.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/JsWrapperFactoryProvider.java index 087e220f3db2..50821f71f370 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/JsWrapperFactoryProvider.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/JsWrapperFactoryProvider.java @@ -41,8 +41,6 @@ private JsWrapperFactoryProvider() { } else if (FrameworkServiceDataHolder.getInstance() .getJsGenericGraphBuilderFactory() instanceof JsGraalGraphBuilderFactory) { jsWrapperBaseFactory = new JsGraalWrapperFactory(); - } else { - jsWrapperBaseFactory = new JsWrapperFactory(); } } 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/graph/RestrictedClassFilter.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/RestrictedClassFilter.java deleted file mode 100644 index f8ae459d2043..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/RestrictedClassFilter.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2021, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * Licensed 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.config.model.graph; - -import jdk.nashorn.api.scripting.ClassFilter; - -/** - * This class filter disallows all classes which are not explicitly - * bound to the Javascript context. - */ -public class RestrictedClassFilter implements ClassFilter { - - @Override - public boolean exposeToScripts(String s) { - - return false; - } -} 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/graph/SerializableJsFunction.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/SerializableJsFunction.java deleted file mode 100644 index 03547862d903..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/SerializableJsFunction.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph; - -import jdk.nashorn.api.scripting.JSObject; -import jdk.nashorn.api.scripting.ScriptObjectMirror; -import jdk.nashorn.api.scripting.ScriptUtils; -import jdk.nashorn.internal.runtime.ScriptFunction; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.script.Compilable; -import javax.script.CompiledScript; -import javax.script.ScriptEngine; -import javax.script.ScriptException; - -/** - * Javascript function wrapper. This allows serialization of a javascript defined function. - */ -public class SerializableJsFunction implements BaseSerializableJsFunction { - - private static final Log log = LogFactory.getLog(SerializableJsFunction.class); - - private static final long serialVersionUID = -7605388897997019588L; - private String source; - private boolean isFunction; - - public SerializableJsFunction(String source, boolean isFunction) { - - this.source = source; - this.isFunction = isFunction; - } - - public String getSource() { - - return source; - } - - public void setSource(String source) { - - this.source = source; - } - - public boolean isFunction() { - - return isFunction; - } - - public void setFunction(boolean function) { - - isFunction = function; - } - - @Override - public Object apply(ScriptEngine scriptEngine, Object... params) { - - Compilable compilable = (Compilable) scriptEngine; - try { - CompiledScript compiledScript = compilable.compile(this.getSource()); - JSObject jsObject = (JSObject) compiledScript.eval(); - if (jsObject instanceof ScriptObjectMirror) { - ScriptObjectMirror scriptObjectMirror = (ScriptObjectMirror) jsObject; - if (!scriptObjectMirror.isFunction()) { - //TODO: throw exception - } - return scriptObjectMirror.call(null, params); - } - } catch (ScriptException e) { - log.error("Error when executing function,", e); - } - return null; - } - - /** - * This will return the converted SerializableJsFunction if the given ScriptObjectMirror is a function. - * @param scriptObjectMirror - * @return null if the ScriptObjectMirror is not a function. - */ - public static SerializableJsFunction toSerializableForm(ScriptObjectMirror scriptObjectMirror) { - - if (!scriptObjectMirror.isFunction()) { - return null; - } - - //TODO try to get rid of ScriptFunction - Object unwrapped = ScriptUtils.unwrap(scriptObjectMirror); - if (unwrapped instanceof ScriptFunction) { - ScriptFunction scriptFunction = (ScriptFunction) unwrapped; - boolean isFunction = scriptObjectMirror.isFunction(); - String source = scriptFunction.toSource(); - - return new SerializableJsFunction(source, isFunction); - } else { - return new SerializableJsFunction(unwrapped.toString(), true); - } - } -} 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/graph/ThreadLocalScriptEngineHolder.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/ThreadLocalScriptEngineHolder.java deleted file mode 100644 index e9a5c59fcdf6..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/ThreadLocalScriptEngineHolder.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2023, 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.config.model.graph; - -import jdk.nashorn.api.scripting.ClassFilter; -import jdk.nashorn.api.scripting.NashornScriptEngineFactory; - -import javax.script.ScriptEngine; - -/** - * ThreadLocal Implementation of the deprecated Nashorn Script Engine. - * This holds different script engine instances for different - * threads. Thread safety is achieved by binding the script - * engine to the current running Thread. - */ -public class ThreadLocalScriptEngineHolder extends BaseThreadLocalScriptEngineHolder { - - protected ClassLoader getClassLoader() { - - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - return classLoader == null ? NashornScriptEngineFactory.class.getClassLoader() : classLoader; - } - - protected ScriptEngine createScriptEngine() { - - NashornScriptEngineFactory factory = new NashornScriptEngineFactory(); - ClassFilter classFilter = new RestrictedClassFilter(); - return factory.getScriptEngine(NASHORN_ARGS, getClassLoader(), classFilter); - } - -} 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/graph/js/nashorn/AbstractJsObject.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/AbstractJsObject.java deleted file mode 100644 index a56efc0fa3af..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/AbstractJsObject.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2022, 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.config.model.graph.js.nashorn; - -import jdk.nashorn.api.scripting.JSObject; -import jdk.nashorn.internal.runtime.JSType; - -import java.util.Collection; -import java.util.Collections; -import java.util.Objects; -import java.util.Set; - -/** - * Abstract JavaScript Proxy Object for Nashorn Implementation. - * Interface Created from modifying jdk.nashorn.api.scripting.AbstractJsObject - */ -public interface AbstractJsObject extends JSObject { - - @Override - default Object call(final Object thiz, final Object... args) { - throw new UnsupportedOperationException("call"); - } - - @Override - default Object newObject(final Object... args) { - throw new UnsupportedOperationException("newObject"); - } - - @Override - default Object eval(final String s) { - throw new UnsupportedOperationException("eval"); - } - - @Override - default Object getMember(final String name) { - Objects.requireNonNull(name); - return null; - } - - @Override - default Object getSlot(final int index) { - return null; - } - - @Override - default boolean hasMember(final String name) { - Objects.requireNonNull(name); - return false; - } - - @Override - default boolean hasSlot(final int slot) { - return false; - } - - @Override - default void removeMember(final String name) { - Objects.requireNonNull(name); - //empty - } - - @Override - default void setMember(final String name, final Object value) { - Objects.requireNonNull(name); - //empty - } - - @Override - default void setSlot(final int index, final Object value) { - //empty - } - - // property and value iteration - - @Override - default Set keySet() { - return Collections.emptySet(); - } - - @Override - default Collection values() { - return Collections.emptySet(); - } - - // JavaScript instanceof check - - @Override - default boolean isInstance(final Object instance) { - return false; - } - - @Override - default boolean isInstanceOf(final Object clazz) { - if (clazz instanceof JSObject) { - return ((JSObject) clazz).isInstance(this); - } - - return false; - } - - @Override - default String getClassName() { - return getClass().getName(); - } - - @Override - default boolean isFunction() { - return false; - } - - @Override - default boolean isStrictFunction() { - return false; - } - - @Override - default boolean isArray() { - return false; - } - - @Override @Deprecated - default double toNumber() { - return JSType.toNumber(JSType.toPrimitive(this, Number.class)); - } -} 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/graph/js/nashorn/JsHeaders.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsHeaders.java deleted file mode 100644 index ef13be939aef..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsHeaders.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js.nashorn; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.CommonJsHeaders; - -import java.util.Map; - -import javax.servlet.http.HttpServletResponse; - -/** - * Javascript wrapper for Java level HashMap of HTTP headers. - * This provides controlled access to HTTPServletResponse object's headers via provided javascript native syntax. - * Also it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime. - */ -public class JsHeaders extends CommonJsHeaders implements AbstractJsObject { - - public JsHeaders(Map wrapped, HttpServletResponse response) { - - super(wrapped, response); - } - - @Override - public Object getMember(String name) { - - Object member = super.getMember(name); - return member != null ? member : AbstractJsObject.super.getMember(name); - } - - @Override - public void removeMember(String name) { - - boolean isRemoved = super.removeMemberObject(name); - if (!isRemoved) { - AbstractJsObject.super.removeMember(name); - } - } - - @Override - public void setMember(String name, Object value) { - - boolean isSet = super.setMemberObject(name, value); - if (!isSet) { - AbstractJsObject.super.setMember(name, value); - } - } -} 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/graph/js/nashorn/JsNashornAuthenticatedUser.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornAuthenticatedUser.java deleted file mode 100644 index cd2f3f4ded2a..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornAuthenticatedUser.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js.nashorn; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticatedUser; -import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; -import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser; - -/** - * Javascript wrapper for Java level AuthenticatedUser. - * This wrapper uses jdk.nashorn engine. - * This provides controlled access to AuthenticatedUser object via provided javascript native syntax. - * e.g - * var userName = context.lastAuthenticatedUser.username - * - * instead of - * var userName = context.getLastAuthenticatedUser().getUserName() - * - * Also it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime - * AuthenticatedUser. - * - * @see AuthenticatedUser - */ -public class JsNashornAuthenticatedUser extends JsAuthenticatedUser implements AbstractJsObject { - - /** - * Constructor to be used when required to access step specific user details. - * - * @param context Authentication context - * @param wrappedUser Authenticated user - * @param step Authentication step - * @param idp Authenticated Idp - */ - public JsNashornAuthenticatedUser(AuthenticationContext context, AuthenticatedUser wrappedUser, - int step, String idp) { - - super(context, wrappedUser, step, idp); - } - - /** - * Constructor to be used when required to access step specific user details. - * - * @param wrappedUser Authenticated user - * @param step Authentication step - * @param idp Authenticated Idp - */ - public JsNashornAuthenticatedUser(AuthenticatedUser wrappedUser, int step, String idp) { - - super(wrappedUser, step, idp); - } - - /** - * Constructor to be used when required to access step independent user. - * - * @param wrappedUser Authenticated user - */ - public JsNashornAuthenticatedUser(AuthenticatedUser wrappedUser) { - - super(wrappedUser); - } - - public JsNashornAuthenticatedUser(AuthenticationContext context, AuthenticatedUser wrappedUser) { - - super(context, wrappedUser); - } -} 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/graph/js/nashorn/JsNashornAuthenticationContext.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornAuthenticationContext.java deleted file mode 100644 index 08018349c77f..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornAuthenticationContext.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js.nashorn; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext; -import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; - -/** - * Javascript wrapper for Java level AuthenticationContext. - * This wrapper uses jdk.nashorn engine. - * This provides controlled access to AuthenticationContext object via provided javascript native syntax. - * e.g - * var requestedAcr = context.requestedAcr - * - * instead of - * var requestedAcr = context.getRequestedAcr() - * - * Also it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime - * AuthenticationContext. - * - * @see AuthenticationContext - */ -public class JsNashornAuthenticationContext extends JsAuthenticationContext implements AbstractJsObject { - - public JsNashornAuthenticationContext(AuthenticationContext wrapped) { - - super(wrapped); - initializeContext(wrapped); - } - - public void setMember(String name, Object value) { - - super.setMemberObject(name, value); - } - - @Override - public void removeMember(String name) { - - if (!super.removeMemberObject(name)) { - AbstractJsObject.super.removeMember(name); - } - } -} 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/graph/js/nashorn/JsNashornClaims.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornClaims.java deleted file mode 100644 index 49a4c37d5b93..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornClaims.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js.nashorn; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsClaims; -import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; -import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser; - -/** - * Represent the user's claim. Can be either remote or local. - * This wrapper uses jdk.nashorn engine. - */ -public class JsNashornClaims extends JsClaims implements AbstractJsObject { - - /** - * Constructor to get the user authenticated in step 'n' - * - * @param step The authentication step - * @param idp The authenticated IdP - * @param isRemoteClaimRequest Whether the request is for remote claim (false for local claim request) - */ - public JsNashornClaims(AuthenticationContext context, int step, String idp, boolean isRemoteClaimRequest) { - - super(context, step, idp, isRemoteClaimRequest); - } - - public JsNashornClaims(int step, String idp, boolean isRemoteClaimRequest) { - - super(step, idp, isRemoteClaimRequest); - } - - /** - * Constructor to get user who is not directly from a authentication step. Eg. Associated user of authenticated - * federated user in a authentication step. - * - * @param authenticatedUser Authenticated user - * @param isRemoteClaimRequest Whether the request is for remote claim (false for local claim request) - */ - public JsNashornClaims(AuthenticatedUser authenticatedUser, boolean isRemoteClaimRequest) { - - super(authenticatedUser, isRemoteClaimRequest); - } - - public JsNashornClaims(AuthenticationContext context, AuthenticatedUser authenticatedUser, - boolean isRemoteClaimRequest) { - - super(context, authenticatedUser, isRemoteClaimRequest); - } - - @Override - public void setMember(String claimUri, Object claimValue) { - - boolean isClaimSet = setMemberObject(claimUri, claimValue); - if (isClaimSet) { - return; - } - AbstractJsObject.super.setMember(claimUri, claimValue); - } -} 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/graph/js/nashorn/JsNashornCookie.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornCookie.java deleted file mode 100644 index c0ae8132540d..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornCookie.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2022, 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.config.model.graph.js.nashorn; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsCookie; - -import javax.servlet.http.Cookie; - -/** - * Javascript wrapper for Java level Cookie. - * This wrapper uses jdk.nashorn engine. - * This provides controlled access to Cookie object via provided javascript native syntax. - * e.g - * var commonAuthIdDomain = context.request.cookies.commonAuthId.domain - * Also it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime Cookie. - */ -public class JsNashornCookie extends JsCookie implements AbstractJsObject { - - public JsNashornCookie(Cookie cookie) { - super(cookie); - } - -} 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/graph/js/nashorn/JsNashornParameters.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornParameters.java deleted file mode 100644 index 8b91a8afe48c..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornParameters.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js.nashorn; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsParameters; - -import java.util.Map; - -/** - * Javascript wrapper for Java level HashMap of HTTP headers/cookies. - * This wrapper uses jdk.nashorn engine. - * This provides controlled access to HTTPServletRequest object's headers and cookies via provided javascript native - * syntax. - * Also it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime. - */ -public class JsNashornParameters extends JsParameters implements AbstractJsObject { - - public JsNashornParameters(Map wrapped) { - - super(wrapped); - } -} 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/graph/js/nashorn/JsNashornRuntimeClaims.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornRuntimeClaims.java deleted file mode 100644 index eface7c11e51..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornRuntimeClaims.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2020, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js.nashorn; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.base.JsBaseRuntimeClaims; -import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; -import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser; - -/** - * Represent the user's runtime claims. - * This wrapper uses jdk.nashorn engine. - */ -public class JsNashornRuntimeClaims extends JsNashornClaims implements JsBaseRuntimeClaims, AbstractJsObject { - - public JsNashornRuntimeClaims(AuthenticationContext context, int step, String idp) { - - super(context, step, idp, false); - } - - public JsNashornRuntimeClaims(AuthenticationContext context, AuthenticatedUser user) { - - super(context, user, false); - } - - public Object getMember(String claimUri) { - - if (authenticatedUser != null) { - return getRuntimeClaim(claimUri); - } - return null; - } - - public boolean hasMember(String claimUri) { - - if (authenticatedUser != null) { - return hasRuntimeClaim(claimUri); - } - return false; - } - - public void setMember(String claimUri, Object claimValue) { - - if (authenticatedUser != null) { - setRuntimeClaim(claimUri, claimValue); - } - } -} 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/graph/js/nashorn/JsNashornServletRequest.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornServletRequest.java deleted file mode 100644 index 3a16e605be05..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornServletRequest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js.nashorn; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsServletRequest; -import org.wso2.carbon.identity.application.authentication.framework.context.TransientObjectWrapper; - -import javax.servlet.http.HttpServletRequest; - -/** - * Javascript wrapper for Java level HTTPServletRequest. - * This wrapper uses jdk.nashorn engine. - * This provides controlled access to HTTPServletRequest object via provided javascript native syntax. - * e.g - * var redirect_uri = context.request.params.redirect_uri - * - * instead of - * var userName = context.getRequest().getParameter("redirect_uri) - * - * Also it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime - * HTTPServletRequest. - */ -public class JsNashornServletRequest extends JsServletRequest implements AbstractJsObject { - - public JsNashornServletRequest(TransientObjectWrapper wrapped) { - - super(wrapped); - } -} - 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/graph/js/nashorn/JsNashornServletResponse.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornServletResponse.java deleted file mode 100644 index d25f8516e4b7..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornServletResponse.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js.nashorn; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsServletResponse; -import org.wso2.carbon.identity.application.authentication.framework.context.TransientObjectWrapper; - -import javax.servlet.http.HttpServletResponse; - -/** - * Javascript wrapper for Java level HttpServletResponse. - * This wrapper uses jdk.nashorn engine. - * This provides controlled access to HttpServletResponse object via provided javascript native syntax. - * e.g - * response.headers.["Set-Cookie"] = ['crsftoken=xxxxxssometokenxxxxx'] - * - * instead of - * context.getResponse().addCookie(cookie); - * - * Also, it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime - * HttpServletResponse. - */ -public class JsNashornServletResponse extends JsServletResponse implements AbstractJsObject { - - public JsNashornServletResponse(TransientObjectWrapper wrapped) { - - super(wrapped); - } - -} 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/graph/js/nashorn/JsNashornStep.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornStep.java deleted file mode 100644 index 6da745a6cdcd..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornStep.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js.nashorn; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsStep; -import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; - -/** - * Represents a authentication step. - * This wrapper uses jdk.nashorn engine. - */ -public class JsNashornStep extends JsStep implements AbstractJsObject { - - @Deprecated - public JsNashornStep(int step, String authenticatedIdp) { - - super(step, authenticatedIdp); - } - - public JsNashornStep(int step, String authenticatedIdp, String authenticatedAuthenticator) { - - super(step, authenticatedIdp, authenticatedAuthenticator); - } - - @Deprecated - public JsNashornStep(AuthenticationContext context, int step, String authenticatedIdp) { - - super(context, step, authenticatedIdp); - } - - public JsNashornStep(AuthenticationContext context, int step, String authenticatedIdp, - String authenticatedAuthenticator) { - - super(context, step, authenticatedIdp, authenticatedAuthenticator); - } - - @Override - public Object getMember(String name) { - - Object member = super.getMember(name); - return member != null ? member : AbstractJsObject.super.getMember(name); - } - - @Override - public boolean hasMember(String name) { - - return super.hasMember(name) || AbstractJsObject.super.hasMember(name); - } - - public void removeMember(String name) { - - super.removeMemberObject(name); - } -} 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/graph/js/nashorn/JsNashornSteps.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornSteps.java deleted file mode 100644 index aeea5c6c6341..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornSteps.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js.nashorn; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsSteps; -import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; - -import java.util.Objects; - -/** - * Returns when context.steps[step_number] is called - * This wrapper uses jdk.nashorn engine. - */ -public class JsNashornSteps extends JsSteps implements AbstractJsObject { - - public JsNashornSteps() { - - super(); - - } - - public JsNashornSteps(AuthenticationContext context) { - - super(context); - } - - @Override - public Object getSlot(int step) { - - Object jsStep = super.getSlot(step); - return Objects.nonNull(jsStep) ? jsStep : AbstractJsObject.super.getSlot(step); - } -} 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/graph/js/nashorn/JsNashornWritableParameters.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornWritableParameters.java deleted file mode 100644 index 70b6ccb596dc..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornWritableParameters.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js.nashorn; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsWrapperFactoryProvider; - -import java.util.Map; - -/** - * Parameters that can be modified from the authentication script. - * This wrapper uses jdk.nashorn engine. - */ -public class JsNashornWritableParameters extends JsNashornParameters implements AbstractJsObject { - - public JsNashornWritableParameters(Map wrapped) { - - super(wrapped); - } - - public Object getMember(String name) { - - Object member = getWrapped().get(name); - if (member instanceof Map) { - return JsWrapperFactoryProvider.getInstance().getWrapperFactory() - .createJsWritableParameters((Map) member); - } - return member; - } - - public void removeMember(String name) { - - super.removeMemberObject(name); - } - - public void setMember(String name, Object value) { - - getWrapped().put(name, value); - } -} diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/GraalSelectAcrFromFunction.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/GraalSelectAcrFromFunction.java index c00268bb0574..3da43f6b370f 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/GraalSelectAcrFromFunction.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/GraalSelectAcrFromFunction.java @@ -34,7 +34,7 @@ */ public class GraalSelectAcrFromFunction implements SelectOneFunction { - private static final Log log = LogFactory.getLog(SelectAcrFromFunction.class); + private static final Log log = LogFactory.getLog(GraalSelectAcrFromFunction.class); @HostAccess.Export public String evaluate(JsAuthenticationContext context, Object possibleOutcomesObj) { diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/SelectAcrFromFunction.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/SelectAcrFromFunction.java deleted file mode 100644 index 8d21b194bb7a..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/SelectAcrFromFunction.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2017, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.handler.sequence.impl; - -import jdk.nashorn.api.scripting.ScriptObjectMirror; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext; -import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants; - -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - -/** - * Select the preferred acr value from the available list. - */ -public class SelectAcrFromFunction implements SelectOneFunction { - - private static final Log log = LogFactory.getLog(SelectAcrFromFunction.class); - - public String evaluate(JsAuthenticationContext context, Object possibleOutcomesObj) { - - String[] possibleOutcomes = extractPossibleOutcomes(context, possibleOutcomesObj); - List acrListRequested = context.getWrapped().getRequestedAcr(); - if (acrListRequested == null || acrListRequested.isEmpty()) { - if (log.isDebugEnabled()) { - log.debug("ACR values from context is empty. Selecting the default outcome as null."); - } - return null; - } - if (possibleOutcomes.length > 0) { - return selectBestOutcome(acrListRequested, possibleOutcomes); - } - return null; - } - - private String[] extractPossibleOutcomes(JsAuthenticationContext context, Object possibleOutcomesObj) { - - String[] possibleOutcomes; - if (possibleOutcomesObj instanceof String[]) { - possibleOutcomes = (String[]) possibleOutcomesObj; - } else if (possibleOutcomesObj instanceof ScriptObjectMirror) { - if (((ScriptObjectMirror) possibleOutcomesObj).isArray()) { - possibleOutcomes = ((ScriptObjectMirror) possibleOutcomesObj).to(String[].class); - } else { - log.error("Invalid argument provided for possible outcomes for " + FrameworkConstants.JSAttributes - .JS_FUNC_SELECT_ACR_FROM + " function in service provider: " + context.getWrapped() - .getServiceProviderName() + ". Expected array of strings."); - possibleOutcomes = new String[0]; - } - } else { - log.error("Invalid argument provided for possible outcomes for " + FrameworkConstants.JSAttributes - .JS_FUNC_SELECT_ACR_FROM + " function in service provider: " + context.getWrapped() - .getServiceProviderName() + ". Expected array of strings."); - possibleOutcomes = new String[0]; - } - return possibleOutcomes; - } - - private String selectBestOutcome(List acrListRequested, String[] possibleOutcomes) { - - Map acrRequestedWithPriority = new TreeMap<>(Collections.reverseOrder( - (Comparator) (o1, o2) -> o2.compareTo(o1))); - String acrSelected = null; - - for (String acrChecked : acrListRequested) { - for (int x = 0; x < possibleOutcomes.length; x++) { - String outcomeToTest = possibleOutcomes[x]; - if (outcomeToTest.equals(acrChecked)) { - if (log.isDebugEnabled()) { - log.debug("Reassigning Best Match for the outcome : " + outcomeToTest + " with priority : " + - x + 1); - } - acrRequestedWithPriority.put(x + 1, acrChecked); - break; - } - } - } - if (!acrRequestedWithPriority.entrySet().isEmpty()) { - acrSelected = acrRequestedWithPriority.entrySet().iterator().next().getValue(); - } - return acrSelected; - } -} diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/inbound/IdentityServlet.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/inbound/IdentityServlet.java index d6168a3f90aa..703bcfd747ce 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/inbound/IdentityServlet.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/inbound/IdentityServlet.java @@ -21,6 +21,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.osgi.service.component.annotations.Component; import org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException; import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder; import org.wso2.carbon.identity.core.util.IdentityUtil; @@ -30,6 +31,7 @@ import java.util.List; import java.util.Map; +import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServlet; @@ -39,6 +41,16 @@ /** * Identity Servlet. */ +//TODO Check if this servlet is working. +@Component( + service = Servlet.class, + immediate = true, + property = { + "osgi.http.whiteboard.servlet.pattern=/identity", + "osgi.http.whiteboard.servlet.name=IdentityServlet", + "osgi.http.whiteboard.servlet.asyncSupported=true" + } +) public class IdentityServlet extends HttpServlet { private static final Log log = LogFactory.getLog(IdentityServlet.class); 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 94519bfbd397..45e4a3aae163 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 @@ -23,7 +23,6 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.eclipse.equinox.http.helper.ContextPathServletAdaptor; import org.osgi.framework.BundleContext; import org.osgi.service.component.ComponentContext; import org.osgi.service.component.annotations.Activate; @@ -32,7 +31,6 @@ import org.osgi.service.component.annotations.Reference; import org.osgi.service.component.annotations.ReferenceCardinality; import org.osgi.service.component.annotations.ReferencePolicy; -import org.osgi.service.http.HttpService; import org.wso2.carbon.consent.mgt.core.ConsentManager; import org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticationService; import org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticator; @@ -76,7 +74,6 @@ import org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityRequestFactory; 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; @@ -84,9 +81,6 @@ import org.wso2.carbon.identity.application.authentication.framework.listener.AuthenticationEndpointTenantActivityListener; import org.wso2.carbon.identity.application.authentication.framework.listener.SessionContextMgtListener; import org.wso2.carbon.identity.application.authentication.framework.services.PostAuthenticationMgtService; -import org.wso2.carbon.identity.application.authentication.framework.servlet.CommonAuthenticationServlet; -import org.wso2.carbon.identity.application.authentication.framework.servlet.LoginContextServlet; -import org.wso2.carbon.identity.application.authentication.framework.servlet.LongWaitStatusServlet; import org.wso2.carbon.identity.application.authentication.framework.session.extender.processor.SessionExtenderProcessor; import org.wso2.carbon.identity.application.authentication.framework.session.extender.request.SessionExtenderRequestFactory; import org.wso2.carbon.identity.application.authentication.framework.session.extender.response.SessionExtenderResponseFactory; @@ -131,10 +125,7 @@ import java.util.List; import java.util.Locale; -import javax.servlet.Servlet; - import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.CUSTOM_AUTHENTICATOR_PREFIX; -import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils.promptOnLongWait; import static org.wso2.carbon.identity.base.IdentityConstants.TRUE; /** @@ -147,15 +138,10 @@ ) public class FrameworkServiceComponent { - public static final String COMMON_SERVLET_URL = "/commonauth"; public static final String IS_HANDLER = "IS_HANDLER"; - private static final String IDENTITY_SERVLET_URL = "/identity"; - private static final String LOGIN_CONTEXT_SERVLET_URL = "/logincontext"; - private static final String LONGWAITSTATUS_SERVLET_URL = "/longwaitstatus"; private static final Log log = LogFactory.getLog(FrameworkServiceComponent.class); private static final String API_AUTH = "APIAuth"; - private HttpService httpService; private ConsentMgtPostAuthnHandler consentMgtPostAuthnHandler = new ConsentMgtPostAuthnHandler(); private String requireCode; private String secretsCode; @@ -243,37 +229,6 @@ protected void activate(ComponentContext ctxt) { .registerService(AuthenticationMethodNameTranslator.class, authenticationMethodNameTranslator, null); dataHolder.setAuthenticationMethodNameTranslator(authenticationMethodNameTranslator); - // Register Common servlet - Servlet commonAuthServlet = new ContextPathServletAdaptor(new CommonAuthenticationServlet(), - COMMON_SERVLET_URL); - - Servlet identityServlet = new ContextPathServletAdaptor(new IdentityServlet(), - IDENTITY_SERVLET_URL); - - Servlet loginContextServlet = new ContextPathServletAdaptor(new LoginContextServlet(), - LOGIN_CONTEXT_SERVLET_URL); - try { - httpService.registerServlet(COMMON_SERVLET_URL, commonAuthServlet, null, null); - httpService.registerServlet(IDENTITY_SERVLET_URL, identityServlet, null, null); - httpService.registerServlet(LOGIN_CONTEXT_SERVLET_URL, loginContextServlet, null, null); - } catch (Exception e) { - String errMsg = "Error when registering servlets via the HttpService."; - log.error(errMsg, e); - throw new RuntimeException(errMsg, e); - } - - if (promptOnLongWait()) { - Servlet longWaitStatusServlet = new ContextPathServletAdaptor(new LongWaitStatusServlet(), - LONGWAITSTATUS_SERVLET_URL); - try { - httpService.registerServlet(LONGWAITSTATUS_SERVLET_URL, longWaitStatusServlet, null, null); - } catch (Exception e) { - String errMsg = "Error when registering longwaitstatus servlet via the HttpService."; - log.error(errMsg, e); - throw new RuntimeException(errMsg, e); - } - } - dataHolder.setBundleContext(bundleContext); dataHolder.getHttpIdentityRequestFactories().add(new HttpIdentityRequestFactory()); dataHolder.getHttpIdentityResponseFactories().add(new FrameworkLoginResponseFactory()); @@ -456,31 +411,6 @@ protected void deactivate(ComponentContext ctxt) { } } - @Reference( - name = "osgi.httpservice", - service = HttpService.class, - cardinality = ReferenceCardinality.MANDATORY, - policy = ReferencePolicy.DYNAMIC, - unbind = "unsetHttpService" - ) - protected void setHttpService(HttpService httpService) { - - if (log.isDebugEnabled()) { - log.debug("HTTP Service is set in the Application Authentication Framework bundle"); - } - - this.httpService = httpService; - } - - protected void unsetHttpService(HttpService httpService) { - - if (log.isDebugEnabled()) { - log.debug("HTTP Service is unset in the Application Authentication Framework bundle"); - } - - this.httpService = null; - } - protected void unsetRealmService(RealmService realmService) { if (log.isDebugEnabled()) { diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/CommonAuthenticationServlet.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/CommonAuthenticationServlet.java index e8e892a2f0b0..710d67e2ddfc 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/CommonAuthenticationServlet.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/CommonAuthenticationServlet.java @@ -18,11 +18,13 @@ package org.wso2.carbon.identity.application.authentication.framework.servlet; +import org.osgi.service.component.annotations.Component; import org.wso2.carbon.identity.application.authentication.framework.CommonAuthenticationHandler; import org.wso2.carbon.identity.application.authentication.framework.config.ConfigurationFacade; import java.io.IOException; +import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -31,6 +33,16 @@ /** * Servlet to handle common authentication requests. */ +//TODO Check if this servlet is working. +@Component( + service = Servlet.class, + immediate = true, + property = { + "osgi.http.whiteboard.servlet.pattern=/commonauth", + "osgi.http.whiteboard.servlet.name=CommonAuthenticationServlet", + "osgi.http.whiteboard.servlet.asyncSupported=true" + } +) public class CommonAuthenticationServlet extends HttpServlet { private final CommonAuthenticationHandler commonAuthenticationHandler = new CommonAuthenticationHandler(); diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/LoginContextServlet.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/LoginContextServlet.java index 9d6f55f9666d..11bd2e2258a6 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/LoginContextServlet.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/LoginContextServlet.java @@ -18,10 +18,12 @@ package org.wso2.carbon.identity.application.authentication.framework.servlet; +import org.osgi.service.component.annotations.Component; import org.wso2.carbon.identity.application.authentication.framework.util.LoginContextManagementUtil; import java.io.IOException; +import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -32,6 +34,16 @@ * authenticationendpoint. In case of invalid sessionDataKey, initiates redirection forcing application to * start authentication flow with new sessionDataKey */ +//TODO Check if this servlet is working. +@Component( + service = Servlet.class, + immediate = true, + property = { + "osgi.http.whiteboard.servlet.pattern=/logincontext", + "osgi.http.whiteboard.servlet.name=LoginContextServlet", + "osgi.http.whiteboard.servlet.asyncSupported=true" + } +) public class LoginContextServlet extends HttpServlet { @Override diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/LongWaitStatusServlet.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/LongWaitStatusServlet.java index 0f2a78acf124..849a421d061c 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/LongWaitStatusServlet.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/LongWaitStatusServlet.java @@ -19,6 +19,7 @@ package org.wso2.carbon.identity.application.authentication.framework.servlet; import com.google.gson.Gson; +import org.osgi.service.component.annotations.Component; import org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException; import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder; import org.wso2.carbon.identity.application.authentication.framework.javascript.flow.LongWaitStatusRequest; @@ -31,6 +32,7 @@ import java.io.IOException; import java.io.PrintWriter; +import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -39,6 +41,16 @@ /** * Servlet to get the status of long wait process. */ +//TODO Check if this servlet is working. +@Component( + service = Servlet.class, + immediate = true, + property = { + "osgi.http.whiteboard.servlet.pattern=/longwaitstatus", + "osgi.http.whiteboard.servlet.name=LongWaitStatusServlet", + "osgi.http.whiteboard.servlet.asyncSupported=true" + } +) public class LongWaitStatusServlet extends HttpServlet { private static final long serialVersionUID = -3714283612680472526L; 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 01cad5bc0448..c0a5d4a63dc4 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 @@ -67,7 +67,6 @@ import org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsBaseGraphBuilderFactory; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGenericGraphBuilderFactory; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilderFactory; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.graaljs.JsGraalGraphBuilderFactory; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.openjdk.nashorn.JsOpenJdkNashornGraphBuilderFactory; import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; @@ -4550,8 +4549,6 @@ public static JsGenericGraphBuilderFactory createJsGenericGraphBuilderFactoryFro return new JsGraalGraphBuilderFactory(); } else if (StringUtils.equalsIgnoreCase(FrameworkConstants.OPENJDK_NASHORN, scriptEngineName)) { return new JsOpenJdkNashornGraphBuilderFactory(); - } else if (StringUtils.equalsIgnoreCase(FrameworkConstants.NASHORN, scriptEngineName)) { - return new JsGraphBuilderFactory(); } } // Config is not set. Hence going with class for name approach. @@ -4563,12 +4560,7 @@ public static JsGenericGraphBuilderFactory createJsGenericGraphBuilderFactoryFro Class.forName(OPENJDK_SCRIPTER_CLASS_NAME); return new JsOpenJdkNashornGraphBuilderFactory(); } catch (ClassNotFoundException classNotFoundException) { - try { - Class.forName(JDK_SCRIPTER_CLASS_NAME); - return new JsGraphBuilderFactory(); - } catch (ClassNotFoundException ex) { - return null; - } + return null; } } } diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/JsNashornGraphBuilderTest.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/JsNashornGraphBuilderTest.java deleted file mode 100644 index 5c71d7ddc9e5..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/JsNashornGraphBuilderTest.java +++ /dev/null @@ -1,391 +0,0 @@ -/* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph; - -import org.mockito.Mock; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import org.wso2.carbon.identity.application.authentication.framework.AbstractFrameworkTest; -import org.wso2.carbon.identity.application.authentication.framework.FederatedApplicationAuthenticator; -import org.wso2.carbon.identity.application.authentication.framework.LocalApplicationAuthenticator; -import org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig; -import org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig; -import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; -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.IdentityProvider; -import org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig; -import org.wso2.carbon.identity.application.common.model.ServiceProvider; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; - -/** - * Tests for graph builder with Javascript. - */ -@Test -public class JsNashornGraphBuilderTest extends AbstractFrameworkTest { - - private JsGraphBuilderFactory jsGraphBuilderFactory; - - @Mock - private LocalApplicationAuthenticator localApplicationAuthenticator; - - @Mock - private LocalApplicationAuthenticator totpApplicationAuthenticator; - - @Mock - private FederatedApplicationAuthenticator federatedApplicationAuthenticator; - - @BeforeTest - public void setUp() { - initMocks(this); - jsGraphBuilderFactory = new JsGraphBuilderFactory(); - jsGraphBuilderFactory.init(); - JSExecutionSupervisor jsExecutionSupervisor = new JSExecutionSupervisor(1, 5000L); - FrameworkServiceDataHolder.getInstance().setJsExecutionSupervisor(jsExecutionSupervisor); - } - - @AfterTest - public void teardown() { - - FrameworkServiceDataHolder.getInstance().getJsExecutionSupervisor().shutdown(); - } - - @Test - public void testCreateDirectJavaInvalidStepId() throws Exception { - - ServiceProvider sp1 = getTestServiceProvider("js-sp-1.xml"); - AuthenticationContext context = getAuthenticationContext(sp1); - Map stepConfigMap = new HashMap<>(); - stepConfigMap.put(1, new StepConfig()); - JsNashornGraphBuilder jsGraphBuilder = jsGraphBuilderFactory.createBuilder(context, stepConfigMap); - jsGraphBuilder.executeStep(2); - - AuthenticationGraph graph = jsGraphBuilder.build(); - assertNull(graph.getStartNode()); - } - - @Test - public void testCreateDirectJava() throws Exception { - - ServiceProvider sp1 = getTestServiceProvider("js-sp-1.xml"); - AuthenticationContext context = getAuthenticationContext(sp1); - Map stepConfigMap = new HashMap<>(); - stepConfigMap.put(1, new StepConfig()); - stepConfigMap.put(2, new StepConfig()); - JsNashornGraphBuilder jsGraphBuilder = jsGraphBuilderFactory.createBuilder(context, stepConfigMap); - jsGraphBuilder.executeStep(1); - jsGraphBuilder.executeStep(2); - - AuthenticationGraph graph = jsGraphBuilder.build(); - assertNotNull(graph.getStartNode()); - assertTrue(graph.getStartNode() instanceof StepConfigGraphNode); - - StepConfigGraphNode firstStep = (StepConfigGraphNode) graph.getStartNode(); - assertNotNull(firstStep.getNext()); - assertTrue(firstStep.getNext() instanceof StepConfigGraphNode); - } - - @Test - public void testCreateJavascript() throws Exception { - - String script = "var onLoginRequest = function(context) { executeStep(1, { onSuccess : function(context) {" - + "executeStep(2);}})};"; - - ServiceProvider sp1 = getTestServiceProvider("js-sp-1.xml"); - AuthenticationContext context = getAuthenticationContext(sp1); - - Map stepConfigMap = new HashMap<>(); - stepConfigMap.put(1, new StepConfig()); - stepConfigMap.put(2, new StepConfig()); - - JsNashornGraphBuilder jsGraphBuilder = jsGraphBuilderFactory.createBuilder(context, stepConfigMap); - jsGraphBuilder.createWith(script); - - AuthenticationGraph graph = jsGraphBuilder.build(); - assertNotNull(graph.getStartNode()); - assertTrue(graph.getStartNode() instanceof StepConfigGraphNode); - - StepConfigGraphNode firstStep = (StepConfigGraphNode) graph.getStartNode(); - assertNotNull(firstStep.getNext()); - assertTrue(firstStep.getNext() instanceof DynamicDecisionNode); - } - - @Test(dataProvider = "filterOptionsDataProvider") - public void testFilterOptions(Map> options, StepConfig stepConfig, int - expectedStepsAfterFilter) - throws Exception { - - ServiceProvider sp1 = getTestServiceProvider("js-sp-1.xml"); - AuthenticationContext context = getAuthenticationContext(sp1); - - Map stepConfigMap = new HashMap<>(); - stepConfigMap.put(1, stepConfig); - - JsNashornGraphBuilder jsGraphBuilder = jsGraphBuilderFactory.createBuilder(context, stepConfigMap); - jsGraphBuilder.filterOptions(options, stepConfig); - assertEquals(stepConfig.getAuthenticatorList().size(), expectedStepsAfterFilter, - "Authentication options after filtering mismatches expected. " + options); - } - - @DataProvider - public Object[][] filterOptionsDataProvider() throws Exception { - - ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().clear(); - LocalAuthenticatorConfig basic = new LocalAuthenticatorConfig(); - basic.setName("BasicAuthenticator"); - basic.setDisplayName("basic"); - LocalAuthenticatorConfig totp = new LocalAuthenticatorConfig(); - totp.setName("TOTPAuthenticator"); - totp.setDisplayName("totp"); - ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().add(basic); - ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().add(totp); - - IdentityProvider localIdp = new IdentityProvider(); - localIdp.setId("LOCAL"); - localIdp.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[0]); - - FederatedAuthenticatorConfig samlFederated = new FederatedAuthenticatorConfig(); - samlFederated.setDisplayName("samlsso"); - samlFederated.setName("SAMLAuthenticator"); - - FederatedAuthenticatorConfig oidcFederated = new FederatedAuthenticatorConfig(); - oidcFederated.setDisplayName("oidc"); - oidcFederated.setName("OIDCAuthenticator"); - - FederatedAuthenticatorConfig twitterFederated = new FederatedAuthenticatorConfig(); - twitterFederated.setDisplayName("twitter"); - twitterFederated.setName("TwitterAuthenticator"); - - IdentityProvider customIdp1 = new IdentityProvider(); - customIdp1.setId("customIdp1"); - customIdp1.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[]{samlFederated, oidcFederated}); - customIdp1.setDefaultAuthenticatorConfig(samlFederated); - - IdentityProvider customIdp2 = new IdentityProvider(); - customIdp2.setId("customIdp2"); - customIdp2.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[]{twitterFederated}); - customIdp2.setDefaultAuthenticatorConfig(twitterFederated); - - AuthenticatorConfig basicAuthConfig = new AuthenticatorConfig(); - basicAuthConfig.setName("BasicAuthenticator"); - basicAuthConfig.setEnabled(true); - basicAuthConfig.getIdps().put("LOCAL", localIdp); - - AuthenticatorConfig totpAuthConfig = new AuthenticatorConfig(); - totpAuthConfig.setName("TOTPAuthenticator"); - totpAuthConfig.setEnabled(true); - totpAuthConfig.getIdps().put("LOCAL", localIdp); - - AuthenticatorConfig samlAuthConfig = new AuthenticatorConfig(); - samlAuthConfig.setName("SAMLAuthenticator"); - samlAuthConfig.setEnabled(true); - samlAuthConfig.getIdps().put("customIdp1", customIdp1); - - AuthenticatorConfig oidcAuthConfig = new AuthenticatorConfig(); - oidcAuthConfig.setName("OIDCAuthenticator"); - oidcAuthConfig.setEnabled(true); - oidcAuthConfig.getIdps().put("customIdp1", customIdp1); - - AuthenticatorConfig twitterAuthConfig = new AuthenticatorConfig(); - twitterAuthConfig.setName("TwitterAuthenticator"); - twitterAuthConfig.setEnabled(true); - twitterAuthConfig.getIdps().put("customIdp2", customIdp2); - - StepConfig stepWithSingleOption = new StepConfig(); - stepWithSingleOption.setAuthenticatorList(Collections.singletonList(basicAuthConfig)); - Map> singleOptionConfig = new HashMap<>(); - singleOptionConfig.put("0", Collections.singletonMap("authenticator", "basic")); - - StepConfig stepWithMultipleOptions = new StepConfig(); - stepWithMultipleOptions.setAuthenticatorList(new ArrayList<>(Arrays.asList(basicAuthConfig, totpAuthConfig, - oidcAuthConfig, twitterAuthConfig))); - - Map oidcOption = new HashMap<>(); - oidcOption.put("idp", "customIdp1"); - oidcOption.put("authenticator", "oidc"); - - Map twitterOption = new HashMap<>(); - twitterOption.put("idp", "customIdp2"); - twitterOption.put("authenticator", "twitter"); - - Map invalidOption = new HashMap<>(); - invalidOption.put("idp", "customIdp1"); - invalidOption.put("authenticator", "twitter"); - - Map> multipleOptionConfig = new HashMap<>(); - multipleOptionConfig.put("0", Collections.singletonMap("authenticator", "basic")); - multipleOptionConfig.put("1", oidcOption); - multipleOptionConfig.put("2", twitterOption); - - Map> multipleAndInvalidOptionConfig = new HashMap<>(); - multipleAndInvalidOptionConfig.put("0", Collections.singletonMap("authenticator", "basic")); - multipleAndInvalidOptionConfig.put("1", oidcOption); - multipleAndInvalidOptionConfig.put("2", invalidOption); - - Map> idpOnlyOptionConfig = new HashMap<>(); - idpOnlyOptionConfig.put("0", Collections.singletonMap("authenticator", "basic")); - idpOnlyOptionConfig.put("1", Collections.singletonMap("idp", "customIdp1")); - - Map> singleInvalidOptionConfig = new HashMap<>(); - singleInvalidOptionConfig.put("0", invalidOption); - - ApplicationAuthenticatorService authenticatorService = mock(ApplicationAuthenticatorService.class); - Field instanceField = ApplicationAuthenticatorService.class.getDeclaredField("instance"); - instanceField.setAccessible(true); - instanceField.set(null, authenticatorService); - when(authenticatorService.getAllLocalAuthenticators(any())) - .thenReturn(new ArrayList<>(Arrays.asList(basic, totp))); - - return new Object[][]{ - {singleOptionConfig, duplicateStepConfig(stepWithSingleOption), 1}, - {singleOptionConfig, duplicateStepConfig(stepWithMultipleOptions), 1}, - {multipleOptionConfig, duplicateStepConfig(stepWithMultipleOptions), 3}, - {multipleAndInvalidOptionConfig, duplicateStepConfig(stepWithMultipleOptions), 2}, - {singleInvalidOptionConfig, duplicateStepConfig(stepWithMultipleOptions), 4}, - {idpOnlyOptionConfig, duplicateStepConfig(stepWithMultipleOptions), 2}, - }; - } - - private StepConfig duplicateStepConfig(StepConfig stepConfig) { - - StepConfig newStepConfig = new StepConfig(); - newStepConfig.setAuthenticatorList(new ArrayList<>(stepConfig.getAuthenticatorList())); - return newStepConfig; - } - - @Test(dataProvider = "filterParamsDataProvider", alwaysRun = true) - public void testParamsOptions(Map options, StepConfig stepConfig, - String authenticatorName, String key, String value) throws Exception { - - ServiceProvider sp1 = getTestServiceProvider("js-sp-1.xml"); - AuthenticationContext context = getAuthenticationContext(sp1); - - Map stepConfigMap = new HashMap<>(); - stepConfigMap.put(1, stepConfig); - - JsNashornGraphBuilder jsGraphBuilder = jsGraphBuilderFactory.createBuilder(context, stepConfigMap); - jsGraphBuilder.authenticatorParamsOptions(options, stepConfig); - assertEquals(context.getAuthenticatorParams(authenticatorName).get(key), value, - "Params are not set expected"); - } - - @DataProvider - public Object[][] filterParamsDataProvider() { - - ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().clear(); - LocalAuthenticatorConfig basic = new LocalAuthenticatorConfig(); - basic.setName("BasicAuthenticator"); - basic.setDisplayName("basic"); - - LocalAuthenticatorConfig totp = new LocalAuthenticatorConfig(); - totp.setName("TOTPAuthenticator"); - totp.setDisplayName("totp"); - - ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().add(basic); - ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().add(totp); - - FederatedAuthenticatorConfig twitterFederated = new FederatedAuthenticatorConfig(); - twitterFederated.setDisplayName("twitter"); - twitterFederated.setName("TwitterAuthenticator"); - - IdentityProvider localIdp = new IdentityProvider(); - localIdp.setId("local"); - localIdp.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[0]); - - IdentityProvider customIdp2 = new IdentityProvider(); - customIdp2.setId("customIdp2"); - customIdp2.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[]{twitterFederated}); - customIdp2.setDefaultAuthenticatorConfig(twitterFederated); - - AuthenticatorConfig basicAuthConfig = new AuthenticatorConfig(); - basicAuthConfig.setName("BasicAuthenticator"); - basicAuthConfig.setEnabled(true); - when(localApplicationAuthenticator.getName()).thenReturn("BasicAuthenticator"); - when(localApplicationAuthenticator.getFriendlyName()).thenReturn("basic"); - basicAuthConfig.setApplicationAuthenticator(localApplicationAuthenticator); - basicAuthConfig.getIdps().put("local", localIdp); - - AuthenticatorConfig totpAuthConfig = new AuthenticatorConfig(); - totpAuthConfig.setName("TOTPAuthenticator"); - totpAuthConfig.setEnabled(true); - when(totpApplicationAuthenticator.getName()).thenReturn("TOTPAuthenticator"); - when(totpApplicationAuthenticator.getFriendlyName()).thenReturn("totp"); - totpAuthConfig.setApplicationAuthenticator(totpApplicationAuthenticator); - totpAuthConfig.getIdps().put("local", localIdp); - - AuthenticatorConfig twitterAuthConfig = new AuthenticatorConfig(); - twitterAuthConfig.setName("TwitterAuthenticator"); - twitterAuthConfig.setEnabled(true); - when(federatedApplicationAuthenticator.getName()).thenReturn("TwitterAuthenticator"); - when(federatedApplicationAuthenticator.getFriendlyName()).thenReturn("twitter"); - twitterAuthConfig.setApplicationAuthenticator(federatedApplicationAuthenticator); - twitterAuthConfig.getIdps().put("customIdp2", customIdp2); - - StepConfig stepWithSingleOption = new StepConfig(); - stepWithSingleOption.setAuthenticatorList(Collections.singletonList(basicAuthConfig)); - - Map singleParamConfig = new HashMap<>(); - Map params = new HashMap<>(); - params.put("BasicAuthenticator", Collections.singletonMap("foo", "xyz")); - singleParamConfig.put("local", params); - - StepConfig stepWithMultipleOptions = new StepConfig(); - stepWithMultipleOptions.setAuthenticatorList(new ArrayList<>(Arrays.asList(basicAuthConfig, totpAuthConfig, - twitterAuthConfig))); - - Map localParams = new HashMap<>(); - localParams.put("BasicAuthenticator", Collections.singletonMap("foo", "xyz")); - localParams.put("TOTPAuthenticator", Collections.singletonMap("domain", "localhost")); - - Map federatedParams = new HashMap<>(); - federatedParams.put("customIdp2", Collections.singletonMap("foo", "user")); - - Map multiParamConfig = new HashMap<>(); - multiParamConfig.put("local", localParams); - multiParamConfig.put("federated", federatedParams); - - return new Object[][]{ - {singleParamConfig, duplicateStepConfig(stepWithSingleOption), "BasicAuthenticator", "foo", "xyz"}, - {singleParamConfig, duplicateStepConfig(stepWithSingleOption), "BasicAuthenticator", "foos", null}, - {singleParamConfig, duplicateStepConfig(stepWithMultipleOptions), "BasicAuthenticator", "foo", "xyz"}, - {multiParamConfig, duplicateStepConfig(stepWithMultipleOptions), "BasicAuthenticator", "domain", null}, - {multiParamConfig, duplicateStepConfig(stepWithMultipleOptions), "TwitterAuthenticator", "foo", "user"}, - {multiParamConfig, duplicateStepConfig(stepWithMultipleOptions), "TOTPAuthenticator", "domain", - "localhost"} - }; - } -} diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/JsNashornAuthenticationContextTest.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/JsNashornAuthenticationContextTest.java deleted file mode 100644 index 0788d9051b7d..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/JsNashornAuthenticationContextTest.java +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js; - -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig; -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.config.model.graph.AuthenticationGraph; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsWrapperFactory; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsWrapperFactoryProvider; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.nashorn.JsNashornAuthenticatedUser; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.nashorn.JsNashornAuthenticationContext; -import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; -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.util.FrameworkConstants; -import org.wso2.carbon.identity.application.common.model.ClaimMapping; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; - -import javax.script.Bindings; -import javax.script.ScriptContext; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -import javax.script.ScriptException; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; - -@Test -public class JsNashornAuthenticationContextTest { - - public static final String TEST_IDP = "testIdP"; - private static final String LAST_ATTEMPTED_USER_USERNAME = "lastAttemptedUsername"; - private static final String LAST_ATTEMPTED_USER_TENANT_DOMAIN = "lastAttemptedTenantDomain"; - private static final String LAST_ATTEMPTED_USER_USERSTORE_DOMAIN = "lastAttemptedUserstoreDomain"; - private static final String SERVICE_PROVIDER_NAME = "service_provider_js_test"; - private static final String BASIC_AUTHENTICATOR = "BasicAuthenticator"; - - private ScriptEngine scriptEngine; - - @BeforeClass - public void setUp() throws NoSuchFieldException, IllegalAccessException { - - scriptEngine = new ScriptEngineManager().getEngineByName("nashorn"); - Field wrapperFactory = JsWrapperFactoryProvider.class.getDeclaredField("jsWrapperBaseFactory"); - wrapperFactory.setAccessible(true); - wrapperFactory.set(JsWrapperFactoryProvider.getInstance(), new JsWrapperFactory()); - } - - @Test - public void testClaimAssignment() throws ScriptException { - - ClaimMapping claimMapping1 = ClaimMapping.build("", "", "", false); - - ClaimMapping claimMapping2 = ClaimMapping.build("Test.Remote.Claim.Url.2", "Test.Remote.Claim.Url.2", "", - false); - - AuthenticatedUser authenticatedUser = new AuthenticatedUser(); - authenticatedUser.getUserAttributes().put(claimMapping1, "TestClaimVal1"); - authenticatedUser.getUserAttributes().put(claimMapping2, "TestClaimVal2"); - AuthenticationContext authenticationContext = new AuthenticationContext(); - setupAuthContextWithStepData(authenticationContext, authenticatedUser); - - JsNashornAuthenticationContext jsNashornAuthenticationContext = - new JsNashornAuthenticationContext(authenticationContext); - Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE); - bindings.put("context", jsNashornAuthenticationContext); - - Object result = scriptEngine.eval("context.steps[1].subject.remoteClaims['Test.Remote.Claim.Url.1']"); - assertNull(result); - result = scriptEngine.eval("context.steps[1].subject.remoteClaims['Test.Remote.Claim.Url.2']"); - assertEquals(result, "TestClaimVal2"); - - scriptEngine.eval("context.steps[1].subject.remoteClaims['Test.Remote.Claim.Url.2'] = 'Modified2'"); - result = scriptEngine.eval("context.steps[1].subject.remoteClaims['Test.Remote.Claim.Url.2']"); - assertEquals(result, "Modified2"); - - } - - private void setupAuthContextWithStepData(AuthenticationContext context, AuthenticatedUser authenticatedUser) { - - AuthenticatorConfig basicAuthenticatorConfig = new AuthenticatorConfig(); - basicAuthenticatorConfig.setName(BASIC_AUTHENTICATOR); - basicAuthenticatorConfig.setEnabled(true); - SequenceConfig sequenceConfig = new SequenceConfig(); - Map stepConfigMap = new HashMap<>(); - StepConfig stepConfig = new StepConfig(); - stepConfig.setOrder(1); - stepConfig.setAuthenticatedIdP(TEST_IDP); - stepConfig.setAuthenticatedAutenticator(basicAuthenticatorConfig); - stepConfigMap.put(1, stepConfig); - sequenceConfig.setStepMap(stepConfigMap); - AuthenticationGraph authenticationGraph = new AuthenticationGraph(); - authenticationGraph.setStepMap(stepConfigMap); - sequenceConfig.setAuthenticationGraph(authenticationGraph); - context.setSequenceConfig(sequenceConfig); - Map idPDataMap = new HashMap<>(); - AuthenticatedIdPData idPData = new AuthenticatedIdPData(); - idPData.setUser(authenticatedUser); - idPData.setIdpName(TEST_IDP); - idPDataMap.put(TEST_IDP, idPData); - context.setCurrentAuthenticatedIdPs(idPDataMap); - } - - @Test - public void testRemoteAddition() throws ScriptException { - - AuthenticatedUser authenticatedUser = new AuthenticatedUser(); - AuthenticationContext authenticationContext = new AuthenticationContext(); - setupAuthContextWithStepData(authenticationContext, authenticatedUser); - - JsNashornAuthenticationContext jsNashornAuthenticationContext = - new JsNashornAuthenticationContext(authenticationContext); - Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE); - bindings.put("context", jsNashornAuthenticationContext); - - scriptEngine.eval("context.steps[1].subject.remoteClaims['testClaim']='testValue'"); - - ClaimMapping claimMapping = ClaimMapping.build("testClaim", "testClaim", "", false); - String claimCreatedByJs = authenticatedUser.getUserAttributes().get(claimMapping); - assertEquals(claimCreatedByJs, "testValue"); - } - - @Test - public void testGetServiceProviderFromWrappedContext() throws Exception { - - AuthenticationContext authenticationContext = new AuthenticationContext(); - authenticationContext.setServiceProviderName(SERVICE_PROVIDER_NAME); - - JsNashornAuthenticationContext jsNashornAuthenticationContext = - new JsNashornAuthenticationContext(authenticationContext); - Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE); - bindings.put("context", jsNashornAuthenticationContext); - - Object result = scriptEngine.eval("context.serviceProviderName"); - assertNotNull(result); - assertEquals(result, SERVICE_PROVIDER_NAME, "Service Provider name set in AuthenticationContext is not " + - "accessible from JSAuthenticationContext"); - } - - - @Test - public void testGetLastLoginFailedUserFromWrappedContext() throws Exception { - - AuthenticatedUser lastAttemptedUser = new AuthenticatedUser(); - lastAttemptedUser.setUserName(LAST_ATTEMPTED_USER_USERNAME); - lastAttemptedUser.setTenantDomain(LAST_ATTEMPTED_USER_TENANT_DOMAIN); - lastAttemptedUser.setUserStoreDomain(LAST_ATTEMPTED_USER_USERSTORE_DOMAIN); - - AuthenticationContext authenticationContext = new AuthenticationContext(); - authenticationContext.setProperty(FrameworkConstants.JSAttributes.JS_LAST_LOGIN_FAILED_USER, lastAttemptedUser); - - JsNashornAuthenticationContext jsNashornAuthenticationContext = - new JsNashornAuthenticationContext(authenticationContext); - Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE); - bindings.put("context", jsNashornAuthenticationContext); - - Object result = scriptEngine.eval("context.lastLoginFailedUser"); - assertNotNull(result); - assertTrue(result instanceof JsNashornAuthenticatedUser); - - String username = (String) scriptEngine.eval("context.lastLoginFailedUser.username"); - assertEquals(username, LAST_ATTEMPTED_USER_USERNAME); - - String tenantDomain = (String) scriptEngine.eval("context.lastLoginFailedUser.tenantDomain"); - assertEquals(tenantDomain, LAST_ATTEMPTED_USER_TENANT_DOMAIN); - - String userStoreDomain = (String) scriptEngine.eval("context.lastLoginFailedUser.userStoreDomain"); - assertEquals(userStoreDomain, LAST_ATTEMPTED_USER_USERSTORE_DOMAIN.toUpperCase()); - } - - @Test - public void testGetLastLoginFailedUserNullFromWrappedContext() throws Exception { - - AuthenticationContext authenticationContext = new AuthenticationContext(); - authenticationContext.setProperty(FrameworkConstants.JSAttributes.JS_LAST_LOGIN_FAILED_USER, null); - - JsNashornAuthenticationContext jsNashornAuthenticationContext = - new JsNashornAuthenticationContext(authenticationContext); - Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE); - bindings.put("context", jsNashornAuthenticationContext); - - Object result = scriptEngine.eval("context.lastLoginFailedUser"); - assertNull(result); - } - - @Test - public void testGetLastLoginAuthenticatorFromStep() throws Exception { - - AuthenticationContext authenticationContext = new AuthenticationContext(); - AuthenticatedUser authenticatedUser = new AuthenticatedUser(); - - setupAuthContextWithStepData(authenticationContext, authenticatedUser); - - JsNashornAuthenticationContext jsNashornAuthenticationContext = - new JsNashornAuthenticationContext(authenticationContext); - Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE); - bindings.put("context", jsNashornAuthenticationContext); - - Object result = scriptEngine.eval("context.steps[1].authenticator"); - assertNotNull(result); - assertEquals(result, BASIC_AUTHENTICATOR, "Authenticator of the step in AuthenticationContext is not " + - "accessible from JSAuthenticationContext"); - - } -} diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/GraphBasedSequenceHandlerAbstractTest.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/GraphBasedSequenceHandlerAbstractTest.java index e75087ad4a38..9218721306d3 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/GraphBasedSequenceHandlerAbstractTest.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/GraphBasedSequenceHandlerAbstractTest.java @@ -34,8 +34,6 @@ import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JSExecutionSupervisor; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsFunctionRegistryImpl; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGenericGraphBuilderFactory; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilderFactory; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsWrapperFactory; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsWrapperFactoryProvider; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.graaljs.JsGraalGraphBuilderFactory; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.graaljs.JsGraalWrapperFactory; @@ -104,17 +102,13 @@ protected void setupSuite(String scriptEngine) throws NoSuchFieldException, Ille configurationLoader = new UIBasedConfigurationLoader(); CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME = false; - if (scriptEngine.contentEquals(FrameworkConstants.JSAttributes.NASHORN)) { - graphBuilderFactory = new JsGraphBuilderFactory(); - } else if (scriptEngine.contentEquals(FrameworkConstants.JSAttributes.GRAALJS)) { + if (scriptEngine.contentEquals(FrameworkConstants.JSAttributes.GRAALJS)) { graphBuilderFactory = new JsGraalGraphBuilderFactory(); } Field wrapperFactory = JsWrapperFactoryProvider.class.getDeclaredField("jsWrapperBaseFactory"); wrapperFactory.setAccessible(true); - if (graphBuilderFactory instanceof JsGraphBuilderFactory) { - wrapperFactory.set(JsWrapperFactoryProvider.getInstance(), new JsWrapperFactory()); - } else if (graphBuilderFactory instanceof JsGraalGraphBuilderFactory) { + if (graphBuilderFactory instanceof JsGraalGraphBuilderFactory) { wrapperFactory.set(JsWrapperFactoryProvider.getInstance(), new JsGraalWrapperFactory()); } diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/resources/testng.xml b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/resources/testng.xml index 0e81b0000e8f..c9670206c7fe 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/resources/testng.xml +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/resources/testng.xml @@ -57,9 +57,7 @@ - - diff --git a/components/authorization-framework/org.wso2.carbon.identity.authorization.common/pom.xml b/components/authorization-framework/org.wso2.carbon.identity.authorization.common/pom.xml index 15656fcfdfee..873fc7d47c22 100644 --- a/components/authorization-framework/org.wso2.carbon.identity.authorization.common/pom.xml +++ b/components/authorization-framework/org.wso2.carbon.identity.authorization.common/pom.xml @@ -80,7 +80,6 @@ javax.xml.namespace, javax.xml.stream, - org.eclipse.equinox.http.helper, javax.servlet.*; version="${imp.pkg.version.javax.servlet}", org.apache.axiom.*; version="${axiom.osgi.version.range}", diff --git a/components/authorization-framework/org.wso2.carbon.identity.authorization.framework/pom.xml b/components/authorization-framework/org.wso2.carbon.identity.authorization.framework/pom.xml index 1e989852dce7..cfa2e1636775 100644 --- a/components/authorization-framework/org.wso2.carbon.identity.authorization.framework/pom.xml +++ b/components/authorization-framework/org.wso2.carbon.identity.authorization.framework/pom.xml @@ -62,7 +62,7 @@ pax-logging-api - org.wso2.eclipse.osgi + org.eclipse.platform org.eclipse.osgi.services @@ -155,7 +155,6 @@ javax.xml.namespace, javax.xml.stream, - org.eclipse.equinox.http.helper, javax.servlet.*; version="${imp.pkg.version.javax.servlet}", org.apache.axiom.*; version="${axiom.osgi.version.range}", diff --git a/components/certificate-mgt/org.wso2.carbon.identity.certificate.management/src/main/java/org/wso2/carbon/identity/certificate/management/service/impl/ApplicationCertificateManagementServiceImpl.java b/components/certificate-mgt/org.wso2.carbon.identity.certificate.management/src/main/java/org/wso2/carbon/identity/certificate/management/service/impl/ApplicationCertificateManagementServiceImpl.java index 66c395efc546..7561d6119ae1 100644 --- a/components/certificate-mgt/org.wso2.carbon.identity.certificate.management/src/main/java/org/wso2/carbon/identity/certificate/management/service/impl/ApplicationCertificateManagementServiceImpl.java +++ b/components/certificate-mgt/org.wso2.carbon.identity.certificate.management/src/main/java/org/wso2/carbon/identity/certificate/management/service/impl/ApplicationCertificateManagementServiceImpl.java @@ -20,6 +20,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.osgi.annotation.bundle.Capability; import org.wso2.carbon.identity.certificate.management.constant.CertificateMgtErrors; import org.wso2.carbon.identity.certificate.management.dao.impl.ApplicationCertificateManagementDAOImpl; import org.wso2.carbon.identity.certificate.management.dao.impl.CacheBackedApplicationCertificateMgtDAO; @@ -40,6 +41,14 @@ * @deprecated It is recommended to use {@link CertificateManagementServiceImpl}, which supports operations with UUID. */ @Deprecated +@Capability( + namespace = "osgi.service", + attribute = { + "objectClass=org.wso2.carbon.identity.certificate.management.service" + + ".ApplicationCertificateManagementService", + "service.scope=singleton" + } +) public class ApplicationCertificateManagementServiceImpl implements ApplicationCertificateManagementService { private static final Log LOG = LogFactory.getLog(ApplicationCertificateManagementServiceImpl.class); diff --git a/components/claim-mgt/org.wso2.carbon.identity.claim.metadata.mgt/src/main/java/org/wso2/carbon/identity/claim/metadata/mgt/ClaimMetadataManagementServiceImpl.java b/components/claim-mgt/org.wso2.carbon.identity.claim.metadata.mgt/src/main/java/org/wso2/carbon/identity/claim/metadata/mgt/ClaimMetadataManagementServiceImpl.java index ec177cf66cc6..02c8eb237039 100644 --- a/components/claim-mgt/org.wso2.carbon.identity.claim.metadata.mgt/src/main/java/org/wso2/carbon/identity/claim/metadata/mgt/ClaimMetadataManagementServiceImpl.java +++ b/components/claim-mgt/org.wso2.carbon.identity.claim.metadata.mgt/src/main/java/org/wso2/carbon/identity/claim/metadata/mgt/ClaimMetadataManagementServiceImpl.java @@ -24,6 +24,7 @@ import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.osgi.annotation.bundle.Capability; import org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataClientException; import org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException; import org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataServerException; @@ -102,6 +103,13 @@ * Default implementation of {@link org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService} * interface. */ +@Capability( + namespace = "osgi.service", + attribute = { + "objectClass=org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService", + "service.scope=singleton" + } +) public class ClaimMetadataManagementServiceImpl implements ClaimMetadataManagementService { private static final Log log = LogFactory.getLog(ClaimMetadataManagementServiceImpl.class); diff --git a/components/client-attestation-mgt/org.wso2.carbon.identity.client.attestation.mgt/pom.xml b/components/client-attestation-mgt/org.wso2.carbon.identity.client.attestation.mgt/pom.xml index 775f2b8bb4aa..b3252eb9d7ba 100644 --- a/components/client-attestation-mgt/org.wso2.carbon.identity.client.attestation.mgt/pom.xml +++ b/components/client-attestation-mgt/org.wso2.carbon.identity.client.attestation.mgt/pom.xml @@ -36,7 +36,7 @@ - org.wso2.eclipse.osgi + org.eclipse.platform org.eclipse.osgi.services diff --git a/components/configuration-mgt/org.wso2.carbon.identity.configuration.mgt.core/pom.xml b/components/configuration-mgt/org.wso2.carbon.identity.configuration.mgt.core/pom.xml index 01b9878d1f2e..4ed0bcc3a90c 100644 --- a/components/configuration-mgt/org.wso2.carbon.identity.configuration.mgt.core/pom.xml +++ b/components/configuration-mgt/org.wso2.carbon.identity.configuration.mgt.core/pom.xml @@ -42,7 +42,7 @@ commons-lang - org.wso2.eclipse.osgi + org.eclipse.platform org.eclipse.osgi.services @@ -54,7 +54,7 @@ org.apache.felix.scr.ds-annotations - org.eclipse.osgi + org.eclipse.platform org.eclipse.osgi diff --git a/components/configuration-mgt/org.wso2.carbon.identity.configuration.mgt.core/src/main/java/org/wso2/carbon/identity/configuration/mgt/core/ConfigurationManagerImpl.java b/components/configuration-mgt/org.wso2.carbon.identity.configuration.mgt.core/src/main/java/org/wso2/carbon/identity/configuration/mgt/core/ConfigurationManagerImpl.java index 0fbe3d76db64..ace2aa4fa1a1 100644 --- a/components/configuration-mgt/org.wso2.carbon.identity.configuration.mgt.core/src/main/java/org/wso2/carbon/identity/configuration/mgt/core/ConfigurationManagerImpl.java +++ b/components/configuration-mgt/org.wso2.carbon.identity.configuration.mgt.core/src/main/java/org/wso2/carbon/identity/configuration/mgt/core/ConfigurationManagerImpl.java @@ -20,6 +20,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.osgi.annotation.bundle.Capability; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.base.IdentityRuntimeException; import org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants; @@ -107,6 +108,13 @@ /** * Resource Manager service implementation. */ +@Capability( + namespace = "osgi.service", + attribute = { + "objectClass=org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager", + "service.scope=singleton" + } +) public class ConfigurationManagerImpl implements ConfigurationManager { private static final Log log = LogFactory.getLog(ConfigurationManagerImpl.class); diff --git a/components/configuration-mgt/org.wso2.carbon.identity.configuration.mgt.endpoint/pom.xml b/components/configuration-mgt/org.wso2.carbon.identity.configuration.mgt.endpoint/pom.xml index a2e5d918a42a..9831da472f8c 100644 --- a/components/configuration-mgt/org.wso2.carbon.identity.configuration.mgt.endpoint/pom.xml +++ b/components/configuration-mgt/org.wso2.carbon.identity.configuration.mgt.endpoint/pom.xml @@ -162,8 +162,9 @@ + org.apache.maven.plugins maven-war-plugin - 2.2 + 3.5.0 diff --git a/components/consent-mgt/org.wso2.carbon.identity.consent.mgt/pom.xml b/components/consent-mgt/org.wso2.carbon.identity.consent.mgt/pom.xml index 7dd994d132eb..2e8e56073c88 100644 --- a/components/consent-mgt/org.wso2.carbon.identity.consent.mgt/pom.xml +++ b/components/consent-mgt/org.wso2.carbon.identity.consent.mgt/pom.xml @@ -70,7 +70,7 @@ org.wso2.carbon.tenant.common - org.wso2.eclipse.osgi + org.eclipse.platform org.eclipse.osgi.services diff --git a/components/consent-server-configs-mgt/org.wso2.carbon.identity.consent.server.configs.mgt/pom.xml b/components/consent-server-configs-mgt/org.wso2.carbon.identity.consent.server.configs.mgt/pom.xml index 681e89f4fd81..426ba123ffc6 100644 --- a/components/consent-server-configs-mgt/org.wso2.carbon.identity.consent.server.configs.mgt/pom.xml +++ b/components/consent-server-configs-mgt/org.wso2.carbon.identity.consent.server.configs.mgt/pom.xml @@ -33,7 +33,7 @@ http://wso2.org - org.wso2.eclipse.osgi + org.eclipse.platform org.eclipse.osgi.services diff --git a/components/cors-mgt/org.wso2.carbon.identity.cors.mgt.core/pom.xml b/components/cors-mgt/org.wso2.carbon.identity.cors.mgt.core/pom.xml index 2b8fe4385421..7d70e88f9d5b 100644 --- a/components/cors-mgt/org.wso2.carbon.identity.cors.mgt.core/pom.xml +++ b/components/cors-mgt/org.wso2.carbon.identity.cors.mgt.core/pom.xml @@ -56,7 +56,7 @@ org.wso2.carbon.identity.organization.resource.hierarchy.traverse.service - org.wso2.eclipse.osgi + org.eclipse.platform org.eclipse.osgi.services diff --git a/components/entitlement/org.wso2.carbon.identity.entitlement.endpoint/pom.xml b/components/entitlement/org.wso2.carbon.identity.entitlement.endpoint/pom.xml index 631d34da6f96..933dc7945f08 100644 --- a/components/entitlement/org.wso2.carbon.identity.entitlement.endpoint/pom.xml +++ b/components/entitlement/org.wso2.carbon.identity.entitlement.endpoint/pom.xml @@ -134,8 +134,9 @@ maven-compiler-plugin + org.apache.maven.plugins maven-war-plugin - 2.2 + 3.5.0 api#identity#entitlement diff --git a/components/entitlement/org.wso2.carbon.identity.entitlement.ui/pom.xml b/components/entitlement/org.wso2.carbon.identity.entitlement.ui/pom.xml index f987d471181e..e0743088627a 100644 --- a/components/entitlement/org.wso2.carbon.identity.entitlement.ui/pom.xml +++ b/components/entitlement/org.wso2.carbon.identity.entitlement.ui/pom.xml @@ -87,7 +87,7 @@ ${project.artifactId} ${project.artifactId} - javax.activation;version="0.0.0", + javax.activation;version="${javax.activation.import.pkg.version}", javax.xml.namespace, javax.xml.stream; version="${equinox.osgi.stax-api.imp.pkg.version.range}", javax.servlet.http; version="${imp.pkg.version.javax.servlet}", diff --git a/components/extension-mgt/org.wso2.carbon.identity.extension.mgt/pom.xml b/components/extension-mgt/org.wso2.carbon.identity.extension.mgt/pom.xml index a64290422511..6645142c60ef 100644 --- a/components/extension-mgt/org.wso2.carbon.identity.extension.mgt/pom.xml +++ b/components/extension-mgt/org.wso2.carbon.identity.extension.mgt/pom.xml @@ -40,7 +40,7 @@ commons-lang - org.wso2.eclipse.osgi + org.eclipse.platform org.eclipse.osgi.services @@ -52,7 +52,7 @@ org.apache.felix.scr.ds-annotations - org.eclipse.osgi + org.eclipse.platform org.eclipse.osgi diff --git a/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/pom.xml b/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/pom.xml index c3d45863d7ce..6a8036bc369b 100644 --- a/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/pom.xml +++ b/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/pom.xml @@ -160,7 +160,7 @@ provided - org.wso2.eclipse.osgi + org.eclipse.platform org.eclipse.osgi.services diff --git a/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/src/main/java/org/wso2/carbon/identity/functions/library/mgt/FunctionLibraryManagementServiceImpl.java b/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/src/main/java/org/wso2/carbon/identity/functions/library/mgt/FunctionLibraryManagementServiceImpl.java index 5c95348a48ec..2c215c902ddf 100644 --- a/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/src/main/java/org/wso2/carbon/identity/functions/library/mgt/FunctionLibraryManagementServiceImpl.java +++ b/components/functions-library-mgt/org.wso2.carbon.identity.functions.library.mgt/src/main/java/org/wso2/carbon/identity/functions/library/mgt/FunctionLibraryManagementServiceImpl.java @@ -21,6 +21,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.osgi.annotation.bundle.Capability; import org.wso2.carbon.identity.application.common.util.IdentityApplicationManagementUtil; import org.wso2.carbon.identity.functions.library.mgt.dao.FunctionLibraryDAO; import org.wso2.carbon.identity.functions.library.mgt.dao.impl.FunctionLibraryDAOImpl; @@ -36,6 +37,13 @@ /** * Function library management service implementation. */ +@Capability( + namespace = "osgi.service", + attribute = { + "objectClass=org.wso2.carbon.identity.functions.library.mgt.FunctionLibraryManagementService", + "service.scope=singleton" + } +) public class FunctionLibraryManagementServiceImpl implements FunctionLibraryManagementService { private static final Log log = LogFactory.getLog(FunctionLibraryManagementServiceImpl.class); diff --git a/components/identity-core/org.wso2.carbon.identity.core/pom.xml b/components/identity-core/org.wso2.carbon.identity.core/pom.xml index 6769613afc81..277084fb8e69 100644 --- a/components/identity-core/org.wso2.carbon.identity.core/pom.xml +++ b/components/identity-core/org.wso2.carbon.identity.core/pom.xml @@ -33,6 +33,14 @@ A custom wso2 products or solution http://www.wso2.com + + org.eclipse.platform + org.eclipse.osgi + + + org.eclipse.platform + org.eclipse.osgi.services + javax.ws.rs javax.ws.rs-api diff --git a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/SAMLSSOServiceProviderManager.java b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/SAMLSSOServiceProviderManager.java index e9cb28da7960..df09b72f2fe2 100644 --- a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/SAMLSSOServiceProviderManager.java +++ b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/SAMLSSOServiceProviderManager.java @@ -21,6 +21,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.osgi.annotation.bundle.Capability; import org.wso2.carbon.database.utils.jdbc.NamedJdbcTemplate; import org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException; import org.wso2.carbon.identity.base.IdentityException; @@ -45,6 +46,13 @@ * This class is used for managing SAML SSO providers. Adding, retrieving and removing service * providers are supported here. */ +@Capability( + namespace = "osgi.service", + attribute = { + "objectClass=org.wso2.carbon.identity.core.SAMLSSOServiceProviderManager", + "service.scope=singleton" + } +) public class SAMLSSOServiceProviderManager { SAMLServiceProviderPersistenceManagerFactory samlSSOPersistenceManagerFactory = diff --git a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/persistence/registry/RegistryResourceMgtServiceImpl.java b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/persistence/registry/RegistryResourceMgtServiceImpl.java index 8a0f2938ba8b..03ef6bd4bf4d 100644 --- a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/persistence/registry/RegistryResourceMgtServiceImpl.java +++ b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/persistence/registry/RegistryResourceMgtServiceImpl.java @@ -19,6 +19,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.osgi.annotation.bundle.Capability; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.base.IdentityRuntimeException; import org.wso2.carbon.identity.core.util.IdentityTenantUtil; @@ -32,6 +33,13 @@ /** * A Util OSGi service that exposes Registry resource management functionality based on locale. */ +@Capability( + namespace = "osgi.service", + attribute = { + "objectClass=org.wso2.carbon.identity.core.persistence.registry.RegistryResourceMgtService", + "service.scope=singleton" + } +) public class RegistryResourceMgtServiceImpl implements RegistryResourceMgtService { private static final Log log = LogFactory.getLog(RegistryResourceMgtServiceImpl.class); diff --git a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/util/IdentityCoreInitializedEventImpl.java b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/util/IdentityCoreInitializedEventImpl.java index 99d2148a761e..9016bc01cc5c 100644 --- a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/util/IdentityCoreInitializedEventImpl.java +++ b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/util/IdentityCoreInitializedEventImpl.java @@ -18,6 +18,8 @@ package org.wso2.carbon.identity.core.util; +import org.osgi.annotation.bundle.Capability; + /** * This empty service can be used to guarantee the order of activation ( No need to have empty service if * there is a valid service). @@ -25,6 +27,12 @@ * can refer to this empty service which will guarantee that, org.wso2.carbon.identity.core will activated * before that. */ - +@Capability( + namespace = "osgi.service", + attribute = { + "objectClass=org.wso2.carbon.identity.core.util.IdentityCoreInitializedEvent", + "service.scope=singleton" + } +) public class IdentityCoreInitializedEventImpl implements IdentityCoreInitializedEvent { } diff --git a/components/identity-event/org.wso2.carbon.identity.event/pom.xml b/components/identity-event/org.wso2.carbon.identity.event/pom.xml index 77f73b2cf995..02a60f5d9d1c 100644 --- a/components/identity-event/org.wso2.carbon.identity.event/pom.xml +++ b/components/identity-event/org.wso2.carbon.identity.event/pom.xml @@ -32,6 +32,14 @@ A custom wso2 products or solution + + org.eclipse.platform + org.eclipse.osgi + + + org.eclipse.platform + org.eclipse.osgi.services + org.wso2.carbon.identity.framework org.wso2.carbon.identity.testutil diff --git a/components/identity-event/org.wso2.carbon.identity.event/src/main/java/org/wso2/carbon/identity/event/services/IdentityEventServiceImpl.java b/components/identity-event/org.wso2.carbon.identity.event/src/main/java/org/wso2/carbon/identity/event/services/IdentityEventServiceImpl.java index 2095aea1c630..f2fc5c104be0 100644 --- a/components/identity-event/org.wso2.carbon.identity.event/src/main/java/org/wso2/carbon/identity/event/services/IdentityEventServiceImpl.java +++ b/components/identity-event/org.wso2.carbon.identity.event/src/main/java/org/wso2/carbon/identity/event/services/IdentityEventServiceImpl.java @@ -21,6 +21,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.osgi.annotation.bundle.Capability; import org.wso2.carbon.identity.event.EventDistributionTask; import org.wso2.carbon.identity.event.IdentityEventException; import org.wso2.carbon.identity.event.bean.IdentityEventMessageContext; @@ -30,6 +31,13 @@ import java.util.List; +@Capability( + namespace = "osgi.service", + attribute = { + "objectClass=org.wso2.carbon.identity.event.services.IdentityEventService", + "service.scope=singleton" + } +) public class IdentityEventServiceImpl implements IdentityEventService { private static final Log log = LogFactory.getLog(IdentityEventServiceImpl.class); diff --git a/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/IdentityProviderManager.java b/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/IdentityProviderManager.java index ce15176ce353..0afe3f8a00ff 100644 --- a/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/IdentityProviderManager.java +++ b/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/IdentityProviderManager.java @@ -24,6 +24,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.osgi.annotation.bundle.Capability; import org.wso2.carbon.identity.application.common.ApplicationAuthenticatorService; import org.wso2.carbon.identity.application.common.ProvisioningConnectorService; import org.wso2.carbon.identity.application.common.exception.AuthenticatorMgtException; @@ -93,6 +94,13 @@ import static org.wso2.carbon.user.core.UserCoreConstants.WORKFLOW_DOMAIN; import static org.wso2.carbon.user.mgt.UserMgtConstants.APPLICATION_DOMAIN; +@Capability( + namespace = "osgi.service", + attribute = { + "objectClass=org.wso2.carbon.idp.mgt.IdpManager", + "service.scope=singleton" + } +) public class IdentityProviderManager implements IdpManager { private static final Log log = LogFactory.getLog(IdentityProviderManager.class); diff --git a/components/input-validation-mgt/org.wso2.carbon.identity.input.validation.mgt/pom.xml b/components/input-validation-mgt/org.wso2.carbon.identity.input.validation.mgt/pom.xml index e081d51d7eca..028e7dfb2828 100644 --- a/components/input-validation-mgt/org.wso2.carbon.identity.input.validation.mgt/pom.xml +++ b/components/input-validation-mgt/org.wso2.carbon.identity.input.validation.mgt/pom.xml @@ -34,7 +34,7 @@ - org.wso2.eclipse.osgi + org.eclipse.platform org.eclipse.osgi.services diff --git a/components/multi-attribute-login/org.wso2.carbon.identity.unique.claim.mgt/pom.xml b/components/multi-attribute-login/org.wso2.carbon.identity.unique.claim.mgt/pom.xml index a323fdbb0984..f6bce1e2dcbc 100644 --- a/components/multi-attribute-login/org.wso2.carbon.identity.unique.claim.mgt/pom.xml +++ b/components/multi-attribute-login/org.wso2.carbon.identity.unique.claim.mgt/pom.xml @@ -36,7 +36,7 @@ org.wso2.carbon.user.core - org.wso2.eclipse.osgi + org.eclipse.platform org.eclipse.osgi.services diff --git a/components/role-mgt/org.wso2.carbon.identity.role.mgt.core/pom.xml b/components/role-mgt/org.wso2.carbon.identity.role.mgt.core/pom.xml index 9b5a6c3637d4..d430788ac30d 100644 --- a/components/role-mgt/org.wso2.carbon.identity.role.mgt.core/pom.xml +++ b/components/role-mgt/org.wso2.carbon.identity.role.mgt.core/pom.xml @@ -53,7 +53,7 @@ org.wso2.carbon.identity.central.log.mgt - org.wso2.eclipse.osgi + org.eclipse.platform org.eclipse.osgi.services diff --git a/components/role-mgt/org.wso2.carbon.identity.role.mgt.core/src/main/java/org/wso2/carbon/identity/role/mgt/core/internal/RoleManagementServiceImpl.java b/components/role-mgt/org.wso2.carbon.identity.role.mgt.core/src/main/java/org/wso2/carbon/identity/role/mgt/core/internal/RoleManagementServiceImpl.java index 2dae0b1f4e77..f72df45d545a 100644 --- a/components/role-mgt/org.wso2.carbon.identity.role.mgt.core/src/main/java/org/wso2/carbon/identity/role/mgt/core/internal/RoleManagementServiceImpl.java +++ b/components/role-mgt/org.wso2.carbon.identity.role.mgt.core/src/main/java/org/wso2/carbon/identity/role/mgt/core/internal/RoleManagementServiceImpl.java @@ -22,6 +22,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.osgi.annotation.bundle.Capability; import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.identity.central.log.mgt.utils.LoggerUtils; @@ -47,6 +48,13 @@ /** * Implementation of the {@link RoleManagementService} interface. */ +@Capability( + namespace = "osgi.service", + attribute = { + "objectClass=org.wso2.carbon.identity.role.mgt.core.RoleManagementService", + "service.scope=singleton" + } +) public class RoleManagementServiceImpl implements RoleManagementService { private static final Log LOG = LogFactory.getLog(RoleManagementServiceImpl.class); diff --git a/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/RoleManagementServiceImpl.java b/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/RoleManagementServiceImpl.java index f3fddb4e06e2..8af1796039ff 100644 --- a/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/RoleManagementServiceImpl.java +++ b/components/role-mgt/org.wso2.carbon.identity.role.v2.mgt.core/src/main/java/org/wso2/carbon/identity/role/v2/mgt/core/RoleManagementServiceImpl.java @@ -21,6 +21,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.osgi.annotation.bundle.Capability; import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.identity.base.IdentityException; @@ -66,6 +67,13 @@ /** * Implementation of the {@link RoleManagementService} interface. */ +@Capability( + namespace = "osgi.service", + attribute = { + "objectClass=org.wso2.carbon.identity.role.v2.mgt.core.RoleManagementService", + "service.scope=singleton" + } +) public class RoleManagementServiceImpl implements RoleManagementService { private static final Log log = LogFactory.getLog(RoleManagementServiceImpl.class); diff --git a/components/rule-mgt/org.wso2.carbon.identity.rule.evaluation/src/main/java/org/wso2/carbon/identity/rule/evaluation/internal/service/impl/RuleEvaluationServiceImpl.java b/components/rule-mgt/org.wso2.carbon.identity.rule.evaluation/src/main/java/org/wso2/carbon/identity/rule/evaluation/internal/service/impl/RuleEvaluationServiceImpl.java index 127723e8de73..854f1bc36c60 100644 --- a/components/rule-mgt/org.wso2.carbon.identity.rule.evaluation/src/main/java/org/wso2/carbon/identity/rule/evaluation/internal/service/impl/RuleEvaluationServiceImpl.java +++ b/components/rule-mgt/org.wso2.carbon.identity.rule.evaluation/src/main/java/org/wso2/carbon/identity/rule/evaluation/internal/service/impl/RuleEvaluationServiceImpl.java @@ -20,6 +20,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.osgi.annotation.bundle.Capability; import org.wso2.carbon.identity.rule.evaluation.api.exception.RuleEvaluationException; import org.wso2.carbon.identity.rule.evaluation.api.model.Field; import org.wso2.carbon.identity.rule.evaluation.api.model.FieldValue; @@ -42,6 +43,13 @@ /** * Implementation of RuleEvaluationService. */ +@Capability( + namespace = "osgi.service", + attribute = { + "objectClass=org.wso2.carbon.identity.rule.evaluation.api.service.RuleEvaluationService", + "service.scope=singleton" + } +) public class RuleEvaluationServiceImpl implements RuleEvaluationService { private static final Log LOG = LogFactory.getLog(RuleEvaluationServiceImpl.class); diff --git a/components/rule-mgt/org.wso2.carbon.identity.rule.management/pom.xml b/components/rule-mgt/org.wso2.carbon.identity.rule.management/pom.xml index fbcf9fda60fe..658637f4334e 100644 --- a/components/rule-mgt/org.wso2.carbon.identity.rule.management/pom.xml +++ b/components/rule-mgt/org.wso2.carbon.identity.rule.management/pom.xml @@ -33,6 +33,14 @@ http://wso2.org + + org.eclipse.platform + org.eclipse.osgi + + + org.eclipse.platform + org.eclipse.osgi.services + org.wso2.carbon.identity.framework org.wso2.carbon.identity.core diff --git a/components/rule-mgt/org.wso2.carbon.identity.rule.management/src/main/java/org/wso2/carbon/identity/rule/management/internal/service/impl/RuleManagementServiceImpl.java b/components/rule-mgt/org.wso2.carbon.identity.rule.management/src/main/java/org/wso2/carbon/identity/rule/management/internal/service/impl/RuleManagementServiceImpl.java index 3bd100574e63..b4e7a2fb8ce8 100644 --- a/components/rule-mgt/org.wso2.carbon.identity.rule.management/src/main/java/org/wso2/carbon/identity/rule/management/internal/service/impl/RuleManagementServiceImpl.java +++ b/components/rule-mgt/org.wso2.carbon.identity.rule.management/src/main/java/org/wso2/carbon/identity/rule/management/internal/service/impl/RuleManagementServiceImpl.java @@ -18,6 +18,7 @@ package org.wso2.carbon.identity.rule.management.internal.service.impl; +import org.osgi.annotation.bundle.Capability; import org.wso2.carbon.identity.core.util.IdentityTenantUtil; import org.wso2.carbon.identity.rule.management.api.exception.RuleManagementClientException; import org.wso2.carbon.identity.rule.management.api.exception.RuleManagementException; @@ -30,6 +31,13 @@ /** * Implementation of Rule Management Service. */ +@Capability( + namespace = "osgi.service", + attribute = { + "objectClass=org.wso2.carbon.identity.rule.management.api.service.RuleManagementService", + "service.scope=singleton" + } +) public class RuleManagementServiceImpl implements RuleManagementService { private static final RuleManagementServiceImpl ruleManagementService = new RuleManagementServiceImpl(); diff --git a/components/rule-mgt/org.wso2.carbon.identity.rule.metadata/pom.xml b/components/rule-mgt/org.wso2.carbon.identity.rule.metadata/pom.xml index 889d8128035b..57875f976308 100644 --- a/components/rule-mgt/org.wso2.carbon.identity.rule.metadata/pom.xml +++ b/components/rule-mgt/org.wso2.carbon.identity.rule.metadata/pom.xml @@ -34,6 +34,14 @@ http://wso2.org + + org.eclipse.platform + org.eclipse.osgi + + + org.eclipse.platform + org.eclipse.osgi.services + org.wso2.carbon.identity.framework org.wso2.carbon.identity.core diff --git a/components/rule-mgt/org.wso2.carbon.identity.rule.metadata/src/main/java/org/wso2/carbon/identity/rule/metadata/internal/service/impl/RuleMetadataServiceImpl.java b/components/rule-mgt/org.wso2.carbon.identity.rule.metadata/src/main/java/org/wso2/carbon/identity/rule/metadata/internal/service/impl/RuleMetadataServiceImpl.java index 615528c02497..4548318c095b 100644 --- a/components/rule-mgt/org.wso2.carbon.identity.rule.metadata/src/main/java/org/wso2/carbon/identity/rule/metadata/internal/service/impl/RuleMetadataServiceImpl.java +++ b/components/rule-mgt/org.wso2.carbon.identity.rule.metadata/src/main/java/org/wso2/carbon/identity/rule/metadata/internal/service/impl/RuleMetadataServiceImpl.java @@ -18,6 +18,7 @@ package org.wso2.carbon.identity.rule.metadata.internal.service.impl; +import org.osgi.annotation.bundle.Capability; import org.wso2.carbon.identity.rule.metadata.api.exception.RuleMetadataException; import org.wso2.carbon.identity.rule.metadata.api.model.FieldDefinition; import org.wso2.carbon.identity.rule.metadata.api.model.FlowType; @@ -30,6 +31,13 @@ * Rule metadata service implementation. * This class is responsible for providing the rule metadata for the given flow type. */ +@Capability( + namespace = "osgi.service", + attribute = { + "objectClass=org.wso2.carbon.identity.rule.metadata.api.service.RuleMetadataService", + "service.scope=singleton" + } +) public class RuleMetadataServiceImpl implements RuleMetadataService { private final RuleMetadataManager ruleMetadataManager; diff --git a/components/secret-mgt/org.wso2.carbon.identity.secret.mgt.core/pom.xml b/components/secret-mgt/org.wso2.carbon.identity.secret.mgt.core/pom.xml index 26efa581d84c..394c08ca17db 100644 --- a/components/secret-mgt/org.wso2.carbon.identity.secret.mgt.core/pom.xml +++ b/components/secret-mgt/org.wso2.carbon.identity.secret.mgt.core/pom.xml @@ -38,7 +38,7 @@ commons-lang - org.wso2.eclipse.osgi + org.eclipse.platform org.eclipse.osgi.services @@ -54,7 +54,7 @@ org.wso2.carbon.core - org.eclipse.osgi + org.eclipse.platform org.eclipse.osgi diff --git a/components/secret-mgt/org.wso2.carbon.identity.secret.mgt.core/src/main/java/org/wso2/carbon/identity/secret/mgt/core/SecretManagerImpl.java b/components/secret-mgt/org.wso2.carbon.identity.secret.mgt.core/src/main/java/org/wso2/carbon/identity/secret/mgt/core/SecretManagerImpl.java index 53d58eedbbbb..872d6e0ddf69 100644 --- a/components/secret-mgt/org.wso2.carbon.identity.secret.mgt.core/src/main/java/org/wso2/carbon/identity/secret/mgt/core/SecretManagerImpl.java +++ b/components/secret-mgt/org.wso2.carbon.identity.secret.mgt.core/src/main/java/org/wso2/carbon/identity/secret/mgt/core/SecretManagerImpl.java @@ -24,6 +24,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.osgi.annotation.bundle.Capability; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.core.util.CryptoException; import org.wso2.carbon.core.util.CryptoUtil; @@ -60,6 +61,13 @@ /** * Secret Manager service implementation. */ +@Capability( + namespace = "osgi.service", + attribute = { + "objectClass=org.wso2.carbon.identity.secret.mgt.core.SecretManager", + "service.scope=singleton" + } +) public class SecretManagerImpl implements SecretManager { private static final Log log = LogFactory.getLog(SecretManagerImpl.class); diff --git a/components/secret-mgt/org.wso2.carbon.identity.secret.mgt.core/src/main/java/org/wso2/carbon/identity/secret/mgt/core/SecretResolveManagerImpl.java b/components/secret-mgt/org.wso2.carbon.identity.secret.mgt.core/src/main/java/org/wso2/carbon/identity/secret/mgt/core/SecretResolveManagerImpl.java index c9c10e09992e..6acd38818107 100644 --- a/components/secret-mgt/org.wso2.carbon.identity.secret.mgt.core/src/main/java/org/wso2/carbon/identity/secret/mgt/core/SecretResolveManagerImpl.java +++ b/components/secret-mgt/org.wso2.carbon.identity.secret.mgt.core/src/main/java/org/wso2/carbon/identity/secret/mgt/core/SecretResolveManagerImpl.java @@ -19,6 +19,7 @@ package org.wso2.carbon.identity.secret.mgt.core; import org.apache.commons.codec.Charsets; +import org.osgi.annotation.bundle.Capability; import org.wso2.carbon.core.util.CryptoException; import org.wso2.carbon.core.util.CryptoUtil; import org.wso2.carbon.identity.secret.mgt.core.exception.SecretManagementException; @@ -29,6 +30,13 @@ import static org.wso2.carbon.identity.secret.mgt.core.constant.SecretConstants.ErrorMessages.ERROR_CODE_GET_SECRET; import static org.wso2.carbon.identity.secret.mgt.core.util.SecretUtils.handleServerException; +@Capability( + namespace = "osgi.service", + attribute = { + "objectClass=org.wso2.carbon.identity.secret.mgt.core.SecretResolveManager", + "service.scope=singleton" + } +) public class SecretResolveManagerImpl implements SecretResolveManager { private final SecretManager secretManager; diff --git a/components/security-mgt/org.wso2.carbon.security.mgt.ui/pom.xml b/components/security-mgt/org.wso2.carbon.security.mgt.ui/pom.xml index 052eae2a516f..2c1d503a8264 100644 --- a/components/security-mgt/org.wso2.carbon.security.mgt.ui/pom.xml +++ b/components/security-mgt/org.wso2.carbon.security.mgt.ui/pom.xml @@ -82,7 +82,7 @@ ${project.artifactId} ${project.artifactId} - javax.activation; version="[0.0.0,0.1.0)", + javax.activation; version="${javax.activation.import.pkg.version}", org.apache.axis2.*; version="${axis2.osgi.version.range}", org.apache.axiom.om.util; version="${axiom.osgi.version.range}", org.apache.commons.fileupload.*; version="${commons-fileupload.imp.pkg.version.range}", diff --git a/components/system-config-mgt/org.wso2.carbon.identity.system.config.mgt/pom.xml b/components/system-config-mgt/org.wso2.carbon.identity.system.config.mgt/pom.xml index 0502b78b6be8..199cc3ee80c9 100644 --- a/components/system-config-mgt/org.wso2.carbon.identity.system.config.mgt/pom.xml +++ b/components/system-config-mgt/org.wso2.carbon.identity.system.config.mgt/pom.xml @@ -42,7 +42,7 @@ org.wso2.carbon.identity.configuration.mgt.core - org.wso2.eclipse.osgi + org.eclipse.platform org.eclipse.osgi.services diff --git a/components/template-mgt/org.wso2.carbon.identity.template.mgt.ui/pom.xml b/components/template-mgt/org.wso2.carbon.identity.template.mgt.ui/pom.xml index 1a762d2536ad..f4b0de375e66 100644 --- a/components/template-mgt/org.wso2.carbon.identity.template.mgt.ui/pom.xml +++ b/components/template-mgt/org.wso2.carbon.identity.template.mgt.ui/pom.xml @@ -84,7 +84,7 @@ - org.wso2.eclipse.osgi + org.eclipse.platform org.eclipse.osgi.services diff --git a/components/template-mgt/org.wso2.carbon.identity.template.mgt/pom.xml b/components/template-mgt/org.wso2.carbon.identity.template.mgt/pom.xml index b3363b9a6857..3760f1ff9dac 100644 --- a/components/template-mgt/org.wso2.carbon.identity.template.mgt/pom.xml +++ b/components/template-mgt/org.wso2.carbon.identity.template.mgt/pom.xml @@ -140,7 +140,7 @@ - org.wso2.eclipse.osgi + org.eclipse.platform org.eclipse.osgi.services diff --git a/components/trusted-app-mgt/org.wso2.carbon.identity.trusted.app.mgt/pom.xml b/components/trusted-app-mgt/org.wso2.carbon.identity.trusted.app.mgt/pom.xml index f1fd065de6b0..15cbe6337a12 100644 --- a/components/trusted-app-mgt/org.wso2.carbon.identity.trusted.app.mgt/pom.xml +++ b/components/trusted-app-mgt/org.wso2.carbon.identity.trusted.app.mgt/pom.xml @@ -35,7 +35,7 @@ - org.wso2.eclipse.osgi + org.eclipse.platform org.eclipse.osgi.services provided @@ -75,7 +75,6 @@ org.wso2.carbon.identity.trusted.app.mgt.internal, - org.eclipse.equinox.http.helper, javax.servlet; version="${imp.pkg.version.javax.servlet}", javax.servlet.http; version="${imp.pkg.version.javax.servlet}", com.google.gson;version="${com.google.code.gson.osgi.version.range}", diff --git a/components/trusted-app-mgt/org.wso2.carbon.identity.trusted.app.mgt/src/main/java/org/wso2/carbon/identity/trusted/app/mgt/internal/TrustedAppMgtServiceComponent.java b/components/trusted-app-mgt/org.wso2.carbon.identity.trusted.app.mgt/src/main/java/org/wso2/carbon/identity/trusted/app/mgt/internal/TrustedAppMgtServiceComponent.java index bd6d2fc4a59c..558febc186fb 100644 --- a/components/trusted-app-mgt/org.wso2.carbon.identity.trusted.app.mgt/src/main/java/org/wso2/carbon/identity/trusted/app/mgt/internal/TrustedAppMgtServiceComponent.java +++ b/components/trusted-app-mgt/org.wso2.carbon.identity.trusted.app.mgt/src/main/java/org/wso2/carbon/identity/trusted/app/mgt/internal/TrustedAppMgtServiceComponent.java @@ -20,7 +20,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.eclipse.equinox.http.helper.ContextPathServletAdaptor; import org.osgi.framework.BundleContext; import org.osgi.service.component.ComponentContext; import org.osgi.service.component.annotations.Activate; @@ -33,13 +32,6 @@ import org.wso2.carbon.identity.application.mgt.ApplicationManagementService; import org.wso2.carbon.identity.trusted.app.mgt.services.TrustedAppMgtService; import org.wso2.carbon.identity.trusted.app.mgt.services.TrustedAppMgtServiceImpl; -import org.wso2.carbon.identity.trusted.app.mgt.servlet.AndroidTrustedAppDiscoveryServlet; -import org.wso2.carbon.identity.trusted.app.mgt.servlet.IosTrustedAppDiscoveryServlet; - -import javax.servlet.Servlet; - -import static org.wso2.carbon.identity.trusted.app.mgt.utils.Constants.CP_ANDROID_TRUSTED_APPS; -import static org.wso2.carbon.identity.trusted.app.mgt.utils.Constants.CP_IOS_TRUSTED_APPS; /** * Trusted App Management Service Component. @@ -64,26 +56,8 @@ protected void activate(ComponentContext context) { if (LOG.isDebugEnabled()) { LOG.debug("TrustedAppMgtServiceComponent is activated."); } - - HttpService httpService = TrustedAppMgtDataHolder.getInstance().getHttpService(); - - Servlet androidTrustedAppDiscoveryServlet = new ContextPathServletAdaptor(new - AndroidTrustedAppDiscoveryServlet(), CP_ANDROID_TRUSTED_APPS); - httpService.registerServlet(CP_ANDROID_TRUSTED_APPS, androidTrustedAppDiscoveryServlet, null, null); - if (LOG.isDebugEnabled()) { - LOG.debug("Registering Android Trusted App Discovery Servlet via the HttpService to " + - CP_ANDROID_TRUSTED_APPS); - } - - Servlet iosTrustedAppDiscoveryServlet = new ContextPathServletAdaptor(new - IosTrustedAppDiscoveryServlet(), CP_IOS_TRUSTED_APPS); - httpService.registerServlet(CP_IOS_TRUSTED_APPS, iosTrustedAppDiscoveryServlet, null, null); - if (LOG.isDebugEnabled()) { - LOG.debug("Registering iOS Trusted App Discovery Servlet via the HttpService to " + - CP_IOS_TRUSTED_APPS); - } } catch (Throwable e) { - LOG.error("Error while activating the ss", e); + LOG.error("Error while activating the TrustedAppMgtServiceComponent.", e); } } diff --git a/components/trusted-app-mgt/org.wso2.carbon.identity.trusted.app.mgt/src/main/java/org/wso2/carbon/identity/trusted/app/mgt/servlet/AndroidTrustedAppDiscoveryServlet.java b/components/trusted-app-mgt/org.wso2.carbon.identity.trusted.app.mgt/src/main/java/org/wso2/carbon/identity/trusted/app/mgt/servlet/AndroidTrustedAppDiscoveryServlet.java index 57df61747147..a6c0d4e951c7 100644 --- a/components/trusted-app-mgt/org.wso2.carbon.identity.trusted.app.mgt/src/main/java/org/wso2/carbon/identity/trusted/app/mgt/servlet/AndroidTrustedAppDiscoveryServlet.java +++ b/components/trusted-app-mgt/org.wso2.carbon.identity.trusted.app.mgt/src/main/java/org/wso2/carbon/identity/trusted/app/mgt/servlet/AndroidTrustedAppDiscoveryServlet.java @@ -22,6 +22,7 @@ import com.google.gson.JsonObject; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.osgi.service.component.annotations.Component; import org.wso2.carbon.identity.trusted.app.mgt.exceptions.TrustedAppMgtException; import org.wso2.carbon.identity.trusted.app.mgt.internal.TrustedAppMgtDataHolder; import org.wso2.carbon.identity.trusted.app.mgt.model.TrustedAndroidApp; @@ -31,12 +32,14 @@ import java.util.List; import java.util.Set; +import javax.servlet.Servlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import static org.wso2.carbon.identity.trusted.app.mgt.utils.Constants.ANDROID_APP_NAMESPACE_VALUE; import static org.wso2.carbon.identity.trusted.app.mgt.utils.Constants.CERT_FINGERPRINT_ATTRIBUTE; +import static org.wso2.carbon.identity.trusted.app.mgt.utils.Constants.CP_ANDROID_TRUSTED_APPS; import static org.wso2.carbon.identity.trusted.app.mgt.utils.Constants.CT_APPLICATION_JSON; import static org.wso2.carbon.identity.trusted.app.mgt.utils.Constants.HTTP_RESP_HEADER_CACHE_CONTROL; import static org.wso2.carbon.identity.trusted.app.mgt.utils.Constants.HTTP_RESP_HEADER_PRAGMA; @@ -50,6 +53,16 @@ /** * Servlet to discover android based trusted apps. */ +//TODO Check if this servlet is working. +@Component( + service = Servlet.class, + immediate = true, + property = { + "osgi.http.whiteboard.servlet.pattern=" + CP_ANDROID_TRUSTED_APPS, + "osgi.http.whiteboard.servlet.name=AndroidTrustedAppDiscoveryServlet", + "osgi.http.whiteboard.servlet.asyncSupported=true" + } +) public class AndroidTrustedAppDiscoveryServlet extends HttpServlet { private static final Log LOG = LogFactory.getLog(AndroidTrustedAppDiscoveryServlet.class); @@ -86,7 +99,7 @@ private String generateJsonResponse(List trustedApps) { relation.add(permission.trim()); } - //Populate target attribute. + // Populate target attribute. JsonObject target = new JsonObject(); target.addProperty(NAMESPACE_ATTRIBUTE, ANDROID_APP_NAMESPACE_VALUE); target.addProperty(PACKAGE_NAME_ATTRIBUTE, app.getPackageName()); diff --git a/components/trusted-app-mgt/org.wso2.carbon.identity.trusted.app.mgt/src/main/java/org/wso2/carbon/identity/trusted/app/mgt/servlet/IosTrustedAppDiscoveryServlet.java b/components/trusted-app-mgt/org.wso2.carbon.identity.trusted.app.mgt/src/main/java/org/wso2/carbon/identity/trusted/app/mgt/servlet/IosTrustedAppDiscoveryServlet.java index ae4832a89b9f..b7cd8c7db118 100644 --- a/components/trusted-app-mgt/org.wso2.carbon.identity.trusted.app.mgt/src/main/java/org/wso2/carbon/identity/trusted/app/mgt/servlet/IosTrustedAppDiscoveryServlet.java +++ b/components/trusted-app-mgt/org.wso2.carbon.identity.trusted.app.mgt/src/main/java/org/wso2/carbon/identity/trusted/app/mgt/servlet/IosTrustedAppDiscoveryServlet.java @@ -22,6 +22,7 @@ import com.google.gson.JsonObject; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.osgi.service.component.annotations.Component; import org.wso2.carbon.identity.trusted.app.mgt.exceptions.TrustedAppMgtException; import org.wso2.carbon.identity.trusted.app.mgt.internal.TrustedAppMgtDataHolder; import org.wso2.carbon.identity.trusted.app.mgt.model.TrustedIosApp; @@ -31,11 +32,13 @@ import java.util.List; import java.util.Set; +import javax.servlet.Servlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import static org.wso2.carbon.identity.trusted.app.mgt.utils.Constants.APPS_ATTRIBUTE; +import static org.wso2.carbon.identity.trusted.app.mgt.utils.Constants.CP_IOS_TRUSTED_APPS; import static org.wso2.carbon.identity.trusted.app.mgt.utils.Constants.CT_APPLICATION_JSON; import static org.wso2.carbon.identity.trusted.app.mgt.utils.Constants.HTTP_RESP_HEADER_CACHE_CONTROL; import static org.wso2.carbon.identity.trusted.app.mgt.utils.Constants.HTTP_RESP_HEADER_PRAGMA; @@ -46,6 +49,16 @@ /** * Servlet to discover iOS based trusted apps. */ +//TODO Check if this servlet is working. +@Component( + service = Servlet.class, + immediate = true, + property = { + "osgi.http.whiteboard.servlet.pattern=" + CP_IOS_TRUSTED_APPS, + "osgi.http.whiteboard.servlet.name=IosTrustedAppDiscoveryServlet", + "osgi.http.whiteboard.servlet.asyncSupported=true" + } +) public class IosTrustedAppDiscoveryServlet extends HttpServlet { private static final Log LOG = LogFactory.getLog(IosTrustedAppDiscoveryServlet.class); @@ -71,7 +84,7 @@ protected void doGet(HttpServletRequest httpServletRequest, } } - private String generateJsonResponse(List trustedApps) { + private String generateJsonResponse(List trustedApps) { JsonObject responseObject = new JsonObject(); JsonObject webCredentials = new JsonObject(); diff --git a/components/user-functionality-mgt/org.wso2.carbon.identity.user.functionality.mgt/pom.xml b/components/user-functionality-mgt/org.wso2.carbon.identity.user.functionality.mgt/pom.xml index 90163f656f85..7f85957a8a2b 100644 --- a/components/user-functionality-mgt/org.wso2.carbon.identity.user.functionality.mgt/pom.xml +++ b/components/user-functionality-mgt/org.wso2.carbon.identity.user.functionality.mgt/pom.xml @@ -159,7 +159,7 @@ - org.wso2.eclipse.osgi + org.eclipse.platform org.eclipse.osgi.services diff --git a/components/user-mgt/org.wso2.carbon.identity.user.profile/src/main/java/org/wso2/carbon/identity/user/profile/mgt/association/federation/FederatedAssociationManagerImpl.java b/components/user-mgt/org.wso2.carbon.identity.user.profile/src/main/java/org/wso2/carbon/identity/user/profile/mgt/association/federation/FederatedAssociationManagerImpl.java index 5f8800cb8ed0..572145651fd5 100644 --- a/components/user-mgt/org.wso2.carbon.identity.user.profile/src/main/java/org/wso2/carbon/identity/user/profile/mgt/association/federation/FederatedAssociationManagerImpl.java +++ b/components/user-mgt/org.wso2.carbon.identity.user.profile/src/main/java/org/wso2/carbon/identity/user/profile/mgt/association/federation/FederatedAssociationManagerImpl.java @@ -22,6 +22,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.osgi.annotation.bundle.Capability; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.identity.application.common.model.IdentityProvider; import org.wso2.carbon.identity.application.common.model.User; @@ -69,6 +70,14 @@ import static org.wso2.carbon.identity.user.profile.mgt.association.federation.constant.FederatedAssociationConstants.ErrorMessages.INVALID_USER_STORE_DOMAIN_PROVIDED; import static org.wso2.carbon.user.mgt.listeners.utils.ListenerUtils.getInitiatorId; +@Capability( + namespace = "osgi.service", + attribute = { + "objectClass=org.wso2.carbon.identity.user.profile.mgt.association.federation" + + ".FederatedAssociationManager", + "service.scope=singleton" + } +) public class FederatedAssociationManagerImpl implements FederatedAssociationManager { private static final Log log = LogFactory.getLog(FederatedAssociationManagerImpl.class); diff --git a/components/user-store/org.wso2.carbon.identity.user.store.configuration/src/main/java/org/wso2/carbon/identity/user/store/configuration/UserStoreConfigServiceImpl.java b/components/user-store/org.wso2.carbon.identity.user.store.configuration/src/main/java/org/wso2/carbon/identity/user/store/configuration/UserStoreConfigServiceImpl.java index 53d7c51fc8a2..1e4b1e8659f0 100644 --- a/components/user-store/org.wso2.carbon.identity.user.store.configuration/src/main/java/org/wso2/carbon/identity/user/store/configuration/UserStoreConfigServiceImpl.java +++ b/components/user-store/org.wso2.carbon.identity.user.store.configuration/src/main/java/org/wso2/carbon/identity/user/store/configuration/UserStoreConfigServiceImpl.java @@ -18,6 +18,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.osgi.annotation.bundle.Capability; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.core.multitenancy.utils.TenantAxisUtils; import org.wso2.carbon.identity.core.util.IdentityUtil; @@ -64,6 +65,13 @@ /** * Implementation class for UserStoreConfigService. */ +@Capability( + namespace = "osgi.service", + attribute = { + "objectClass=org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService", + "service.scope=singleton" + } +) public class UserStoreConfigServiceImpl implements UserStoreConfigService { private static final Log LOG = LogFactory.getLog(UserStoreConfigServiceImpl.class); diff --git a/components/user-store/org.wso2.carbon.identity.user.store.count/pom.xml b/components/user-store/org.wso2.carbon.identity.user.store.count/pom.xml index 9c09a9864ada..ad8b5602a2f8 100644 --- a/components/user-store/org.wso2.carbon.identity.user.store.count/pom.xml +++ b/components/user-store/org.wso2.carbon.identity.user.store.count/pom.xml @@ -74,7 +74,6 @@ javax.xml.namespace, javax.xml.stream, - org.eclipse.equinox.http.helper, javax.servlet.*; version="${imp.pkg.version.javax.servlet}", org.apache.axiom.*; version="${axiom.osgi.version.range}", diff --git a/pom.xml b/pom.xml index d11ee6e12175..843b51260020 100644 --- a/pom.xml +++ b/pom.xml @@ -153,7 +153,7 @@ - org.eclipse.osgi + org.eclipse.platform org.eclipse.osgi ${version.equinox.osgi} @@ -1269,7 +1269,7 @@ ${encoder-jsp.version} - org.wso2.eclipse.osgi + org.eclipse.platform org.eclipse.osgi.services ${equinox.osgi.services.version} @@ -2051,7 +2051,7 @@ [1.2.1, 2.0.0) [1.7.0, 2.0.0) [1.5.1, 2.0.0) - 3.5.100.v20160504-1419 + 3.12.0 1.2.8 @@ -2115,10 +2115,10 @@ 2.6.0 - [2.6.0, 3.0.0) + [3.1.0, 4.0.0) - 5.1.2 + 5.4.12-SNAPSHOT 10.4.2.0 1.1 1.4 @@ -2175,8 +2175,7 @@ [1.6.1,2.0.0) - 3.3.100.v20130513-1956 - 3.9.1.v20130814-1242 + 3.19.0 [1.0.1,2.0.0) 1.4.1 @@ -2280,7 +2279,7 @@ [5.0.0,6.0.0) 1.27.1.wso2v1 5.1.1.wso2v1 - [0.0.0, 1.0.0) + [1.0.0, 2.0.0) 0.14.0 1.2.0.wso2v1 [1.2.0, 2.0.0) @@ -2323,8 +2322,8 @@ 0.5.2 3.9.1 - 1.8 - 1.8 + 21 + 21 2.2.224 @@ -2385,7 +2384,7 @@ org.apache.felix maven-bundle-plugin - 3.2.0 + 5.1.9 true NONE
- * instead of - * var userName = context.getLastAuthenticatedUser().getUserName() - *
- * Also it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime - * AuthenticatedUser. - * - * @see AuthenticatedUser - */ -public class JsNashornAuthenticatedUser extends JsAuthenticatedUser implements AbstractJsObject { - - /** - * Constructor to be used when required to access step specific user details. - * - * @param context Authentication context - * @param wrappedUser Authenticated user - * @param step Authentication step - * @param idp Authenticated Idp - */ - public JsNashornAuthenticatedUser(AuthenticationContext context, AuthenticatedUser wrappedUser, - int step, String idp) { - - super(context, wrappedUser, step, idp); - } - - /** - * Constructor to be used when required to access step specific user details. - * - * @param wrappedUser Authenticated user - * @param step Authentication step - * @param idp Authenticated Idp - */ - public JsNashornAuthenticatedUser(AuthenticatedUser wrappedUser, int step, String idp) { - - super(wrappedUser, step, idp); - } - - /** - * Constructor to be used when required to access step independent user. - * - * @param wrappedUser Authenticated user - */ - public JsNashornAuthenticatedUser(AuthenticatedUser wrappedUser) { - - super(wrappedUser); - } - - public JsNashornAuthenticatedUser(AuthenticationContext context, AuthenticatedUser wrappedUser) { - - super(context, wrappedUser); - } -} 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/graph/js/nashorn/JsNashornAuthenticationContext.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornAuthenticationContext.java deleted file mode 100644 index 08018349c77f..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornAuthenticationContext.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js.nashorn; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext; -import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; - -/** - * Javascript wrapper for Java level AuthenticationContext. - * This wrapper uses jdk.nashorn engine. - * This provides controlled access to AuthenticationContext object via provided javascript native syntax. - * e.g - * var requestedAcr = context.requestedAcr - *
- * instead of - * var requestedAcr = context.getRequestedAcr() - *
- * Also it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime - * AuthenticationContext. - * - * @see AuthenticationContext - */ -public class JsNashornAuthenticationContext extends JsAuthenticationContext implements AbstractJsObject { - - public JsNashornAuthenticationContext(AuthenticationContext wrapped) { - - super(wrapped); - initializeContext(wrapped); - } - - public void setMember(String name, Object value) { - - super.setMemberObject(name, value); - } - - @Override - public void removeMember(String name) { - - if (!super.removeMemberObject(name)) { - AbstractJsObject.super.removeMember(name); - } - } -} 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/graph/js/nashorn/JsNashornClaims.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornClaims.java deleted file mode 100644 index 49a4c37d5b93..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornClaims.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js.nashorn; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsClaims; -import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; -import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser; - -/** - * Represent the user's claim. Can be either remote or local. - * This wrapper uses jdk.nashorn engine. - */ -public class JsNashornClaims extends JsClaims implements AbstractJsObject { - - /** - * Constructor to get the user authenticated in step 'n' - * - * @param step The authentication step - * @param idp The authenticated IdP - * @param isRemoteClaimRequest Whether the request is for remote claim (false for local claim request) - */ - public JsNashornClaims(AuthenticationContext context, int step, String idp, boolean isRemoteClaimRequest) { - - super(context, step, idp, isRemoteClaimRequest); - } - - public JsNashornClaims(int step, String idp, boolean isRemoteClaimRequest) { - - super(step, idp, isRemoteClaimRequest); - } - - /** - * Constructor to get user who is not directly from a authentication step. Eg. Associated user of authenticated - * federated user in a authentication step. - * - * @param authenticatedUser Authenticated user - * @param isRemoteClaimRequest Whether the request is for remote claim (false for local claim request) - */ - public JsNashornClaims(AuthenticatedUser authenticatedUser, boolean isRemoteClaimRequest) { - - super(authenticatedUser, isRemoteClaimRequest); - } - - public JsNashornClaims(AuthenticationContext context, AuthenticatedUser authenticatedUser, - boolean isRemoteClaimRequest) { - - super(context, authenticatedUser, isRemoteClaimRequest); - } - - @Override - public void setMember(String claimUri, Object claimValue) { - - boolean isClaimSet = setMemberObject(claimUri, claimValue); - if (isClaimSet) { - return; - } - AbstractJsObject.super.setMember(claimUri, claimValue); - } -} 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/graph/js/nashorn/JsNashornCookie.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornCookie.java deleted file mode 100644 index c0ae8132540d..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornCookie.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2022, 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.config.model.graph.js.nashorn; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsCookie; - -import javax.servlet.http.Cookie; - -/** - * Javascript wrapper for Java level Cookie. - * This wrapper uses jdk.nashorn engine. - * This provides controlled access to Cookie object via provided javascript native syntax. - * e.g - * var commonAuthIdDomain = context.request.cookies.commonAuthId.domain - * Also it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime Cookie. - */ -public class JsNashornCookie extends JsCookie implements AbstractJsObject { - - public JsNashornCookie(Cookie cookie) { - super(cookie); - } - -} 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/graph/js/nashorn/JsNashornParameters.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornParameters.java deleted file mode 100644 index 8b91a8afe48c..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornParameters.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js.nashorn; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsParameters; - -import java.util.Map; - -/** - * Javascript wrapper for Java level HashMap of HTTP headers/cookies. - * This wrapper uses jdk.nashorn engine. - * This provides controlled access to HTTPServletRequest object's headers and cookies via provided javascript native - * syntax. - * Also it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime. - */ -public class JsNashornParameters extends JsParameters implements AbstractJsObject { - - public JsNashornParameters(Map wrapped) { - - super(wrapped); - } -} 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/graph/js/nashorn/JsNashornRuntimeClaims.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornRuntimeClaims.java deleted file mode 100644 index eface7c11e51..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornRuntimeClaims.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2020, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js.nashorn; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.base.JsBaseRuntimeClaims; -import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; -import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser; - -/** - * Represent the user's runtime claims. - * This wrapper uses jdk.nashorn engine. - */ -public class JsNashornRuntimeClaims extends JsNashornClaims implements JsBaseRuntimeClaims, AbstractJsObject { - - public JsNashornRuntimeClaims(AuthenticationContext context, int step, String idp) { - - super(context, step, idp, false); - } - - public JsNashornRuntimeClaims(AuthenticationContext context, AuthenticatedUser user) { - - super(context, user, false); - } - - public Object getMember(String claimUri) { - - if (authenticatedUser != null) { - return getRuntimeClaim(claimUri); - } - return null; - } - - public boolean hasMember(String claimUri) { - - if (authenticatedUser != null) { - return hasRuntimeClaim(claimUri); - } - return false; - } - - public void setMember(String claimUri, Object claimValue) { - - if (authenticatedUser != null) { - setRuntimeClaim(claimUri, claimValue); - } - } -} 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/graph/js/nashorn/JsNashornServletRequest.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornServletRequest.java deleted file mode 100644 index 3a16e605be05..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornServletRequest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js.nashorn; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsServletRequest; -import org.wso2.carbon.identity.application.authentication.framework.context.TransientObjectWrapper; - -import javax.servlet.http.HttpServletRequest; - -/** - * Javascript wrapper for Java level HTTPServletRequest. - * This wrapper uses jdk.nashorn engine. - * This provides controlled access to HTTPServletRequest object via provided javascript native syntax. - * e.g - * var redirect_uri = context.request.params.redirect_uri - *
- * instead of - * var userName = context.getRequest().getParameter("redirect_uri) - *
- * Also it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime - * HTTPServletRequest. - */ -public class JsNashornServletRequest extends JsServletRequest implements AbstractJsObject { - - public JsNashornServletRequest(TransientObjectWrapper wrapped) { - - super(wrapped); - } -} - 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/graph/js/nashorn/JsNashornServletResponse.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornServletResponse.java deleted file mode 100644 index d25f8516e4b7..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornServletResponse.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js.nashorn; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsServletResponse; -import org.wso2.carbon.identity.application.authentication.framework.context.TransientObjectWrapper; - -import javax.servlet.http.HttpServletResponse; - -/** - * Javascript wrapper for Java level HttpServletResponse. - * This wrapper uses jdk.nashorn engine. - * This provides controlled access to HttpServletResponse object via provided javascript native syntax. - * e.g - * response.headers.["Set-Cookie"] = ['crsftoken=xxxxxssometokenxxxxx'] - * - * instead of - * context.getResponse().addCookie(cookie); - * - * Also, it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime - * HttpServletResponse. - */ -public class JsNashornServletResponse extends JsServletResponse implements AbstractJsObject { - - public JsNashornServletResponse(TransientObjectWrapper wrapped) { - - super(wrapped); - } - -} 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/graph/js/nashorn/JsNashornStep.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornStep.java deleted file mode 100644 index 6da745a6cdcd..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornStep.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js.nashorn; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsStep; -import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; - -/** - * Represents a authentication step. - * This wrapper uses jdk.nashorn engine. - */ -public class JsNashornStep extends JsStep implements AbstractJsObject { - - @Deprecated - public JsNashornStep(int step, String authenticatedIdp) { - - super(step, authenticatedIdp); - } - - public JsNashornStep(int step, String authenticatedIdp, String authenticatedAuthenticator) { - - super(step, authenticatedIdp, authenticatedAuthenticator); - } - - @Deprecated - public JsNashornStep(AuthenticationContext context, int step, String authenticatedIdp) { - - super(context, step, authenticatedIdp); - } - - public JsNashornStep(AuthenticationContext context, int step, String authenticatedIdp, - String authenticatedAuthenticator) { - - super(context, step, authenticatedIdp, authenticatedAuthenticator); - } - - @Override - public Object getMember(String name) { - - Object member = super.getMember(name); - return member != null ? member : AbstractJsObject.super.getMember(name); - } - - @Override - public boolean hasMember(String name) { - - return super.hasMember(name) || AbstractJsObject.super.hasMember(name); - } - - public void removeMember(String name) { - - super.removeMemberObject(name); - } -} 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/graph/js/nashorn/JsNashornSteps.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornSteps.java deleted file mode 100644 index aeea5c6c6341..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornSteps.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js.nashorn; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsSteps; -import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; - -import java.util.Objects; - -/** - * Returns when context.steps[step_number] is called - * This wrapper uses jdk.nashorn engine. - */ -public class JsNashornSteps extends JsSteps implements AbstractJsObject { - - public JsNashornSteps() { - - super(); - - } - - public JsNashornSteps(AuthenticationContext context) { - - super(context); - } - - @Override - public Object getSlot(int step) { - - Object jsStep = super.getSlot(step); - return Objects.nonNull(jsStep) ? jsStep : AbstractJsObject.super.getSlot(step); - } -} 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/graph/js/nashorn/JsNashornWritableParameters.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornWritableParameters.java deleted file mode 100644 index 70b6ccb596dc..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornWritableParameters.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js.nashorn; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsWrapperFactoryProvider; - -import java.util.Map; - -/** - * Parameters that can be modified from the authentication script. - * This wrapper uses jdk.nashorn engine. - */ -public class JsNashornWritableParameters extends JsNashornParameters implements AbstractJsObject { - - public JsNashornWritableParameters(Map wrapped) { - - super(wrapped); - } - - public Object getMember(String name) { - - Object member = getWrapped().get(name); - if (member instanceof Map) { - return JsWrapperFactoryProvider.getInstance().getWrapperFactory() - .createJsWritableParameters((Map) member); - } - return member; - } - - public void removeMember(String name) { - - super.removeMemberObject(name); - } - - public void setMember(String name, Object value) { - - getWrapped().put(name, value); - } -} diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/GraalSelectAcrFromFunction.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/GraalSelectAcrFromFunction.java index c00268bb0574..3da43f6b370f 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/GraalSelectAcrFromFunction.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/GraalSelectAcrFromFunction.java @@ -34,7 +34,7 @@ */ public class GraalSelectAcrFromFunction implements SelectOneFunction { - private static final Log log = LogFactory.getLog(SelectAcrFromFunction.class); + private static final Log log = LogFactory.getLog(GraalSelectAcrFromFunction.class); @HostAccess.Export public String evaluate(JsAuthenticationContext context, Object possibleOutcomesObj) { diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/SelectAcrFromFunction.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/SelectAcrFromFunction.java deleted file mode 100644 index 8d21b194bb7a..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/SelectAcrFromFunction.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2017, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.handler.sequence.impl; - -import jdk.nashorn.api.scripting.ScriptObjectMirror; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext; -import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants; - -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - -/** - * Select the preferred acr value from the available list. - */ -public class SelectAcrFromFunction implements SelectOneFunction { - - private static final Log log = LogFactory.getLog(SelectAcrFromFunction.class); - - public String evaluate(JsAuthenticationContext context, Object possibleOutcomesObj) { - - String[] possibleOutcomes = extractPossibleOutcomes(context, possibleOutcomesObj); - List acrListRequested = context.getWrapped().getRequestedAcr(); - if (acrListRequested == null || acrListRequested.isEmpty()) { - if (log.isDebugEnabled()) { - log.debug("ACR values from context is empty. Selecting the default outcome as null."); - } - return null; - } - if (possibleOutcomes.length > 0) { - return selectBestOutcome(acrListRequested, possibleOutcomes); - } - return null; - } - - private String[] extractPossibleOutcomes(JsAuthenticationContext context, Object possibleOutcomesObj) { - - String[] possibleOutcomes; - if (possibleOutcomesObj instanceof String[]) { - possibleOutcomes = (String[]) possibleOutcomesObj; - } else if (possibleOutcomesObj instanceof ScriptObjectMirror) { - if (((ScriptObjectMirror) possibleOutcomesObj).isArray()) { - possibleOutcomes = ((ScriptObjectMirror) possibleOutcomesObj).to(String[].class); - } else { - log.error("Invalid argument provided for possible outcomes for " + FrameworkConstants.JSAttributes - .JS_FUNC_SELECT_ACR_FROM + " function in service provider: " + context.getWrapped() - .getServiceProviderName() + ". Expected array of strings."); - possibleOutcomes = new String[0]; - } - } else { - log.error("Invalid argument provided for possible outcomes for " + FrameworkConstants.JSAttributes - .JS_FUNC_SELECT_ACR_FROM + " function in service provider: " + context.getWrapped() - .getServiceProviderName() + ". Expected array of strings."); - possibleOutcomes = new String[0]; - } - return possibleOutcomes; - } - - private String selectBestOutcome(List acrListRequested, String[] possibleOutcomes) { - - Map acrRequestedWithPriority = new TreeMap<>(Collections.reverseOrder( - (Comparator) (o1, o2) -> o2.compareTo(o1))); - String acrSelected = null; - - for (String acrChecked : acrListRequested) { - for (int x = 0; x < possibleOutcomes.length; x++) { - String outcomeToTest = possibleOutcomes[x]; - if (outcomeToTest.equals(acrChecked)) { - if (log.isDebugEnabled()) { - log.debug("Reassigning Best Match for the outcome : " + outcomeToTest + " with priority : " + - x + 1); - } - acrRequestedWithPriority.put(x + 1, acrChecked); - break; - } - } - } - if (!acrRequestedWithPriority.entrySet().isEmpty()) { - acrSelected = acrRequestedWithPriority.entrySet().iterator().next().getValue(); - } - return acrSelected; - } -} diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/inbound/IdentityServlet.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/inbound/IdentityServlet.java index d6168a3f90aa..703bcfd747ce 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/inbound/IdentityServlet.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/inbound/IdentityServlet.java @@ -21,6 +21,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.osgi.service.component.annotations.Component; import org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException; import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder; import org.wso2.carbon.identity.core.util.IdentityUtil; @@ -30,6 +31,7 @@ import java.util.List; import java.util.Map; +import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServlet; @@ -39,6 +41,16 @@ /** * Identity Servlet. */ +//TODO Check if this servlet is working. +@Component( + service = Servlet.class, + immediate = true, + property = { + "osgi.http.whiteboard.servlet.pattern=/identity", + "osgi.http.whiteboard.servlet.name=IdentityServlet", + "osgi.http.whiteboard.servlet.asyncSupported=true" + } +) public class IdentityServlet extends HttpServlet { private static final Log log = LogFactory.getLog(IdentityServlet.class); 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 94519bfbd397..45e4a3aae163 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 @@ -23,7 +23,6 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.eclipse.equinox.http.helper.ContextPathServletAdaptor; import org.osgi.framework.BundleContext; import org.osgi.service.component.ComponentContext; import org.osgi.service.component.annotations.Activate; @@ -32,7 +31,6 @@ import org.osgi.service.component.annotations.Reference; import org.osgi.service.component.annotations.ReferenceCardinality; import org.osgi.service.component.annotations.ReferencePolicy; -import org.osgi.service.http.HttpService; import org.wso2.carbon.consent.mgt.core.ConsentManager; import org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticationService; import org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticator; @@ -76,7 +74,6 @@ import org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityRequestFactory; 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; @@ -84,9 +81,6 @@ import org.wso2.carbon.identity.application.authentication.framework.listener.AuthenticationEndpointTenantActivityListener; import org.wso2.carbon.identity.application.authentication.framework.listener.SessionContextMgtListener; import org.wso2.carbon.identity.application.authentication.framework.services.PostAuthenticationMgtService; -import org.wso2.carbon.identity.application.authentication.framework.servlet.CommonAuthenticationServlet; -import org.wso2.carbon.identity.application.authentication.framework.servlet.LoginContextServlet; -import org.wso2.carbon.identity.application.authentication.framework.servlet.LongWaitStatusServlet; import org.wso2.carbon.identity.application.authentication.framework.session.extender.processor.SessionExtenderProcessor; import org.wso2.carbon.identity.application.authentication.framework.session.extender.request.SessionExtenderRequestFactory; import org.wso2.carbon.identity.application.authentication.framework.session.extender.response.SessionExtenderResponseFactory; @@ -131,10 +125,7 @@ import java.util.List; import java.util.Locale; -import javax.servlet.Servlet; - import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.CUSTOM_AUTHENTICATOR_PREFIX; -import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils.promptOnLongWait; import static org.wso2.carbon.identity.base.IdentityConstants.TRUE; /** @@ -147,15 +138,10 @@ ) public class FrameworkServiceComponent { - public static final String COMMON_SERVLET_URL = "/commonauth"; public static final String IS_HANDLER = "IS_HANDLER"; - private static final String IDENTITY_SERVLET_URL = "/identity"; - private static final String LOGIN_CONTEXT_SERVLET_URL = "/logincontext"; - private static final String LONGWAITSTATUS_SERVLET_URL = "/longwaitstatus"; private static final Log log = LogFactory.getLog(FrameworkServiceComponent.class); private static final String API_AUTH = "APIAuth"; - private HttpService httpService; private ConsentMgtPostAuthnHandler consentMgtPostAuthnHandler = new ConsentMgtPostAuthnHandler(); private String requireCode; private String secretsCode; @@ -243,37 +229,6 @@ protected void activate(ComponentContext ctxt) { .registerService(AuthenticationMethodNameTranslator.class, authenticationMethodNameTranslator, null); dataHolder.setAuthenticationMethodNameTranslator(authenticationMethodNameTranslator); - // Register Common servlet - Servlet commonAuthServlet = new ContextPathServletAdaptor(new CommonAuthenticationServlet(), - COMMON_SERVLET_URL); - - Servlet identityServlet = new ContextPathServletAdaptor(new IdentityServlet(), - IDENTITY_SERVLET_URL); - - Servlet loginContextServlet = new ContextPathServletAdaptor(new LoginContextServlet(), - LOGIN_CONTEXT_SERVLET_URL); - try { - httpService.registerServlet(COMMON_SERVLET_URL, commonAuthServlet, null, null); - httpService.registerServlet(IDENTITY_SERVLET_URL, identityServlet, null, null); - httpService.registerServlet(LOGIN_CONTEXT_SERVLET_URL, loginContextServlet, null, null); - } catch (Exception e) { - String errMsg = "Error when registering servlets via the HttpService."; - log.error(errMsg, e); - throw new RuntimeException(errMsg, e); - } - - if (promptOnLongWait()) { - Servlet longWaitStatusServlet = new ContextPathServletAdaptor(new LongWaitStatusServlet(), - LONGWAITSTATUS_SERVLET_URL); - try { - httpService.registerServlet(LONGWAITSTATUS_SERVLET_URL, longWaitStatusServlet, null, null); - } catch (Exception e) { - String errMsg = "Error when registering longwaitstatus servlet via the HttpService."; - log.error(errMsg, e); - throw new RuntimeException(errMsg, e); - } - } - dataHolder.setBundleContext(bundleContext); dataHolder.getHttpIdentityRequestFactories().add(new HttpIdentityRequestFactory()); dataHolder.getHttpIdentityResponseFactories().add(new FrameworkLoginResponseFactory()); @@ -456,31 +411,6 @@ protected void deactivate(ComponentContext ctxt) { } } - @Reference( - name = "osgi.httpservice", - service = HttpService.class, - cardinality = ReferenceCardinality.MANDATORY, - policy = ReferencePolicy.DYNAMIC, - unbind = "unsetHttpService" - ) - protected void setHttpService(HttpService httpService) { - - if (log.isDebugEnabled()) { - log.debug("HTTP Service is set in the Application Authentication Framework bundle"); - } - - this.httpService = httpService; - } - - protected void unsetHttpService(HttpService httpService) { - - if (log.isDebugEnabled()) { - log.debug("HTTP Service is unset in the Application Authentication Framework bundle"); - } - - this.httpService = null; - } - protected void unsetRealmService(RealmService realmService) { if (log.isDebugEnabled()) { diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/CommonAuthenticationServlet.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/CommonAuthenticationServlet.java index e8e892a2f0b0..710d67e2ddfc 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/CommonAuthenticationServlet.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/CommonAuthenticationServlet.java @@ -18,11 +18,13 @@ package org.wso2.carbon.identity.application.authentication.framework.servlet; +import org.osgi.service.component.annotations.Component; import org.wso2.carbon.identity.application.authentication.framework.CommonAuthenticationHandler; import org.wso2.carbon.identity.application.authentication.framework.config.ConfigurationFacade; import java.io.IOException; +import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -31,6 +33,16 @@ /** * Servlet to handle common authentication requests. */ +//TODO Check if this servlet is working. +@Component( + service = Servlet.class, + immediate = true, + property = { + "osgi.http.whiteboard.servlet.pattern=/commonauth", + "osgi.http.whiteboard.servlet.name=CommonAuthenticationServlet", + "osgi.http.whiteboard.servlet.asyncSupported=true" + } +) public class CommonAuthenticationServlet extends HttpServlet { private final CommonAuthenticationHandler commonAuthenticationHandler = new CommonAuthenticationHandler(); diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/LoginContextServlet.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/LoginContextServlet.java index 9d6f55f9666d..11bd2e2258a6 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/LoginContextServlet.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/LoginContextServlet.java @@ -18,10 +18,12 @@ package org.wso2.carbon.identity.application.authentication.framework.servlet; +import org.osgi.service.component.annotations.Component; import org.wso2.carbon.identity.application.authentication.framework.util.LoginContextManagementUtil; import java.io.IOException; +import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -32,6 +34,16 @@ * authenticationendpoint. In case of invalid sessionDataKey, initiates redirection forcing application to * start authentication flow with new sessionDataKey */ +//TODO Check if this servlet is working. +@Component( + service = Servlet.class, + immediate = true, + property = { + "osgi.http.whiteboard.servlet.pattern=/logincontext", + "osgi.http.whiteboard.servlet.name=LoginContextServlet", + "osgi.http.whiteboard.servlet.asyncSupported=true" + } +) public class LoginContextServlet extends HttpServlet { @Override diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/LongWaitStatusServlet.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/LongWaitStatusServlet.java index 0f2a78acf124..849a421d061c 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/LongWaitStatusServlet.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/LongWaitStatusServlet.java @@ -19,6 +19,7 @@ package org.wso2.carbon.identity.application.authentication.framework.servlet; import com.google.gson.Gson; +import org.osgi.service.component.annotations.Component; import org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException; import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder; import org.wso2.carbon.identity.application.authentication.framework.javascript.flow.LongWaitStatusRequest; @@ -31,6 +32,7 @@ import java.io.IOException; import java.io.PrintWriter; +import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -39,6 +41,16 @@ /** * Servlet to get the status of long wait process. */ +//TODO Check if this servlet is working. +@Component( + service = Servlet.class, + immediate = true, + property = { + "osgi.http.whiteboard.servlet.pattern=/longwaitstatus", + "osgi.http.whiteboard.servlet.name=LongWaitStatusServlet", + "osgi.http.whiteboard.servlet.asyncSupported=true" + } +) public class LongWaitStatusServlet extends HttpServlet { private static final long serialVersionUID = -3714283612680472526L; 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 01cad5bc0448..c0a5d4a63dc4 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 @@ -67,7 +67,6 @@ import org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsBaseGraphBuilderFactory; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGenericGraphBuilderFactory; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilderFactory; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.graaljs.JsGraalGraphBuilderFactory; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.openjdk.nashorn.JsOpenJdkNashornGraphBuilderFactory; import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; @@ -4550,8 +4549,6 @@ public static JsGenericGraphBuilderFactory createJsGenericGraphBuilderFactoryFro return new JsGraalGraphBuilderFactory(); } else if (StringUtils.equalsIgnoreCase(FrameworkConstants.OPENJDK_NASHORN, scriptEngineName)) { return new JsOpenJdkNashornGraphBuilderFactory(); - } else if (StringUtils.equalsIgnoreCase(FrameworkConstants.NASHORN, scriptEngineName)) { - return new JsGraphBuilderFactory(); } } // Config is not set. Hence going with class for name approach. @@ -4563,12 +4560,7 @@ public static JsGenericGraphBuilderFactory createJsGenericGraphBuilderFactoryFro Class.forName(OPENJDK_SCRIPTER_CLASS_NAME); return new JsOpenJdkNashornGraphBuilderFactory(); } catch (ClassNotFoundException classNotFoundException) { - try { - Class.forName(JDK_SCRIPTER_CLASS_NAME); - return new JsGraphBuilderFactory(); - } catch (ClassNotFoundException ex) { - return null; - } + return null; } } } diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/JsNashornGraphBuilderTest.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/JsNashornGraphBuilderTest.java deleted file mode 100644 index 5c71d7ddc9e5..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/JsNashornGraphBuilderTest.java +++ /dev/null @@ -1,391 +0,0 @@ -/* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph; - -import org.mockito.Mock; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import org.wso2.carbon.identity.application.authentication.framework.AbstractFrameworkTest; -import org.wso2.carbon.identity.application.authentication.framework.FederatedApplicationAuthenticator; -import org.wso2.carbon.identity.application.authentication.framework.LocalApplicationAuthenticator; -import org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig; -import org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig; -import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; -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.IdentityProvider; -import org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig; -import org.wso2.carbon.identity.application.common.model.ServiceProvider; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; - -/** - * Tests for graph builder with Javascript. - */ -@Test -public class JsNashornGraphBuilderTest extends AbstractFrameworkTest { - - private JsGraphBuilderFactory jsGraphBuilderFactory; - - @Mock - private LocalApplicationAuthenticator localApplicationAuthenticator; - - @Mock - private LocalApplicationAuthenticator totpApplicationAuthenticator; - - @Mock - private FederatedApplicationAuthenticator federatedApplicationAuthenticator; - - @BeforeTest - public void setUp() { - initMocks(this); - jsGraphBuilderFactory = new JsGraphBuilderFactory(); - jsGraphBuilderFactory.init(); - JSExecutionSupervisor jsExecutionSupervisor = new JSExecutionSupervisor(1, 5000L); - FrameworkServiceDataHolder.getInstance().setJsExecutionSupervisor(jsExecutionSupervisor); - } - - @AfterTest - public void teardown() { - - FrameworkServiceDataHolder.getInstance().getJsExecutionSupervisor().shutdown(); - } - - @Test - public void testCreateDirectJavaInvalidStepId() throws Exception { - - ServiceProvider sp1 = getTestServiceProvider("js-sp-1.xml"); - AuthenticationContext context = getAuthenticationContext(sp1); - Map stepConfigMap = new HashMap<>(); - stepConfigMap.put(1, new StepConfig()); - JsNashornGraphBuilder jsGraphBuilder = jsGraphBuilderFactory.createBuilder(context, stepConfigMap); - jsGraphBuilder.executeStep(2); - - AuthenticationGraph graph = jsGraphBuilder.build(); - assertNull(graph.getStartNode()); - } - - @Test - public void testCreateDirectJava() throws Exception { - - ServiceProvider sp1 = getTestServiceProvider("js-sp-1.xml"); - AuthenticationContext context = getAuthenticationContext(sp1); - Map stepConfigMap = new HashMap<>(); - stepConfigMap.put(1, new StepConfig()); - stepConfigMap.put(2, new StepConfig()); - JsNashornGraphBuilder jsGraphBuilder = jsGraphBuilderFactory.createBuilder(context, stepConfigMap); - jsGraphBuilder.executeStep(1); - jsGraphBuilder.executeStep(2); - - AuthenticationGraph graph = jsGraphBuilder.build(); - assertNotNull(graph.getStartNode()); - assertTrue(graph.getStartNode() instanceof StepConfigGraphNode); - - StepConfigGraphNode firstStep = (StepConfigGraphNode) graph.getStartNode(); - assertNotNull(firstStep.getNext()); - assertTrue(firstStep.getNext() instanceof StepConfigGraphNode); - } - - @Test - public void testCreateJavascript() throws Exception { - - String script = "var onLoginRequest = function(context) { executeStep(1, { onSuccess : function(context) {" - + "executeStep(2);}})};"; - - ServiceProvider sp1 = getTestServiceProvider("js-sp-1.xml"); - AuthenticationContext context = getAuthenticationContext(sp1); - - Map stepConfigMap = new HashMap<>(); - stepConfigMap.put(1, new StepConfig()); - stepConfigMap.put(2, new StepConfig()); - - JsNashornGraphBuilder jsGraphBuilder = jsGraphBuilderFactory.createBuilder(context, stepConfigMap); - jsGraphBuilder.createWith(script); - - AuthenticationGraph graph = jsGraphBuilder.build(); - assertNotNull(graph.getStartNode()); - assertTrue(graph.getStartNode() instanceof StepConfigGraphNode); - - StepConfigGraphNode firstStep = (StepConfigGraphNode) graph.getStartNode(); - assertNotNull(firstStep.getNext()); - assertTrue(firstStep.getNext() instanceof DynamicDecisionNode); - } - - @Test(dataProvider = "filterOptionsDataProvider") - public void testFilterOptions(Map> options, StepConfig stepConfig, int - expectedStepsAfterFilter) - throws Exception { - - ServiceProvider sp1 = getTestServiceProvider("js-sp-1.xml"); - AuthenticationContext context = getAuthenticationContext(sp1); - - Map stepConfigMap = new HashMap<>(); - stepConfigMap.put(1, stepConfig); - - JsNashornGraphBuilder jsGraphBuilder = jsGraphBuilderFactory.createBuilder(context, stepConfigMap); - jsGraphBuilder.filterOptions(options, stepConfig); - assertEquals(stepConfig.getAuthenticatorList().size(), expectedStepsAfterFilter, - "Authentication options after filtering mismatches expected. " + options); - } - - @DataProvider - public Object[][] filterOptionsDataProvider() throws Exception { - - ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().clear(); - LocalAuthenticatorConfig basic = new LocalAuthenticatorConfig(); - basic.setName("BasicAuthenticator"); - basic.setDisplayName("basic"); - LocalAuthenticatorConfig totp = new LocalAuthenticatorConfig(); - totp.setName("TOTPAuthenticator"); - totp.setDisplayName("totp"); - ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().add(basic); - ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().add(totp); - - IdentityProvider localIdp = new IdentityProvider(); - localIdp.setId("LOCAL"); - localIdp.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[0]); - - FederatedAuthenticatorConfig samlFederated = new FederatedAuthenticatorConfig(); - samlFederated.setDisplayName("samlsso"); - samlFederated.setName("SAMLAuthenticator"); - - FederatedAuthenticatorConfig oidcFederated = new FederatedAuthenticatorConfig(); - oidcFederated.setDisplayName("oidc"); - oidcFederated.setName("OIDCAuthenticator"); - - FederatedAuthenticatorConfig twitterFederated = new FederatedAuthenticatorConfig(); - twitterFederated.setDisplayName("twitter"); - twitterFederated.setName("TwitterAuthenticator"); - - IdentityProvider customIdp1 = new IdentityProvider(); - customIdp1.setId("customIdp1"); - customIdp1.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[]{samlFederated, oidcFederated}); - customIdp1.setDefaultAuthenticatorConfig(samlFederated); - - IdentityProvider customIdp2 = new IdentityProvider(); - customIdp2.setId("customIdp2"); - customIdp2.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[]{twitterFederated}); - customIdp2.setDefaultAuthenticatorConfig(twitterFederated); - - AuthenticatorConfig basicAuthConfig = new AuthenticatorConfig(); - basicAuthConfig.setName("BasicAuthenticator"); - basicAuthConfig.setEnabled(true); - basicAuthConfig.getIdps().put("LOCAL", localIdp); - - AuthenticatorConfig totpAuthConfig = new AuthenticatorConfig(); - totpAuthConfig.setName("TOTPAuthenticator"); - totpAuthConfig.setEnabled(true); - totpAuthConfig.getIdps().put("LOCAL", localIdp); - - AuthenticatorConfig samlAuthConfig = new AuthenticatorConfig(); - samlAuthConfig.setName("SAMLAuthenticator"); - samlAuthConfig.setEnabled(true); - samlAuthConfig.getIdps().put("customIdp1", customIdp1); - - AuthenticatorConfig oidcAuthConfig = new AuthenticatorConfig(); - oidcAuthConfig.setName("OIDCAuthenticator"); - oidcAuthConfig.setEnabled(true); - oidcAuthConfig.getIdps().put("customIdp1", customIdp1); - - AuthenticatorConfig twitterAuthConfig = new AuthenticatorConfig(); - twitterAuthConfig.setName("TwitterAuthenticator"); - twitterAuthConfig.setEnabled(true); - twitterAuthConfig.getIdps().put("customIdp2", customIdp2); - - StepConfig stepWithSingleOption = new StepConfig(); - stepWithSingleOption.setAuthenticatorList(Collections.singletonList(basicAuthConfig)); - Map> singleOptionConfig = new HashMap<>(); - singleOptionConfig.put("0", Collections.singletonMap("authenticator", "basic")); - - StepConfig stepWithMultipleOptions = new StepConfig(); - stepWithMultipleOptions.setAuthenticatorList(new ArrayList<>(Arrays.asList(basicAuthConfig, totpAuthConfig, - oidcAuthConfig, twitterAuthConfig))); - - Map oidcOption = new HashMap<>(); - oidcOption.put("idp", "customIdp1"); - oidcOption.put("authenticator", "oidc"); - - Map twitterOption = new HashMap<>(); - twitterOption.put("idp", "customIdp2"); - twitterOption.put("authenticator", "twitter"); - - Map invalidOption = new HashMap<>(); - invalidOption.put("idp", "customIdp1"); - invalidOption.put("authenticator", "twitter"); - - Map> multipleOptionConfig = new HashMap<>(); - multipleOptionConfig.put("0", Collections.singletonMap("authenticator", "basic")); - multipleOptionConfig.put("1", oidcOption); - multipleOptionConfig.put("2", twitterOption); - - Map> multipleAndInvalidOptionConfig = new HashMap<>(); - multipleAndInvalidOptionConfig.put("0", Collections.singletonMap("authenticator", "basic")); - multipleAndInvalidOptionConfig.put("1", oidcOption); - multipleAndInvalidOptionConfig.put("2", invalidOption); - - Map> idpOnlyOptionConfig = new HashMap<>(); - idpOnlyOptionConfig.put("0", Collections.singletonMap("authenticator", "basic")); - idpOnlyOptionConfig.put("1", Collections.singletonMap("idp", "customIdp1")); - - Map> singleInvalidOptionConfig = new HashMap<>(); - singleInvalidOptionConfig.put("0", invalidOption); - - ApplicationAuthenticatorService authenticatorService = mock(ApplicationAuthenticatorService.class); - Field instanceField = ApplicationAuthenticatorService.class.getDeclaredField("instance"); - instanceField.setAccessible(true); - instanceField.set(null, authenticatorService); - when(authenticatorService.getAllLocalAuthenticators(any())) - .thenReturn(new ArrayList<>(Arrays.asList(basic, totp))); - - return new Object[][]{ - {singleOptionConfig, duplicateStepConfig(stepWithSingleOption), 1}, - {singleOptionConfig, duplicateStepConfig(stepWithMultipleOptions), 1}, - {multipleOptionConfig, duplicateStepConfig(stepWithMultipleOptions), 3}, - {multipleAndInvalidOptionConfig, duplicateStepConfig(stepWithMultipleOptions), 2}, - {singleInvalidOptionConfig, duplicateStepConfig(stepWithMultipleOptions), 4}, - {idpOnlyOptionConfig, duplicateStepConfig(stepWithMultipleOptions), 2}, - }; - } - - private StepConfig duplicateStepConfig(StepConfig stepConfig) { - - StepConfig newStepConfig = new StepConfig(); - newStepConfig.setAuthenticatorList(new ArrayList<>(stepConfig.getAuthenticatorList())); - return newStepConfig; - } - - @Test(dataProvider = "filterParamsDataProvider", alwaysRun = true) - public void testParamsOptions(Map options, StepConfig stepConfig, - String authenticatorName, String key, String value) throws Exception { - - ServiceProvider sp1 = getTestServiceProvider("js-sp-1.xml"); - AuthenticationContext context = getAuthenticationContext(sp1); - - Map stepConfigMap = new HashMap<>(); - stepConfigMap.put(1, stepConfig); - - JsNashornGraphBuilder jsGraphBuilder = jsGraphBuilderFactory.createBuilder(context, stepConfigMap); - jsGraphBuilder.authenticatorParamsOptions(options, stepConfig); - assertEquals(context.getAuthenticatorParams(authenticatorName).get(key), value, - "Params are not set expected"); - } - - @DataProvider - public Object[][] filterParamsDataProvider() { - - ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().clear(); - LocalAuthenticatorConfig basic = new LocalAuthenticatorConfig(); - basic.setName("BasicAuthenticator"); - basic.setDisplayName("basic"); - - LocalAuthenticatorConfig totp = new LocalAuthenticatorConfig(); - totp.setName("TOTPAuthenticator"); - totp.setDisplayName("totp"); - - ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().add(basic); - ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().add(totp); - - FederatedAuthenticatorConfig twitterFederated = new FederatedAuthenticatorConfig(); - twitterFederated.setDisplayName("twitter"); - twitterFederated.setName("TwitterAuthenticator"); - - IdentityProvider localIdp = new IdentityProvider(); - localIdp.setId("local"); - localIdp.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[0]); - - IdentityProvider customIdp2 = new IdentityProvider(); - customIdp2.setId("customIdp2"); - customIdp2.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[]{twitterFederated}); - customIdp2.setDefaultAuthenticatorConfig(twitterFederated); - - AuthenticatorConfig basicAuthConfig = new AuthenticatorConfig(); - basicAuthConfig.setName("BasicAuthenticator"); - basicAuthConfig.setEnabled(true); - when(localApplicationAuthenticator.getName()).thenReturn("BasicAuthenticator"); - when(localApplicationAuthenticator.getFriendlyName()).thenReturn("basic"); - basicAuthConfig.setApplicationAuthenticator(localApplicationAuthenticator); - basicAuthConfig.getIdps().put("local", localIdp); - - AuthenticatorConfig totpAuthConfig = new AuthenticatorConfig(); - totpAuthConfig.setName("TOTPAuthenticator"); - totpAuthConfig.setEnabled(true); - when(totpApplicationAuthenticator.getName()).thenReturn("TOTPAuthenticator"); - when(totpApplicationAuthenticator.getFriendlyName()).thenReturn("totp"); - totpAuthConfig.setApplicationAuthenticator(totpApplicationAuthenticator); - totpAuthConfig.getIdps().put("local", localIdp); - - AuthenticatorConfig twitterAuthConfig = new AuthenticatorConfig(); - twitterAuthConfig.setName("TwitterAuthenticator"); - twitterAuthConfig.setEnabled(true); - when(federatedApplicationAuthenticator.getName()).thenReturn("TwitterAuthenticator"); - when(federatedApplicationAuthenticator.getFriendlyName()).thenReturn("twitter"); - twitterAuthConfig.setApplicationAuthenticator(federatedApplicationAuthenticator); - twitterAuthConfig.getIdps().put("customIdp2", customIdp2); - - StepConfig stepWithSingleOption = new StepConfig(); - stepWithSingleOption.setAuthenticatorList(Collections.singletonList(basicAuthConfig)); - - Map singleParamConfig = new HashMap<>(); - Map params = new HashMap<>(); - params.put("BasicAuthenticator", Collections.singletonMap("foo", "xyz")); - singleParamConfig.put("local", params); - - StepConfig stepWithMultipleOptions = new StepConfig(); - stepWithMultipleOptions.setAuthenticatorList(new ArrayList<>(Arrays.asList(basicAuthConfig, totpAuthConfig, - twitterAuthConfig))); - - Map localParams = new HashMap<>(); - localParams.put("BasicAuthenticator", Collections.singletonMap("foo", "xyz")); - localParams.put("TOTPAuthenticator", Collections.singletonMap("domain", "localhost")); - - Map federatedParams = new HashMap<>(); - federatedParams.put("customIdp2", Collections.singletonMap("foo", "user")); - - Map multiParamConfig = new HashMap<>(); - multiParamConfig.put("local", localParams); - multiParamConfig.put("federated", federatedParams); - - return new Object[][]{ - {singleParamConfig, duplicateStepConfig(stepWithSingleOption), "BasicAuthenticator", "foo", "xyz"}, - {singleParamConfig, duplicateStepConfig(stepWithSingleOption), "BasicAuthenticator", "foos", null}, - {singleParamConfig, duplicateStepConfig(stepWithMultipleOptions), "BasicAuthenticator", "foo", "xyz"}, - {multiParamConfig, duplicateStepConfig(stepWithMultipleOptions), "BasicAuthenticator", "domain", null}, - {multiParamConfig, duplicateStepConfig(stepWithMultipleOptions), "TwitterAuthenticator", "foo", "user"}, - {multiParamConfig, duplicateStepConfig(stepWithMultipleOptions), "TOTPAuthenticator", "domain", - "localhost"} - }; - } -} diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/JsNashornAuthenticationContextTest.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/JsNashornAuthenticationContextTest.java deleted file mode 100644 index 0788d9051b7d..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/JsNashornAuthenticationContextTest.java +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js; - -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig; -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.config.model.graph.AuthenticationGraph; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsWrapperFactory; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsWrapperFactoryProvider; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.nashorn.JsNashornAuthenticatedUser; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.nashorn.JsNashornAuthenticationContext; -import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; -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.util.FrameworkConstants; -import org.wso2.carbon.identity.application.common.model.ClaimMapping; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; - -import javax.script.Bindings; -import javax.script.ScriptContext; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -import javax.script.ScriptException; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; - -@Test -public class JsNashornAuthenticationContextTest { - - public static final String TEST_IDP = "testIdP"; - private static final String LAST_ATTEMPTED_USER_USERNAME = "lastAttemptedUsername"; - private static final String LAST_ATTEMPTED_USER_TENANT_DOMAIN = "lastAttemptedTenantDomain"; - private static final String LAST_ATTEMPTED_USER_USERSTORE_DOMAIN = "lastAttemptedUserstoreDomain"; - private static final String SERVICE_PROVIDER_NAME = "service_provider_js_test"; - private static final String BASIC_AUTHENTICATOR = "BasicAuthenticator"; - - private ScriptEngine scriptEngine; - - @BeforeClass - public void setUp() throws NoSuchFieldException, IllegalAccessException { - - scriptEngine = new ScriptEngineManager().getEngineByName("nashorn"); - Field wrapperFactory = JsWrapperFactoryProvider.class.getDeclaredField("jsWrapperBaseFactory"); - wrapperFactory.setAccessible(true); - wrapperFactory.set(JsWrapperFactoryProvider.getInstance(), new JsWrapperFactory()); - } - - @Test - public void testClaimAssignment() throws ScriptException { - - ClaimMapping claimMapping1 = ClaimMapping.build("", "", "", false); - - ClaimMapping claimMapping2 = ClaimMapping.build("Test.Remote.Claim.Url.2", "Test.Remote.Claim.Url.2", "", - false); - - AuthenticatedUser authenticatedUser = new AuthenticatedUser(); - authenticatedUser.getUserAttributes().put(claimMapping1, "TestClaimVal1"); - authenticatedUser.getUserAttributes().put(claimMapping2, "TestClaimVal2"); - AuthenticationContext authenticationContext = new AuthenticationContext(); - setupAuthContextWithStepData(authenticationContext, authenticatedUser); - - JsNashornAuthenticationContext jsNashornAuthenticationContext = - new JsNashornAuthenticationContext(authenticationContext); - Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE); - bindings.put("context", jsNashornAuthenticationContext); - - Object result = scriptEngine.eval("context.steps[1].subject.remoteClaims['Test.Remote.Claim.Url.1']"); - assertNull(result); - result = scriptEngine.eval("context.steps[1].subject.remoteClaims['Test.Remote.Claim.Url.2']"); - assertEquals(result, "TestClaimVal2"); - - scriptEngine.eval("context.steps[1].subject.remoteClaims['Test.Remote.Claim.Url.2'] = 'Modified2'"); - result = scriptEngine.eval("context.steps[1].subject.remoteClaims['Test.Remote.Claim.Url.2']"); - assertEquals(result, "Modified2"); - - } - - private void setupAuthContextWithStepData(AuthenticationContext context, AuthenticatedUser authenticatedUser) { - - AuthenticatorConfig basicAuthenticatorConfig = new AuthenticatorConfig(); - basicAuthenticatorConfig.setName(BASIC_AUTHENTICATOR); - basicAuthenticatorConfig.setEnabled(true); - SequenceConfig sequenceConfig = new SequenceConfig(); - Map stepConfigMap = new HashMap<>(); - StepConfig stepConfig = new StepConfig(); - stepConfig.setOrder(1); - stepConfig.setAuthenticatedIdP(TEST_IDP); - stepConfig.setAuthenticatedAutenticator(basicAuthenticatorConfig); - stepConfigMap.put(1, stepConfig); - sequenceConfig.setStepMap(stepConfigMap); - AuthenticationGraph authenticationGraph = new AuthenticationGraph(); - authenticationGraph.setStepMap(stepConfigMap); - sequenceConfig.setAuthenticationGraph(authenticationGraph); - context.setSequenceConfig(sequenceConfig); - Map idPDataMap = new HashMap<>(); - AuthenticatedIdPData idPData = new AuthenticatedIdPData(); - idPData.setUser(authenticatedUser); - idPData.setIdpName(TEST_IDP); - idPDataMap.put(TEST_IDP, idPData); - context.setCurrentAuthenticatedIdPs(idPDataMap); - } - - @Test - public void testRemoteAddition() throws ScriptException { - - AuthenticatedUser authenticatedUser = new AuthenticatedUser(); - AuthenticationContext authenticationContext = new AuthenticationContext(); - setupAuthContextWithStepData(authenticationContext, authenticatedUser); - - JsNashornAuthenticationContext jsNashornAuthenticationContext = - new JsNashornAuthenticationContext(authenticationContext); - Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE); - bindings.put("context", jsNashornAuthenticationContext); - - scriptEngine.eval("context.steps[1].subject.remoteClaims['testClaim']='testValue'"); - - ClaimMapping claimMapping = ClaimMapping.build("testClaim", "testClaim", "", false); - String claimCreatedByJs = authenticatedUser.getUserAttributes().get(claimMapping); - assertEquals(claimCreatedByJs, "testValue"); - } - - @Test - public void testGetServiceProviderFromWrappedContext() throws Exception { - - AuthenticationContext authenticationContext = new AuthenticationContext(); - authenticationContext.setServiceProviderName(SERVICE_PROVIDER_NAME); - - JsNashornAuthenticationContext jsNashornAuthenticationContext = - new JsNashornAuthenticationContext(authenticationContext); - Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE); - bindings.put("context", jsNashornAuthenticationContext); - - Object result = scriptEngine.eval("context.serviceProviderName"); - assertNotNull(result); - assertEquals(result, SERVICE_PROVIDER_NAME, "Service Provider name set in AuthenticationContext is not " + - "accessible from JSAuthenticationContext"); - } - - - @Test - public void testGetLastLoginFailedUserFromWrappedContext() throws Exception { - - AuthenticatedUser lastAttemptedUser = new AuthenticatedUser(); - lastAttemptedUser.setUserName(LAST_ATTEMPTED_USER_USERNAME); - lastAttemptedUser.setTenantDomain(LAST_ATTEMPTED_USER_TENANT_DOMAIN); - lastAttemptedUser.setUserStoreDomain(LAST_ATTEMPTED_USER_USERSTORE_DOMAIN); - - AuthenticationContext authenticationContext = new AuthenticationContext(); - authenticationContext.setProperty(FrameworkConstants.JSAttributes.JS_LAST_LOGIN_FAILED_USER, lastAttemptedUser); - - JsNashornAuthenticationContext jsNashornAuthenticationContext = - new JsNashornAuthenticationContext(authenticationContext); - Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE); - bindings.put("context", jsNashornAuthenticationContext); - - Object result = scriptEngine.eval("context.lastLoginFailedUser"); - assertNotNull(result); - assertTrue(result instanceof JsNashornAuthenticatedUser); - - String username = (String) scriptEngine.eval("context.lastLoginFailedUser.username"); - assertEquals(username, LAST_ATTEMPTED_USER_USERNAME); - - String tenantDomain = (String) scriptEngine.eval("context.lastLoginFailedUser.tenantDomain"); - assertEquals(tenantDomain, LAST_ATTEMPTED_USER_TENANT_DOMAIN); - - String userStoreDomain = (String) scriptEngine.eval("context.lastLoginFailedUser.userStoreDomain"); - assertEquals(userStoreDomain, LAST_ATTEMPTED_USER_USERSTORE_DOMAIN.toUpperCase()); - } - - @Test - public void testGetLastLoginFailedUserNullFromWrappedContext() throws Exception { - - AuthenticationContext authenticationContext = new AuthenticationContext(); - authenticationContext.setProperty(FrameworkConstants.JSAttributes.JS_LAST_LOGIN_FAILED_USER, null); - - JsNashornAuthenticationContext jsNashornAuthenticationContext = - new JsNashornAuthenticationContext(authenticationContext); - Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE); - bindings.put("context", jsNashornAuthenticationContext); - - Object result = scriptEngine.eval("context.lastLoginFailedUser"); - assertNull(result); - } - - @Test - public void testGetLastLoginAuthenticatorFromStep() throws Exception { - - AuthenticationContext authenticationContext = new AuthenticationContext(); - AuthenticatedUser authenticatedUser = new AuthenticatedUser(); - - setupAuthContextWithStepData(authenticationContext, authenticatedUser); - - JsNashornAuthenticationContext jsNashornAuthenticationContext = - new JsNashornAuthenticationContext(authenticationContext); - Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE); - bindings.put("context", jsNashornAuthenticationContext); - - Object result = scriptEngine.eval("context.steps[1].authenticator"); - assertNotNull(result); - assertEquals(result, BASIC_AUTHENTICATOR, "Authenticator of the step in AuthenticationContext is not " + - "accessible from JSAuthenticationContext"); - - } -} diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/GraphBasedSequenceHandlerAbstractTest.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/GraphBasedSequenceHandlerAbstractTest.java index e75087ad4a38..9218721306d3 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/GraphBasedSequenceHandlerAbstractTest.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/GraphBasedSequenceHandlerAbstractTest.java @@ -34,8 +34,6 @@ import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JSExecutionSupervisor; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsFunctionRegistryImpl; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGenericGraphBuilderFactory; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilderFactory; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsWrapperFactory; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsWrapperFactoryProvider; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.graaljs.JsGraalGraphBuilderFactory; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.graaljs.JsGraalWrapperFactory; @@ -104,17 +102,13 @@ protected void setupSuite(String scriptEngine) throws NoSuchFieldException, Ille configurationLoader = new UIBasedConfigurationLoader(); CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME = false; - if (scriptEngine.contentEquals(FrameworkConstants.JSAttributes.NASHORN)) { - graphBuilderFactory = new JsGraphBuilderFactory(); - } else if (scriptEngine.contentEquals(FrameworkConstants.JSAttributes.GRAALJS)) { + if (scriptEngine.contentEquals(FrameworkConstants.JSAttributes.GRAALJS)) { graphBuilderFactory = new JsGraalGraphBuilderFactory(); } Field wrapperFactory = JsWrapperFactoryProvider.class.getDeclaredField("jsWrapperBaseFactory"); wrapperFactory.setAccessible(true); - if (graphBuilderFactory instanceof JsGraphBuilderFactory) { - wrapperFactory.set(JsWrapperFactoryProvider.getInstance(), new JsWrapperFactory()); - } else if (graphBuilderFactory instanceof JsGraalGraphBuilderFactory) { + if (graphBuilderFactory instanceof JsGraalGraphBuilderFactory) { wrapperFactory.set(JsWrapperFactoryProvider.getInstance(), new JsGraalWrapperFactory()); } diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/resources/testng.xml b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/resources/testng.xml index 0e81b0000e8f..c9670206c7fe 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/resources/testng.xml +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/resources/testng.xml @@ -57,9 +57,7 @@ - - diff --git a/components/authorization-framework/org.wso2.carbon.identity.authorization.common/pom.xml b/components/authorization-framework/org.wso2.carbon.identity.authorization.common/pom.xml index 15656fcfdfee..873fc7d47c22 100644 --- a/components/authorization-framework/org.wso2.carbon.identity.authorization.common/pom.xml +++ b/components/authorization-framework/org.wso2.carbon.identity.authorization.common/pom.xml @@ -80,7 +80,6 @@ javax.xml.namespace, javax.xml.stream, - org.eclipse.equinox.http.helper, javax.servlet.*; version="${imp.pkg.version.javax.servlet}", org.apache.axiom.*; version="${axiom.osgi.version.range}", diff --git a/components/authorization-framework/org.wso2.carbon.identity.authorization.framework/pom.xml b/components/authorization-framework/org.wso2.carbon.identity.authorization.framework/pom.xml index 1e989852dce7..cfa2e1636775 100644 --- a/components/authorization-framework/org.wso2.carbon.identity.authorization.framework/pom.xml +++ b/components/authorization-framework/org.wso2.carbon.identity.authorization.framework/pom.xml @@ -62,7 +62,7 @@ pax-logging-api
- * instead of - * context.getResponse().addCookie(cookie); - *
- * Also, it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime - * HttpServletResponse. - */ -public class JsNashornServletResponse extends JsServletResponse implements AbstractJsObject { - - public JsNashornServletResponse(TransientObjectWrapper wrapped) { - - super(wrapped); - } - -} 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/graph/js/nashorn/JsNashornStep.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornStep.java deleted file mode 100644 index 6da745a6cdcd..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornStep.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js.nashorn; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsStep; -import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; - -/** - * Represents a authentication step. - * This wrapper uses jdk.nashorn engine. - */ -public class JsNashornStep extends JsStep implements AbstractJsObject { - - @Deprecated - public JsNashornStep(int step, String authenticatedIdp) { - - super(step, authenticatedIdp); - } - - public JsNashornStep(int step, String authenticatedIdp, String authenticatedAuthenticator) { - - super(step, authenticatedIdp, authenticatedAuthenticator); - } - - @Deprecated - public JsNashornStep(AuthenticationContext context, int step, String authenticatedIdp) { - - super(context, step, authenticatedIdp); - } - - public JsNashornStep(AuthenticationContext context, int step, String authenticatedIdp, - String authenticatedAuthenticator) { - - super(context, step, authenticatedIdp, authenticatedAuthenticator); - } - - @Override - public Object getMember(String name) { - - Object member = super.getMember(name); - return member != null ? member : AbstractJsObject.super.getMember(name); - } - - @Override - public boolean hasMember(String name) { - - return super.hasMember(name) || AbstractJsObject.super.hasMember(name); - } - - public void removeMember(String name) { - - super.removeMemberObject(name); - } -} 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/graph/js/nashorn/JsNashornSteps.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornSteps.java deleted file mode 100644 index aeea5c6c6341..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornSteps.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js.nashorn; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsSteps; -import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; - -import java.util.Objects; - -/** - * Returns when context.steps[step_number] is called - * This wrapper uses jdk.nashorn engine. - */ -public class JsNashornSteps extends JsSteps implements AbstractJsObject { - - public JsNashornSteps() { - - super(); - - } - - public JsNashornSteps(AuthenticationContext context) { - - super(context); - } - - @Override - public Object getSlot(int step) { - - Object jsStep = super.getSlot(step); - return Objects.nonNull(jsStep) ? jsStep : AbstractJsObject.super.getSlot(step); - } -} 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/graph/js/nashorn/JsNashornWritableParameters.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornWritableParameters.java deleted file mode 100644 index 70b6ccb596dc..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/nashorn/JsNashornWritableParameters.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js.nashorn; - -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsWrapperFactoryProvider; - -import java.util.Map; - -/** - * Parameters that can be modified from the authentication script. - * This wrapper uses jdk.nashorn engine. - */ -public class JsNashornWritableParameters extends JsNashornParameters implements AbstractJsObject { - - public JsNashornWritableParameters(Map wrapped) { - - super(wrapped); - } - - public Object getMember(String name) { - - Object member = getWrapped().get(name); - if (member instanceof Map) { - return JsWrapperFactoryProvider.getInstance().getWrapperFactory() - .createJsWritableParameters((Map) member); - } - return member; - } - - public void removeMember(String name) { - - super.removeMemberObject(name); - } - - public void setMember(String name, Object value) { - - getWrapped().put(name, value); - } -} diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/GraalSelectAcrFromFunction.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/GraalSelectAcrFromFunction.java index c00268bb0574..3da43f6b370f 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/GraalSelectAcrFromFunction.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/GraalSelectAcrFromFunction.java @@ -34,7 +34,7 @@ */ public class GraalSelectAcrFromFunction implements SelectOneFunction { - private static final Log log = LogFactory.getLog(SelectAcrFromFunction.class); + private static final Log log = LogFactory.getLog(GraalSelectAcrFromFunction.class); @HostAccess.Export public String evaluate(JsAuthenticationContext context, Object possibleOutcomesObj) { diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/SelectAcrFromFunction.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/SelectAcrFromFunction.java deleted file mode 100644 index 8d21b194bb7a..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/SelectAcrFromFunction.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2017, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.handler.sequence.impl; - -import jdk.nashorn.api.scripting.ScriptObjectMirror; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext; -import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants; - -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - -/** - * Select the preferred acr value from the available list. - */ -public class SelectAcrFromFunction implements SelectOneFunction { - - private static final Log log = LogFactory.getLog(SelectAcrFromFunction.class); - - public String evaluate(JsAuthenticationContext context, Object possibleOutcomesObj) { - - String[] possibleOutcomes = extractPossibleOutcomes(context, possibleOutcomesObj); - List acrListRequested = context.getWrapped().getRequestedAcr(); - if (acrListRequested == null || acrListRequested.isEmpty()) { - if (log.isDebugEnabled()) { - log.debug("ACR values from context is empty. Selecting the default outcome as null."); - } - return null; - } - if (possibleOutcomes.length > 0) { - return selectBestOutcome(acrListRequested, possibleOutcomes); - } - return null; - } - - private String[] extractPossibleOutcomes(JsAuthenticationContext context, Object possibleOutcomesObj) { - - String[] possibleOutcomes; - if (possibleOutcomesObj instanceof String[]) { - possibleOutcomes = (String[]) possibleOutcomesObj; - } else if (possibleOutcomesObj instanceof ScriptObjectMirror) { - if (((ScriptObjectMirror) possibleOutcomesObj).isArray()) { - possibleOutcomes = ((ScriptObjectMirror) possibleOutcomesObj).to(String[].class); - } else { - log.error("Invalid argument provided for possible outcomes for " + FrameworkConstants.JSAttributes - .JS_FUNC_SELECT_ACR_FROM + " function in service provider: " + context.getWrapped() - .getServiceProviderName() + ". Expected array of strings."); - possibleOutcomes = new String[0]; - } - } else { - log.error("Invalid argument provided for possible outcomes for " + FrameworkConstants.JSAttributes - .JS_FUNC_SELECT_ACR_FROM + " function in service provider: " + context.getWrapped() - .getServiceProviderName() + ". Expected array of strings."); - possibleOutcomes = new String[0]; - } - return possibleOutcomes; - } - - private String selectBestOutcome(List acrListRequested, String[] possibleOutcomes) { - - Map acrRequestedWithPriority = new TreeMap<>(Collections.reverseOrder( - (Comparator) (o1, o2) -> o2.compareTo(o1))); - String acrSelected = null; - - for (String acrChecked : acrListRequested) { - for (int x = 0; x < possibleOutcomes.length; x++) { - String outcomeToTest = possibleOutcomes[x]; - if (outcomeToTest.equals(acrChecked)) { - if (log.isDebugEnabled()) { - log.debug("Reassigning Best Match for the outcome : " + outcomeToTest + " with priority : " + - x + 1); - } - acrRequestedWithPriority.put(x + 1, acrChecked); - break; - } - } - } - if (!acrRequestedWithPriority.entrySet().isEmpty()) { - acrSelected = acrRequestedWithPriority.entrySet().iterator().next().getValue(); - } - return acrSelected; - } -} diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/inbound/IdentityServlet.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/inbound/IdentityServlet.java index d6168a3f90aa..703bcfd747ce 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/inbound/IdentityServlet.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/inbound/IdentityServlet.java @@ -21,6 +21,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.osgi.service.component.annotations.Component; import org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException; import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder; import org.wso2.carbon.identity.core.util.IdentityUtil; @@ -30,6 +31,7 @@ import java.util.List; import java.util.Map; +import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServlet; @@ -39,6 +41,16 @@ /** * Identity Servlet. */ +//TODO Check if this servlet is working. +@Component( + service = Servlet.class, + immediate = true, + property = { + "osgi.http.whiteboard.servlet.pattern=/identity", + "osgi.http.whiteboard.servlet.name=IdentityServlet", + "osgi.http.whiteboard.servlet.asyncSupported=true" + } +) public class IdentityServlet extends HttpServlet { private static final Log log = LogFactory.getLog(IdentityServlet.class); 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 94519bfbd397..45e4a3aae163 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 @@ -23,7 +23,6 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.eclipse.equinox.http.helper.ContextPathServletAdaptor; import org.osgi.framework.BundleContext; import org.osgi.service.component.ComponentContext; import org.osgi.service.component.annotations.Activate; @@ -32,7 +31,6 @@ import org.osgi.service.component.annotations.Reference; import org.osgi.service.component.annotations.ReferenceCardinality; import org.osgi.service.component.annotations.ReferencePolicy; -import org.osgi.service.http.HttpService; import org.wso2.carbon.consent.mgt.core.ConsentManager; import org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticationService; import org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticator; @@ -76,7 +74,6 @@ import org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityRequestFactory; 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; @@ -84,9 +81,6 @@ import org.wso2.carbon.identity.application.authentication.framework.listener.AuthenticationEndpointTenantActivityListener; import org.wso2.carbon.identity.application.authentication.framework.listener.SessionContextMgtListener; import org.wso2.carbon.identity.application.authentication.framework.services.PostAuthenticationMgtService; -import org.wso2.carbon.identity.application.authentication.framework.servlet.CommonAuthenticationServlet; -import org.wso2.carbon.identity.application.authentication.framework.servlet.LoginContextServlet; -import org.wso2.carbon.identity.application.authentication.framework.servlet.LongWaitStatusServlet; import org.wso2.carbon.identity.application.authentication.framework.session.extender.processor.SessionExtenderProcessor; import org.wso2.carbon.identity.application.authentication.framework.session.extender.request.SessionExtenderRequestFactory; import org.wso2.carbon.identity.application.authentication.framework.session.extender.response.SessionExtenderResponseFactory; @@ -131,10 +125,7 @@ import java.util.List; import java.util.Locale; -import javax.servlet.Servlet; - import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants.CUSTOM_AUTHENTICATOR_PREFIX; -import static org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils.promptOnLongWait; import static org.wso2.carbon.identity.base.IdentityConstants.TRUE; /** @@ -147,15 +138,10 @@ ) public class FrameworkServiceComponent { - public static final String COMMON_SERVLET_URL = "/commonauth"; public static final String IS_HANDLER = "IS_HANDLER"; - private static final String IDENTITY_SERVLET_URL = "/identity"; - private static final String LOGIN_CONTEXT_SERVLET_URL = "/logincontext"; - private static final String LONGWAITSTATUS_SERVLET_URL = "/longwaitstatus"; private static final Log log = LogFactory.getLog(FrameworkServiceComponent.class); private static final String API_AUTH = "APIAuth"; - private HttpService httpService; private ConsentMgtPostAuthnHandler consentMgtPostAuthnHandler = new ConsentMgtPostAuthnHandler(); private String requireCode; private String secretsCode; @@ -243,37 +229,6 @@ protected void activate(ComponentContext ctxt) { .registerService(AuthenticationMethodNameTranslator.class, authenticationMethodNameTranslator, null); dataHolder.setAuthenticationMethodNameTranslator(authenticationMethodNameTranslator); - // Register Common servlet - Servlet commonAuthServlet = new ContextPathServletAdaptor(new CommonAuthenticationServlet(), - COMMON_SERVLET_URL); - - Servlet identityServlet = new ContextPathServletAdaptor(new IdentityServlet(), - IDENTITY_SERVLET_URL); - - Servlet loginContextServlet = new ContextPathServletAdaptor(new LoginContextServlet(), - LOGIN_CONTEXT_SERVLET_URL); - try { - httpService.registerServlet(COMMON_SERVLET_URL, commonAuthServlet, null, null); - httpService.registerServlet(IDENTITY_SERVLET_URL, identityServlet, null, null); - httpService.registerServlet(LOGIN_CONTEXT_SERVLET_URL, loginContextServlet, null, null); - } catch (Exception e) { - String errMsg = "Error when registering servlets via the HttpService."; - log.error(errMsg, e); - throw new RuntimeException(errMsg, e); - } - - if (promptOnLongWait()) { - Servlet longWaitStatusServlet = new ContextPathServletAdaptor(new LongWaitStatusServlet(), - LONGWAITSTATUS_SERVLET_URL); - try { - httpService.registerServlet(LONGWAITSTATUS_SERVLET_URL, longWaitStatusServlet, null, null); - } catch (Exception e) { - String errMsg = "Error when registering longwaitstatus servlet via the HttpService."; - log.error(errMsg, e); - throw new RuntimeException(errMsg, e); - } - } - dataHolder.setBundleContext(bundleContext); dataHolder.getHttpIdentityRequestFactories().add(new HttpIdentityRequestFactory()); dataHolder.getHttpIdentityResponseFactories().add(new FrameworkLoginResponseFactory()); @@ -456,31 +411,6 @@ protected void deactivate(ComponentContext ctxt) { } } - @Reference( - name = "osgi.httpservice", - service = HttpService.class, - cardinality = ReferenceCardinality.MANDATORY, - policy = ReferencePolicy.DYNAMIC, - unbind = "unsetHttpService" - ) - protected void setHttpService(HttpService httpService) { - - if (log.isDebugEnabled()) { - log.debug("HTTP Service is set in the Application Authentication Framework bundle"); - } - - this.httpService = httpService; - } - - protected void unsetHttpService(HttpService httpService) { - - if (log.isDebugEnabled()) { - log.debug("HTTP Service is unset in the Application Authentication Framework bundle"); - } - - this.httpService = null; - } - protected void unsetRealmService(RealmService realmService) { if (log.isDebugEnabled()) { diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/CommonAuthenticationServlet.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/CommonAuthenticationServlet.java index e8e892a2f0b0..710d67e2ddfc 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/CommonAuthenticationServlet.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/CommonAuthenticationServlet.java @@ -18,11 +18,13 @@ package org.wso2.carbon.identity.application.authentication.framework.servlet; +import org.osgi.service.component.annotations.Component; import org.wso2.carbon.identity.application.authentication.framework.CommonAuthenticationHandler; import org.wso2.carbon.identity.application.authentication.framework.config.ConfigurationFacade; import java.io.IOException; +import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -31,6 +33,16 @@ /** * Servlet to handle common authentication requests. */ +//TODO Check if this servlet is working. +@Component( + service = Servlet.class, + immediate = true, + property = { + "osgi.http.whiteboard.servlet.pattern=/commonauth", + "osgi.http.whiteboard.servlet.name=CommonAuthenticationServlet", + "osgi.http.whiteboard.servlet.asyncSupported=true" + } +) public class CommonAuthenticationServlet extends HttpServlet { private final CommonAuthenticationHandler commonAuthenticationHandler = new CommonAuthenticationHandler(); diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/LoginContextServlet.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/LoginContextServlet.java index 9d6f55f9666d..11bd2e2258a6 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/LoginContextServlet.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/LoginContextServlet.java @@ -18,10 +18,12 @@ package org.wso2.carbon.identity.application.authentication.framework.servlet; +import org.osgi.service.component.annotations.Component; import org.wso2.carbon.identity.application.authentication.framework.util.LoginContextManagementUtil; import java.io.IOException; +import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -32,6 +34,16 @@ * authenticationendpoint. In case of invalid sessionDataKey, initiates redirection forcing application to * start authentication flow with new sessionDataKey */ +//TODO Check if this servlet is working. +@Component( + service = Servlet.class, + immediate = true, + property = { + "osgi.http.whiteboard.servlet.pattern=/logincontext", + "osgi.http.whiteboard.servlet.name=LoginContextServlet", + "osgi.http.whiteboard.servlet.asyncSupported=true" + } +) public class LoginContextServlet extends HttpServlet { @Override diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/LongWaitStatusServlet.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/LongWaitStatusServlet.java index 0f2a78acf124..849a421d061c 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/LongWaitStatusServlet.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/main/java/org/wso2/carbon/identity/application/authentication/framework/servlet/LongWaitStatusServlet.java @@ -19,6 +19,7 @@ package org.wso2.carbon.identity.application.authentication.framework.servlet; import com.google.gson.Gson; +import org.osgi.service.component.annotations.Component; import org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException; import org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder; import org.wso2.carbon.identity.application.authentication.framework.javascript.flow.LongWaitStatusRequest; @@ -31,6 +32,7 @@ import java.io.IOException; import java.io.PrintWriter; +import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -39,6 +41,16 @@ /** * Servlet to get the status of long wait process. */ +//TODO Check if this servlet is working. +@Component( + service = Servlet.class, + immediate = true, + property = { + "osgi.http.whiteboard.servlet.pattern=/longwaitstatus", + "osgi.http.whiteboard.servlet.name=LongWaitStatusServlet", + "osgi.http.whiteboard.servlet.asyncSupported=true" + } +) public class LongWaitStatusServlet extends HttpServlet { private static final long serialVersionUID = -3714283612680472526L; 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 01cad5bc0448..c0a5d4a63dc4 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 @@ -67,7 +67,6 @@ import org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsBaseGraphBuilderFactory; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGenericGraphBuilderFactory; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilderFactory; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.graaljs.JsGraalGraphBuilderFactory; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.openjdk.nashorn.JsOpenJdkNashornGraphBuilderFactory; import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; @@ -4550,8 +4549,6 @@ public static JsGenericGraphBuilderFactory createJsGenericGraphBuilderFactoryFro return new JsGraalGraphBuilderFactory(); } else if (StringUtils.equalsIgnoreCase(FrameworkConstants.OPENJDK_NASHORN, scriptEngineName)) { return new JsOpenJdkNashornGraphBuilderFactory(); - } else if (StringUtils.equalsIgnoreCase(FrameworkConstants.NASHORN, scriptEngineName)) { - return new JsGraphBuilderFactory(); } } // Config is not set. Hence going with class for name approach. @@ -4563,12 +4560,7 @@ public static JsGenericGraphBuilderFactory createJsGenericGraphBuilderFactoryFro Class.forName(OPENJDK_SCRIPTER_CLASS_NAME); return new JsOpenJdkNashornGraphBuilderFactory(); } catch (ClassNotFoundException classNotFoundException) { - try { - Class.forName(JDK_SCRIPTER_CLASS_NAME); - return new JsGraphBuilderFactory(); - } catch (ClassNotFoundException ex) { - return null; - } + return null; } } } diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/JsNashornGraphBuilderTest.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/JsNashornGraphBuilderTest.java deleted file mode 100644 index 5c71d7ddc9e5..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/JsNashornGraphBuilderTest.java +++ /dev/null @@ -1,391 +0,0 @@ -/* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph; - -import org.mockito.Mock; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import org.wso2.carbon.identity.application.authentication.framework.AbstractFrameworkTest; -import org.wso2.carbon.identity.application.authentication.framework.FederatedApplicationAuthenticator; -import org.wso2.carbon.identity.application.authentication.framework.LocalApplicationAuthenticator; -import org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig; -import org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig; -import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; -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.IdentityProvider; -import org.wso2.carbon.identity.application.common.model.LocalAuthenticatorConfig; -import org.wso2.carbon.identity.application.common.model.ServiceProvider; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; - -/** - * Tests for graph builder with Javascript. - */ -@Test -public class JsNashornGraphBuilderTest extends AbstractFrameworkTest { - - private JsGraphBuilderFactory jsGraphBuilderFactory; - - @Mock - private LocalApplicationAuthenticator localApplicationAuthenticator; - - @Mock - private LocalApplicationAuthenticator totpApplicationAuthenticator; - - @Mock - private FederatedApplicationAuthenticator federatedApplicationAuthenticator; - - @BeforeTest - public void setUp() { - initMocks(this); - jsGraphBuilderFactory = new JsGraphBuilderFactory(); - jsGraphBuilderFactory.init(); - JSExecutionSupervisor jsExecutionSupervisor = new JSExecutionSupervisor(1, 5000L); - FrameworkServiceDataHolder.getInstance().setJsExecutionSupervisor(jsExecutionSupervisor); - } - - @AfterTest - public void teardown() { - - FrameworkServiceDataHolder.getInstance().getJsExecutionSupervisor().shutdown(); - } - - @Test - public void testCreateDirectJavaInvalidStepId() throws Exception { - - ServiceProvider sp1 = getTestServiceProvider("js-sp-1.xml"); - AuthenticationContext context = getAuthenticationContext(sp1); - Map stepConfigMap = new HashMap<>(); - stepConfigMap.put(1, new StepConfig()); - JsNashornGraphBuilder jsGraphBuilder = jsGraphBuilderFactory.createBuilder(context, stepConfigMap); - jsGraphBuilder.executeStep(2); - - AuthenticationGraph graph = jsGraphBuilder.build(); - assertNull(graph.getStartNode()); - } - - @Test - public void testCreateDirectJava() throws Exception { - - ServiceProvider sp1 = getTestServiceProvider("js-sp-1.xml"); - AuthenticationContext context = getAuthenticationContext(sp1); - Map stepConfigMap = new HashMap<>(); - stepConfigMap.put(1, new StepConfig()); - stepConfigMap.put(2, new StepConfig()); - JsNashornGraphBuilder jsGraphBuilder = jsGraphBuilderFactory.createBuilder(context, stepConfigMap); - jsGraphBuilder.executeStep(1); - jsGraphBuilder.executeStep(2); - - AuthenticationGraph graph = jsGraphBuilder.build(); - assertNotNull(graph.getStartNode()); - assertTrue(graph.getStartNode() instanceof StepConfigGraphNode); - - StepConfigGraphNode firstStep = (StepConfigGraphNode) graph.getStartNode(); - assertNotNull(firstStep.getNext()); - assertTrue(firstStep.getNext() instanceof StepConfigGraphNode); - } - - @Test - public void testCreateJavascript() throws Exception { - - String script = "var onLoginRequest = function(context) { executeStep(1, { onSuccess : function(context) {" - + "executeStep(2);}})};"; - - ServiceProvider sp1 = getTestServiceProvider("js-sp-1.xml"); - AuthenticationContext context = getAuthenticationContext(sp1); - - Map stepConfigMap = new HashMap<>(); - stepConfigMap.put(1, new StepConfig()); - stepConfigMap.put(2, new StepConfig()); - - JsNashornGraphBuilder jsGraphBuilder = jsGraphBuilderFactory.createBuilder(context, stepConfigMap); - jsGraphBuilder.createWith(script); - - AuthenticationGraph graph = jsGraphBuilder.build(); - assertNotNull(graph.getStartNode()); - assertTrue(graph.getStartNode() instanceof StepConfigGraphNode); - - StepConfigGraphNode firstStep = (StepConfigGraphNode) graph.getStartNode(); - assertNotNull(firstStep.getNext()); - assertTrue(firstStep.getNext() instanceof DynamicDecisionNode); - } - - @Test(dataProvider = "filterOptionsDataProvider") - public void testFilterOptions(Map> options, StepConfig stepConfig, int - expectedStepsAfterFilter) - throws Exception { - - ServiceProvider sp1 = getTestServiceProvider("js-sp-1.xml"); - AuthenticationContext context = getAuthenticationContext(sp1); - - Map stepConfigMap = new HashMap<>(); - stepConfigMap.put(1, stepConfig); - - JsNashornGraphBuilder jsGraphBuilder = jsGraphBuilderFactory.createBuilder(context, stepConfigMap); - jsGraphBuilder.filterOptions(options, stepConfig); - assertEquals(stepConfig.getAuthenticatorList().size(), expectedStepsAfterFilter, - "Authentication options after filtering mismatches expected. " + options); - } - - @DataProvider - public Object[][] filterOptionsDataProvider() throws Exception { - - ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().clear(); - LocalAuthenticatorConfig basic = new LocalAuthenticatorConfig(); - basic.setName("BasicAuthenticator"); - basic.setDisplayName("basic"); - LocalAuthenticatorConfig totp = new LocalAuthenticatorConfig(); - totp.setName("TOTPAuthenticator"); - totp.setDisplayName("totp"); - ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().add(basic); - ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().add(totp); - - IdentityProvider localIdp = new IdentityProvider(); - localIdp.setId("LOCAL"); - localIdp.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[0]); - - FederatedAuthenticatorConfig samlFederated = new FederatedAuthenticatorConfig(); - samlFederated.setDisplayName("samlsso"); - samlFederated.setName("SAMLAuthenticator"); - - FederatedAuthenticatorConfig oidcFederated = new FederatedAuthenticatorConfig(); - oidcFederated.setDisplayName("oidc"); - oidcFederated.setName("OIDCAuthenticator"); - - FederatedAuthenticatorConfig twitterFederated = new FederatedAuthenticatorConfig(); - twitterFederated.setDisplayName("twitter"); - twitterFederated.setName("TwitterAuthenticator"); - - IdentityProvider customIdp1 = new IdentityProvider(); - customIdp1.setId("customIdp1"); - customIdp1.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[]{samlFederated, oidcFederated}); - customIdp1.setDefaultAuthenticatorConfig(samlFederated); - - IdentityProvider customIdp2 = new IdentityProvider(); - customIdp2.setId("customIdp2"); - customIdp2.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[]{twitterFederated}); - customIdp2.setDefaultAuthenticatorConfig(twitterFederated); - - AuthenticatorConfig basicAuthConfig = new AuthenticatorConfig(); - basicAuthConfig.setName("BasicAuthenticator"); - basicAuthConfig.setEnabled(true); - basicAuthConfig.getIdps().put("LOCAL", localIdp); - - AuthenticatorConfig totpAuthConfig = new AuthenticatorConfig(); - totpAuthConfig.setName("TOTPAuthenticator"); - totpAuthConfig.setEnabled(true); - totpAuthConfig.getIdps().put("LOCAL", localIdp); - - AuthenticatorConfig samlAuthConfig = new AuthenticatorConfig(); - samlAuthConfig.setName("SAMLAuthenticator"); - samlAuthConfig.setEnabled(true); - samlAuthConfig.getIdps().put("customIdp1", customIdp1); - - AuthenticatorConfig oidcAuthConfig = new AuthenticatorConfig(); - oidcAuthConfig.setName("OIDCAuthenticator"); - oidcAuthConfig.setEnabled(true); - oidcAuthConfig.getIdps().put("customIdp1", customIdp1); - - AuthenticatorConfig twitterAuthConfig = new AuthenticatorConfig(); - twitterAuthConfig.setName("TwitterAuthenticator"); - twitterAuthConfig.setEnabled(true); - twitterAuthConfig.getIdps().put("customIdp2", customIdp2); - - StepConfig stepWithSingleOption = new StepConfig(); - stepWithSingleOption.setAuthenticatorList(Collections.singletonList(basicAuthConfig)); - Map> singleOptionConfig = new HashMap<>(); - singleOptionConfig.put("0", Collections.singletonMap("authenticator", "basic")); - - StepConfig stepWithMultipleOptions = new StepConfig(); - stepWithMultipleOptions.setAuthenticatorList(new ArrayList<>(Arrays.asList(basicAuthConfig, totpAuthConfig, - oidcAuthConfig, twitterAuthConfig))); - - Map oidcOption = new HashMap<>(); - oidcOption.put("idp", "customIdp1"); - oidcOption.put("authenticator", "oidc"); - - Map twitterOption = new HashMap<>(); - twitterOption.put("idp", "customIdp2"); - twitterOption.put("authenticator", "twitter"); - - Map invalidOption = new HashMap<>(); - invalidOption.put("idp", "customIdp1"); - invalidOption.put("authenticator", "twitter"); - - Map> multipleOptionConfig = new HashMap<>(); - multipleOptionConfig.put("0", Collections.singletonMap("authenticator", "basic")); - multipleOptionConfig.put("1", oidcOption); - multipleOptionConfig.put("2", twitterOption); - - Map> multipleAndInvalidOptionConfig = new HashMap<>(); - multipleAndInvalidOptionConfig.put("0", Collections.singletonMap("authenticator", "basic")); - multipleAndInvalidOptionConfig.put("1", oidcOption); - multipleAndInvalidOptionConfig.put("2", invalidOption); - - Map> idpOnlyOptionConfig = new HashMap<>(); - idpOnlyOptionConfig.put("0", Collections.singletonMap("authenticator", "basic")); - idpOnlyOptionConfig.put("1", Collections.singletonMap("idp", "customIdp1")); - - Map> singleInvalidOptionConfig = new HashMap<>(); - singleInvalidOptionConfig.put("0", invalidOption); - - ApplicationAuthenticatorService authenticatorService = mock(ApplicationAuthenticatorService.class); - Field instanceField = ApplicationAuthenticatorService.class.getDeclaredField("instance"); - instanceField.setAccessible(true); - instanceField.set(null, authenticatorService); - when(authenticatorService.getAllLocalAuthenticators(any())) - .thenReturn(new ArrayList<>(Arrays.asList(basic, totp))); - - return new Object[][]{ - {singleOptionConfig, duplicateStepConfig(stepWithSingleOption), 1}, - {singleOptionConfig, duplicateStepConfig(stepWithMultipleOptions), 1}, - {multipleOptionConfig, duplicateStepConfig(stepWithMultipleOptions), 3}, - {multipleAndInvalidOptionConfig, duplicateStepConfig(stepWithMultipleOptions), 2}, - {singleInvalidOptionConfig, duplicateStepConfig(stepWithMultipleOptions), 4}, - {idpOnlyOptionConfig, duplicateStepConfig(stepWithMultipleOptions), 2}, - }; - } - - private StepConfig duplicateStepConfig(StepConfig stepConfig) { - - StepConfig newStepConfig = new StepConfig(); - newStepConfig.setAuthenticatorList(new ArrayList<>(stepConfig.getAuthenticatorList())); - return newStepConfig; - } - - @Test(dataProvider = "filterParamsDataProvider", alwaysRun = true) - public void testParamsOptions(Map options, StepConfig stepConfig, - String authenticatorName, String key, String value) throws Exception { - - ServiceProvider sp1 = getTestServiceProvider("js-sp-1.xml"); - AuthenticationContext context = getAuthenticationContext(sp1); - - Map stepConfigMap = new HashMap<>(); - stepConfigMap.put(1, stepConfig); - - JsNashornGraphBuilder jsGraphBuilder = jsGraphBuilderFactory.createBuilder(context, stepConfigMap); - jsGraphBuilder.authenticatorParamsOptions(options, stepConfig); - assertEquals(context.getAuthenticatorParams(authenticatorName).get(key), value, - "Params are not set expected"); - } - - @DataProvider - public Object[][] filterParamsDataProvider() { - - ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().clear(); - LocalAuthenticatorConfig basic = new LocalAuthenticatorConfig(); - basic.setName("BasicAuthenticator"); - basic.setDisplayName("basic"); - - LocalAuthenticatorConfig totp = new LocalAuthenticatorConfig(); - totp.setName("TOTPAuthenticator"); - totp.setDisplayName("totp"); - - ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().add(basic); - ApplicationAuthenticatorService.getInstance().getAllSystemDefinedLocalAuthenticators().add(totp); - - FederatedAuthenticatorConfig twitterFederated = new FederatedAuthenticatorConfig(); - twitterFederated.setDisplayName("twitter"); - twitterFederated.setName("TwitterAuthenticator"); - - IdentityProvider localIdp = new IdentityProvider(); - localIdp.setId("local"); - localIdp.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[0]); - - IdentityProvider customIdp2 = new IdentityProvider(); - customIdp2.setId("customIdp2"); - customIdp2.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[]{twitterFederated}); - customIdp2.setDefaultAuthenticatorConfig(twitterFederated); - - AuthenticatorConfig basicAuthConfig = new AuthenticatorConfig(); - basicAuthConfig.setName("BasicAuthenticator"); - basicAuthConfig.setEnabled(true); - when(localApplicationAuthenticator.getName()).thenReturn("BasicAuthenticator"); - when(localApplicationAuthenticator.getFriendlyName()).thenReturn("basic"); - basicAuthConfig.setApplicationAuthenticator(localApplicationAuthenticator); - basicAuthConfig.getIdps().put("local", localIdp); - - AuthenticatorConfig totpAuthConfig = new AuthenticatorConfig(); - totpAuthConfig.setName("TOTPAuthenticator"); - totpAuthConfig.setEnabled(true); - when(totpApplicationAuthenticator.getName()).thenReturn("TOTPAuthenticator"); - when(totpApplicationAuthenticator.getFriendlyName()).thenReturn("totp"); - totpAuthConfig.setApplicationAuthenticator(totpApplicationAuthenticator); - totpAuthConfig.getIdps().put("local", localIdp); - - AuthenticatorConfig twitterAuthConfig = new AuthenticatorConfig(); - twitterAuthConfig.setName("TwitterAuthenticator"); - twitterAuthConfig.setEnabled(true); - when(federatedApplicationAuthenticator.getName()).thenReturn("TwitterAuthenticator"); - when(federatedApplicationAuthenticator.getFriendlyName()).thenReturn("twitter"); - twitterAuthConfig.setApplicationAuthenticator(federatedApplicationAuthenticator); - twitterAuthConfig.getIdps().put("customIdp2", customIdp2); - - StepConfig stepWithSingleOption = new StepConfig(); - stepWithSingleOption.setAuthenticatorList(Collections.singletonList(basicAuthConfig)); - - Map singleParamConfig = new HashMap<>(); - Map params = new HashMap<>(); - params.put("BasicAuthenticator", Collections.singletonMap("foo", "xyz")); - singleParamConfig.put("local", params); - - StepConfig stepWithMultipleOptions = new StepConfig(); - stepWithMultipleOptions.setAuthenticatorList(new ArrayList<>(Arrays.asList(basicAuthConfig, totpAuthConfig, - twitterAuthConfig))); - - Map localParams = new HashMap<>(); - localParams.put("BasicAuthenticator", Collections.singletonMap("foo", "xyz")); - localParams.put("TOTPAuthenticator", Collections.singletonMap("domain", "localhost")); - - Map federatedParams = new HashMap<>(); - federatedParams.put("customIdp2", Collections.singletonMap("foo", "user")); - - Map multiParamConfig = new HashMap<>(); - multiParamConfig.put("local", localParams); - multiParamConfig.put("federated", federatedParams); - - return new Object[][]{ - {singleParamConfig, duplicateStepConfig(stepWithSingleOption), "BasicAuthenticator", "foo", "xyz"}, - {singleParamConfig, duplicateStepConfig(stepWithSingleOption), "BasicAuthenticator", "foos", null}, - {singleParamConfig, duplicateStepConfig(stepWithMultipleOptions), "BasicAuthenticator", "foo", "xyz"}, - {multiParamConfig, duplicateStepConfig(stepWithMultipleOptions), "BasicAuthenticator", "domain", null}, - {multiParamConfig, duplicateStepConfig(stepWithMultipleOptions), "TwitterAuthenticator", "foo", "user"}, - {multiParamConfig, duplicateStepConfig(stepWithMultipleOptions), "TOTPAuthenticator", "domain", - "localhost"} - }; - } -} diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/JsNashornAuthenticationContextTest.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/JsNashornAuthenticationContextTest.java deleted file mode 100644 index 0788d9051b7d..000000000000 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/config/model/graph/js/JsNashornAuthenticationContextTest.java +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.config.model.graph.js; - -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import org.wso2.carbon.identity.application.authentication.framework.config.model.AuthenticatorConfig; -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.config.model.graph.AuthenticationGraph; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsWrapperFactory; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsWrapperFactoryProvider; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.nashorn.JsNashornAuthenticatedUser; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.nashorn.JsNashornAuthenticationContext; -import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext; -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.util.FrameworkConstants; -import org.wso2.carbon.identity.application.common.model.ClaimMapping; - -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; - -import javax.script.Bindings; -import javax.script.ScriptContext; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -import javax.script.ScriptException; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; - -@Test -public class JsNashornAuthenticationContextTest { - - public static final String TEST_IDP = "testIdP"; - private static final String LAST_ATTEMPTED_USER_USERNAME = "lastAttemptedUsername"; - private static final String LAST_ATTEMPTED_USER_TENANT_DOMAIN = "lastAttemptedTenantDomain"; - private static final String LAST_ATTEMPTED_USER_USERSTORE_DOMAIN = "lastAttemptedUserstoreDomain"; - private static final String SERVICE_PROVIDER_NAME = "service_provider_js_test"; - private static final String BASIC_AUTHENTICATOR = "BasicAuthenticator"; - - private ScriptEngine scriptEngine; - - @BeforeClass - public void setUp() throws NoSuchFieldException, IllegalAccessException { - - scriptEngine = new ScriptEngineManager().getEngineByName("nashorn"); - Field wrapperFactory = JsWrapperFactoryProvider.class.getDeclaredField("jsWrapperBaseFactory"); - wrapperFactory.setAccessible(true); - wrapperFactory.set(JsWrapperFactoryProvider.getInstance(), new JsWrapperFactory()); - } - - @Test - public void testClaimAssignment() throws ScriptException { - - ClaimMapping claimMapping1 = ClaimMapping.build("", "", "", false); - - ClaimMapping claimMapping2 = ClaimMapping.build("Test.Remote.Claim.Url.2", "Test.Remote.Claim.Url.2", "", - false); - - AuthenticatedUser authenticatedUser = new AuthenticatedUser(); - authenticatedUser.getUserAttributes().put(claimMapping1, "TestClaimVal1"); - authenticatedUser.getUserAttributes().put(claimMapping2, "TestClaimVal2"); - AuthenticationContext authenticationContext = new AuthenticationContext(); - setupAuthContextWithStepData(authenticationContext, authenticatedUser); - - JsNashornAuthenticationContext jsNashornAuthenticationContext = - new JsNashornAuthenticationContext(authenticationContext); - Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE); - bindings.put("context", jsNashornAuthenticationContext); - - Object result = scriptEngine.eval("context.steps[1].subject.remoteClaims['Test.Remote.Claim.Url.1']"); - assertNull(result); - result = scriptEngine.eval("context.steps[1].subject.remoteClaims['Test.Remote.Claim.Url.2']"); - assertEquals(result, "TestClaimVal2"); - - scriptEngine.eval("context.steps[1].subject.remoteClaims['Test.Remote.Claim.Url.2'] = 'Modified2'"); - result = scriptEngine.eval("context.steps[1].subject.remoteClaims['Test.Remote.Claim.Url.2']"); - assertEquals(result, "Modified2"); - - } - - private void setupAuthContextWithStepData(AuthenticationContext context, AuthenticatedUser authenticatedUser) { - - AuthenticatorConfig basicAuthenticatorConfig = new AuthenticatorConfig(); - basicAuthenticatorConfig.setName(BASIC_AUTHENTICATOR); - basicAuthenticatorConfig.setEnabled(true); - SequenceConfig sequenceConfig = new SequenceConfig(); - Map stepConfigMap = new HashMap<>(); - StepConfig stepConfig = new StepConfig(); - stepConfig.setOrder(1); - stepConfig.setAuthenticatedIdP(TEST_IDP); - stepConfig.setAuthenticatedAutenticator(basicAuthenticatorConfig); - stepConfigMap.put(1, stepConfig); - sequenceConfig.setStepMap(stepConfigMap); - AuthenticationGraph authenticationGraph = new AuthenticationGraph(); - authenticationGraph.setStepMap(stepConfigMap); - sequenceConfig.setAuthenticationGraph(authenticationGraph); - context.setSequenceConfig(sequenceConfig); - Map idPDataMap = new HashMap<>(); - AuthenticatedIdPData idPData = new AuthenticatedIdPData(); - idPData.setUser(authenticatedUser); - idPData.setIdpName(TEST_IDP); - idPDataMap.put(TEST_IDP, idPData); - context.setCurrentAuthenticatedIdPs(idPDataMap); - } - - @Test - public void testRemoteAddition() throws ScriptException { - - AuthenticatedUser authenticatedUser = new AuthenticatedUser(); - AuthenticationContext authenticationContext = new AuthenticationContext(); - setupAuthContextWithStepData(authenticationContext, authenticatedUser); - - JsNashornAuthenticationContext jsNashornAuthenticationContext = - new JsNashornAuthenticationContext(authenticationContext); - Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE); - bindings.put("context", jsNashornAuthenticationContext); - - scriptEngine.eval("context.steps[1].subject.remoteClaims['testClaim']='testValue'"); - - ClaimMapping claimMapping = ClaimMapping.build("testClaim", "testClaim", "", false); - String claimCreatedByJs = authenticatedUser.getUserAttributes().get(claimMapping); - assertEquals(claimCreatedByJs, "testValue"); - } - - @Test - public void testGetServiceProviderFromWrappedContext() throws Exception { - - AuthenticationContext authenticationContext = new AuthenticationContext(); - authenticationContext.setServiceProviderName(SERVICE_PROVIDER_NAME); - - JsNashornAuthenticationContext jsNashornAuthenticationContext = - new JsNashornAuthenticationContext(authenticationContext); - Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE); - bindings.put("context", jsNashornAuthenticationContext); - - Object result = scriptEngine.eval("context.serviceProviderName"); - assertNotNull(result); - assertEquals(result, SERVICE_PROVIDER_NAME, "Service Provider name set in AuthenticationContext is not " + - "accessible from JSAuthenticationContext"); - } - - - @Test - public void testGetLastLoginFailedUserFromWrappedContext() throws Exception { - - AuthenticatedUser lastAttemptedUser = new AuthenticatedUser(); - lastAttemptedUser.setUserName(LAST_ATTEMPTED_USER_USERNAME); - lastAttemptedUser.setTenantDomain(LAST_ATTEMPTED_USER_TENANT_DOMAIN); - lastAttemptedUser.setUserStoreDomain(LAST_ATTEMPTED_USER_USERSTORE_DOMAIN); - - AuthenticationContext authenticationContext = new AuthenticationContext(); - authenticationContext.setProperty(FrameworkConstants.JSAttributes.JS_LAST_LOGIN_FAILED_USER, lastAttemptedUser); - - JsNashornAuthenticationContext jsNashornAuthenticationContext = - new JsNashornAuthenticationContext(authenticationContext); - Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE); - bindings.put("context", jsNashornAuthenticationContext); - - Object result = scriptEngine.eval("context.lastLoginFailedUser"); - assertNotNull(result); - assertTrue(result instanceof JsNashornAuthenticatedUser); - - String username = (String) scriptEngine.eval("context.lastLoginFailedUser.username"); - assertEquals(username, LAST_ATTEMPTED_USER_USERNAME); - - String tenantDomain = (String) scriptEngine.eval("context.lastLoginFailedUser.tenantDomain"); - assertEquals(tenantDomain, LAST_ATTEMPTED_USER_TENANT_DOMAIN); - - String userStoreDomain = (String) scriptEngine.eval("context.lastLoginFailedUser.userStoreDomain"); - assertEquals(userStoreDomain, LAST_ATTEMPTED_USER_USERSTORE_DOMAIN.toUpperCase()); - } - - @Test - public void testGetLastLoginFailedUserNullFromWrappedContext() throws Exception { - - AuthenticationContext authenticationContext = new AuthenticationContext(); - authenticationContext.setProperty(FrameworkConstants.JSAttributes.JS_LAST_LOGIN_FAILED_USER, null); - - JsNashornAuthenticationContext jsNashornAuthenticationContext = - new JsNashornAuthenticationContext(authenticationContext); - Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE); - bindings.put("context", jsNashornAuthenticationContext); - - Object result = scriptEngine.eval("context.lastLoginFailedUser"); - assertNull(result); - } - - @Test - public void testGetLastLoginAuthenticatorFromStep() throws Exception { - - AuthenticationContext authenticationContext = new AuthenticationContext(); - AuthenticatedUser authenticatedUser = new AuthenticatedUser(); - - setupAuthContextWithStepData(authenticationContext, authenticatedUser); - - JsNashornAuthenticationContext jsNashornAuthenticationContext = - new JsNashornAuthenticationContext(authenticationContext); - Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE); - bindings.put("context", jsNashornAuthenticationContext); - - Object result = scriptEngine.eval("context.steps[1].authenticator"); - assertNotNull(result); - assertEquals(result, BASIC_AUTHENTICATOR, "Authenticator of the step in AuthenticationContext is not " + - "accessible from JSAuthenticationContext"); - - } -} diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/GraphBasedSequenceHandlerAbstractTest.java b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/GraphBasedSequenceHandlerAbstractTest.java index e75087ad4a38..9218721306d3 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/GraphBasedSequenceHandlerAbstractTest.java +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/java/org/wso2/carbon/identity/application/authentication/framework/handler/sequence/impl/GraphBasedSequenceHandlerAbstractTest.java @@ -34,8 +34,6 @@ import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JSExecutionSupervisor; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsFunctionRegistryImpl; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGenericGraphBuilderFactory; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilderFactory; -import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsWrapperFactory; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsWrapperFactoryProvider; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.graaljs.JsGraalGraphBuilderFactory; import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.graaljs.JsGraalWrapperFactory; @@ -104,17 +102,13 @@ protected void setupSuite(String scriptEngine) throws NoSuchFieldException, Ille configurationLoader = new UIBasedConfigurationLoader(); CarbonConstants.ENABLE_LEGACY_AUTHZ_RUNTIME = false; - if (scriptEngine.contentEquals(FrameworkConstants.JSAttributes.NASHORN)) { - graphBuilderFactory = new JsGraphBuilderFactory(); - } else if (scriptEngine.contentEquals(FrameworkConstants.JSAttributes.GRAALJS)) { + if (scriptEngine.contentEquals(FrameworkConstants.JSAttributes.GRAALJS)) { graphBuilderFactory = new JsGraalGraphBuilderFactory(); } Field wrapperFactory = JsWrapperFactoryProvider.class.getDeclaredField("jsWrapperBaseFactory"); wrapperFactory.setAccessible(true); - if (graphBuilderFactory instanceof JsGraphBuilderFactory) { - wrapperFactory.set(JsWrapperFactoryProvider.getInstance(), new JsWrapperFactory()); - } else if (graphBuilderFactory instanceof JsGraalGraphBuilderFactory) { + if (graphBuilderFactory instanceof JsGraalGraphBuilderFactory) { wrapperFactory.set(JsWrapperFactoryProvider.getInstance(), new JsGraalWrapperFactory()); } diff --git a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/resources/testng.xml b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/resources/testng.xml index 0e81b0000e8f..c9670206c7fe 100644 --- a/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/resources/testng.xml +++ b/components/authentication-framework/org.wso2.carbon.identity.application.authentication.framework/src/test/resources/testng.xml @@ -57,9 +57,7 @@ - - diff --git a/components/authorization-framework/org.wso2.carbon.identity.authorization.common/pom.xml b/components/authorization-framework/org.wso2.carbon.identity.authorization.common/pom.xml index 15656fcfdfee..873fc7d47c22 100644 --- a/components/authorization-framework/org.wso2.carbon.identity.authorization.common/pom.xml +++ b/components/authorization-framework/org.wso2.carbon.identity.authorization.common/pom.xml @@ -80,7 +80,6 @@ javax.xml.namespace, javax.xml.stream, - org.eclipse.equinox.http.helper, javax.servlet.*; version="${imp.pkg.version.javax.servlet}", org.apache.axiom.*; version="${axiom.osgi.version.range}", diff --git a/components/authorization-framework/org.wso2.carbon.identity.authorization.framework/pom.xml b/components/authorization-framework/org.wso2.carbon.identity.authorization.framework/pom.xml index 1e989852dce7..cfa2e1636775 100644 --- a/components/authorization-framework/org.wso2.carbon.identity.authorization.framework/pom.xml +++ b/components/authorization-framework/org.wso2.carbon.identity.authorization.framework/pom.xml @@ -62,7 +62,7 @@ pax-logging-api