4 Replies Latest reply on Jun 26, 2006 5:36 AM by Maciek Maq

    How get user role

    Vincenzo Segreto Newbie

      Hi,
      I have to make a redirection based on user role, how can I get user role?

        • 1. Re: How get user role
          Viet Master

          request.isUserInRole("abc"), of course read the spec as you need to declare you role in the portlet.xml

          • 2. Re: How get user role
            Vincenzo Segreto Newbie

            I've seen this method, its return value is boolean. There is a method that return the string of the role?

            • 3. Re: How get user role
              Vincenzo Segreto Newbie

              I've written in web.xml these role:

              <xml version="1.0" encoding="UTF-8">
              <web-app>
              
               <security-constraint>
               <web-resource-collection>
               <web-resource-name>Secure Content for administrators</web-resource-name>
               <url-pattern>/administrator/*</url-pattern>
               </web-resource-collection>
               <auth-constraint>
               <role-name>Administrators</role-name>
               </auth-constraint>
               <user-data-constraint>
               <transport-guarantee>NONE</transport-guarantee>
               </user-data-constraint>
               </security-constraint>
              
               <security-constraint>
               <web-resource-collection>
               <web-resource-name>Secure Content for users</web-resource-name>
               <url-pattern>/user/*</url-pattern>
               </web-resource-collection>
               <auth-constraint>
               <role-name>Users</role-name>
               </auth-constraint>
               <user-data-constraint>
               <transport-guarantee>NONE</transport-guarantee>
               </user-data-constraint>
               </security-constraint>
              
               <login-config>
               <auth-method>BASIC</auth-method>
               <realm-name>The Restricted Zone</realm-name>
               </login-config>
              
               <security-role>
               <description>Role for the administrators</description>
               <role-name>Administrators</role-name>
               </security-role>
               <security-role>
               <description>Role for the users</description>
               <role-name>Users</role-name>
               </security-role>
              
              </web-app>
              </xml>


              But method isUserInRole(String) return me alwasy false...
              There's something wrong?

              • 4. Re: How get user role
                Maciek Maq Newbie

                If u use JBP 2.2.0, it is normal situation, because, You should add to the your portlet declaration (in a portlet.xml file) declaration of a roles.

                <security-role-ref>
                <role-name>role_name</role-name>
                </security-role-ref>

                When u use this portlet (using user witch role role_name), then this role will be detected by isUserInRole("role_name") function, by returning true value.


                reg.
                MB