0 Replies Latest reply on Mar 29, 2007 11:57 PM by liutaiyo

    How to get user role in custom login ?

    liutaiyo

      I configured the portal login using DatabaseServerLoginModule

      And I want to get the user role at
      jboss-portal.sar\portal-core.war\WEB-INF\jsp\loginindex.jsp

      Below is the code adding to the index.jsp to retrieve the user role.

      But i can't get the user role which only create in our custom database.
      It only work on default portal user (user / admin)

      How can i get the role name of the login user?

      <%


      try{
      Context initContext = new InitialContext();
      RoleModule role = (RoleModule)initContext.lookup("java:/portal/RoleModule");
      UserModule user = (UserModule)initContext.lookup("java:/portal/UserModule");
      String username = request.getRemoteUser();
      if(username != null){
      if(role != null){

      %>
      HAS ROLE <%= username %> ROLE COUNT = <%=role.getRolesCount() %>
      <%


      User u = null;
      if(user != null){
      //u = user.findUserByUserName(username);


      }else{

      %>
      NO USER OBJECT

      <%
      u = new UserImpl(username);
      }
      if(u != null){
      Set s = role.getRoles(u);
      Iterator i = s.iterator();
      while(i.hasNext()){
      Role r = (Role)i.next();
      %>
      AA <%= r.getName() %>
      <%


      }
      }
      %>
      HAS ROLE
      <%
      }else{
      %>
      NO ROLE
      <%
      }
      }
      }catch(Exception e){
      e.printStackTrace();
      %>
      System Exception

      <%
      }
      %>