Inject ApplicationEventPublisher
Previously, the auto-configured `OAuth2ClientAuthenticationProcessingFilter` instance had no `ApplicationEventPublisher`. As a result, no event was fired. This commit makes sure to associate the event publisher instance. Closes gh-5853
This commit is contained in:
parent
5a730a916c
commit
6f4ec4e741
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -23,12 +23,12 @@ import org.aopalliance.intercept.MethodInvocation;
|
|||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
|
||||
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
|
||||
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2SsoCustomConfiguration.WebSecurityEnhancerCondition;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.annotation.ConditionContext;
|
||||
import org.springframework.context.annotation.Conditional;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
@ -51,15 +51,15 @@ import org.springframework.util.ReflectionUtils;
|
|||
@Configuration
|
||||
@Conditional(WebSecurityEnhancerCondition.class)
|
||||
public class OAuth2SsoCustomConfiguration
|
||||
implements ImportAware, BeanPostProcessor, BeanFactoryAware {
|
||||
implements ImportAware, BeanPostProcessor, ApplicationContextAware {
|
||||
|
||||
private Class<?> configType;
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
this.beanFactory = beanFactory;
|
||||
public void setApplicationContext(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -82,7 +82,7 @@ public class OAuth2SsoCustomConfiguration
|
|||
&& bean instanceof WebSecurityConfigurerAdapter) {
|
||||
ProxyFactory factory = new ProxyFactory();
|
||||
factory.setTarget(bean);
|
||||
factory.addAdvice(new SsoSecurityAdapter(this.beanFactory));
|
||||
factory.addAdvice(new SsoSecurityAdapter(this.applicationContext));
|
||||
bean = factory.getProxy();
|
||||
}
|
||||
return bean;
|
||||
|
@ -92,8 +92,8 @@ public class OAuth2SsoCustomConfiguration
|
|||
|
||||
private SsoSecurityConfigurer configurer;
|
||||
|
||||
SsoSecurityAdapter(BeanFactory beanFactory) {
|
||||
this.configurer = new SsoSecurityConfigurer(beanFactory);
|
||||
SsoSecurityAdapter(ApplicationContext applicationContext) {
|
||||
this.configurer = new SsoSecurityConfigurer(applicationContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
|
||||
package org.springframework.boot.autoconfigure.security.oauth2.client;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
|
||||
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
|
||||
import org.springframework.boot.autoconfigure.security.SecurityProperties;
|
||||
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2SsoDefaultConfiguration.NeedsWebSecurityCondition;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.ConditionContext;
|
||||
import org.springframework.context.annotation.Conditional;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
@ -44,20 +44,20 @@ import org.springframework.util.ClassUtils;
|
|||
public class OAuth2SsoDefaultConfiguration extends WebSecurityConfigurerAdapter
|
||||
implements Ordered {
|
||||
|
||||
private final BeanFactory beanFactory;
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
private final OAuth2SsoProperties sso;
|
||||
|
||||
public OAuth2SsoDefaultConfiguration(BeanFactory beanFactory,
|
||||
public OAuth2SsoDefaultConfiguration(ApplicationContext applicationContext,
|
||||
OAuth2SsoProperties sso) {
|
||||
this.beanFactory = beanFactory;
|
||||
this.applicationContext = applicationContext;
|
||||
this.sso = sso;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http.antMatcher("/**").authorizeRequests().anyRequest().authenticated();
|
||||
new SsoSecurityConfigurer(this.beanFactory).configure(http);
|
||||
new SsoSecurityConfigurer(this.applicationContext).configure(http);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -18,7 +18,7 @@ package org.springframework.boot.autoconfigure.security.oauth2.client;
|
|||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
|
||||
|
@ -39,14 +39,14 @@ import org.springframework.web.accept.HeaderContentNegotiationStrategy;
|
|||
|
||||
class SsoSecurityConfigurer {
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
SsoSecurityConfigurer(BeanFactory beanFactory) {
|
||||
this.beanFactory = beanFactory;
|
||||
SsoSecurityConfigurer(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
public void configure(HttpSecurity http) throws Exception {
|
||||
OAuth2SsoProperties sso = this.beanFactory.getBean(OAuth2SsoProperties.class);
|
||||
OAuth2SsoProperties sso = this.applicationContext.getBean(OAuth2SsoProperties.class);
|
||||
// Delay the processing of the filter until we know the
|
||||
// SessionAuthenticationStrategy is available:
|
||||
http.apply(new OAuth2ClientAuthenticationConfigurer(oauth2SsoFilter(sso)));
|
||||
|
@ -76,14 +76,15 @@ class SsoSecurityConfigurer {
|
|||
|
||||
private OAuth2ClientAuthenticationProcessingFilter oauth2SsoFilter(
|
||||
OAuth2SsoProperties sso) {
|
||||
OAuth2RestOperations restTemplate = this.beanFactory
|
||||
OAuth2RestOperations restTemplate = this.applicationContext
|
||||
.getBean(OAuth2RestOperations.class);
|
||||
ResourceServerTokenServices tokenServices = this.beanFactory
|
||||
ResourceServerTokenServices tokenServices = this.applicationContext
|
||||
.getBean(ResourceServerTokenServices.class);
|
||||
OAuth2ClientAuthenticationProcessingFilter filter = new OAuth2ClientAuthenticationProcessingFilter(
|
||||
sso.getLoginPath());
|
||||
filter.setRestTemplate(restTemplate);
|
||||
filter.setTokenServices(tokenServices);
|
||||
filter.setApplicationEventPublisher(this.applicationContext);
|
||||
return filter;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue