0 Replies Latest reply on Dec 14, 2015 10:43 PM by Vineeth V Nair

    Issue With using a FormAuthenticationMechanism

    Vineeth V Nair Newbie

      Hi,

       

      I am trying to add one more authentication on top of the existing authentication in my application. Below is the code for ServletExtention class

       

       

      public class MyServletExtentionClass implements ServletExtension{

        @Override

        public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext arg1) {

        deploymentInfo.addLastAuthenticationMechanism("test", new MyAuthenticaor("form","/login","/error"));

        }

      }

       

      The code for FormAuthenticationMechanism is like below.

       

      public class MyAuthenticaor extends FormAuthenticationMechanism{

        static FormParserFactory formParserFactory = FormParserFactory.builder().build();

        public MyAuthenticaor(String name, String loginPage, String errorPage) {

        super(formParserFactory,name, loginPage, errorPage);

        }

        @Override

        public AuthenticationMechanismOutcome authenticate(HttpServerExchange exchange,

        SecurityContext securityContext) {

        System.out.println("Authenticated using new mechanism");

        AuthenticationMechanismOutcome superResult = super.authenticate(exchange, securityContext);

        return superResult;

        }

      }


      Just for testing I am calling the super.authenticate method. But in real scenarios I have to do some validations. Right now when i request for the page, the below error is coming in the logs.


      2015-12-15 09:02:28,609 ERROR [io.undertow.request] (default task-2) UT005023: Exception handling request to /webapps/login.html: java.lang.IllegalStateException: UT000012: Session manager was not attached to the request. Make sure that the SessionAttachmentHander is installed in the handler chain

        at io.undertow.util.Sessions.getOrCreateSession(Sessions.java:57) [undertow-core-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.security.impl.FormAuthenticationMechanism.storeInitialLocation(FormAuthenticationMechanism.java:163) [undertow-core-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.security.impl.FormAuthenticationMechanism.sendChallenge(FormAuthenticationMechanism.java:154) [undertow-core-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.security.impl.SecurityContextImpl$ChallengeSender.transition(SecurityContextImpl.java:332) [undertow-core-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.security.impl.SecurityContextImpl$ChallengeSender.transition(SecurityContextImpl.java:351) [undertow-core-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.security.impl.SecurityContextImpl$ChallengeSender.transition(SecurityContextImpl.java:351) [undertow-core-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.security.impl.SecurityContextImpl$ChallengeSender.transition(SecurityContextImpl.java:351) [undertow-core-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.security.impl.SecurityContextImpl$ChallengeSender.access$300(SecurityContextImpl.java:316) [undertow-core-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.security.impl.SecurityContextImpl.sendChallenges(SecurityContextImpl.java:137) [undertow-core-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.security.impl.SecurityContextImpl.authTransition(SecurityContextImpl.java:111) [undertow-core-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.security.impl.SecurityContextImpl.authTransition(SecurityContextImpl.java:116) [undertow-core-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.security.impl.SecurityContextImpl.authenticate(SecurityContextImpl.java:101) [undertow-core-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:55) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.server.handlers.DisableCacheHandler.handleRequest(DisableCacheHandler.java:33) [undertow-core-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51) [undertow-core-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) [undertow-core-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:56) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final]

        at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)

        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:248) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:77) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:167) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.server.Connectors.executeRootHandler(Connectors.java:199) [undertow-core-1.1.8.Final.jar:1.1.8.Final]

        at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:761) [undertow-core-1.1.8.Final.jar:1.1.8.Final]

        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_65]

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_65]

        at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_65]