Generic UI role based homepage

Is it possible to have different homepages after a user is logged in based on his role?

Like the ‘Administrator’ will see a page with side menu showing a admin page and a ‘Backoffice’ user has for example a top menu with a backoffice page.

I get the feeling there is only one fixed layout for all userroles.

Hello @martijn.raats

The cuba.web.mainScreenId property defines the screen that will be used as Main screen, but the platform does not have a mechanism to define the property value based on role.

You can override DefaultApp bean and use DefaultApp#routeTopLeveleWindowIdmethod to define the main screen based on user role:
SampleApp

package com.company.sample.web;

import com.haulmont.cuba.security.entity.UserRole;
import com.haulmont.cuba.security.global.UserSession;
import com.haulmont.cuba.web.DefaultApp;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

public class SampleApp extends DefaultApp {

    @Override
    protected String routeTopLevelWindowId() {
        if (connection.isAuthenticated()) {
            UserSession userSession = userSessionSource.getUserSession();
            List<UserRole> roles = userSession.getUser().getUserRoles();
            if (!CollectionUtils.isEmpty(roles)) {
                List<String> roleNames = roles.stream().map(UserRole::getRoleName).collect(Collectors.toList());
                if (roleNames.contains("system-full-access")) {
                    return "topMenuMainScreen";
                } else {
                    return "main";
                }
            }
        }

        return super.routeTopLevelWindowId();
    }
}

web-spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:gui="http://schemas.haulmont.com/cuba/spring/cuba-gui.xsd">

    <!-- Annotation-based beans -->
    <context:component-scan base-package="com.company.sample"/>

    <gui:screens base-packages="com.company.sample.web"/>

    <bean name="cuba_App" class="com.company.sample.web.SampleApp" scope="vaadin"/>
</beans>

If the User has a system-full-access user role than the main screen with the top menu will be displayed, otherwise the main screen with side menu.

Regards,
Gleb