java - error while setting authorities with Spring security -


i use spring security , have problems when starting authentication process

here class user

    @entity @table(name="membre") public class membre  implements userdetails, serializable {      ...................     private arraylist<role> authorities;      @manytomany     @jointable(             name="membre_role",             joincolumns={@joincolumn(name="id_membre", referencedcolumnname="id_membre")},             inversejoincolumns={@joincolumn(name="id_role", referencedcolumnname="id_role")})     public collection<role> getauthorities() {         return this.authorities;     }      public void setauthorities(arraylist<role> authorities) {         this.authorities = authorities;     }     ................     } 

here class role (grantedauthority)

    @entity @table(name="role") public class role  implements grantedauthority, serializable {      /**      *      */     private static final long serialversionuid = 4160725609927520747l;      private integer id;      private string role;      @transient     public string getauthority() {         return this.role;     }      @id     @generatedvalue     @column(name = "id_role", unique = true, nullable = false, precision = 9, scale = 0)     public integer getid() {         return this.id;     }      @column(name = "role", nullable = false, length = 20)     public string getrole() {         return this.role;     }      public void setid(integer id) {         this.id = id;     }      public void setrole(string role) {         this.role = role;     }  } 

here table membre_role

    create  table if not exists `membre_role` (   `id_role` int not null auto_increment ,   `id_membre` int not null),   primary key (`id_role`, `id_membre`) ,   constraint `fk_membre_role_membre`     foreign key (`id_membre` )     references `membre` (`id_membre` )     on delete no action     on update no action,   constraint `fk_membre_role_role`     foreign key (`id_role` )     references `role` (`id_role` )     on delete no action     on update no action) engine = innodb default character set = utf8; 

and when try authenticate, following error

org.springframework.security.authentication.internalauthenticationserviceexception: illegalargumentexception occurred while calling setter property [domain.membre.authorities (expected type = java.util.arraylist)]; target = [domain.membre@1807f3f2], property value = [[domain.role@16cc0706, domain.role@88b48]] setter of domain.membre.authorities; nested exception illegalargumentexception occurred while calling setter property [domain.membre.authorities (expected type = java.util.arraylist)]; target = [domain.membre@1807f3f2], property value = [[domain.role@16cc0706, domain.role@88b48]]

i understand setter isn't defined, can' see how manage , if mapping of authorities defined considering spring security

to not confuse jpa, use same type field, getter , setter:

private collection<role> authorities;  public collection<role> getauthorities() {     return this.authorities; }  public void setauthorities(collection<role> authorities) {     this.authorities = authorities; } 

(jpa annotations omitted brevity.)


Comments