12 Replies Latest reply on Jan 31, 2009 11:48 AM by Hicham GLIA

    seam 2.1 identity management...

    Denis Gautier Newbie
      Hi,
      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;} }


        • 1. Re: seam 2.1 identity management...
          Shane Bryzak Master

          Is there an exception?  How does it not work?

          • 2. Re: seam 2.1 identity management...
            Raghunath Nandy Newbie

            hi
            i too got same problem , but i fixed it ..


            plz check seamspace example project in latest seam pack.


            u can easily achieve it ..


            thanks
            raghu

            • 3. Re: seam 2.1 identity management...
              Denis Gautier Newbie

              Hello Shane,
              No, there was NO exception. When I remove the config of the authentication method (in components.xml), hoping that Seam will have a look at the data in my DB tables, it doesn't...
              Nor is the view generated the way I thought it would be... OK, there's a Users List, a role List, but the link between the two is not generated in the user interface.


              I can't find what's wrong with my annotations...


              Do you think it's because of the version of Seam ? or the version of JBoss Dev Studio ? Or should have it worked ?


              Anyway, thank you very much...

              • 4. Re: seam 2.1 identity management...
                Denis Gautier Newbie

                Hi Raghu, thanks.
                Could you be more precise...
                - did you see what's wrong in my code ? If not, what was wrong in yours ???  ;-)
                - latest seam pack : the brand new 2.1 GA ?


                Thanks.
                Denis.

                • 5. Re: seam 2.1 identity management...
                  Hicham GLIA Newbie

                  I am using 2.1.1GA and I have exactly the same problem.


                  No Exception is trown!

                  • 6. Re: seam 2.1 identity management...
                    Ingo Jobling Master

                    Try setting log4j to trace level.

                    • 7. Re: seam 2.1 identity management...
                      Hicham GLIA Newbie

                      I don't know how to use  log4j but when I remove the messages tag  I get some more details:



                      sourceId=null[severity=(INFO 0), summary=(Login failed), detail=(Login failed)];|WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
                      sourceId=null[severity=(INFO 0), summary=(Login failed), detail=(Login failed)]
                      


                      • 8. Re: seam 2.1 identity management...
                        Ingo Jobling Master

                        Log4j is indispensable to debug Seam applications.  It is the default logging mechanism used by Seam.


                        If you are running your Seam application in JBoss, you will find a file called jboss-log4j.xml in the Jboss /server/default/conf directory.  In this file you can add entries to specify that you want all Seam classes to log messages at the TRACE, DEBUG, INFO or ERROR level. 


                        If you generated your project with Seam-Gen you probably have a sample log4j.xml file. If not, just add the entries to the jboss-log4j.xml described above. 


                        After doing this you should see lots of messages in the console log, which will undoubtedly help in diagnosing your problem.

                        • 9. Re: seam 2.1 identity management...
                          Hicham GLIA Newbie

                          Thank you for your quick answer!
                          I am using GLASSFISH as AS.
                          I am searching on the Web for a ready to use log4j.xml file.


                          Please if you have one share it with me :-)

                          • 10. Re: seam 2.1 identity management...
                            Hicham GLIA Newbie

                            I have used the following file :


                            My Link



                            <?xml version="1.0" encoding="UTF-8"?>
                            <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
                            
                            <!-- ===================================================================== -->
                            <!--                                                                       -->
                            <!--  Log4j Configuration                                                  -->
                            <!--                                                                       -->
                            <!-- ===================================================================== -->
                            
                            <!-- $Id: log4j.xml 5706 2007-07-06 21:41:35Z myuan $ -->
                            
                            <!--
                               | For more configuration infromation and examples see the Jakarta Log4j
                               | owebsite: http://jakarta.apache.org/log4j
                             -->
                            
                            <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
                               
                               <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
                                  <param name="Target" value="System.out"/>
                            
                                  <layout class="org.apache.log4j.PatternLayout">
                                     <param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{1}] %m%n"/>
                                  </layout>
                               </appender>
                               
                            
                               <category name="org.hibernate">
                                  <priority value="DEBUG"/>
                               </category>
                             
                               <category name="org.jboss.seam">
                                  <priority value="DEBUG"/>
                               </category>
                            
                               <category name="org.jboss.kernel">
                                  <priority value="DEBUG"/>
                               </category>
                            
                            
                               <root>
                                  <priority value="INFO"/>
                                  <appender-ref ref="CONSOLE"/>
                               </root>
                            
                            </log4j:configuration>



                            I put thie file in many places :
                            WEB-INF in my web module
                            META-INF in the ejb-jar
                            domain/domain1/lib for glassfish


                            My application is still silent and there is nothing new in the log output!!!!


                            Can you help please!


                            • 11. Re: seam 2.1 identity management...
                              Ingo Jobling Master

                              Glassfish uses JDK logging by default, not Log4j.  However, Seam should automtically choose JDK instead, according to Gavin King in this post


                              Here is some information about logging configuration in Glassfish.
                              Administering Logging(Glassfish)


                              The general idea is the same as with Log4j, you want to configure the logging system to display messages generated by org.jboss.seam classes at the TRACE level.

                              • 12. Re: seam 2.1 identity management...
                                Hicham GLIA Newbie

                                I'm using a Library (I called SEAM) with the following jar files :


                                1. jboss-seam.jar
                                2. jboss-seam-debug.jar
                                3. jboss-seam-ui.jar
                                4. jboss-el.ja
                                5. thirdparty-all.jar
                                6. hibernate-all.jar


                                When I add : jboss-embedded-all.jar, I get a lot of information and I have descovered that I have forgotten to annotate the Role Name in the role class!!!


                                But I still have one more problem that is : enable to find entityManager?


                                1. I don't know what entityManager SEAM is talkining about?
                                2. I wonder if the 6 jar files that I have added to the SEAM Library are suffusant to use seam on GLASSFISH correctly?!