0 Replies Latest reply on May 28, 2015 11:59 AM by Akshay Ransing

    Unable to handle 401 with custom message

    Akshay Ransing Newbie

      Hi,

       

      I am using jboss-as-7.1.3 with KEYCLOAK as <login-config> and I want to handle 401 with custom reply.

      Please let me how can I do this, I have tried adding <error-page><error-code>401</error-code> in my web.xml for application running on root context as well as specific context application. below is my server log, I want catch this and return custom json response instead of jboss default 401 page.

       

      21:25:51,463 ERROR [org.keycloak.adapters.BearerTokenRequestAuthenticator] (http-/0.0.0.0:8085-1) Failed to verify token: org.keycloak.VerificationException: Token is not active.

        at org.keycloak.RSATokenVerifier.verifyToken(RSATokenVerifier.java:43) [keycloak-core-1.1.0.Final.jar:1.1.0.Final]

        at org.keycloak.RSATokenVerifier.verifyToken(RSATokenVerifier.java:16) [keycloak-core-1.1.0.Final.jar:1.1.0.Final]

        at org.keycloak.adapters.BearerTokenRequestAuthenticator.authenticateToken(BearerTokenRequestAuthenticator.java:67) [keycloak-adapter-core-1.1.0.Final.jar:1.1.0.Final]

        at org.keycloak.adapters.BearerTokenRequestAuthenticator.authenticate(BearerTokenRequestAuthenticator.java:62) [keycloak-adapter-core-1.1.0.Final.jar:1.1.0.Final]

        at org.keycloak.adapters.RequestAuthenticator.authenticate(RequestAuthenticator.java:45) [keycloak-adapter-core-1.1.0.Final.jar:1.1.0.Final]

        at org.keycloak.adapters.tomcat.AbstractKeycloakAuthenticatorValve.authenticateInternal(AbstractKeycloakAuthenticatorValve.java:192) [keycloak-tomcat-core-adapter-1.1.0.Final.jar:1.1.0.Final]

        at org.keycloak.adapters.jbossweb.KeycloakAuthenticatorValve.authenticate(KeycloakAuthenticatorValve.java:26) [keycloak-as7-adapter-1.1.0.Final.jar:1.1.0.Final]

        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:455) [jbossweb-7.0.17.Final.jar:]

        at org.keycloak.adapters.tomcat.AbstractKeycloakAuthenticatorValve.invoke(AbstractKeycloakAuthenticatorValve.java:173) [keycloak-tomcat-core-adapter-1.1.0.Final.jar:1.1.0.Final]

        at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.3.Final.jar:7.1.3.Final]

        at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:165) [jboss-as-web-7.1.3.Final.jar:7.1.3.Final]

        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.17.Final.jar:]

        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.17.Final.jar:]

        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.17.Final.jar:]

        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:372) [jbossweb-7.0.17.Final.jar:]

        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.17.Final.jar:]

        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:679) [jbossweb-7.0.17.Final.jar:]

        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:931) [jbossweb-7.0.17.Final.jar:]

        at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_79]