List of usage examples for org.hibernate Session enableFilter
Filter enableFilter(String filterName);
From source file:gov.nih.nci.caarray.util.CaArrayHibernateHelperImpl.java
License:BSD License
/** * {@inheritDoc}/*from w ww.j a va2 s . com*/ */ @Override public Session getCurrentSession() { Session result = super.getCurrentSession(); if (filtersEnabled && !securityFiltersEnabledInSession(result)) { InstanceLevelSecurityHelper.initializeFiltersForGroups(getGroupNames(), result, SecurityUtils.getAuthorizationManager()); } result.enableFilter("BiomaterialFilter"); return result; }
From source file:gov.nih.nci.security.authorization.instancelevel.InstanceLevelSecurityHelper.java
License:BSD License
/** * This method initializes the filter that are already added to the Sessionfactory. * <br>// w ww.j a v a 2 s .com * This method also initializes the defined filters configured in HBM/Classes/Packages based on the definedFilterNamesMap. * If definedFilterNamesMap contains 'ALL' as the Filter Name (key) then all defined filters are enabled. * <br> * This method first obtains the list of all the defined filters from the SessionFactory in the passes Session object. * It then just iterates through the filter list and sets the group names and the application name parameter. * * @param groupNames The names of the groups which are invoking the query * @param session The Hibernate Session initialized to execute this query * @param authorizationManager The CSM AuthorizationManager instance for this application * @param definedFilterNamesMap - Map of defined Filter Names and string value ( enable / disable ) to indicate that the filter should be enabled of disabled.<br>. * */ public static void initializeFiltersForGroups(String[] groupNames, Session session, AuthorizationManager authorizationManager, Map<String, String> definedFilterNamesMap) { List<String> sessionGroupFilterNamesList = new ArrayList<String>(); List<String> sessionDefinedFilterNamesList = new ArrayList<String>(); boolean enableAllDefinedFilterNames = false; Set definedFilterNames = null; if (definedFilterNamesMap != null && !definedFilterNamesMap.isEmpty()) { definedFilterNames = definedFilterNamesMap.keySet(); if (definedFilterNames.contains("ALL")) enableAllDefinedFilterNames = true; } SessionFactory sessionFactory = session.getSessionFactory(); Set sessionFilterNamesSet = sessionFactory.getDefinedFilterNames(); Iterator sessionFilterNamesSetIterator = sessionFilterNamesSet.iterator(); while (sessionFilterNamesSetIterator.hasNext()) { String filterName = (String) sessionFilterNamesSetIterator.next(); if (null != definedFilterNames) { if (enableAllDefinedFilterNames) { sessionDefinedFilterNamesList.add(filterName); } else { if (definedFilterNames.contains(filterName)) { String value = (String) definedFilterNamesMap.get(filterName); if (Constants.ENABLE.equalsIgnoreCase(value)) { sessionDefinedFilterNamesList.add(filterName); } } } } FilterDefinition filterDefinition = sessionFactory.getFilterDefinition(filterName); if (filterDefinition != null) { Set<String> parameterNamesSet = filterDefinition.getParameterNames(); if (parameterNamesSet != null && parameterNamesSet.contains("GROUP_NAMES")) { sessionGroupFilterNamesList.add(filterName); // remove this filter name from sessionDefinedFilterNamesList if it exists in there. if (sessionDefinedFilterNamesList.contains(filterName)) sessionDefinedFilterNamesList.remove(filterName); } } } //Enable the User Filters from CSM database for the application Iterator sessionGroupFilterNamesListIterator = sessionGroupFilterNamesList.iterator(); while (sessionGroupFilterNamesListIterator.hasNext()) { String filterName = (String) sessionGroupFilterNamesListIterator.next(); Filter filter = session.enableFilter(filterName); filter.setParameterList("GROUP_NAMES", groupNames); filter.setParameter("APPLICATION_ID", authorizationManager.getApplicationContext().getApplicationId()); } //Enable the Defined Filters available in HBM/Classes. Iterator sessionDefinedFilterNamesListIterator = sessionDefinedFilterNamesList.iterator(); while (sessionDefinedFilterNamesListIterator.hasNext()) { String filterName = (String) sessionDefinedFilterNamesListIterator.next(); Filter filter = session.enableFilter(filterName); } }
From source file:gov.nih.nci.security.authorization.instancelevel.InstanceLevelSecurityHelper.java
License:BSD License
/** * This method initializes the User filter from CSM Database that are already added to the Sessionfactory. * <br>/*from ww w. java 2 s . co m*/ * This method also initializes the defined filters configured in HBM/Classes/Packages based on the definedFilterNamesMap. * If definedFilterNamesMap contains 'ALL' as the Filter Name (key) then all defined filters are enabled. * <br> * This method first obtains the list of all the defined filters from the SessionFactory in the passes Session object. * It then just iterates through the filter list and sets the user name and the application name parameter. * * @param userName The name of the logged in user or group which is invoking the query * @param session The Hibernate Session initialized to execute this query * @param authorizationManager The CSM AuthorizationManager instance for this application * @param definedFilterNamesMap - Map of defined Filter Names and string value ( enable / disable ) to indicate that the filter should be enabled of disabled. * */ public static void initializeFilters(String userName, Session session, AuthorizationManager authorizationManager, Map<String, String> definedFilterNamesMap) { List<String> initUserFilterNames = new ArrayList<String>(); List<String> initSessionDefinedFilterNames = new ArrayList<String>(); boolean enableAllSessionDefinedFilters = false; Set definedFilterNames = null; if (definedFilterNamesMap != null && !definedFilterNamesMap.isEmpty()) { definedFilterNames = definedFilterNamesMap.keySet(); if (definedFilterNames.contains("ALL")) enableAllSessionDefinedFilters = true; } Iterator sessionFilterNamesSetIterator = session.getSessionFactory().getDefinedFilterNames().iterator(); while (sessionFilterNamesSetIterator.hasNext()) { String filterName = (String) sessionFilterNamesSetIterator.next(); if (enableAllSessionDefinedFilters) { initSessionDefinedFilterNames.add(filterName); } else if (definedFilterNames != null && definedFilterNames.contains(filterName)) { String value = (String) definedFilterNamesMap.get(filterName); if (Constants.ENABLE.equalsIgnoreCase(value)) { initSessionDefinedFilterNames.add(filterName); } } FilterDefinition filterDefinition = session.getSessionFactory().getFilterDefinition(filterName); if (filterDefinition != null) { Set<String> parameterNamesSet = filterDefinition.getParameterNames(); if (parameterNamesSet != null && parameterNamesSet.contains("USER_NAME")) { initUserFilterNames.add(filterName); // remove this filter name from sessionDefinedFilterNamesList if it exists in there. initSessionDefinedFilterNames.remove(filterName); } } } //Enable the User Filters from CSM database for the application Iterator sessionUserFilterNamesListIterator = initUserFilterNames.iterator(); while (sessionUserFilterNamesListIterator.hasNext()) { String filterName = (String) sessionUserFilterNamesListIterator.next(); Filter filter = session.enableFilter(filterName); filter.setParameter("USER_NAME", userName); filter.setParameter("APPLICATION_ID", authorizationManager.getApplicationContext().getApplicationId()); } //Enable the Defined Filters available in HBM/Classes. Iterator sessionDefinedFilterNamesListIterator = initSessionDefinedFilterNames.iterator(); while (sessionDefinedFilterNamesListIterator.hasNext()) { String filterName = (String) sessionDefinedFilterNamesListIterator.next(); Filter filter = session.enableFilter(filterName); } }
From source file:it.av.youeat.service.impl.RistoranteServiceHibernate.java
License:Apache License
/** * {@inheritDoc}/*from ww w. j av a2s .c o m*/ */ @Override public List<Ristorante> freeTextSearch(String pattern, ArrayList<Eater> eaters, int firstResult, int maxResult) { FullTextQuery persistenceQuery = createFreeTextQuery(pattern); if (maxResult >= 0) { persistenceQuery.setMaxResults(maxResult); } if (firstResult >= 0) { persistenceQuery.setFirstResult(firstResult); } if (eaters != null) { Session session = (Session) getJpaTemplate().getEntityManager().getDelegate(); session.enableFilter("friends").setParameterList("friendlist", eaters); List<Ristorante> results = persistenceQuery.getResultList(); session.disableFilter("friends"); return results; } return persistenceQuery.getResultList(); }
From source file:it.eng.spagobi.commons.dao.AbstractHibernateDAO.java
License:Mozilla Public License
protected void enableTenantFilter(Session session, String tenantId) { Filter filter = session.enableFilter(TENANT_FILTER_NAME); filter.setParameter("tenant", tenantId); }
From source file:ome.security.basic.AbstractSecurityFilter.java
License:Open Source License
protected void enableBaseFilters(Session sess, int admin01, Long currentUserId) { final Filter sessionFilter = sess.enableFilter("owner_or_admin"); sessionFilter.setParameter("is_admin", admin01); sessionFilter.setParameter("current_user", currentUserId); }
From source file:ome.security.basic.AllGroupsSecurityFilter.java
License:Open Source License
/*** * Since we assume that the group is "-1" for this method, we have to pass * in lists of all groups as we did before group permissions (~4.2). *//*from www . j av a 2 s. c o m*/ public void enable(Session sess, EventContext ec) { final Filter filter = sess.enableFilter(getName()); final int share01 = isShare(ec) ? 1 : 0; final int admin01 = ec.isCurrentUserAdmin() ? 1 : 0; filter.setParameter(is_admin, admin01); filter.setParameter(SecurityFilter.is_share, share01); // ticket:2219, not checking -1 here. filter.setParameter(SecurityFilter.current_user, ec.getCurrentUserId()); filter.setParameterList(member_of_groups, configGroup(ec, ec.getMemberOfGroupsList())); filter.setParameterList(leader_of_groups, configGroup(ec, ec.getLeaderOfGroupsList())); enableBaseFilters(sess, admin01, ec.getCurrentUserId()); }
From source file:ome.security.basic.OneGroupSecurityFilter.java
License:Open Source License
public void enable(Session sess, EventContext ec) { final Filter filter = sess.enableFilter(getName()); final Long groupId = ec.getCurrentGroupId(); final Long shareId = ec.getCurrentShareId(); int share01 = shareId != null ? 1 : 0; // non-final; "ticket:3529" below final int adminOrPi01 = (ec.isCurrentUserAdmin() || ec.getLeaderOfGroupsList().contains(ec.getCurrentGroupId())) ? 1 : 0; final int nonpriv01 = (ec.getCurrentGroupPermissions().isGranted(Role.GROUP, Right.READ) || ec.getCurrentGroupPermissions().isGranted(Role.WORLD, Right.READ)) ? 1 : 0; if (groupId < 0) { // Special marker throwNegOne();/*from www.j av a 2 s . c om*/ } filter.setParameter(SecurityFilter.is_share, share01); // ticket:2219, not checking -1 here. filter.setParameter(SecurityFilter.is_adminorpi, adminOrPi01); filter.setParameter(SecurityFilter.is_nonprivate, nonpriv01); filter.setParameter(SecurityFilter.current_user, ec.getCurrentUserId()); filter.setParameter(current_group, groupId); enableBaseFilters(sess, ec.isCurrentUserAdmin() ? 1 : 0, ec.getCurrentUserId()); }
From source file:ome.security.basic.SharingSecurityFilter.java
License:Open Source License
@Override public void enable(Session session, EventContext ec) { List<Long> imageIds = null; final Long shareId = ec.getCurrentShareId(); if (shareId != null) { final ShareData shareData = shares.get(shareId); if (shareData != null && shareData.enabled) { imageIds = shareData.objectMap.get(Image.class.getName()); }// w w w . j ava 2s .c o m } if (CollectionUtils.isEmpty(imageIds)) { imageIds = ImmutableList.of(-1L); } final int isAdmin01 = ec.isCurrentUserAdmin() ? 1 : 0; final int isShare01 = isShare(ec) ? 1 : 0; final Filter filter = session.enableFilter(getName()); filter.setParameter("is_admin", isAdmin01); filter.setParameter("is_share", isShare01); filter.setParameterList("images", imageIds); enableBaseFilters(session, isAdmin01, ec.getCurrentUserId()); }
From source file:ome.services.query.Query.java
License:Open Source License
/** * standard filter used by many subclasses which uses the * {@link PojoOptions#isExperimenter()} and {@link PojoOptions#isGroup()} * booleans to see if a filter should be turned on. If both booleans are * active, group wins. The constant {@link Parameters#OWNER_ID} or * {@link Parameters#GROUP_ID} is then used to define a filter. *//* www . j a va 2s . com*/ protected void ownerOrGroupFilters(Session session, String[] ownerFilters, String[] groupFilters) { if (params.isGroup()) { for (String filter : groupFilters) { if (session.getEnabledFilter(filter) != null) { newlyEnabledFilters.add(filter); } session.enableFilter(filter).setParameter(GROUP_ID, params.getGroup()); } } else if (params.isExperimenter()) { for (String filter : ownerFilters) { if (session.getEnabledFilter(filter) != null) { newlyEnabledFilters.add(filter); } session.enableFilter(filter).setParameter(OWNER_ID, params.getExperimenter()); } } }