login - Spring Security: authentication userdao is null -


i have set jsf spring security.

i narrowed problem down createcriteria method returns nothing.  

any ideas?

why userdao return null?

i have myuserdetailsservice:

    public class myuserdetailsservice implements userdetailsservice, serializable {  /**  *   */ private static final long serialversionuid = 1864276199817921495l; private userdao userdao;  @override public userdetails loaduserbyusername(final string username)             throws usernamenotfoundexception {      bla.bla.bla.model.user user = userdao.getuser(username);      list<grantedauthority> authorities = builduserauthority(user.getpermissions());      return builduserforauthentication(user, authorities);   }  private user builduserforauthentication(bla.bla.bla.model.user user,      list<grantedauthority> authorities) {     return new user(user.getusername(),          user.getpassword(), user.getenabled(),                      true, true, true, authorities); }  private list<grantedauthority> builduserauthority(set<permission> permissions) {      set<grantedauthority> setauths = new hashset<grantedauthority>();      // build user's authorities     (permission permission : permissions) {         setauths.add(new simplegrantedauthority(permission.getpermission()));     }      list<grantedauthority> result = new arraylist<grantedauthority>(setauths);      return result; }  /*  * userdao  */ public userdao getuserdao() {     return userdao; }  /*  * set userdao  */ public void setuserdao(userdao userdao) {     this.userdao = userdao; }  } 

i able final string username , pass userdao.getuser(username) method returns null user object when access method following error:

[error]     org.springframework.security.web.authentication.usernamepasswordauthenticationfi    lter:226 - internal error occurred while trying authenticate user. org.springframework.security.authentication.internalauthenticationserviceexception 

this called getuser(username):

public genericdaoimpl(final class<t> type) {     super();     this.type = type; }  @suppresswarnings("unchecked") public t getbysinglevalue(string field, object value){      session session = sessionfactory.getcurrentsession();      try{         if(!session.gettransaction().isactive())             session.begintransaction();          //create new criteria instance, given entity class         //executes query against particular persistent class         criteria criteria = session.createcriteria(type);         criteria.add(restrictions.eq(field, value));         t object = (t)criteria.uniqueresult();          return object;     } catch (exception e){         system.out.println("error");         e.printstacktrace();         return null;     } {         if(session.gettransaction().isactive())             session.gettransaction().commit();     }        } 

criteria criteria = session.createcriteria(type); returns null when shouldn't. no hibernate sql statements printed out.

my jpa mappings here:

@entity @table(name="users") public class user {  private integer id; private string username; private string firstname; private string lastname; private string password; private set<permission> permissions = new hashset<permission>(0);  /**  * default constructor  */ public user(){ }  public user(string username, string firstname,          string lastname,string password){     this.username = username;     this.firstname = firstname;     this.lastname = lastname;     this.password = password; }  public user(string username, string firstname,          string lastname,string password,          set<permission> permissions) {     this.username = username;     this.firstname = firstname;     this.lastname = lastname;     this.password = password;     this.permissions = permissions; }  /**get id  * @return id  */ @id @generatedvalue(strategy = generationtype.identity) @column(name="id", unique = true, nullable = false) public integer getid() {     return this.id; }  /**set id  * @param id id set  */ public void setid(integer id) {     this.id = id; }  /**get username  * @return username  */ @column(name="username", unique=true, nullable = false, length=25) public string getusername() {     return this.username; }  /**set username  * @param username username set  */ public void setusername(string username) {     this.username = username; }  /**  * @return firstname  */ @column(name="firstname", nullable = false, length=20) public string getfirstname() {     return this.firstname; }  /**  * @param firstname firstname set  */ public void setfirstname(string firstname) {     this.firstname = firstname; }  /**  * @return lastname  */ @column(name="lastname", nullable = false, length=20) public string getlastname() {     return this.lastname; }  /**  * @param lastname lastname set  */ public void setlastname(string lastname) {     this.lastname = lastname; }  /**  * @return password  */ @column(name="password", nullable = false, length=60) public string getpassword() {     return this.password; }  /**  * @param password password set  */ public void setpassword(string password) {     this.password = password; }  /**  * @return userpermissions  */ @manytomany(fetch=fetchtype.lazy) @jointable(name="user_permission",         joincolumns = @joincolumn(name="user_id", nullable=false),         inversejoincolumns = @joincolumn(name="permission_id",nullable=false)) public set<permission> getpermissions() {     return this.permissions; }  /**  * @param userpermissions userpermissions set  */ public void setpermissions(set<permission> userpermissions) {     this.permissions = userpermissions; } }  @entity @table(name="permission") public class permission {  private integer id; private string permission; private string description; private set<user> users = new hashset<user>(0);  /**  * default constructor  */ public permission(){  }  public permission(string permission, string description,         set<user> users) {     this.permission = permission;     this.description = description;     this.users = users; }  /**  * @return id  */ @id @generatedvalue(strategy = generationtype.identity) @column(name="id", unique = true, nullable = false) public integer getid() {     return this.id; } /**  * @param id id set  */ public void setid(integer id) {     this.id = id; } /**  * @return permission  */ @column(name = "permission", unique = true, nullable = false, length = 50) public string getpermission() {     return this.permission; } /**  * @param permission permission set  */ public void setpermission(string permission) {     this.permission = permission; } /**  * @return description  */ @column(name = "description", length = 150) public string getdescription() {     return this.description; } /**  * @param description description set  */ public void setdescription(string description) {     this.description = description; } /**  * @return users  */ @manytomany(fetch = fetchtype.lazy, mappedby = "permissions") public set<user> getusers() {     return this.users; } /**  * @param users users set  */ public void setusers(set<user> users) {     this.users = users; }     } 

my userdao , myuserservicedetail defined in xml file:

<bean id="userdao" class="bla.bla.bla.dao.userdaoimpl">     <property name="sessionfactory" ref="sessionfactory" /> </bean>  <bean id="myuserdetailsservice"                 class="bla.bla.bla.service.myuserdetailsservice">     <property name="userdao" ref="userdao" /> </bean> 

i think jpa mappings wrong...

figured out:

i added hibernate session configuration:

    <property name="annotatedclasses">     <list>         <value>bla.blah.bla.user</value>         <value>bla.blah.bla.model.userorganization</value>          <value>bla.blah.bla.model.permission</value>     </list> </property> 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -