/** * Get user session attribute. Attribute is a named serializable object bound to session. * * @param name attribute name. The following names have predefined values: * <ul> * <li>userId - current or substituted user ID</li> * <li>userLogin - current or substituted user login in lower case</li> * </ul> * @return attribute value or null if attribute with the given name is not found */ @SuppressWarnings("unchecked") @Nullable public <T> T getAttribute(String name) { if ("userId".equals(name)) return (T) getCurrentOrSubstitutedUser().getId(); if ("userLogin".equals(name)) return (T) getCurrentOrSubstitutedUser().getLoginLowerCase(); else return (T) attributes.get(name); }
private User getCurrentUser() { return getUserSessionSource().getUserSession().getCurrentOrSubstitutedUser(); }
protected void revertToCurrentUser() { UserSessionSource uss = beanLocator.get(UserSessionSource.NAME); UserSession us = uss.getUserSession(); userComboBox.setValue(us.getCurrentOrSubstitutedUser()); }
@Override public LockInfo lock(String name, String id) { LockKey key = new LockKey(name, id); LockInfo lockInfo = locks.get(key); if (lockInfo != null) { log.debug("Already locked: " + lockInfo); return lockInfo; } LockDescriptor ld = getConfig().get(name); if (ld == null) { return new LockNotSupported(); } lockInfo = new LockInfo(userSessionSource.getUserSession().getCurrentOrSubstitutedUser(), name, id); locks.put(key, lockInfo); log.debug("Locked " + name + "/" + id); clusterManager.send(lockInfo); return null; }
protected boolean isOwner(SearchFolder folder) { return userSessionSource.getUserSession().getCurrentOrSubstitutedUser().equals(folder.getUser()); }
protected void initEnabledRules(UserManagementService userManagementService) { addEnabledRule(() -> { Set selected = target.getSelected(); if (!selected.isEmpty()) { return !(selected.contains(userSession.getUser()) || userSession.getCurrentOrSubstitutedUser().equals(target.getSingleSelected())); } return false; }); addEnabledRule(() -> { Set<User> selected = target.getSelected(); if (selected.isEmpty()) return false; List<String> logins = selected.stream() .map(User::getLogin) .collect(Collectors.toList()); return userManagementService.isUsersRemovingAllowed(logins); }); } }
public UserInfo getUserInfo() { User user = userSessionSource.getUserSession().getCurrentOrSubstitutedUser(); UserInfo userInfo = new UserInfo(user); userInfo.setLocale(userSessionSource.getUserSession().getLocale().toString()); return userInfo; } }
@Override public void handle(ExternalLinkContext linkContext) { UUID userId = getUUID(linkContext.getRequestParams().get("user")); assert userId != null; UserSession userSession = App.getInstance().getConnection().getSession(); if (userSession == null) { log.warn("No user session"); return; } if (!userSession.getCurrentOrSubstitutedUser().getId().equals(userId)) { substituteUserAndOpenWindow(linkContext, userId); } else { screenHandler.handle(linkContext); } }
@Override public String createConnectorId(ClientConnector connector) { if (connector instanceof Component) { Component component = (Component) connector; String id = component.getId() == null ? super.createConnectorId(connector) : component.getId(); UserSession session = getAttribute(UserSession.class); String login = null; String locale = null; if (session != null) { login = session.getCurrentOrSubstitutedUser().getLogin(); if (session.getLocale() != null) { locale = session.getLocale().toLanguageTag(); } } StringBuilder idParts = new StringBuilder(); if (login != null) { idParts.append(login); } if (locale != null) { idParts.append(locale); } idParts.append(id); return toLongNumberString(idParts.toString()); } return super.createConnectorId(connector); }
public String loadReportsList() { checkCanReadEntity(metadata.getClassNN(Report.class)); LoadContext<Report> loadContext = new LoadContext<>(Report.class); loadContext.setView( new View(Report.class) .addProperty("id") .addProperty("name") .addProperty("code")) .setQueryString("select r from report$Report r where r.restAccess = true"); reportSecurityManager.applySecurityPolicies(loadContext, null, userSessionSource.getUserSession().getCurrentOrSubstitutedUser()); List<Report> reports = dataManager.loadList(loadContext); List<ReportInfo> objects = reports.stream() .map(this::mapToReportInfo) .collect(Collectors.toList()); return createGson().toJson(objects); }
protected void checkImportPermissions(Folder folder) { UserSession userSession = userSessionSource.getUserSession(); if (folder instanceof SearchFolder) { SearchFolder searchFolder = (SearchFolder) folder; User currentUser = userSession.getCurrentOrSubstitutedUser(); if (searchFolder.getUser() != null && !currentUser.equals(searchFolder.getUser())) { throw new AccessDeniedException(PermissionType.ENTITY_OP, Folder.class.getSimpleName()); } if (searchFolder.getUser() == null && !userSession.isSpecificPermitted("cuba.gui.searchFolder.global")) { throw new AccessDeniedException(PermissionType.ENTITY_OP, Folder.class.getSimpleName()); } } if (folder instanceof AppFolder) { if (!userSession.isSpecificPermitted("cuba.gui.appFolder.global")) { throw new AccessDeniedException(PermissionType.ENTITY_OP, Folder.class.getSimpleName()); } } }
/** * Load filter entities from database and saves them in {@code filterEntities} collection. */ protected void loadFilterEntities() { LoadContext<FilterEntity> ctx = LoadContext.create(FilterEntity.class); ctx.setView("app"); ctx.setQueryString("select f from sec$Filter f left join f.user u " + "where f.componentId = :component and (u.id = :userId or u is null) order by f.name") .setParameter("component", ComponentsHelper.getFilterComponentPath(filter)) .setParameter("userId", userSessionSource.getUserSession().getCurrentOrSubstitutedUser().getId()); filterEntities = new ArrayList<>(dataService.loadList(ctx)); }
private void checkLoad() { if (presentations == null) { DataService ds = AppBeans.get(DataService.NAME); LoadContext ctx = new LoadContext(Presentation.class); ctx.setView("app"); UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME); UserSession session = sessionSource.getUserSession(); User user = session.getCurrentOrSubstitutedUser(); ctx.setQueryString("select p from sec$Presentation p " + "where p.componentId = :component and (p.user is null or p.user.id = :userId)") .setParameter("component", name) .setParameter("userId", user.getId()); final List<Presentation> list = ds.loadList(ctx); presentations = new LinkedHashMap<>(list.size()); for (final Presentation p : list) { presentations.put(p.getId(), p); } } }
protected void addProcAttachment(FileDescriptor file) { ProcAttachment procAttachment = metadata.create(ProcAttachment.class); procAttachment.setFile(file); procAttachment.setProcInstance(procInstance); procAttachment.setProcTask(procTask); procAttachment.setAuthor(userSessionSource.getUserSession().getCurrentOrSubstitutedUser()); procAttachmentsDs.addItem(procAttachment); }
protected void initAdHocFilter() { adHocFilter = metadata.create(FilterEntity.class); String emptyXml = filterParser.getXml(new ConditionsTree(), Param.ValueProperty.VALUE); adHocFilter.setXml(emptyXml); adHocFilter.setComponentId(ComponentsHelper.getFilterComponentPath(filter)); adHocFilter.setUser(userSessionSource.getUserSession().getCurrentOrSubstitutedUser()); adHocFilter.setName(getMainMessage("filter.adHocFilter")); }
protected void setComponentsEditable() { if (getItem().getStartDate() != null) { procDefinitionLookup.setEditable(false); } if (getItem().getStartedBy() != null && !userSession.getCurrentOrSubstitutedUser().equals(getItem().getStartedBy())) { entityNameLookup.setEditable(false); entityIdPickerField.setEditable(false); entityEditorNameField.setEditable(false); } }
protected void commit() { Presentations presentations = component.getPresentations(); Document doc = DocumentHelper.createDocument(); doc.setRootElement(doc.addElement("presentation")); component.saveSettings(doc.getRootElement()); String xml = Dom4j.writeDocument(doc, false); presentation.setXml(xml); presentation.setName(nameField.getValue()); presentation.setAutoSave(autoSaveField.getValue()); presentation.setDefault(defaultField.getValue()); User user = sessionSource.getUserSession().getCurrentOrSubstitutedUser(); boolean userOnly = !allowGlobalPresentations || !BooleanUtils.isTrue(globalField.getValue()); presentation.setUser(userOnly ? user : null); if (log.isTraceEnabled()) { log.trace(String.format("XML: %s", Dom4j.writeDocument(doc, true))); } if (isNew) { presentations.add(presentation); } else { presentations.modify(presentation); } presentations.commit(); addCloseListener(e -> { if (isNew) { component.applyPresentation(presentation.getId()); } }); }
protected Report loadReportInternal(String entityId) { checkCanReadEntity(metadata.getClassNN(Report.class)); LoadContext<Report> loadContext = new LoadContext<>(Report.class); loadContext.setView(ReportService.MAIN_VIEW_NAME) .setQueryString("select r from report$Report r where r.id = :id and r.restAccess = true") .setParameter("id", getReportIdFromString(entityId)); reportSecurityManager.applySecurityPolicies(loadContext, null, userSessionSource.getUserSession().getCurrentOrSubstitutedUser()); Report report = dataManager.load(loadContext); checkEntityIsNotNull(metadata.getClassNN(Report.class).getName(), entityId, report); return report; }
protected void applyFilter(Filter filterComponent) { Metadata metadata = AppBeans.get(Metadata.class); FilterEntity filterEntity = metadata.create(FilterEntity.class); filterEntity.setComponentId(ComponentsHelper.getFilterComponentPath(filterComponent)); filterEntity.setName(messages.getMainMessage("dynamicAttributes.entity.filter")); filterEntity.setXml(createFilterXml(filterComponent)); UserSession userSession = AppBeans.get(UserSessionSource.class).getUserSession(); filterEntity.setUser(userSession.getCurrentOrSubstitutedUser()); filterComponent.setFilterEntity(filterEntity); filterComponent.apply(true); }
protected void applyFilter(Filter component, Collection<? extends Entity> selectedParents, RelatedScreenDescriptor descriptor, MetaDataDescriptor metaDataDescriptor) { FilterEntity filterEntity = metadata.create(FilterEntity.class); filterEntity.setComponentId(ComponentsHelper.getFilterComponentPath(component)); if (StringUtils.isNotEmpty(descriptor.getFilterCaption())) { filterEntity.setName(descriptor.getFilterCaption()); } else { MetaProperty metaProperty = metaDataDescriptor.getMetaProperty(); filterEntity.setName(messages.getMainMessage("actions.Related.Filter") + " " + messageTools.getPropertyCaption(metaProperty.getDomain(), metaProperty.getName())); } MetaClass effectiveMetaClass = extendedEntities.getEffectiveMetaClass(metaDataDescriptor.getRelatedMetaClass()); filterEntity.setXml(getRelatedEntitiesFilterXml(effectiveMetaClass, selectedParents, component, metaDataDescriptor)); filterEntity.setUser(userSessionSource.getUserSession().getCurrentOrSubstitutedUser()); component.setFilterEntity(filterEntity); component.apply(Filter.FilterOptions.create() .setNotifyInvalidConditions(true) .setLoadData(false)); }