private static void parseFilterDef(Element element, Mappings mappings) { String name = element.attributeValue( "name" ); log.debug( "Parsing filter-def [" + name + "]" ); String defaultCondition = element.getTextTrim(); if ( StringHelper.isEmpty( defaultCondition ) ) { defaultCondition = element.attributeValue( "condition" ); } HashMap paramMappings = new HashMap(); Iterator params = element.elementIterator( "filter-param" ); while ( params.hasNext() ) { final Element param = (Element) params.next(); final String paramName = param.attributeValue( "name" ); final String paramType = param.attributeValue( "type" ); log.debug( "adding filter parameter : " + paramName + " -> " + paramType ); final Type heuristicType = TypeFactory.heuristicType( paramType ); log.debug( "parameter heuristic type : " + heuristicType ); paramMappings.put( paramName, heuristicType ); } log.debug( "Parsed filter-def [" + name + "]" ); FilterDefinition def = new FilterDefinition( name, defaultCondition, paramMappings ); mappings.addFilterDefinition( def ); }
public void testGetFiltersForUsers() throws Exception { SessionFactory sf=null; Configuration configuration = null; if(null == sf || sf.isClosed()){ configuration = new Configuration().configure(hibernateCfgFileName); InstanceLevelSecurityHelper.getFiltersForUser(authorizationManager); sf = configuration.buildSessionFactory(); } List<FilterDefinition> filterList=InstanceLevelSecurityHelper.getFiltersForGroups(authorizationManager); sf.close(); for (Object filter:filterList) { try { printObject(filter, false); } catch (Exception e) { // TODO: handle exception } } assertEquals("GetFiltersForGroups Method successful",2, filterList.size()); }
private void testGetFiltersForGroups() throws Exception { SessionFactory sf=null; Configuration configuration = null; if(null == sf || sf.isClosed()){ configuration = new Configuration().configure(hibernateCfgFileName); InstanceLevelSecurityHelper.getFiltersForGroups(authorizationManager); sf = configuration.buildSessionFactory(); } List<FilterDefinition> filterList=InstanceLevelSecurityHelper.getFiltersForGroups(authorizationManager); sf.close(); for (Object filter:filterList) { try { printObject(filter, false); } catch (Exception e) { // TODO: handle exception } } assertEquals("GetFiltersForGroups Method successful",2, filterList.size()); }
@Override protected Configuration newConfiguration() throws HibernateException { return new Configuration() { @Override public void addFilterDefinition(FilterDefinition definition) { registeredFilterDefinitions.add(definition); } }; }
public Type getFilterParameterType(String filterParameterName) { errorIfClosed(); checkTransactionSynchStatus(); String[] parsed = parseFilterParameterName(filterParameterName); FilterDefinition filterDef = factory.getFilterDefinition( parsed[0] ); if (filterDef == null) { throw new IllegalArgumentException("Filter [" + parsed[0] + "] not defined"); } Type type = filterDef.getParameterType( parsed[1] ); if (type == null) { // this is an internal error of some sort... throw new InternalError("Unable to locate type for filter parameter"); } return type; }
public FilterDefinition getFilterDefinition(String filterName) throws HibernateException { FilterDefinition def = ( FilterDefinition ) filters.get( filterName ); if ( def == null ) { throw new HibernateException( "No such filter configured [" + filterName + "]" ); } return def; }
/** * This method injects the security filters which are created for this application. It retrieves a list of all the filters which have * been defined for this application from the CSM Database. Now for each filter in the list, it creates a new FilterDefinition object. * It then retrieves the Persistent Class from the passed Configuration Object using the class name for which the filter is defined. * It then adds the filter to the persistent class by setting the filtering query. * @param authorizationManager The CSM AuthorizationManager instance for this application * @param configuration The Hibernate Configuration initialized for this application * */ public static void addFiltersForGroups(AuthorizationManager authorizationManager,Configuration configuration) { boolean needsOptimisation = false; Properties props = configuration.getProperties(); if(!isExistActiveMappingElement(authorizationManager)) needsOptimisation = isMySQLDatabase(props,true); FilterClause searchFilterClause = new FilterClause(); searchFilterClause.setClassName("*"); SearchCriteria searchCriteria = new FilterClauseSearchCriteria(searchFilterClause); List list = authorizationManager.getObjects(searchCriteria); Iterator iterator = list.iterator(); while (iterator.hasNext()) { HashMap parameters = new HashMap(); parameters.put("GROUP_NAMES", new StringType()); parameters.put("APPLICATION_ID", new LongType()); FilterClause filterClause = (FilterClause)iterator.next(); FilterDefinition filterDefinition = new FilterDefinition ( filterClause.getClassName().substring(filterClause.getClassName().lastIndexOf('.') + 1) + filterClause.getId(), "", parameters); configuration.addFilterDefinition(filterDefinition); PersistentClass persistentClass = configuration.getClassMapping(filterClause.getClassName()); persistentClass.addFilter( filterClause.getClassName().substring(filterClause.getClassName().lastIndexOf('.') + 1) + filterClause.getId() , optimiseFilterQuery(needsOptimisation,filterClause.getGeneratedSQLForGroup())); } }
/** * This method injects the security filters which are created for this application. It retrieves a list of all the filters which have * been defined for this application from the CSM Database. Now for each filter in the list, it creates a new FilterDefinition object. * * @param authorizationManager The CSM AuthorizationManager instance for this application * @param List<FilterDefinition> The Hibernate FilterDefinition List. */ public static List<FilterDefinition> getFiltersForGroups(AuthorizationManager authorizationManager) throws CSException { Properties props = new Properties(); ApplicationContext ac = authorizationManager.getApplicationContext(); props.setProperty("hibernate.connection.url", ac.getDatabaseURL()); props.setProperty("hibernate.connection.username", ac.getDatabaseUserName()); props.setProperty("hibernate.connection.password", ac.getDatabasePassword()); props.setProperty("hibernate.connection.driver", ac.getDatabaseDriver()); props.setProperty("hibernate.dialect", ac.getDatabaseDialect()); boolean needsOptimisation = false; if(!isExistActiveMappingElement(authorizationManager)) needsOptimisation = isMySQLDatabase(props,false); List<FilterDefinition> filterDefinitionList = new ArrayList<FilterDefinition>(); FilterClause searchFilterClause = new FilterClause(); searchFilterClause.setClassName("*"); SearchCriteria searchCriteria = new FilterClauseSearchCriteria(searchFilterClause); List list = authorizationManager.getObjects(searchCriteria); Iterator iterator = list.iterator(); while (iterator.hasNext()) { HashMap parameters = new HashMap(); parameters.put("GROUP_NAMES", new StringType()); parameters.put("APPLICATION_ID", new LongType()); FilterClause filterClause = (FilterClause)iterator.next(); FilterDefinition filterDefinition = new FilterDefinition ( filterClause.getClassName().substring( filterClause.getClassName().lastIndexOf('.') + 1) + filterClause.getId(), optimiseFilterQuery(needsOptimisation,filterClause.getGeneratedSQLForGroup()), parameters); if(filterDefinition!=null) filterDefinitionList.add(filterDefinition); } return filterDefinitionList; }
/** * This method injects the security filters which are created for this application. It retrieves a list of all the filters which have * been defined for this application from the CSM Database. Now for each filter in the list, it creates a new FilterDefinition object. * It then retrieves the Persistent Class from the passed Configuration Object using the class name for which the filter is defined. * It then adds the filter to the persistent class by setting the filtering query. * @param authorizationManager The CSM AuthorizationManager instance for this application * @param configuration The Hibernate Configuration initialized for this application */ public static void addFilters(AuthorizationManager authorizationManager,Configuration configuration) { boolean needsOptimisation = false; Properties props = configuration.getProperties(); if(!isExistActiveMappingElement(authorizationManager)) needsOptimisation = isMySQLDatabase(props,true); FilterClause searchFilterClause = new FilterClause(); searchFilterClause.setClassName("*"); SearchCriteria searchCriteria = new FilterClauseSearchCriteria(searchFilterClause); List list = authorizationManager.getObjects(searchCriteria); Iterator iterator = list.iterator(); while (iterator.hasNext()) { HashMap parameters = new HashMap(); parameters.put("USER_NAME", new StringType()); parameters.put("APPLICATION_ID", new LongType()); FilterClause filterClause = (FilterClause)iterator.next(); FilterDefinition filterDefinition = new FilterDefinition (filterClause.getClassName().substring(filterClause.getClassName().lastIndexOf('.') + 1) + filterClause.getId(), "", parameters); configuration.addFilterDefinition(filterDefinition); PersistentClass persistentClass = configuration.getClassMapping(filterClause.getClassName()); persistentClass.addFilter( filterClause.getClassName().substring(filterClause.getClassName().lastIndexOf('.') + 1) + filterClause.getId() ,optimiseFilterQuery(needsOptimisation,filterClause.getGeneratedSQLForUser())); } }
/** * This method injects the security filters which are created for this application. It retrieves a list of all the filters which have * been defined for this application from the CSM Database. Now for each filter in the list, it creates a new FilterDefinition object. * * * @param authorizationManager The CSM AuthorizationManager instance for this application * @param List<FilterDefinition> The Hibernate FilterDefinition List. */ public static List<FilterDefinition> getFiltersForUser(AuthorizationManager authorizationManager) throws CSException { Properties props = new Properties(); ApplicationContext ac = authorizationManager.getApplicationContext(); props.setProperty("hibernate.connection.url", ac.getDatabaseURL()); props.setProperty("hibernate.connection.username", ac.getDatabaseUserName()); props.setProperty("hibernate.connection.password", ac.getDatabasePassword()); props.setProperty("hibernate.connection.driver", ac.getDatabaseDriver()); props.setProperty("hibernate.dialect", ac.getDatabaseDialect()); boolean needsOptimisation = false; if(!isExistActiveMappingElement(authorizationManager)) needsOptimisation = isMySQLDatabase(props,false); List<FilterDefinition> filterDefinitionList = new ArrayList<FilterDefinition>(); FilterClause searchFilterClause = new FilterClause(); searchFilterClause.setClassName("*"); SearchCriteria searchCriteria = new FilterClauseSearchCriteria(searchFilterClause); List list = authorizationManager.getObjects(searchCriteria); Iterator iterator = list.iterator(); while (iterator.hasNext()) { HashMap parameters = new HashMap(); parameters.put("USER_NAME", new StringType()); parameters.put("APPLICATION_ID", new LongType()); FilterClause filterClause = (FilterClause)iterator.next(); FilterDefinition filterDefinition = new FilterDefinition ( filterClause.getClassName().substring(filterClause.getClassName().lastIndexOf('.') + 1) + filterClause.getId(), optimiseFilterQuery(needsOptimisation,filterClause.getGeneratedSQLForUser()), parameters); if(filterDefinition!=null) filterDefinitionList.add(filterDefinition); } return filterDefinitionList; }
/** * This method injects the security filters which are created for this application. It retrieves a list of all the filters which have * been defined for this application from the CSM Database. Now for each filter in the list, it creates a new FilterDefinition object. * It then retrieves the Persistent Class from the passed Configuration Object using the class name for which the filter is defined. * It then adds the filter to the persistent class by setting the filtering query. * @param authorizationManager The CSM AuthorizationManager instance for this application * @param configuration The Hibernate Configuration initialized for this application * */ public static void addFiltersForGroups(AuthorizationManager authorizationManager,Configuration configuration) { boolean needsOptimisation = false; Properties props = configuration.getProperties(); //If using InstanceLevel Query Performance Enhancements of 4.2, then no need to optimize query for MySQL Db. if(!isExistActiveMappingElement(authorizationManager)) needsOptimisation = isMySQLDatabase(props,true); // Inject CSM Filters for Group List list = retriveAllCsmFilterClause(authorizationManager); Iterator iterator = list.iterator(); while (iterator.hasNext()) { HashMap parameters = new HashMap(); parameters.put("GROUP_NAMES", new StringType()); parameters.put("APPLICATION_ID", new LongType()); FilterClause filterClause = (FilterClause)iterator.next(); FilterDefinition filterDefinition = new FilterDefinition ( filterClause.getClassName().substring(filterClause.getClassName().lastIndexOf('.') + 1) + filterClause.getId(), "", parameters); configuration.addFilterDefinition(filterDefinition); PersistentClass persistentClass = configuration.getClassMapping(filterClause.getClassName()); persistentClass.addFilter( filterClause.getClassName().substring(filterClause.getClassName().lastIndexOf('.') + 1) + filterClause.getId() , optimiseFilterQuery(needsOptimisation,filterClause.getGeneratedSQLForGroup())); } }
/** * This method injects the security filters which are created for this application. It retrieves a list of all the filters which have * been defined for this application from the CSM Database. Now for each filter in the list, it creates a new FilterDefinition object. * * @param authorizationManager The CSM AuthorizationManager instance for this application * @param List<FilterDefinition> The Hibernate FilterDefinition List. */ public static List<FilterDefinition> getFiltersForGroups(AuthorizationManager authorizationManager) throws CSException { Properties props = new Properties(); ApplicationContext ac = authorizationManager.getApplicationContext(); props.setProperty("hibernate.connection.url", ac.getDatabaseURL()); props.setProperty("hibernate.connection.username", ac.getDatabaseUserName()); props.setProperty("hibernate.connection.password", ac.getDatabasePassword()); props.setProperty("hibernate.connection.driver", ac.getDatabaseDriver()); props.setProperty("hibernate.dialect", ac.getDatabaseDialect()); boolean needsOptimisation = false; if(!isExistActiveMappingElement(authorizationManager)) needsOptimisation = isMySQLDatabase(props,false); List<FilterDefinition> filterDefinitionList = new ArrayList<FilterDefinition>(); List list = retriveAllCsmFilterClause(authorizationManager); Iterator iterator = list.iterator(); while (iterator.hasNext()) { HashMap parameters = new HashMap(); parameters.put("GROUP_NAMES", new StringType()); parameters.put("APPLICATION_ID", new LongType()); FilterClause filterClause = (FilterClause)iterator.next(); FilterDefinition filterDefinition = new FilterDefinition ( filterClause.getClassName().substring( filterClause.getClassName().lastIndexOf('.') + 1) + filterClause.getId(), optimiseFilterQuery(needsOptimisation,filterClause.getGeneratedSQLForGroup()), parameters); if(filterDefinition!=null) filterDefinitionList.add(filterDefinition); } return filterDefinitionList; }
/** * This method injects the security filters which are created for this application. It retrieves a list of all the filters which have * been defined for this application from the CSM Database. Now for each filter in the list, it creates a new FilterDefinition object. * It then retrieves the Persistent Class from the passed Configuration Object using the class name for which the filter is defined. * It then adds the filter to the persistent class by setting the filtering query. * @param authorizationManager The CSM AuthorizationManager instance for this application * @param configuration The Hibernate Configuration initialized for this application */ public static void addFilters(AuthorizationManager authorizationManager,Configuration configuration) { boolean needsOptimisation = false; Properties props = configuration.getProperties(); if(!isExistActiveMappingElement(authorizationManager)) needsOptimisation = isMySQLDatabase(props,true); // Inject CSM defined Filters List list = retriveAllCsmFilterClause(authorizationManager); Iterator iterator = list.iterator(); while (iterator.hasNext()) { HashMap parameters = new HashMap(); parameters.put("USER_NAME", new StringType()); parameters.put("APPLICATION_ID", new LongType()); FilterClause filterClause = (FilterClause)iterator.next(); FilterDefinition filterDefinition = new FilterDefinition (filterClause.getClassName().substring(filterClause.getClassName().lastIndexOf('.') + 1) + filterClause.getId(), "", parameters); configuration.addFilterDefinition(filterDefinition); PersistentClass persistentClass = configuration.getClassMapping(filterClause.getClassName()); persistentClass.addFilter( filterClause.getClassName().substring(filterClause.getClassName().lastIndexOf('.') + 1) + filterClause.getId() ,optimiseFilterQuery(needsOptimisation,filterClause.getGeneratedSQLForUser())); } }
/** * This method injects the security filters which are created for this application. It retrieves a list of all the filters which have * been defined for this application from the CSM Database. Now for each filter in the list, it creates a new FilterDefinition object. * * * @param authorizationManager The CSM AuthorizationManager instance for this application * @param List<FilterDefinition> The Hibernate FilterDefinition List. */ public static List<FilterDefinition> getFiltersForUser(AuthorizationManager authorizationManager) throws CSException { Properties props = new Properties(); ApplicationContext ac = authorizationManager.getApplicationContext(); props.setProperty("hibernate.connection.url", ac.getDatabaseURL()); props.setProperty("hibernate.connection.username", ac.getDatabaseUserName()); props.setProperty("hibernate.connection.password", ac.getDatabasePassword()); props.setProperty("hibernate.connection.driver", ac.getDatabaseDriver()); props.setProperty("hibernate.dialect", ac.getDatabaseDialect()); boolean needsOptimisation = false; if(!isExistActiveMappingElement(authorizationManager)) needsOptimisation = isMySQLDatabase(props,false); List<FilterDefinition> filterDefinitionList = new ArrayList<FilterDefinition>(); List list = retriveAllCsmFilterClause(authorizationManager); Iterator iterator = list.iterator(); while (iterator.hasNext()) { HashMap parameters = new HashMap(); parameters.put("USER_NAME", new StringType()); parameters.put("APPLICATION_ID", new LongType()); FilterClause filterClause = (FilterClause)iterator.next(); FilterDefinition filterDefinition = new FilterDefinition ( filterClause.getClassName().substring(filterClause.getClassName().lastIndexOf('.') + 1) + filterClause.getId(), optimiseFilterQuery(needsOptimisation,filterClause.getGeneratedSQLForUser()), parameters); if(filterDefinition!=null) filterDefinitionList.add(filterDefinition); } return filterDefinitionList; }
private void disableFilters(Session session) { Set<String> filters = session.getSessionFactory().getDefinedFilterNames(); for (String filterName : filters) { // we only want to disable the security filters. assume security filters are ones // with GROUP_NAMES and APPLICATION_ID parameters FilterDefinition fd = session.getSessionFactory().getFilterDefinition(filterName); if (fd.getParameterNames().contains("GROUP_NAMES") && fd.getParameterNames().contains("APPLICATION_ID")) { session.disableFilter(filterName); } } }
@Override public void afterPropertiesSet() { this.filterDefinition = new FilterDefinition(this.filterName, this.defaultFilterCondition, this.parameterTypeMap); }
@Override public FilterDefinition getObject() { return this.filterDefinition; }
@Override public Class<FilterDefinition> getObjectType() { return FilterDefinition.class; }
public FilterDefinition getFilterDefinition(String filterName) throws HibernateException { return delegate.getFilterDefinition(filterName); }
public FilterDefinition getFilterDefinition(String arg0) throws HibernateException { return sessionFactory.getFilterDefinition(arg0); }
public FilterDefinition getFilterDefinition(String filterName) throws HibernateException { return delegateSessionFactory.getFilterDefinition(filterName); }
public void addFilterDefinition(FilterDefinition definition) { filterDefinitions.put( definition.getFilterName(), definition ); }
public FilterDefinition getFilterDefinition(String name) { return (FilterDefinition) filterDefinitions.get(name); }
public FilterDefinition getFilterDefinition(String filterName) throws HibernateException { return getImpl().getFilterDefinition( filterName ); }
public FilterDefinition getFilterDefinition() { return definition; }
@Override public FilterDefinition getFilterDefinition(String s) throws HibernateException { return original.getFilterDefinition(s); }
public void afterPropertiesSet() { this.filterDefinition = new FilterDefinition(this.filterName, this.defaultFilterCondition, this.parameterTypeMap); }
public FilterDefinition getObject() { return this.filterDefinition; }
public Class<FilterDefinition> getObjectType() { return FilterDefinition.class; }
public void setDeleteHibernateFilter(FilterDefinition deleteHibernateFilter) { this.deleteHibernateFilter = deleteHibernateFilter; }
public void setDeleteFilterDefinition(FilterDefinition deleteFilterDefinition) { this.deleteFilterDefinition = deleteFilterDefinition; }
/** * Specify the Hibernate FilterDefinitions to register with the SessionFactory. * This is an alternative to specifying <<filter-def> elements in * Hibernate mapping files. * <p>Typically, the passed-in FilterDefinition objects will have been defined * as Spring FilterDefinitionFactoryBeans, probably as inner beans within the * LocalSessionFactoryBean definition. * @see FilterDefinitionFactoryBean * @see org.hibernate.cfg.Configuration#addFilterDefinition */ public void setFilterDefinitions(FilterDefinition... filterDefinitions) { this.filterDefinitions = filterDefinitions; }
/** * Get the filter definition containing additional information about the * filter (such as default-condition and expected parameter names/types). * * @return The filter definition */ public FilterDefinition getFilterDefinition();