0 Replies Latest reply on Dec 29, 2007 8:10 PM by robert trudel

    invoking login method

    robert trudel Newbie

      hi


      i use HSQLD, jboss 4.2 and seam 2

      my user class

      @Entity
      @Name("user")
      @Scope(SESSION)
      public class User implements Serializable{
      
       @Id @GeneratedValue
       private long id;
      
       private String userName;
       private String password;
      
       private String firstName;
       private String lastName;
      
       private int sexe;
       private int sexualOrientation;
      
       private String email;
      
       private Date birthday;
      ...
      }
      


      the login action

      @Stateless
      @Name("authenticator")
      public class AuthenticatorAction implements Authenticator{
      
       @In
       Identity identity;
      
       @Out
       private User user;
      
       @PersistenceContext
       private EntityManager em;
      
       @In
       private transient Context sessionContext;
       @In
       private transient FacesContext facesContext;
      
       public boolean authenticate() {
       facesContext.addMessage(null, new FacesMessage("authenticate"));
       List<User> results = em.createQuery("select u from User u where userName=:username and password=:password")
       .setParameter("username", identity.getUsername())
       .setParameter("password", identity.getPassword())
       .getResultList();
      
      
       if ( results.size()==0 )
       {
       facesContext.addMessage(null, new FacesMessage("Invalid login"));
       return false;
       }
       else
       {
       user = results.get(0);
       identity.addRole("visitor");
       return true;
       }
       }
      
      }
      


      my persistence.xml

      <persistence xmlns="http://java.sun.com/xml/ns/persistence"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
       version="1.0">
      
       <persistence-unit name="colocfacile">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/colocfacileDatasource</jta-data-source>
       <properties>
       <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
       <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
       <property name="hibernate.show_sql" value="true"/>
       <property name="hibernate.format_sql" value="true"/>
       <property name="jboss.entity.manager.factory.jndi.name" value="java:/colocfacileEntityManagerFactory"/>
       </properties>
       </persistence-unit>
      
      </persistence>
      



      in the database i done

      insert into User (userName, password, firstName, lastName, sexe, sexualOrientation, email, birthday) values ('demo', 'demo', 'paul', 'smith', 1, 1, 'paul@smith.com', '1979-01-01')
      


      if i enter the wrong information, i can't login

      and i get this message

      INFO [STDOUT] Hibernate:
       select
       user0_.id as id0_,
       user0_.userName as userName0_,
       user0_.password as password0_,
       user0_.firstName as firstName0_,
       user0_.lastName as lastName0_,
       user0_.sexe as sexe0_,
       user0_.sexualOrientation as sexualOr7_0_,
       user0_.email as email0_,
       user0_.birthday as birthday0_
       from
       User user0_
       where
       user0_.userName=?
       and user0_.password=?
      00:31:53,390 ERROR [SeamLoginModule] Error invoking login method
      javax.el.ELException: javax.ejb.EJBTransactionRolledbackException: @Out attribute requires non-null value: authenticator.user
       at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:332)
       at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:341)
       at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
       at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
       at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
       at org.jboss.seam.core.Expressions$2.invoke(Expressions.java:174)
       at org.jboss.seam.security.jaas.SeamLoginModule.login(SeamLoginModule.java:108)
       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 javax.security.auth.login.LoginContext.invoke(LoginContext.java:769)
       at javax.security.auth.login.LoginContext.access$000(LoginContext.java:186)
       at javax.security.auth.login.LoginContext$5.run(LoginContext.java:706)
       at java.security.AccessController.doPrivileged(Native Method)
       at javax.security.auth.login.LoginContext.invokeCreatorPriv(LoginContext.java:703)
       at javax.security.auth.login.LoginContext.login(LoginContext.java:575)
       at org.jboss.seam.security.Identity.authenticate(Identity.java:335)
       at org.jboss.seam.security.Identity.authenticate(Identity.java:324)
       at org.jboss.seam.security.Identity.quietLogin(Identity.java:265)
       at org.jboss.seam.security.Identity.isLoggedIn(Identity.java:182)
       at org.jboss.seam.security.Identity.isLoggedIn(Identity.java:172)
       at org.jboss.seam.security.Identity.authenticate(Identity.java:322)
       at org.jboss.seam.security.Identity.login(Identity.java:237)
       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.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:328)
       at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:341)
       at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
       at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
       at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
       at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
       at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)
       at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
       at javax.faces.component.UICommand.broadcast(UICommand.java:383)
       at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:184)
       at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:162)
       at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:350)
       at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
       at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
       at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
       at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:44)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
       at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
       at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
       at java.lang.Thread.run(Thread.java:619)
      Caused by: javax.ejb.EJBTransactionRolledbackException: @Out attribute requires non-null value: authenticator.user
       at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:87)
      
      



      if i enter the correct information i get
      INFO [STDOUT] Hibernate:
       select
       user0_.id as id0_,
       user0_.userName as userName0_,
       user0_.password as password0_,
       user0_.firstName as firstName0_,
       user0_.lastName as lastName0_,
       user0_.sexe as sexe0_,
       user0_.sexualOrientation as sexualOr7_0_,
       user0_.email as email0_,
       user0_.birthday as birthday0_
       from
       User user0_
       where
       user0_.userName=?
       and user0_.password=?
      


      so i would like to know how to avoid theses error when the information entered by the user is bad

      any idea?