Search in sources :

Example 71 with UserSession

use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.

the class WebUserIndicator method refreshUserSubstitutions.

@Override
public void refreshUserSubstitutions() {
    component.removeAllComponents();
    UserSessionSource uss = AppBeans.get(UserSessionSource.NAME);
    List<UserSubstitution> substitutions = getUserSubstitutions();
    User user = uss.getUserSession().getUser();
    AppUI ui = AppUI.getCurrent();
    String substitutedUserCaption = getSubstitutedUserCaption(user);
    if (substitutions.isEmpty()) {
        userComboBox = null;
        userNameLabel = new Label(substitutedUserCaption);
        userNameLabel.setStyleName("c-user-select-label");
        userNameLabel.setSizeUndefined();
        if (ui.isTestMode()) {
            userNameLabel.setCubaId("currentUserLabel");
        }
        component.addComponent(userNameLabel);
        component.setDescription(substitutedUserCaption);
    } else {
        userNameLabel = null;
        userComboBox = new CubaComboBox();
        userComboBox.setFilteringMode(FilteringMode.CONTAINS);
        userComboBox.setNullSelectionAllowed(false);
        userComboBox.setImmediate(true);
        if (ui.isTestMode()) {
            userComboBox.setCubaId("substitutedUserSelect");
            userComboBox.setId(ui.getTestIdManager().getTestId("substitutedUserSelect"));
        }
        userComboBox.setStyleName("c-user-select-combobox");
        userComboBox.addItem(user);
        userComboBox.setItemCaption(user, substitutedUserCaption);
        for (UserSubstitution substitution : substitutions) {
            User substitutedUser = substitution.getSubstitutedUser();
            userComboBox.addItem(substitutedUser);
            userComboBox.setItemCaption(substitutedUser, getSubstitutedUserCaption(substitutedUser));
        }
        UserSession session = uss.getUserSession();
        userComboBox.select(session.getSubstitutedUser() == null ? session.getUser() : session.getSubstitutedUser());
        userComboBox.addValueChangeListener(new SubstitutedUserChangeListener(userComboBox));
        component.addComponent(userComboBox);
        component.setDescription(null);
    }
    adjustWidth();
    adjustHeight();
}
Also used : User(com.haulmont.cuba.security.entity.User) CubaComboBox(com.haulmont.cuba.web.toolkit.ui.CubaComboBox) UserSession(com.haulmont.cuba.security.global.UserSession) Label(com.vaadin.ui.Label) UserSubstitution(com.haulmont.cuba.security.entity.UserSubstitution) AppUI(com.haulmont.cuba.web.AppUI)

Example 72 with UserSession

use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.

the class WebUserIndicator method revertToCurrentUser.

protected void revertToCurrentUser() {
    UserSessionSource uss = AppBeans.get(UserSessionSource.NAME);
    UserSession us = uss.getUserSession();
    userComboBox.select(us.getCurrentOrSubstitutedUser());
}
Also used : UserSession(com.haulmont.cuba.security.global.UserSession)

Example 73 with UserSession

use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.

the class SpecificPermissionTreeDatasource method filterPermitted.

private Tree<BasicPermissionTarget> filterPermitted(Tree<BasicPermissionTarget> permissions) {
    UserSession session = uss.getUserSession();
    List<Node<BasicPermissionTarget>> newRootNodes = permissions.getRootNodes().stream().map(root -> filterNode(session, root)).filter(// empty nodes
    root -> root.getNumberOfChildren() > 0).collect(Collectors.toCollection(LinkedList::new));
    return new Tree<>(newRootNodes);
}
Also used : UserSession(com.haulmont.cuba.security.global.UserSession) BasicPermissionTarget(com.haulmont.cuba.gui.app.security.entity.BasicPermissionTarget) List(java.util.List) PermissionConfig(com.haulmont.cuba.gui.config.PermissionConfig) Tree(com.haulmont.bali.datastruct.Tree) Node(com.haulmont.bali.datastruct.Node) LinkedList(java.util.LinkedList) AppBeans(com.haulmont.cuba.core.global.AppBeans) UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) Collectors(java.util.stream.Collectors) UserSession(com.haulmont.cuba.security.global.UserSession) Node(com.haulmont.bali.datastruct.Node) Tree(com.haulmont.bali.datastruct.Tree)

Example 74 with UserSession

use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.

the class WindowCreationHelper method applyUiPermissions.

/**
 * Apply UI permissions to a frame.
 *
 * @param container frame
 */
public static void applyUiPermissions(Frame container) {
    Window window = container instanceof Window ? (Window) container : ComponentsHelper.getWindow(container);
    if (window == null) {
        log.warn(String.format("Unable to find window for container %s with id '%s'", container.getClass(), container.getId()));
        return;
    }
    UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
    UserSession userSession = sessionSource.getUserSession();
    String screenId = window.getId();
    Map<String, Integer> uiPermissions = userSession.getPermissionsByType(PermissionType.UI);
    for (Map.Entry<String, Integer> permissionEntry : uiPermissions.entrySet()) {
        String target = permissionEntry.getKey();
        String targetComponentId = getTargetComponentId(target, screenId);
        if (targetComponentId != null) {
            if (targetComponentId.contains("[")) {
                applyCompositeComponentPermission(window, screenId, permissionEntry.getValue(), targetComponentId);
            } else if (targetComponentId.contains(">")) {
                applyComponentActionPermission(window, screenId, permissionEntry.getValue(), targetComponentId);
            } else {
                applyComponentPermission(window, screenId, permissionEntry.getValue(), targetComponentId);
            }
        }
    }
}
Also used : Window(com.haulmont.cuba.gui.components.Window) UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) UserSession(com.haulmont.cuba.security.global.UserSession) Map(java.util.Map)

Example 75 with UserSession

use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.

the class Param method createDateField.

protected Component createDateField(Class javaClass, final ValueProperty valueProperty) {
    UserSession userSession = userSessionSource.getUserSession();
    boolean supportTimezones = false;
    boolean dateOnly = false;
    if (property != null) {
        TemporalType tt = (TemporalType) property.getAnnotations().get(MetadataTools.TEMPORAL_ANN_NAME);
        dateOnly = (tt == TemporalType.DATE);
        Object ignoreUserTimeZone = metadataTools.getMetaAnnotationValue(property, IgnoreUserTimeZone.class);
        supportTimezones = !dateOnly && !Boolean.TRUE.equals(ignoreUserTimeZone);
    } else if (javaClass.equals(java.sql.Date.class)) {
        dateOnly = true;
        if (useUserTimeZone) {
            supportTimezones = true;
        }
    } else {
        supportTimezones = true;
    }
    if (inExpr) {
        ListEditor listEditor = componentsFactory.createComponent(ListEditor.class);
        ListEditor.ItemType itemType = dateOnly ? ListEditor.ItemType.DATE : ListEditor.ItemType.DATETIME;
        listEditor.setItemType(itemType);
        if (userSession.getTimeZone() != null && supportTimezones) {
            listEditor.setTimeZone(userSession.getTimeZone());
        }
        initListEditor(listEditor, valueProperty);
        return listEditor;
    }
    DateField dateField = componentsFactory.createComponent(DateField.class);
    DateField.Resolution resolution;
    String formatStr;
    Messages messages = AppBeans.get(Messages.NAME);
    if (dateOnly) {
        resolution = com.haulmont.cuba.gui.components.DateField.Resolution.DAY;
        formatStr = messages.getMainMessage("dateFormat");
    } else {
        resolution = com.haulmont.cuba.gui.components.DateField.Resolution.MIN;
        formatStr = messages.getMainMessage("dateTimeFormat");
    }
    dateField.setResolution(resolution);
    dateField.setDateFormat(formatStr);
    if (userSession.getTimeZone() != null && supportTimezones) {
        dateField.setTimeZone(userSession.getTimeZone());
    }
    dateField.addValueChangeListener(e -> _setValue(e.getValue(), valueProperty));
    dateField.setValue(_getValue(valueProperty));
    return dateField;
}
Also used : UserSession(com.haulmont.cuba.security.global.UserSession) TemporalType(javax.persistence.TemporalType)

Aggregations

UserSession (com.haulmont.cuba.security.global.UserSession)127 SecurityContext (com.haulmont.cuba.core.sys.SecurityContext)29 LoginWorker (com.haulmont.cuba.security.app.LoginWorker)25 TestUserSessionSource (com.haulmont.cuba.testsupport.TestUserSessionSource)24 LoginException (com.haulmont.cuba.security.global.LoginException)23 Test (org.junit.Test)19 User (com.haulmont.cuba.security.entity.User)17 UUID (java.util.UUID)16 IOException (java.io.IOException)14 NoUserSessionException (com.haulmont.cuba.security.global.NoUserSessionException)12 ArrayList (java.util.ArrayList)11 Locale (java.util.Locale)11 List (java.util.List)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 FileStorageException (com.haulmont.cuba.core.global.FileStorageException)7 LogFileNotFoundException (com.haulmont.cuba.core.sys.logging.LogFileNotFoundException)6 UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)5 FileDescriptor (com.haulmont.cuba.core.entity.FileDescriptor)4