seam 2.1 identity management...
dgautier Dec 22, 2008 10:46 AMHi,
I'm trying to put at work the built in identity management component. It works fine when I code the "authenticate()" method on the authenticator component. But I want to let Seam do the work for me, unsuccessfully so far...
I tried the following :
- I annotated my User and UserRole classes (@UserPrincipal, @UserPassword, @UserRoles, and @ManyToMany for the association)
- I modified "components.xml" :
<security:identity />
<security:jpa-identity-store
user-class="my.package.Utilisateur"
role-class="my.package.Role" />
It doesn't work.
Further info that may help :
- I'm using jboss-seam-2.1.0.SP1 (new Seam web project with seam 2.0 in "technology preview")
- I've generated the code using seam-gen via JBoss Developer Studio 1.1.0.GA (with the 'generate from existing entities' option)
Any idea about what's wrong ?
Thanks a lot,
Denis.
(below is my java code)
------------------------------------------------------------------------
@Entity
@Table(name = "utilisateur", uniqueConstraints = { @UniqueConstraint(columnNames = "userid") }) public class Utilisateur implements Serializable {
// Attributs utilisés par JPA : identifiant et version
private Integer id;
private Integer version;
private String userid;
private String passwordHash;
private UtilisateurCategorie categorie;
private Set<Role> listeRoles = new HashSet<Role>();
@Column(name = "utilisateur_id", nullable = false, unique = true)
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "utilisateur_seq")
@SequenceGenerator(name = "utilisateur_seq", sequenceName = "agora.utilisateur_seq")
@NotNull
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
/**
* Gestion de l'optimistic locking par Hibernate
* @Version
* @return la version courante
*/
@Version
@Column(name = "version")
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
@Column(name = "userid", nullable=false)
@NotNull @Length(min=3, max=25)
@UserPrincipal
public String getUserid() {
return userid;
}
public void setUserid(String userid) {
this.userid = userid;
}
@Column(name = "password_hash", nullable=false)
@NotNull @Length(min=6, max=25)
@UserPassword(hash="md5")
public String getPasswordHash() {
return passwordHash;
}
public void setPasswordHash(String passwordHash) {
this.passwordHash = passwordHash;
}
@Enumerated(EnumType.STRING)
@Column(name="utilisateur_categorie", nullable=false)
public UtilisateurCategorie getCategorie() {
return categorie;
}
public void setCategorie(UtilisateurCategorie categorie) {
this.categorie = categorie;
}
@ManyToMany(targetEntity = Role.class)
@JoinTable(name = "utilisateur_role", joinColumns = @JoinColumn(name = "utilisateur_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
@UserRoles
public Set<Role> getListeRoles() {
return listeRoles;
}
public void setListeRoles(Set<Role> listeRoles) {
this.listeRoles = listeRoles;
}
}
------------------------------------------------------------------------
@Entity
@Table (name="role", schema="agora", uniqueConstraints = @UniqueConstraint(columnNames="role_libelle"))
public class Role implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private String libelle;
public Role(String string) {
// TODO Auto-generated constructor stub
}
public Role() {
// TODO Auto-generated constructor stub
}
@Column(name="role_id", nullable = false, unique = true)
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "role_seq")
@SequenceGenerator(name = "role_seq", sequenceName = "agora.role_seq")
@NotNull
public Long getId() {return id;}
public void setId(Long id) {this.id = id;}
@Column(name="role_libelle", unique=true, length=40, nullable=true)
@NotNull
@RoleName
public String getLibelle() {return libelle;}
public void setLibelle(String libelle) {this.libelle = libelle;} }
I'm trying to put at work the built in identity management component. It works fine when I code the "authenticate()" method on the authenticator component. But I want to let Seam do the work for me, unsuccessfully so far...
I tried the following :
- I annotated my User and UserRole classes (@UserPrincipal, @UserPassword, @UserRoles, and @ManyToMany for the association)
- I modified "components.xml" :
<security:identity />
<security:jpa-identity-store
user-class="my.package.Utilisateur"
role-class="my.package.Role" />
It doesn't work.
Further info that may help :
- I'm using jboss-seam-2.1.0.SP1 (new Seam web project with seam 2.0 in "technology preview")
- I've generated the code using seam-gen via JBoss Developer Studio 1.1.0.GA (with the 'generate from existing entities' option)
Any idea about what's wrong ?
Thanks a lot,
Denis.
(below is my java code)
------------------------------------------------------------------------
@Entity
@Table(name = "utilisateur", uniqueConstraints = { @UniqueConstraint(columnNames = "userid") }) public class Utilisateur implements Serializable {
// Attributs utilisés par JPA : identifiant et version
private Integer id;
private Integer version;
private String userid;
private String passwordHash;
private UtilisateurCategorie categorie;
private Set<Role> listeRoles = new HashSet<Role>();
@Column(name = "utilisateur_id", nullable = false, unique = true)
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "utilisateur_seq")
@SequenceGenerator(name = "utilisateur_seq", sequenceName = "agora.utilisateur_seq")
@NotNull
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
/**
* Gestion de l'optimistic locking par Hibernate
* @Version
* @return la version courante
*/
@Version
@Column(name = "version")
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
@Column(name = "userid", nullable=false)
@NotNull @Length(min=3, max=25)
@UserPrincipal
public String getUserid() {
return userid;
}
public void setUserid(String userid) {
this.userid = userid;
}
@Column(name = "password_hash", nullable=false)
@NotNull @Length(min=6, max=25)
@UserPassword(hash="md5")
public String getPasswordHash() {
return passwordHash;
}
public void setPasswordHash(String passwordHash) {
this.passwordHash = passwordHash;
}
@Enumerated(EnumType.STRING)
@Column(name="utilisateur_categorie", nullable=false)
public UtilisateurCategorie getCategorie() {
return categorie;
}
public void setCategorie(UtilisateurCategorie categorie) {
this.categorie = categorie;
}
@ManyToMany(targetEntity = Role.class)
@JoinTable(name = "utilisateur_role", joinColumns = @JoinColumn(name = "utilisateur_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
@UserRoles
public Set<Role> getListeRoles() {
return listeRoles;
}
public void setListeRoles(Set<Role> listeRoles) {
this.listeRoles = listeRoles;
}
}
------------------------------------------------------------------------
@Entity
@Table (name="role", schema="agora", uniqueConstraints = @UniqueConstraint(columnNames="role_libelle"))
public class Role implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private String libelle;
public Role(String string) {
// TODO Auto-generated constructor stub
}
public Role() {
// TODO Auto-generated constructor stub
}
@Column(name="role_id", nullable = false, unique = true)
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "role_seq")
@SequenceGenerator(name = "role_seq", sequenceName = "agora.role_seq")
@NotNull
public Long getId() {return id;}
public void setId(Long id) {this.id = id;}
@Column(name="role_libelle", unique=true, length=40, nullable=true)
@NotNull
@RoleName
public String getLibelle() {return libelle;}
public void setLibelle(String libelle) {this.libelle = libelle;} }