List of usage examples for org.springframework.aop.framework ProxyFactoryBean setTargetSource
@Override public void setTargetSource(@Nullable TargetSource targetSource)
From source file:com.github.lothar.security.acl.jpa.query.AclJpaQuery.java
private AclPredicateTargetSource installAclPredicateTargetSource() { synchronized (cachedCriteriaQuery) { Predicate restriction = cachedCriteriaQuery.getRestriction(); if (restriction instanceof Advised) { Advised advised = (Advised) restriction; if (advised.getTargetSource() instanceof AclPredicateTargetSource) { return (AclPredicateTargetSource) advised.getTargetSource(); }/*w w w .j a va 2 s .c o m*/ } AclPredicateTargetSource targetSource = new AclPredicateTargetSource(em.getCriteriaBuilder(), restriction); ProxyFactoryBean factoryBean = new ProxyFactoryBean(); factoryBean.setTargetSource(targetSource); factoryBean.setAutodetectInterfaces(true); Predicate enhancedPredicate = (Predicate) factoryBean.getObject(); logger.debug("ACL Jpa Specification target source initialized for criteria {}", cachedCriteriaQuery); // install proxy inside criteria cachedCriteriaQuery.where(enhancedPredicate); return targetSource; } }
From source file:org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration.java
@SuppressWarnings("unchecked") private <T> T lazyBean(Class<T> interfaceName) { LazyInitTargetSource lazyTargetSource = new LazyInitTargetSource(); String[] beanNamesForType = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(applicationContext, interfaceName);//from w w w . j a v a2 s . c o m if (beanNamesForType.length == 0) { return null; } String beanName; if (beanNamesForType.length > 1) { List<String> primaryBeanNames = Arrays.stream(beanNamesForType) .filter(i -> applicationContext instanceof ConfigurableApplicationContext) .filter(n -> ((ConfigurableApplicationContext) applicationContext).getBeanFactory() .getBeanDefinition(n).isPrimary()) .collect(Collectors.toList()); Assert.isTrue(primaryBeanNames.size() != 0, () -> "Found " + beanNamesForType.length + " beans for type " + interfaceName + ", but none marked as primary"); Assert.isTrue(primaryBeanNames.size() == 1, () -> "Found " + primaryBeanNames.size() + " beans for type " + interfaceName + " marked as primary"); beanName = primaryBeanNames.get(0); } else { beanName = beanNamesForType[0]; } lazyTargetSource.setTargetBeanName(beanName); lazyTargetSource.setBeanFactory(applicationContext); ProxyFactoryBean proxyFactory = new ProxyFactoryBean(); proxyFactory = objectPostProcessor.postProcess(proxyFactory); proxyFactory.setTargetSource(lazyTargetSource); return (T) proxyFactory.getObject(); }