Search in sources :

Example 1 with App

use of com.haulmont.cuba.web.App in project cuba by cuba-platform.

the class WebTimeField method updateWidth.

protected void updateWidth() {
    if (!App.isBound()) {
        return;
    }
    App app = App.getInstance();
    ThemeConstants theme = app.getThemeConstants();
    int digitWidth = theme.getInt("cuba.web.WebTimeField.digitWidth");
    int digitPadding = theme.getInt("cuba.web.WebTimeField.digitPadding");
    int separatorWidth = theme.getInt("cuba.web.WebTimeField.separatorWidth");
    int partsCount = isAmPmUsed() ? 1 : 0;
    int newWidth = isAmPmUsed() ? digitWidth + digitPadding : digitPadding;
    if (showSeconds) {
        newWidth = newWidth + digitWidth;
        partsCount += 1;
    }
    switch(resolution) {
        case HOUR:
            partsCount += 1;
            newWidth = digitWidth + newWidth;
            break;
        case MIN:
        case SEC:
            partsCount += 2;
            newWidth = digitWidth * 2 + newWidth;
            break;
    }
    newWidth += (partsCount - 1) * separatorWidth;
    component.setWidth(newWidth + "px");
}
Also used : App(com.haulmont.cuba.web.App) ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants)

Example 2 with App

use of com.haulmont.cuba.web.App in project cuba by cuba-platform.

the class ChangeSubstUserAction method actionPerform.

@Override
public void actionPerform(com.haulmont.cuba.gui.components.Component component) {
    AppUI ui = AppUI.getCurrent();
    WebScreens screens = (WebScreens) ui.getScreens();
    screens.checkModificationsAndCloseAll().then(() -> {
        App app = ui.getApp();
        try {
            app.getConnection().substituteUser(user);
            doAfterChangeUser();
        } catch (javax.persistence.NoResultException e) {
            Messages messages = AppBeans.get(Messages.NAME);
            app.getWindowManager().showNotification(messages.formatMainMessage("substitutionNotPerformed", user.getName()), Frame.NotificationType.WARNING);
            doRevert();
        }
    }).otherwise(this::doRevert);
}
Also used : WebScreens(com.haulmont.cuba.web.sys.WebScreens) App(com.haulmont.cuba.web.App) Messages(com.haulmont.cuba.core.global.Messages) AppUI(com.haulmont.cuba.web.AppUI)

Example 3 with App

use of com.haulmont.cuba.web.App in project cuba by cuba-platform.

the class WebUserSessionSource method checkCurrentUserSession.

@Override
public boolean checkCurrentUserSession() {
    if (App.isBound()) {
        App app = App.getInstance();
        Connection connection = app.getConnection();
        return connection.isConnected() && connection.getSession() != null;
    } else {
        SecurityContext securityContext = AppContext.getSecurityContext();
        if (securityContext == null) {
            return false;
        }
        if (securityContext.getSession() != null) {
            return true;
        } else if (AppContext.isStarted()) {
            try {
                getUserSessionFromMiddleware(securityContext.getSessionId());
                return true;
            } catch (Exception e) {
                return false;
            }
        } else
            return false;
    }
}
Also used : App(com.haulmont.cuba.web.App) Connection(com.haulmont.cuba.web.Connection) SecurityContext(com.haulmont.cuba.core.sys.SecurityContext) MismatchedUserSessionException(com.haulmont.cuba.security.global.MismatchedUserSessionException)

Example 4 with App

use of com.haulmont.cuba.web.App in project cuba by cuba-platform.

the class ChangePasswordAfterLoginListener method onApplicationEvent.

@Override
public void onApplicationEvent(AppLoggedInEvent event) {
    App app = event.getApp();
    Connection connection = app.getConnection();
    if (connection.isAuthenticated() && !isLoggedInWithExternalAuth(connection.getSessionNN())) {
        User user = connection.getSessionNN().getUser();
        // Change password on logon
        if (Boolean.TRUE.equals(user.getChangePasswordAtNextLogon())) {
            WindowManager wm = app.getWindowManager();
            for (Window window : wm.getOpenWindows()) {
                window.setEnabled(false);
            }
            WindowInfo changePasswordDialog = windowConfig.getWindowInfo("sec$User.changePassword");
            Window changePasswordWindow = wm.openWindow(changePasswordDialog, WindowManager.OpenType.DIALOG.closeable(false), ParamsMap.of("cancelEnabled", Boolean.FALSE));
            changePasswordWindow.addCloseListener(actionId -> {
                for (Window window : wm.getOpenWindows()) {
                    window.setEnabled(true);
                }
            });
        }
    }
}
Also used : App(com.haulmont.cuba.web.App) Window(com.haulmont.cuba.gui.components.Window) User(com.haulmont.cuba.security.entity.User) Connection(com.haulmont.cuba.web.Connection) WindowManager(com.haulmont.cuba.gui.WindowManager) WindowInfo(com.haulmont.cuba.gui.config.WindowInfo)

Example 5 with App

use of com.haulmont.cuba.web.App in project cuba by cuba-platform.

the class LegacyLoginEventsForwarder method appStarted.

@Order(Events.HIGHEST_PLATFORM_PRECEDENCE + 10)
@EventListener
protected void appStarted(AppStartedEvent event) {
    App app = event.getApp();
    Locale locale = app.getLocale();
    Principal principal = getSessionPrincipal();
    // Login on start only on first request from user
    if (isTryLoginOnStart() && principal != null && webAuthConfig.getExternalAuthentication()) {
        String userName = principal.getName();
        log.debug("Trying to login after external authentication as {}", userName);
        try {
            app.getConnection().loginAfterExternalAuthentication(userName, locale);
        } catch (LoginException e) {
            log.trace("Unable to login on start", e);
        } finally {
            // Close attempt login on start
            setTryLoginOnStart(false);
        }
    }
}
Also used : App(com.haulmont.cuba.web.App) Locale(java.util.Locale) LoginException(com.haulmont.cuba.security.global.LoginException) Principal(java.security.Principal) Order(org.springframework.core.annotation.Order) EventListener(org.springframework.context.event.EventListener)

Aggregations

App (com.haulmont.cuba.web.App)11 AppUI (com.haulmont.cuba.web.AppUI)4 Connection (com.haulmont.cuba.web.Connection)4 Messages (com.haulmont.cuba.core.global.Messages)3 WindowInfo (com.haulmont.cuba.gui.config.WindowInfo)2 User (com.haulmont.cuba.security.entity.User)2 Page (com.vaadin.server.Page)2 List (java.util.List)2 Locale (java.util.Locale)2 Logger (org.slf4j.Logger)2 ClientConfig (com.haulmont.cuba.client.ClientConfig)1 DataService (com.haulmont.cuba.core.app.DataService)1 Entity (com.haulmont.cuba.core.entity.Entity)1 BeanLocator (com.haulmont.cuba.core.global.BeanLocator)1 Configuration (com.haulmont.cuba.core.global.Configuration)1 LoadContext (com.haulmont.cuba.core.global.LoadContext)1 TimeSource (com.haulmont.cuba.core.global.TimeSource)1 BeanLocatorAware (com.haulmont.cuba.core.sys.BeanLocatorAware)1 SecurityContext (com.haulmont.cuba.core.sys.SecurityContext)1 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)1