Thursday, 11 June 2015

Custom Landing Page Using hook Based On Role

Step 1:

Define portal.properties in WEB-INF/liferay-hook.xml.

<hook>
    <portal-properties>portal.properties</portal-properties>
</hook>  

Step 2:

Go to WEB-INF/src/portal.properties and define the following.

 login.events.post=CustomLandingPage


Step 3:

Go to WEB-INF/src and create new class "CustomLandingPage.java"

public class CustomLandingPage extends Action {

    @Override
    public void run(HttpServletRequest request, HttpServletResponse response) {

        try {
            String roleName =null;
            User users= PortalUtil.getUser(request);
            long []roleIds = users.getRoleIds();
            LastPath publiclastPath= null;
            for(long i:roleIds){
                Role role = RoleLocalServiceUtil.getRole(i);
                roleName = role.getName();
                
                if(roleName.equalsIgnoreCase("Role name")){
                     publiclastPath = new LastPath(StringPool.BLANK, "specific page path where page to land");
                     HttpSession session = request.getSession();
                       session.setAttribute(WebKeys.LAST_PATH, publiclastPath);
                       break;
                }
                
            }
        }
        
        catch (Exception e) {
        }
    
    }

No comments:

Post a Comment