Skip to content

Commit

Permalink
Fix checkstyle issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
shanggeeth committed Jan 9, 2024
1 parent ffab507 commit 855a850
Show file tree
Hide file tree
Showing 20 changed files with 138 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

import java.util.Map;

import javax.script.ScriptEngine;

/**
* Interface for Factory to create a Javascript based sequence builder.
* This factory is there to reuse of script engine and any related expensive objects.
*
* @param <T> Type of the Javascript Engine
*/
public interface JsBaseGraphBuilderFactory<T> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

package org.wso2.carbon.identity.application.authentication.framework.config.model.graph;

import jdk.nashorn.api.scripting.ScriptObjectMirror;
import org.apache.abdera.model.Base;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand All @@ -46,7 +43,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;

import javax.script.ScriptEngine;
import javax.script.ScriptException;
Expand Down Expand Up @@ -77,6 +73,7 @@ public abstract class JsGraphBuilder implements JsBaseGraphBuilder {
"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', {});";

/**
* Returns the built graph.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

/**
* Interface for serializer class supports Multiple JS Engines.
*
* @param <T> Js Engine.
*/
public interface JsSerializer<T> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
import java.io.IOException;
import java.util.function.Function;

/**
* Javascript function wrapper. This allows serialization of a javascript defined function.
* Since Nashorn is deprecated in JDK 11 and onwards. We replaced it with GraalJS classes.
*/
public class GraalSerializableJsFunction implements BaseSerializableJsFunction<Context> {

private static final Log log = LogFactory.getLog(GraalSerializableJsFunction.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@

package org.wso2.carbon.identity.application.authentication.framework.config.model.graph.graaljs;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsSerializer;
import org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException;

import org.apache.commons.logging.Log;
import org.graalvm.polyglot.Context;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants;

import java.io.Serializable;
Expand All @@ -34,6 +33,9 @@
import java.util.List;
import java.util.Map;

/**
* Serializer class supports GraalJS Engine.
*/
public class GraalSerializer implements JsSerializer<Context> {

private static final Log log = LogFactory.getLog(GraalSerializer.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,24 @@

import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.wso2.carbon.identity.application.authentication.framework.AsyncProcess;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.AuthGraphNode;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.AuthenticationGraph;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.BaseSerializableJsFunction;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.DynamicDecisionNode;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.FailNode;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JSExecutionMonitorData;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JSExecutionSupervisor;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilder;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.PolyglotException;
import org.graalvm.polyglot.Source;
import org.graalvm.polyglot.Value;
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.StepConfig;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.AuthGraphNode;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.AuthenticationGraph;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.BaseSerializableJsFunction;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.DynamicDecisionNode;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.FailNode;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JSExecutionMonitorData;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JSExecutionSupervisor;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilder;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.LongWaitNode;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.ShowPromptNode;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.StepConfigGraphNode;
Expand All @@ -55,6 +54,12 @@
import java.util.function.BiConsumer;
import java.util.stream.Collectors;

/**
* Translate the authentication graph config to runtime model.
* This is not thread safe. Should be discarded after each build.
*
* Since Nashorn is deprecated in JDK 11 and onwards. We are introducing GraalJS engine.
*/
public class JsGraalGraphBuilder extends JsGraphBuilder {

private static final Log log = LogFactory.getLog(JsGraalGraphBuilder.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@

package org.wso2.carbon.identity.application.authentication.framework.config.model.graph.graaljs;

import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.AuthGraphNode;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsBaseGraphBuilder;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsBaseGraphBuilderFactory;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.HostAccess;
import org.graalvm.polyglot.Value;
import org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.AuthGraphNode;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsBaseGraphBuilder;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsBaseGraphBuilderFactory;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsSerializer;
import org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsLogger;
import org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext;
Expand All @@ -37,6 +36,12 @@
import java.util.HashMap;
import java.util.Map;

/**
* Factory to create a Javascript based sequence builder.
* This factory is there to reuse of GraalJS Polyglot Context and any related expensive objects.
* <p>
* Since Nashorn is deprecated in JDK 11 and onwards. We are introducing GraalJS engine.
*/
public class JsGraalGraphBuilderFactory implements JsBaseGraphBuilderFactory<Context> {

private static final Log LOG = LogFactory.getLog(JsGraalGraphBuilderFactory.class);
Expand Down Expand Up @@ -77,8 +82,7 @@ public Context createEngine(AuthenticationContext authenticationContext) {

Context context =
Context.newBuilder(FrameworkConstants.JSAttributes.POLYGLOT_LANGUAGE).allowHostAccess(HostAccess.ALL)
.option("engine.WarnInterpreterOnly", "false")
.build();
.option("engine.WarnInterpreterOnly", "false").build();

Value bindings = context.getBindings(FrameworkConstants.JSAttributes.POLYGLOT_LANGUAGE);
JsLogger jsLogger = new JsLogger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Factory to create a Javascript Object Wrappers for GraalJS execution.
* Since Nashorn is deprecated in JDK 11 and onwards. We are introducing GraalJS engine.
*/
public class JsGraalWrapperFactory implements JsWrapperBaseFactory {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
import java.util.Map;
import java.util.Optional;

/**
* Represent the user's claim for Javascript Execution. This contains the common methods all script engines.
*/
public class JsClaims extends AbstractJSContextMemberObject {

protected static final Log LOG = LogFactory.getLog(JsClaims.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@
import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser;
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants;

/**
* Javascript wrapper for Java level AuthenticatedUser.
* This wrapper uses GraalJS polyglot context.
* This provides controlled access to AuthenticatedUser object via provided javascript native syntax.
* e.g
* var userName = context.lastAuthenticatedUser.username
* <p>
* instead of
* var userName = context.getLastAuthenticatedUser().getUserName()
* <p>
* Also it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime
* AuthenticatedUser.
*
* @see AuthenticatedUser
*/
public class JsGraalAuthenticatedUser extends JsAuthenticatedUser implements ProxyObject {

public JsGraalAuthenticatedUser(AuthenticationContext context, AuthenticatedUser wrappedUser, int step,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@
import org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser;
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkConstants;

/**
* Javascript wrapper for Java level AuthenticationContext.
* This wrapper uses GraalJS polyglot context.
* This provides controlled access to AuthenticationContext object via provided javascript native syntax.
* e.g
* var requestedAcr = context.requestedAcr
* <p>
* instead of
* var requestedAcr = context.getRequestedAcr()
* <p>
* Also it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime
* AuthenticationContext.
*
* @see AuthenticationContext
*/
public class JsGraalAuthenticationContext extends JsAuthenticationContext implements ProxyObject {

public JsGraalAuthenticationContext(AuthenticationContext wrapped) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@

import javax.servlet.http.Cookie;

/**
* Javascript wrapper for Java level Cookie.
* This wrapper uses GraalJS polyglot context.
* 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 JsGraalCookie extends JsCookie implements ProxyObject {

protected static final Log LOG = LogFactory.getLog(JsGraalCookie.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@

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 JsGraalHeaders implements ProxyObject {

private final Map wrapped;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@

import java.util.Map;

/**
* Javascript wrapper for Java level HashMap of HTTP headers/cookies.
* This wrapper uses GraalJS polyglot context.
* 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 JsGraalParameters extends JsParameters implements ProxyObject {

public JsGraalParameters(Map wrapped) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
* Javascript wrapper for Java level HTTPServletRequest.
* This wrapper uses GraalJS polyglot context.
* This provides controlled access to HTTPServletRequest object via provided javascript native syntax.
* e.g
* var redirect_uri = context.request.params.redirect_uri
* <p>
* instead of
* var userName = context.getRequest().getParameter("redirect_uri)
* <p>
* Also it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime
* HTTPServletRequest.
*/
public class JsGraalServletRequest extends JsServletRequest implements ProxyObject {

protected static final Log LOG = LogFactory.getLog(JsGraalServletRequest.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,22 @@

import javax.servlet.http.HttpServletResponse;

/**
* Javascript wrapper for Java level HttpServletResponse.
* This wrapper uses GraalJS polyglot context.
* This provides controlled access to HttpServletResponse object via provided javascript native syntax.
* e.g
* response.headers.["Set-Cookie"] = ['crsftoken=xxxxxssometokenxxxxx']
* <p>
* instead of
* context.getResponse().addCookie(cookie);
* <p>
* Also, it prevents writing an arbitrary values to the respective fields, keeping consistency on runtime
* HttpServletResponse.
*/
public class JsGraalServletResponse extends JsServletResponse implements ProxyObject {

Log LOG = LogFactory.getLog(JsGraalServletResponse.class);
Log log = LogFactory.getLog(JsGraalServletResponse.class);

public JsGraalServletResponse(TransientObjectWrapper<HttpServletResponse> wrapped) {

Expand Down Expand Up @@ -80,7 +93,7 @@ public boolean hasMember(String name) {
@Override
public void putMember(String key, Value value) {

LOG.warn("Unsupported operation. Servlet Response is read only. Can't set parameter " + key + " to value: " +
log.warn("Unsupported operation. Servlet Response is read only. Can't set parameter " + key + " to value: " +
value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
import java.util.Map;
import java.util.Optional;

/**
* Represents a authentication step.
* This wrapper uses GraalJS polyglot context.
*/
public class JsGraalStep extends AbstractJSContextMemberObject implements ProxyObject {

protected static final Log LOG = LogFactory.getLog(JsGraalStep.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@

import java.util.Optional;

/**
* Returns when context.steps[<step_number] is called
* This wrapper uses GraalJS polyglot context.
*/
public class JsGraalSteps extends AbstractJSContextMemberObject implements ProxyArray {

private static final Log LOG = LogFactory.getLog(JsGraalSteps.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
import java.util.List;
import java.util.Map;

/**
* Parameters that can be modified from the authentication script.
* This wrapper uses GraalJS polyglot context.
*/
public class JsGraalWritableParameters extends JsGraalParameters {

public JsGraalWritableParameters(Map wrapped) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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;

import java.util.Map;
import java.util.Optional;

Expand Down

0 comments on commit 855a850

Please sign in to comment.