Kombinált nézet Egyszerű nézet Fa-nézet
Szálak [ Előző | Következő ]
toggle
mark anderson
how to authenticate against site roles
2012. június 22. 1:56
Válasz

mark anderson

Rangsorolás: New Member

Hozzászólások: 3

Csatlakozás dátuma: 2012. június 19.

Legújabb hozzászólások

Hi,

I'm having some issues, first a bit of background:

I have a jsf 2 icefaces 3 portlet deployed on Liferay community 6.1 (tomcat bundle), Everything works but i've come to an issue i can't get round.

I've created several private sites within the portal, the portlet is then deployed onto the one of the site pages, i want the 'site administrator' to be able to assign the roles used in the portlet to site members. The issue was that the roles used were Regular roles, and couldn't be changed by the site administrator. So i moved the roles to site roles. However, the app then fails saying

java.lang.IllegalArgumentException: TableWhseEditor is not a regular role

to identify the roles in my portlet, i'm using the icefaces tag element RenderedOnUserRole and also

facesContext.getExternalContext().isUserInRole(role);

How do i make my portlet pick up the site roles instead of the regular roles?

I've looked at the scopeable element but it doesn't seem to make any difference.

Am i tackling this issue the correct way?
Neil Griffin
RE: how to authenticate against site roles
2012. június 22. 6:42
Válasz

Neil Griffin

LIFERAY STAFF

Rangsorolás: Liferay Legend

Hozzászólások: 1454

Csatlakozás dátuma: 2005. július 26.

Legújabb hozzászólások

This is a limitation Liferay's implementation of the Portlet API. Specifically, the com.liferay.portlet.PortletRequestImpl.isUserInRole(String role) method delegates to the RoleLocalServiceImpl.hasUserRole(long userId, long companyId, String name, boolean inherited) method, which only checks for regular (portal scoped) roles. In other words, it does not have the ability to check for site role membership.

My recommendation would be that you use the rendered attribute instead, and use an EL-expression to test for role membership yourself.

For example in your Facelet view:

1<h:outputText value="some text" rendered="#{backingBean.userPermitted}" />


And in BackingBean.java:

 1
 2@RequestScoped
 3public class BackingBean {
 4
 5   private Boolean userPermitted;
 6
 7   public boolean isUserPermitted() {
 8      if (userPermitted == null) {
 9        userPermitted = ...; // determine if user has site role
10      }
11      return userPermitted;
12   }
13}


Alternatively, if you are checking Liferay portlet permissions (not model permissions), you can use the Liferay Faces Portal dependency to do things like this:

1<h:outputText value="some text" rendered="#{liferay.userHasPortletPermission['some_portlet_permission_name']}" />
mark anderson
RE: how to authenticate against site roles
2012. június 22. 7:38
Válasz

mark anderson

Rangsorolás: New Member

Hozzászólások: 3

Csatlakozás dátuma: 2012. június 19.

Legújabb hozzászólások

Thanks for that Neil,

But how do i determine if user is in the particular site role?

looking at the forums there are several options but which is the most appropriate for this situation? this particular portlet could be used in several different sites.

From the forums it looks like the 'site' roles are stored as 'group' roles so should i use:

1UserGroupRoleLocalServiceUtil.hasUserGroupRole(long userId, long groupId, String roleName)


looking at the below post it would seem i'd need to find the groupid of the site (or community), how do i do that? can i use something like this?:

1ThemeDisplay themeDisplay = (ThemeDisplay)context.getExternalContext().getRequestMap().get(WebKeys.THEME_DISPLAY);
2        long portletGroupId= themeDisplay.getPortletGroupId();


sorry , this is depricated. Looks like i should use .getScopeGroupId()

http://www.liferay.com/community/forums/-/message_boards/message/13776870

Thanks,

Mark
mark anderson
RE: how to authenticate against site roles
2012. június 22. 8:18
Válasz

mark anderson

Rangsorolás: New Member

Hozzászólások: 3

Csatlakozás dátuma: 2012. június 19.

Legújabb hozzászólások

It's ok, i got it working.

For completeness here's the method:

 1public static boolean isUserInRole(String role) {
 2       
 3        ThemeDisplay themeDisplay = (ThemeDisplay)getFacesContextProvider().getFacesContext().getExternalContext().getRequestMap().get(WebKeys.THEME_DISPLAY);
 4        long portletGroupId= themeDisplay.getScopeGroupId();
 5        long userId = themeDisplay.getUserId();
 6        try {
 7            return UserGroupRoleLocalServiceUtil.hasUserGroupRole(userId, portletGroupId, role, true);
 8        } catch (PortalException e) {
 9            logger.error(e);
10            return false;
11        } catch (SystemException e) {
12            logger.error(e);
13            return false;
14        }
15    }


Thanks,

Mark