/** * Performs post processing of an object. The default is to delegate to the * {@link ObjectPostProcessor}. * * @param object the Object to post process * @return the possibly modified Object to use */ protected <P> P postProcess(P object) { return this.objectPostProcessor.postProcess(object); }
@Autowired(required = false) public void setObjectPostProcessor(ObjectPostProcessor<Object> objectPostProcessor) { this.objectPostProcessor = objectPostProcessor; this.defaultMethodExpressionHandler = objectPostProcessor .postProcess(defaultMethodExpressionHandler); }
@Autowired(required = false) public void setObjectPostProcessor(ObjectPostProcessor<Object> objectPostProcessor) { defaultExpressionHandler = objectPostProcessor.postProcess(defaultExpressionHandler); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public Object postProcess(Object object) { for (ObjectPostProcessor opp : postProcessors) { Class<?> oppClass = opp.getClass(); Class<?> oppType = GenericTypeResolver.resolveTypeArgument(oppClass, ObjectPostProcessor.class); if (oppType == null || oppType.isAssignableFrom(object.getClass())) { object = opp.postProcess(object); } } return object; }
@Autowired public void configure(ObjectPostProcessor<Object> p) { p.postProcess(this.toTest); } }
/** * Creates the Spring Security Filter Chain * @return the {@link Filter} that represents the security filter chain * @throws Exception */ @Bean(name = AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME) public Filter springSecurityFilterChain() throws Exception { boolean hasConfigurers = webSecurityConfigurers != null && !webSecurityConfigurers.isEmpty(); if (!hasConfigurers) { WebSecurityConfigurerAdapter adapter = objectObjectPostProcessor .postProcess(new WebSecurityConfigurerAdapter() { }); webSecurity.apply(adapter); } return webSecurity.build(); }
@Autowired public void configure(ObjectPostProcessor<Object> p) { p.postProcess(new Object()); } }
@Test public void getAuthenticationManagerWhenPostProcessThenUsesBeanClassLoaderOnProxyFactoryBean() throws Exception { this.spring.register(Sec2531Config.class).autowire(); ObjectPostProcessor<Object> opp = this.spring.getContext().getBean(ObjectPostProcessor.class); when(opp.postProcess(any())).thenAnswer(a -> a.getArgument(0)); AuthenticationConfiguration config = this.spring.getContext().getBean(AuthenticationConfiguration.class); config.getAuthenticationManager(); verify(opp).postProcess(any(ProxyFactoryBean.class)); }
@Test public void configureWhenRegisteringObjectPostProcessorThenInvokedOnExceptionTranslationFilter() { this.spring.register(ObjectPostProcessorConfig.class, DefaultSecurityConfig.class).autowire(); verify(ObjectPostProcessorConfig.objectPostProcessor) .postProcess(any(ExceptionTranslationFilter.class)); }
@Test public void buildWhenAddAuthenticationProviderThenDoesNotPerformRegistration() throws Exception { ObjectPostProcessor<Object> opp = mock(ObjectPostProcessor.class); AuthenticationProvider provider = mock(AuthenticationProvider.class); AuthenticationManagerBuilder builder = new AuthenticationManagerBuilder(opp); builder.authenticationProvider(provider); builder.build(); verify(opp, never()).postProcess(provider); }
@Test public void configureWhenRegisteringObjectPostProcessorThenInvokedOnExceptionTranslationFilter() { this.spring.register(ObjectPostProcessorConfig.class, DefaultSecurityConfig.class).autowire(); verify(ObjectPostProcessorConfig.objectPostProcessor) .postProcess(any(RequestCacheAwareFilter.class)); }
@Test public void customAuthenticationEventPublisherWithWeb() throws Exception { ObjectPostProcessor<Object> opp = mock(ObjectPostProcessor.class); AuthenticationEventPublisher aep = mock(AuthenticationEventPublisher.class); when(opp.postProcess(any())).thenAnswer(a -> a.getArgument(0)); AuthenticationManager am = new AuthenticationManagerBuilder(opp) .authenticationEventPublisher(aep) .inMemoryAuthentication() .and() .build(); try { am.authenticate(new UsernamePasswordAuthenticationToken("user", "password")); } catch (AuthenticationException success) {} verify(aep).publishAuthenticationFailure(any(), any()); }
@Test public void postProcessWhenDisposableBeanThenAwareInvoked() throws Exception { this.spring.register(Config.class).autowire(); DisposableBean toPostProcess = mock(DisposableBean.class); this.objectObjectPostProcessor.postProcess(toPostProcess); this.spring.getContext().close(); verify(toPostProcess).destroy(); }
@Test public void postProcessWhenApplicationContextAwareThenAwareInvoked() { this.spring.register(Config.class).autowire(); ApplicationContextAware toPostProcess = mock(ApplicationContextAware.class); this.objectObjectPostProcessor.postProcess(toPostProcess); verify(toPostProcess).setApplicationContext(isNotNull()); }
@Test public void postProcessWhenBeanClassLoaderAwareThenAwareInvoked() { this.spring.register(Config.class).autowire(); BeanClassLoaderAware toPostProcess = mock(BeanClassLoaderAware.class); this.objectObjectPostProcessor.postProcess(toPostProcess); verify(toPostProcess).setBeanClassLoader(isNotNull()); }
@Test public void postProcessWhenBeanFactoryAwareThenAwareInvoked() { this.spring.register(Config.class).autowire(); BeanFactoryAware toPostProcess = mock(BeanFactoryAware.class); this.objectObjectPostProcessor.postProcess(toPostProcess); verify(toPostProcess).setBeanFactory(isNotNull()); }
@Test public void postProcessWhenEnvironmentAwareThenAwareInvoked() { this.spring.register(Config.class).autowire(); EnvironmentAware toPostProcess = mock(EnvironmentAware.class); this.objectObjectPostProcessor.postProcess(toPostProcess); verify(toPostProcess).setEnvironment(isNotNull()); }
@Test public void postProcessWhenApplicationEventPublisherAwareThenAwareInvoked() { this.spring.register(Config.class).autowire(); ApplicationEventPublisherAware toPostProcess = mock(ApplicationEventPublisherAware.class); this.objectObjectPostProcessor.postProcess(toPostProcess); verify(toPostProcess).setApplicationEventPublisher(isNotNull()); }
@Test public void postProcessWhenMessageSourceAwareThenAwareInvoked() { this.spring.register(Config.class).autowire(); MessageSourceAware toPostProcess = mock(MessageSourceAware.class); this.objectObjectPostProcessor.postProcess(toPostProcess); verify(toPostProcess).setMessageSource(isNotNull()); }
@Test public void postProcessWhenServletContextAwareThenAwareInvoked() { this.spring.register(Config.class).autowire(); ServletContextAware toPostProcess = mock(ServletContextAware.class); this.objectObjectPostProcessor.postProcess(toPostProcess); verify(toPostProcess).setServletContext(isNotNull()); }