3 Replies Latest reply on Nov 3, 2009 8:06 PM by nicevision2020

    s:hasRole

    nicevision2020
      I followed the seam documentation about authorization.  But i can't to work with s:hasRole.  there is a user objec with @UserRole and stored in session when i tried rendered='#{s:hasRole('admin')}' it always return false.

      what is my problem

      components.xml

      <security:identity-manager role-identity-store='#{jpaIdentityStore}'/>
         <security:jpa-identity-store user-class='com.demo.entities.User' role-class='com.demo.entities.Role'/>
        
        • 1. Re: s:hasRole
          cash1981

          Please post your User entity and Role entity, also look in the database to actually see that the UserRole table is correctly setup and that it correctly contain the data.

          • 2. Re: s:hasRole
            nicevision2020
            @Name("user")
            @Entity
            @Table(name = "USERS")
            @Scope(ScopeType.SESSION)
            public class User implements java.io.Serializable {

                 private static final long serialVersionUID = 3286368646102955349L;

                 @Id
                 private Integer id;

                 @UserPrincipal
                 @Column(name = "USER_IDENT", nullable = false, length = 300)
                 private String user_ident;


                 @UserPassword(hash = "sha-256")
                 @Column(name = "PASSWORD_HASH", nullable = false, length = 300)
                 private String passwordHash;

                 @UserFirstName
                 @Column(name = "FIRSTNAME", length = 50)
                 private String firstName;
                 
                 @UserLastName
                 @Column(name = "LASTNAME", length = 50)
                 private String lastName;

                 @UserRoles
                 @ManyToMany(targetEntity = Role.class)
                 @JoinTable(name = "USERS_ROLES", joinColumns = @JoinColumn(name = "USERS_KEY"), inverseJoinColumns = @JoinColumn(name = "ROLES_KEY"))
                 private Set<Role> roles = new HashSet<Role>(0);
                 
                 // Constructors

                 /** default constructor */
                 public User() {
                 }

            }



            @Name("role")
            @Entity
            @Table(name = "ROLES", uniqueConstraints = @UniqueConstraint(columnNames = "ROLES_NAME"))
            public class Role implements java.io.Serializable {

                 
                 private static final long serialVersionUID = -3521059209735275880L;

                 @Id
                 private Integer id;

                 @RoleName
                 @Column(name = "ROLES_NAME", unique = true, length = 300)
                 private String roles_name;

                 @Column(name = "ROLES_DESCRIPTION")
                 private String description;
                 
                 // Constructors

                 /** default constructor */
                 public Role() {
                 }

            }
            • 3. Re: s:hasRole
              nicevision2020

              Sorry i fixed the issue.  Thats my bad.  Deployment problem. Thanks for helping.