Search in sources :

Example 1 with UiShowScreenContext

use of io.jmix.ui.accesscontext.UiShowScreenContext in project jmix by jmix-framework.

the class UserActionsButtonImpl method initUserMenuButton.

protected void initUserMenuButton(boolean authenticated) {
    MenuBar.MenuItem userMenuButton = component.addItem("");
    userMenuButton.setDescription(messages.getMessage("userActionsBtnDescription"));
    userMenuButton.setIcon(getIconResource(JmixIcon.USER));
    userMenuButton.setVisible(authenticated);
    UiShowScreenContext showScreenContext = new UiShowScreenContext("settings");
    accessManager.applyRegisteredConstraints(showScreenContext);
    if (showScreenContext.isPermitted()) {
        userMenuButton.addItem(messages.getMessage("settings"), getIconResource(JmixIcon.GEAR), item -> openSettings());
    }
    userMenuButton.addItem(messages.getMessage("logoutBtnDescription"), getIconResource(JmixIcon.SIGN_OUT), item -> logout());
}
Also used : JmixMenuBar(io.jmix.ui.widget.JmixMenuBar) MenuBar(com.vaadin.ui.MenuBar) UiShowScreenContext(io.jmix.ui.accesscontext.UiShowScreenContext)

Example 2 with UiShowScreenContext

use of io.jmix.ui.accesscontext.UiShowScreenContext in project jmix by jmix-framework.

the class JmixApp method routeTopLevelWindowId.

@Override
protected String routeTopLevelWindowId() {
    if (isAnonymousAuthentication()) {
        String screenId = uiProperties.getLoginScreenId();
        if (!windowConfig.hasWindow(screenId)) {
            screenId = uiProperties.getMainScreenId();
        }
        String initialScreenId = uiProperties.getInitialScreenId();
        if (Strings.isNullOrEmpty(initialScreenId)) {
            return screenId;
        }
        if (!windowConfig.hasWindow(initialScreenId)) {
            log.info("Initial screen '{}' is not found", initialScreenId);
            return screenId;
        }
        UiShowScreenContext context = new UiShowScreenContext(initialScreenId);
        accessManager.applyRegisteredConstraints(context);
        if (!context.isPermitted()) {
            log.info("Initial screen '{}' is not permitted", initialScreenId);
            return screenId;
        }
        return initialScreenId;
    } else {
        return uiProperties.getMainScreenId();
    }
}
Also used : UiShowScreenContext(io.jmix.ui.accesscontext.UiShowScreenContext)

Example 3 with UiShowScreenContext

use of io.jmix.ui.accesscontext.UiShowScreenContext in project jmix by jmix-framework.

the class UrlChangeHandler method shouldRedirect.

public boolean shouldRedirect(WindowInfo windowInfo) {
    if (ui.hasAuthenticatedSession()) {
        return false;
    }
    boolean allowAnonymousAccess = uiProperties.isAllowAnonymousAccess();
    UiShowScreenContext showScreenContext = new UiShowScreenContext(windowInfo.getId());
    accessManager.applyRegisteredConstraints(showScreenContext);
    return !allowAnonymousAccess || !showScreenContext.isPermitted();
}
Also used : UiShowScreenContext(io.jmix.ui.accesscontext.UiShowScreenContext)

Example 4 with UiShowScreenContext

use of io.jmix.ui.accesscontext.UiShowScreenContext in project jmix by jmix-framework.

the class UrlChangeHandler method isPermittedToNavigate.

public boolean isPermittedToNavigate(NavigationState requestedState, WindowInfo windowInfo) {
    UiShowScreenContext showScreenContext = new UiShowScreenContext(windowInfo.getId());
    accessManager.applyRegisteredConstraints(showScreenContext);
    if (!showScreenContext.isPermitted()) {
        revertNavigationState();
        throw new AccessDeniedException("screen", windowInfo.getId());
    }
    NavigationFilter.AccessCheckResult navigationAllowed = navigationAllowed(requestedState);
    if (navigationAllowed.isRejected()) {
        if (isNotEmpty(navigationAllowed.getMessage())) {
            showNotification(navigationAllowed.getMessage());
        }
        revertNavigationState();
        return false;
    }
    return true;
}
Also used : AccessDeniedException(io.jmix.core.security.AccessDeniedException) UiShowScreenContext(io.jmix.ui.accesscontext.UiShowScreenContext) AccessCheckResult(io.jmix.ui.navigation.NavigationFilter.AccessCheckResult)

Example 5 with UiShowScreenContext

use of io.jmix.ui.accesscontext.UiShowScreenContext in project jmix by jmix-framework.

the class ScreensHelper method getDefaultBrowseScreen.

@Nullable
public WindowInfo getDefaultBrowseScreen(MetaClass metaClass) {
    WindowInfo browseWindow = windowConfig.findWindowInfo(windowConfig.getBrowseScreenId(metaClass));
    if (browseWindow != null) {
        UiShowScreenContext screenContext = new UiShowScreenContext(browseWindow.getId());
        accessManager.applyRegisteredConstraints(screenContext);
        if (screenContext.isPermitted()) {
            return browseWindow;
        }
    }
    WindowInfo lookupWindow = windowConfig.findWindowInfo(windowConfig.getLookupScreenId(metaClass));
    if (lookupWindow != null) {
        UiShowScreenContext screenContext = new UiShowScreenContext(lookupWindow.getId());
        accessManager.applyRegisteredConstraints(screenContext);
        if (screenContext.isPermitted()) {
            return lookupWindow;
        }
    }
    return null;
}
Also used : UiShowScreenContext(io.jmix.ui.accesscontext.UiShowScreenContext) WindowInfo(io.jmix.ui.WindowInfo) Nullable(javax.annotation.Nullable)

Aggregations

UiShowScreenContext (io.jmix.ui.accesscontext.UiShowScreenContext)6 AccessDeniedException (io.jmix.core.security.AccessDeniedException)2 MenuBar (com.vaadin.ui.MenuBar)1 WindowInfo (io.jmix.ui.WindowInfo)1 AccessCheckResult (io.jmix.ui.navigation.NavigationFilter.AccessCheckResult)1 JmixMenuBar (io.jmix.ui.widget.JmixMenuBar)1 Nullable (javax.annotation.Nullable)1