1 Reply Latest reply on Jul 28, 2013 9:19 PM by Ahmed KHAN

    JSF Authentication Error

    Ahmed KHAN Newbie

      Hi,

       

      I have just started working on Picketlink for my JSF application. I copied the code from

       

      https://github.com/jboss-jdf/jboss-as-quickstart/tree/master/picketlink-authentication-idm-jsf

       

      I had to make a few changes like removing the SIngleton and Startup Annotations from the IDMInitializer since I am using Tomcat.


      The code in the quick start link above won't compile as is against Picketlink 2.5 beta 5 so I had to make quite a few changes that I am not sure if is correct. Below is the code and Exception. Appreciate any pointers especially if any one has a link to a working example with JSF (on Tomcat)

       

      Exception

       

      javax.faces.el.EvaluationException: org.picketlink.authentication.AuthenticationException: Authentication failed.
      at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
      at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
      at javax.faces.component.UICommand.broadcast(UICommand.java:315)
      at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
      at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
      at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
      at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      at java.lang.Thread.run(Thread.java:619)
      Caused by: org.picketlink.authentication.AuthenticationException: Authentication failed.
      at org.picketlink.internal.DefaultIdentity.authenticate(DefaultIdentity.java:204)
      at org.picketlink.internal.DefaultIdentity.login(DefaultIdentity.java:110)
      at org.picketlink.internal.DefaultIdentity$Proxy$_$$_WeldClientProxy.login(Unknown Source)
      at picketlinkDemo.LoginController.login(LoginController.java:59)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
      at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
      at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
      at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
      at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
      at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
      ... 27 more
      Caused by: org.picketlink.idm.config.SecurityConfigurationException: To use JPAIdentityStore you must provide an EntityManager producer method qualified with @org.picketlink.annotations.PicketLink.
      at org.picketlink.internal.EEJPAContextInitializer.initContextForStore(EEJPAContextInitializer.java:26)
      at org.picketlink.idm.internal.DefaultStoreFactory.getStoreForFeature(DefaultStoreFactory.java:213)
      at org.picketlink.idm.internal.DefaultStoreFactory.getStoreForFeature(DefaultStoreFactory.java:187)
      at org.picketlink.idm.internal.DefaultIdentityManager.validateCredentials(DefaultIdentityManager.java:384)
      at org.picketlink.internal.SecuredIdentityManager.validateCredentials(SecuredIdentityManager.java:171)
      at org.picketlink.authentication.internal.IdmAuthenticator.authenticate(IdmAuthenticator.java:47)
      at org.picketlink.internal.DefaultIdentity.authenticate(DefaultIdentity.java:187)
      ... 40 more

       

       

       

      My code


      /*

      * To change this template, choose Tools | Templates

      * and open the template in the editor.

      */

      package picketlinkDemo;

       

       

      import javax.faces.application.FacesMessage;

      import javax.faces.context.FacesContext;

      import javax.inject.Inject;

      import javax.inject.Named;

      import org.picketlink.Identity;

      import org.picketlink.Identity.AuthenticationResult;

      import org.picketlink.idm.IdentityManager;

      import org.picketlink.idm.config.FileIdentityStoreConfiguration;

      import org.picketlink.idm.config.FileStoreConfigurationBuilder;

      import org.picketlink.idm.config.IdentityConfiguration;

      import org.picketlink.idm.config.IdentityConfigurationBuilder;

      import org.picketlink.idm.config.IdentityStoresConfigurationBuilder;

       

       

      import org.picketlink.idm.credential.Password;

      import org.picketlink.idm.file.internal.FileDataSource;

      import org.picketlink.idm.internal.IdentityManagerFactory;

      import org.picketlink.idm.model.Realm;

      import org.picketlink.idm.model.SimpleUser;

      import org.picketlink.idm.model.User;

       

       

      @Named

      public class LoginController {

       

       

          //@Inject

          //private IdentityManager identityManager;

          @Inject

          private Identity identity;

          @Inject

          private FacesContext facesContext;

         IdentityConfigurationBuilder builder = new IdentityConfigurationBuilder();

          FileIdentityStoreConfiguration configuration;

          //IDMInitializer initMethod = new IDMInitializer ();

          public void login() {

             builder.stores().file().preserveState(false).addRealm(Realm.DEFAULT_REALM, "Testing").addTier("Application")

                      .supportAllFeatures();

       

       

              IdentityStoresConfigurationBuilder store = new IdentityStoresConfigurationBuilder(builder);

              FileStoreConfigurationBuilder fileStore = store.file();

              configuration = fileStore.create();

      //Config is an instance of FileIdentityStoreConfiguration

              IdentityConfiguration configuration = builder.build();

              IdentityManagerFactory identityManagerFactory = new IdentityManagerFactory(configuration);

             IdentityManager identityManager = identityManagerFactory.createIdentityManager();

              User user = new SimpleUser("jane");

       

       

              user.setEmail("jane@doe.com");

              user.setFirstName("Jane");

              user.setLastName("Doe");

       

       

              identityManager.add(user);

              identityManager.updateCredential(user, new Password("abcd1234"));

       

       

              AuthenticationResult result = identity.login();

              if (AuthenticationResult.FAILED.equals(result)) {

                  facesContext.addMessage(null, new FacesMessage(

                          "Authentication was unsuccessful.  Please check your username and password " + "before trying again."));

              }

          }

      }

        • 1. Re: JSF Authentication Error
          Ahmed KHAN Newbie

          Just an update - I couldn't find much on PicketLink in terms of examples and documentation and decided to use Apache Shiro which meets my requirement. I hope the documentation and Sample applications for PicketLink improves because its such a great project with great potential.

           

          Thanks

          Ahmed