JBoss - JAAS - Role info

Discussion in 'Java' started by puneet.maini@gmail.com, Nov 22, 2006.

  1. Guest

    Hi,

    I've configured JBoss server to use the JAAS (password & role).

    Now, do anybody has the piece of code to fetch the role of the logged
    in user (Principal).

    Thanks,
    - Puneet
    , Nov 22, 2006
    #1
    1. Advertising

  2. Danno Guest

    wrote:
    > Hi,
    >
    > I've configured JBoss server to use the JAAS (password & role).
    >
    > Now, do anybody has the piece of code to fetch the role of the logged
    > in user (Principal).
    >
    > Thanks,
    > - Puneet


    from where? an EJB? a Servlet? or Application?
    Danno, Nov 22, 2006
    #2
    1. Advertising

  3. Guest

    Lets say from a servlet.

    I'm using the following piece of code in a JSP to get the logged in
    user_id:
    ((Principal) SecurityAssociation.getPrincipal()).getName()

    but, how to get the role info

    Thanks

    Danno wrote:
    > wrote:
    > > Hi,
    > >
    > > I've configured JBoss server to use the JAAS (password & role).
    > >
    > > Now, do anybody has the piece of code to fetch the role of the logged
    > > in user (Principal).
    > >
    > > Thanks,
    > > - Puneet

    >
    > from where? an EJB? a Servlet? or Application?
    , Nov 22, 2006
    #3
  4. Wesley Hall Guest


    > I'm using the following piece of code in a JSP to get the logged in
    > user_id:
    > ((Principal) SecurityAssociation.getPrincipal()).getName()


    Dont do this!! SecurityAssociation is a JBoss specific class and would
    tie your JSPs to JBoss. Even if you don't expect to change application
    server there is no reason to do it this way because...

    request.getUserPrincipal().getName()

    ....will work just as well and will work on any platform.

    > but, how to get the role info


    To the best of my knowledge there isn't a standard API call to enumerate
    roles for a given user. You can use 'request.isUserInRole("RoleName")
    which will return true or false depending on whether the user has the
    role specified but this does require that you know which role you are
    asking about.

    If you require something more, you might want to load the user/role data
    from a database (if you aren't already), JBoss provides a LoginModule to
    do this. Then you can write your own code that will be something like...

    String[] roles = getRolesForUser(username);

    ....which will query your database and return the result.
    Wesley Hall, Nov 23, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. yoz
    Replies:
    5
    Views:
    8,650
  2. Bud Curtis

    JBoss/JAAS Principal Initializing

    Bud Curtis, Feb 24, 2004, in forum: Java
    Replies:
    0
    Views:
    798
    Bud Curtis
    Feb 24, 2004
  3. davout
    Replies:
    8
    Views:
    27,300
    josesuero
    Nov 12, 2010
  4. Replies:
    0
    Views:
    686
  5. priyom
    Replies:
    0
    Views:
    634
    priyom
    Nov 8, 2006
Loading...

Share This Page