Liferay 7 Role/ Permission issue : You do not have the roles required to access this portlet

2.6k Views Asked by At

I created a PortletMVC in Liferay 7.3.0 it is deployed successfully in Tomcat 9 but when I drag it in the portal, I cannot see it and the message displayed is the following :

" You do not have the roles required to access this portlet.
" 

[Image]

enter image description here

I checked the permission of the page it was public and the guest can view it,

enter image description here

Can anyone please help if there is something wrong thanks. This is the classController:

@Component(
    immediate = true, 
    property = {
            "path=/login/login",
            "javax.portlet.security-role-ref=guest,power-user,user",
    },
    service = StrutsPortletAction.class
)
public class BladePortletAction extends BaseStrutsPortletAction {

    @Override
    public void processAction(
            StrutsPortletAction originalStrutsPortletAction,
            PortletConfig portletConfig, ActionRequest actionRequest,
            ActionResponse actionResponse)
        throws Exception {....}

the console display :

[SecurityPortletContainerWrapper:235] Invalid portlet ID /app_WAR_app
2

There are 2 best solutions below

0
iLyas On BEST ANSWER

As the error says:

[SecurityPortletContainerWrapper:235] Invalid portlet ID /app_WAR_app

You didn't attach a unique ID to your portlet yet, you should know that in Liferay, every portlet have a unique ID (KEY) using the property javax.portlet.name

Take this code as an example:

@Component(
        immediate = true,
        property = {
                "javax.portlet.name=com_fr_bladeExamplePortlet"
        },
        properties = "OSGI-INF/portlet.properties",
        service = Portlet.class
)
public class SearchPortlet extends MVCPortlet {
}

If you are using Liferay DXP, I recommend you to work with MVCPortlet, it's simple, light, effective and ease of use.

Liferay MVC Porlet

Best regards,

2
Peter Petrekanics On

From your code I can see that you are using: BaseStrutsPortletAction but it is not the same as MVCPortlet. Please note that since Liferay 7.0, the BaseStrutsPortletAction mechanism no longer applies for most portlets because Liferay no longer use Struts Actions, but uses Liferay MVCCommands instead, see:

https://help.liferay.com/hc/en-us/articles/360029005292-Upgrading-Struts-Action-Hooks https://liferay.dev/forums/-/message_boards/message/96576834

I recommend using Liferay Developer Studio, that way you can see which classes/methods are available during portlet development.

In case you need further assistance, I am happy to help, just please send more detailed information like: what you would like to achieve, and more detailed steps like:

  1. Downloaded the Liferay Portal from: https://sourceforge.net/projects/lportal/files/Liferay%20Portal/7.3.0%20GA1/liferay-ce-portal-tomcat-7.3.0-ga1-20200127150653953.tar.gz/download
  2. Executed:
    blade update
    mkdir lr_workspace
    blade init
  3. Edited: gradle.properties and ensured it contains Liferay 7.3.0 specific values: liferay.version.default=7.3 profile.name=gradle liferay.workspace.bundle.url=https://releases-cdn.liferay.com/portal/7.3.0-ga1/liferay-ce-portal-tomcat-7.3.0-ga1-20200127150653953.tar.gz app.server.tomcat.version=9.0.33 liferay.workspace.target.platform.version=7.3.0 target.platform.index.sources=false
  4. Created my Portlet by executing: blade create -t mvc-portlet -v 7.3 -p com.liferay.test MVCPortlet7303

etc.
Kind Regards,
Peter