/** * Current portal session * * @return current user session instance */ public static PortalSession getUserSession() { return (PortalSession) getSource().getUserSession(); }
@Override public Object evaluateConstraintScript(Entity entity, String groovyScript) { Map<String, Object> context = new HashMap<>(); context.put("__entity__", entity); context.put("parse", new MethodClosure(this, "parseValue")); context.put("userSession", userSessionSource.getUserSession()); fillGroovyConstraintsContext(context); return scripting.evaluateGroovy(groovyScript.replace("{E}", "__entity__"), context); }
private Tree<BasicPermissionTarget> filterPermitted(Tree<BasicPermissionTarget> permissions) { UserSession session = uss.getUserSession(); List<Node<BasicPermissionTarget>> newRootNodes = permissions.getRootNodes().stream() .map(root -> filterNode(session, root)) .filter(root -> root.getNumberOfChildren() > 0) //empty nodes .collect(Collectors.toCollection(LinkedList::new)); return new Tree<>(newRootNodes); }
@Override public EntitySnapshot createSnapshot(Entity entity, View view, Date snapshotDate) { User user = userSessionSource.getUserSession().getUser(); return createSnapshot(entity, view, snapshotDate, user); }
protected List<ConstraintData> getConstraints(MetaClass metaClass) { UserSession userSession = userSessionSource.getUserSession(); MetaClass mainMetaClass = extendedEntities.getOriginalOrThisMetaClass(metaClass); List<ConstraintData> constraints = new ArrayList<>(); constraints.addAll(userSession.getConstraints(mainMetaClass.getName())); for (MetaClass parent : mainMetaClass.getAncestors()) { constraints.addAll(userSession.getConstraints(parent.getName())); } return constraints; }
@Override protected Locale getUserLocale() { return userSessionSource.checkCurrentUserSession() ? userSessionSource.getUserSession().getLocale() : messageTools.getDefaultLocale(); }
@Override public String getCurrentUserLogin() { return userSessionSource.checkCurrentUserSession() ? userSessionSource.getUserSession().getUser().getLogin() : null; }
protected void revertToCurrentUser() { UserSessionSource uss = beanLocator.get(UserSessionSource.NAME); UserSession us = uss.getUserSession(); userComboBox.setValue(us.getCurrentOrSubstitutedUser()); }
@PostConstruct protected void init() { UserSession userSession = AppBeans.get(UserSessionSource.class).getUserSession(); setUser(userSession.getUser()); setSubstitutedUser(userSession.getSubstitutedUser()); } }
protected boolean isEntityAttrPermitted(MetaClass metaClass, MetaPropertyPath propertyPath, EntityAttrAccess access) { MetaClass originalMetaClass = extendedEntities.getOriginalMetaClass(metaClass); if (originalMetaClass != null) { metaClass = originalMetaClass; } return userSessionSource.getUserSession() .isEntityAttrPermitted(metaClass, propertyPath.getMetaProperty().getName(), access); }
protected boolean isGlobalPresentation() { Presentations presentations = table.getPresentations(); Presentation presentation = presentations.getCurrent(); return presentation != null && (!presentations.isGlobal(presentation) || userSessionSource.getUserSession().isSpecificPermitted("cuba.gui.presentations.global")); } }
protected boolean needToApplyInMemoryReadConstraints(LoadContext context) { return isAuthorizationRequired(context) && userSessionSource.getUserSession().hasConstraints() && needToApplyByPredicate(context, metaClass -> security.hasInMemoryConstraints(metaClass, ConstraintOperationType.READ, ConstraintOperationType.ALL)); }
protected boolean needToFilterByInMemoryReadConstraints(LoadContext context) { return userSessionSource.getUserSession().hasConstraints() && security.hasInMemoryConstraints(metadata.getClassNN(context.getMetaClass()), ConstraintOperationType.READ, ConstraintOperationType.ALL); }
protected List<UserSubstitution> getUserSubstitutions() { UserManagementService userManagementService = beanLocator.get(UserManagementService.NAME); UserSessionSource uss = beanLocator.get(UserSessionSource.NAME); return userManagementService.getSubstitutedUsers(uss.getUserSession().getUser().getId()); }
@Inject public void setBeanLocator(BeanLocator beanLocator) { super.setBeanLocator(beanLocator); UserSessionSource uss = beanLocator.get(UserSessionSource.NAME); TimeZone timeZone = uss.getUserSession().getTimeZone(); TimeZones timeZones = beanLocator.get(TimeZones.NAME); component.setValue(timeZones.getDisplayNameShort(timeZone)); if (timeZone == null) { // hidden by default if timeZone is null setVisible(false); } }
@Override public String loadOwnLocale() { try (Transaction tx = persistence.createTransaction()) { EntityManager em = persistence.getEntityManager(); User user = em.find(User.class, userSessionSource.getUserSession().getUser().getId(), "user.locale"); if (user == null) throw new EntityAccessException(User.class, userSessionSource.getUserSession().getUser().getId()); tx.commit(); return user.getLanguage(); } }
/** * 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)); }
@Nullable protected UserSetting findUserSettings(ClientType clientType, String name) { EntityManager em = persistence.getEntityManager(); TypedQuery<UserSetting> q = em.createQuery( "select s from sec$UserSetting s where s.user.id = ?1 and s.name =?2 and s.clientType = ?3", UserSetting.class); q.setParameter(1, userSessionSource.getUserSession().getUser().getId()); q.setParameter(2, name); q.setParameter(3, clientType == null ? null : clientType.getId()); return q.getFirstResult(); }
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 checkOperationPermitted(Entity entity, ConstraintOperationType operationType) { if (userSessionSource.getUserSession().hasConstraints() && security.hasConstraints(entity.getMetaClass()) && !security.isPermitted(entity, operationType)) { throw new RowLevelSecurityException( operationType + " is not permitted for entity " + entity, entity.getMetaClass().getName(), operationType); } }