wso2 / product-is

Welcome to the WSO2 Identity Server source code! For info on working with the WSO2 Identity Server repository and contributing code, click the link below.
http://wso2.github.io/
Apache License 2.0
730 stars 713 forks source link

currentKnownSubject is not set correctly if previous login attempt was failed #5790

Open rksk opened 5 years ago

rksk commented 5 years ago

Steps to reproduce

  1. Configure a service provider with basic authenticator as the first step
  2. Add the following script to script based adaptive authentication
    function onLoginRequest(context) {
    executeStep(1, {
        onSuccess: function (context) {
            // Extracting authenticated subject from the first step
            var user = context.currentKnownSubject;
        }
    });
    }
  3. First try to login with an invalid credentials pair
  4. Try to login with a valid credentials pair
  5. Following error is logged and authentication fails
    ERROR {org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilder} -  Error in executing the javascript for service provider : test, Javascript Fragment : 
    function (context) {
            // Extracting authenticated subject from the first step
            var user = context.currentKnownSubject;
        }
    java.lang.IllegalArgumentException: Wrapped object cannot be null.
    at org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.AbstractJSObjectWrapper.<init>(AbstractJSObjectWrapper.java:32)
    at org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticatedUser.<init>(JsAuthenticatedUser.java:78)
    at org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticatedUser.<init>(JsAuthenticatedUser.java:65)
    at org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext.getMember(JsAuthenticationContext.java:79)
    at jdk.nashorn.internal.scripts.Script$Recompilation$29$19A$\^eval\_.L:1(<eval>:3)
    at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:659)
    at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494)
    at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
    at jdk.nashorn.api.scripting.ScriptObjectMirror.call(ScriptObjectMirror.java:117)
    at org.wso2.carbon.identity.application.authentication.framework.handler.sequence.impl.GraphBasedSequenceHandler.lambda$executeFunction$1(GraphBasedSequenceHandler.java:606)
    at org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilder$JsBasedEvaluator.evaluate(JsGraphBuilder.java:840)
    at org.wso2.carbon.identity.application.authentication.framework.handler.sequence.impl.GraphBasedSequenceHandler.executeFunction(GraphBasedSequenceHandler.java:606)
    at org.wso2.carbon.identity.application.authentication.framework.handler.sequence.impl.GraphBasedSequenceHandler.handleDecisionPoint(GraphBasedSequenceHandler.java:571)
    at org.wso2.carbon.identity.application.authentication.framework.handler.sequence.impl.GraphBasedSequenceHandler.handleNode(GraphBasedSequenceHandler.java:168)
    at org.wso2.carbon.identity.application.authentication.framework.handler.sequence.impl.GraphBasedSequenceHandler.handle(GraphBasedSequenceHandler.java:125)
    at org.wso2.carbon.identity.application.authentication.framework.handler.request.impl.DefaultAuthenticationRequestHandler.handle(DefaultAuthenticationRequestHandler.java:139)
    at org.wso2.carbon.identity.application.authentication.framework.handler.request.impl.DefaultRequestCoordinator.handle(DefaultRequestCoordinator.java:244)
    at org.wso2.carbon.identity.application.authentication.framework.servlet.CommonAuthenticationServlet.doPost(CommonAuthenticationServlet.java:53)

Workaround To avoid this issue, we can get the subject from the previous step as below. var user = context.steps[1].subject;

pamodaaw commented 4 years ago

This issue occurs for the same reason as https://github.com/wso2/product-is/issues/5779. It has been fixed with https://github.com/wso2/carbon-identity-framework/pull/2264