5 Replies Latest reply on Sep 4, 2007 4:48 AM by mnrz

    how to use @Roles?

    mnrz

      Hello

      I've read something in Seam reference about @Roles which you can define many roles for an entity, a User stated as an example as follows:

      @Roles({
       @Role(name="user", scope=ScopeType.CONVERSATION),
       @Role(name="currentUser", scope=ScopeType.SESSION)
       })
      


      it seems to me very useful but I can't comprehend its concepts and the benefits and also I don't know how to use? unfortunately I couldn't find any sample in which this feature is utilized.

      can anyone explain this annotation and tell me how to use it?

      thanks

        • 1. Re: how to use @Roles?
          atao

          With @Name and @Role you can define only two components, with the same scope or not:

          @Name("user")
          @Scope(SESSION)
          @Role(name="user2", scope=SESSION)
          


          There is no such limitations with @Roles

          @Name("user")
          @Scope(SESSION)
          @Roles({
           @Role(name="user2", scope=SESSION),
           @Role(name="user3", scope=SESSION),
           @Role(name="user4", scope=SESSION),
           @Role(name="user5", scope=SESSION),
           })
          
          


          The scopes can be differents.

          Then all the "Role" names can be used as the "Name" one.



          • 2. Re: how to use @Roles?
            mnrz

            ok, I know about it. Assume that we defined those roles, now, in our session beans how we can use it?

            for example, I have an Authenticator Session bean in which a User instance variable is defined as follows:

            
            @Stateless
            @Name("authenticator")
            class Authenticator {
            
             @Out("currentUser", scope=ScopeType.SESSION)
             private User user;
            
             // rest of the codes....
            }
            
            


            and in another bean in which I provide a facility to manage other users for administrators as follows:

            @Name("userManager")
            @Stateful
            class UsreManagerAction implements UserManager {
            
             private User user;
            
             //rest of the codes....
            }
            


            I want to know how do I use those roles in such these beans?

            thanks again
            how can I use

            • 3. Re: how to use @Roles?
              mnrz

              any other idea? :)

              • 4. Re: how to use @Roles?
                pmuir

                 

                @In(create=true) User user2;
                etc.

                • 5. Re: how to use @Roles?
                  mnrz

                  what simple :)
                  ok so it has an issue only with auto instantiation and not further benefits.

                  I thought a great usability for that.

                  thank you both for your reply