1 Reply Latest reply on Aug 14, 2014 8:27 PM by Pedro Igor

    Use Identity in Servlet

    Alex Po Newbie

      Is it possible to use Identity class in Servlet? When I try to do it I get error:

       

      Exception handling request to /login: org.picketlink.authentication.AuthenticationException: Authentication failed.
        at org.picketlink.internal.AbstractIdentity.authenticate(AbstractIdentity.java:198) [picketlink-2.6.1.Final.jar:]
        at org.picketlink.internal.AbstractIdentity.login(AbstractIdentity.java:105) [picketlink-2.6.1.Final.jar:]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_05]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_05]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_05]
        at java.lang.reflect.Method.invoke(Method.java:483) [rt.jar:1.8.0_05]
        at org.jboss.weld.bean.proxy.AbstractBeanInstance.invoke(AbstractBeanInstance.java:40) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
        at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:100) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
        at org.jboss.weld.proxies.Identity$1509662680$Proxy$_$$_WeldClientProxy.login(Unknown Source) [weld-core-impl-2.1.2.Final.jar:]
        at me.alekspo.sp.servlet.LoginServlet.doPost(LoginServlet.java:48) [classes:]
        at me.alekspo.sp.servlet.LoginServlet$Proxy$_$$_WeldSubclass.doPost(Unknown Source) [classes:]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
        at me.alekspo.sp.servlet.LoginServlet$Proxy$_$$_WeldSubclass.service(Unknown Source) [classes:]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
        at me.alekspo.sp.servlet.LoginServlet$Proxy$_$$_WeldSubclass.service(Unknown Source) [classes:]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_05]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_05]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_05]
        at java.lang.reflect.Method.invoke(Method.java:483) [rt.jar:1.8.0_05]
        at org.jboss.weld.interceptor.proxy.SimpleInterceptionChain.interceptorChainCompleted(SimpleInterceptionChain.java:52) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
        at org.jboss.weld.interceptor.chain.AbstractInterceptionChain.invokeNextInterceptor(AbstractInterceptionChain.java:83) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
        at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeInterception(InterceptorMethodHandler.java:48) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
        at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.invoke(InterceptorMethodHandler.java:41) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
        at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:53) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
        at me.alekspo.sp.servlet.LoginServlet$Proxy$_$$_WeldSubclass.service(Unknown Source) [classes:]
        at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
        at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
        at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
        at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
        at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
        at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
        at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
        at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
        at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
        at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:56) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
        at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
        at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
        at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
        at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
        at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
        at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
        at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
        at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
        at io.undertow.server.Connectors.executeRootHandler(Connectors.java:177) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
        at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:727) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_05]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_05]
        at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_05]
      Caused by: org.picketlink.idm.IdentityManagementException: PLIDM000200: Credential validation failed [org.picketlink.idm.credential.UsernamePasswordCredentials@e4fa137].
        at org.picketlink.idm.internal.ContextualIdentityManager.validateCredentials(ContextualIdentityManager.java:185) [picketlink-2.6.1.Final.jar:]
        at org.picketlink.internal.SecuredIdentityManager.validateCredentials(SecuredIdentityManager.java:76) [picketlink-2.6.1.Final.jar:]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_05]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_05]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_05]
        at java.lang.reflect.Method.invoke(Method.java:483) [rt.jar:1.8.0_05]
        at org.jboss.weld.bean.proxy.AbstractBeanInstance.invoke(AbstractBeanInstance.java:40) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
        at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:100) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
        at org.jboss.weld.proxies.IdentityManager$1791517898$Proxy$_$$_WeldClientProxy.validateCredentials(Unknown Source) [weld-core-impl-2.1.2.Final.jar:]
        at org.picketlink.authentication.internal.IdmAuthenticator.authenticate(IdmAuthenticator.java:54) [picketlink-2.6.1.Final.jar:]
        at org.picketlink.internal.AbstractIdentity.authenticate(AbstractIdentity.java:185) [picketlink-2.6.1.Final.jar:]
        ... 52 more
      Caused by: org.picketlink.idm.IdentityManagementException: PLIDM000501: Could not query IdentityType using query [org.picketlink.idm.query.internal.DefaultIdentityQuery@4e0fcc19].
        at org.picketlink.idm.query.internal.DefaultIdentityQuery.getResultList(DefaultIdentityQuery.java:148) [picketlink-2.6.1.Final.jar:]
        at org.picketlink.idm.credential.handler.AbstractCredentialHandler.getAccount(AbstractCredentialHandler.java:85) [picketlink-2.6.1.Final.jar:]
        at org.picketlink.idm.credential.handler.PasswordCredentialHandler.getAccount(PasswordCredentialHandler.java:148) [picketlink-2.6.1.Final.jar:]
        at org.picketlink.idm.credential.handler.PasswordCredentialHandler.getAccount(PasswordCredentialHandler.java:56) [picketlink-2.6.1.Final.jar:]
        at org.picketlink.idm.credential.handler.AbstractCredentialHandler.validate(AbstractCredentialHandler.java:112) [picketlink-2.6.1.Final.jar:]
        at org.picketlink.idm.credential.handler.AbstractCredentialHandler.validate(AbstractCredentialHandler.java:49) [picketlink-2.6.1.Final.jar:]
        at org.picketlink.idm.internal.AbstractIdentityStore.validateCredentials(AbstractIdentityStore.java:139) [picketlink-2.6.1.Final.jar:]
        at org.picketlink.idm.internal.ContextualIdentityManager.validateCredentials(ContextualIdentityManager.java:183) [picketlink-2.6.1.Final.jar:]
        ... 62 more
      Caused by: org.picketlink.idm.IdentityManagementException: Could not create [User  from entity [org.picketlink.idm.jpa.model.custom.entity.UserTypeEntity@5797dda0].
        at org.picketlink.idm.jpa.internal.mappers.EntityMapper.createType(EntityMapper.java:209) [picketlink-2.6.1.Final.jar:]
        at org.picketlink.idm.jpa.internal.JPAIdentityStore.fetchQueryResults(JPAIdentityStore.java:524) [picketlink-2.6.1.Final.jar:]
        at org.picketlink.idm.query.internal.DefaultIdentityQuery.getResultList(DefaultIdentityQuery.java:137) [picketlink-2.6.1.Final.jar:]
        ... 69 more
      Caused by: org.picketlink.idm.IdentityManagementException: No mapper for entity type [class org.picketlink.idm.jpa.model.custom.entity.RealmTypeEntity_$$_jvst201_7f].
        at org.picketlink.idm.jpa.internal.JPAIdentityStore.getMapperForEntity(JPAIdentityStore.java:863) [picketlink-2.6.1.Final.jar:]
        at org.picketlink.idm.jpa.internal.mappers.EntityMapper.createType(EntityMapper.java:184) [picketlink-2.6.1.Final.jar:]
        ... 71 more
      

       

      I use custom Identity Model from this example lynx-r/picketlink-deltaspike-authorization-and-idm-custom-identity-model · GitHub

        • 1. Re: Use Identity in Servlet
          Pedro Igor Master

          Hey Alex,

           

              Yes it is. You can use the Identity bean wherever you are able to inject beans using CDI.

           

              In your case, I think this looks like an issue with your Identity Management configuration. It seems you are using the JPA Identity Store, but have not configured it properly.

           

              I would suggest you to take on of the our quickstarts as a template. Also, we are going to release the PicketLink Forge Addon, which will provide a lot of features to create and configure PicketLink in a project.

           

              One more thing. There were a lot of improvements to the PicketLink configuration, specially when using the JPA Identity Store. In the next few weeks we're going to release 2.7.0.Beta1 with all those improvements.

           

          Regards.