1 Reply Latest reply on Apr 7, 2009 3:43 PM by d sailer

    Authenticator not bound error

    ipsita mohapatra Newbie
      Hi,

      i am getting (NameNotFound exception:authenticator not bound) while trying authentication using seam.please reply what may be the error.

      Authenticator.java


      package org.domain.seamdata.session;

      import javax.ejb.Local;

      @Local
      public interface Authenticator {

      }


      AuthenticatorAction.Java


      package org.domain.seamdata.session;

      import static org.jboss.seam.ScopeType.SESSION;

      import java.util.List;

      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;

      import org.domain.seamdata.entity.LoginInfo;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Out;

      @Stateless
      @Name("authenticator")

      public class AuthenticatorAction implements Authenticator{
           @PersistenceContext
              private EntityManager em;
            
              @Out(required=true, scope = SESSION)
              private LoginInfo user;
             
              public boolean authenticate()
              {
                 List results = em.createQuery("select u from LoginInfo u where u.username=#{credentials.username} and u.password=#{credentials.password}")
                       .getResultList();
                
                 if ( results.size()==0 )
                 {
                    return false;
                 }
                 else
                 {
                    user = (LoginInfo) results.get(0);
                    return true;
                 }
              }

      }





      LoginInfo.java


      package org.domain.seamdata.entity;

      // Generated Apr 7, 2009 10:19:39 AM by Hibernate Tools 3.2.4.CR1

      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.Id;
      import javax.persistence.Table;
      import javax.persistence.UniqueConstraint;
      import org.hibernate.validator.Length;
      import org.hibernate.validator.NotNull;
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;

      /**
      * LoginInfo generated by hbm2java
      */
      @Entity
      @Name("logininfo")
      @Scope(ScopeType.SESSION)


      @Table(name = "login_info", catalog = "lic", uniqueConstraints = @UniqueConstraint(columnNames = "id"))
      public class LoginInfo implements java.io.Serializable {

           private String username;
           private String password;
           private String id;

           public LoginInfo() {
           }

           public LoginInfo(String username, String password) {
                this.username = username;
                this.password = password;
           }

           public LoginInfo(String username, String password, String id) {
                this.username = username;
                this.password = password;
                this.id = id;
           }

           @Id
           @Column(name = "username", unique = true, nullable = false, length = 45)
           @NotNull
           @Length(max = 45)
           public String getUsername() {
                return this.username;
           }

           public void setUsername(String username) {
                this.username = username;
           }

           @Column(name = "password", nullable = false, length = 45)
           @NotNull
           @Length(max = 45)
           public String getPassword() {
                return this.password;
           }

           public void setPassword(String password) {
                this.password = password;
           }

           @Column(name = "id", unique = true, length = 45)
           @Length(max = 45)
           public String getId() {
                return this.id;
           }

           public void setId(String id) {
                this.id = id;
           }
            @Override
              public String toString()
              {
                 return "User(" + username + ")";
              }


      }




        • 1. Re: Authenticator not bound error
          d sailer Newbie

          not sure it matters (I'm still learning this stuff), but the seam-gen generated version is a simple javabean:


          @Name("authenticator")
          public class Authenticator {
               @Logger
               private Log log;
          
               @In
               Identity identity;
               @In
               Credentials credentials;
          
               public boolean authenticate() {
                    log.info("authenticating {0}", credentials.getUsername());
                    if ("admin".equals(credentials.getUsername())) {
                         identity.addRole("admin");
                         return true;
                    }
                    return false;
               }
          
          }
          



          might be worth trying.