@EnableOAuth2Sso, it is enhanced by adding an authentication filter and an
- * authentication entry point. If the user only has @EnableOAuth2Sso but not
- * on a WebSecurityConfigurerAdapter then one is added with all paths secured and with an
- * order that puts it ahead of the default HTTP Basic security chain in Spring Boot.
- *
- * @author Dave Syer
+ * {@code @EnableOAuth2Sso}, it is enhanced by adding an authentication filter and an
+ * authentication entry point. If the user only has {@code @EnableOAuth2Sso} but not on a
+ * WebSecurityConfigurerAdapter then one is added with all paths secured and with an order
+ * that puts it ahead of the default HTTP Basic security chain in Spring Boot.
*
+ * @author Dave Syer
+ * @since 1.3.0
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@EnableOAuth2Client
-@Import({ OAuth2SsoDefaultConfiguration.class, OAuth2SsoCustomConfiguration.class, ResourceServerTokenServicesConfiguration.class })
+@Import({ OAuth2SsoDefaultConfiguration.class, OAuth2SsoCustomConfiguration.class,
+ ResourceServerTokenServicesConfiguration.class })
public @interface EnableOAuth2Sso {
}
diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration.java
index 744530be97..fd21d7daac 100644
--- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration.java
+++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2014 the original author or authors.
+ * Copyright 2012-2015 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.boot.autoconfigure.security.oauth2.client;
import javax.annotation.Resource;
@@ -49,8 +50,10 @@ import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails;
/**
- * @author Dave Syer
+ * Configuration for OAuth2 Single Sign On REST operations.
*
+ * @author Dave Syer
+ * @since 1.3.0
*/
@Configuration
@ConditionalOnClass(EnableOAuth2Client.class)
@@ -109,7 +112,7 @@ public class OAuth2RestOperationsConfiguration {
@Bean
@Scope(value = "session", proxyMode = ScopedProxyMode.INTERFACES)
public OAuth2ClientContext oauth2ClientContext() {
- return new DefaultOAuth2ClientContext(accessTokenRequest);
+ return new DefaultOAuth2ClientContext(this.accessTokenRequest);
}
@Bean
diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2SsoCustomConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2SsoCustomConfiguration.java
index 5fea93f814..92dd7e3c4f 100644
--- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2SsoCustomConfiguration.java
+++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2SsoCustomConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 the original author or authors.
+ * Copyright 2012-2015 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.
@@ -44,9 +44,8 @@ import org.springframework.util.ReflectionUtils;
* {@link WebSecurityConfigurerAdapter} provided by the user and annotated with
* @EnableOAuth2Sso. The user-provided configuration is enhanced by adding an
* authentication filter and an authentication entry point.
- *
- * @author Dave Syer
*
+ * @author Dave Syer
*/
@Configuration
@Conditional(WebSecurityEnhancerCondition.class)
@@ -64,7 +63,8 @@ public class OAuth2SsoCustomConfiguration implements ImportAware, BeanPostProces
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
- configType = ClassUtils.resolveClassName(importMetadata.getClassName(), null);
+ this.configType = ClassUtils
+ .resolveClassName(importMetadata.getClassName(), null);
}
@@ -77,11 +77,11 @@ public class OAuth2SsoCustomConfiguration implements ImportAware, BeanPostProces
@Override
public Object postProcessAfterInitialization(Object bean, String beanName)
throws BeansException {
- if (configType.isAssignableFrom(bean.getClass())
+ if (this.configType.isAssignableFrom(bean.getClass())
&& bean instanceof WebSecurityConfigurerAdapter) {
ProxyFactory factory = new ProxyFactory();
factory.setTarget(bean);
- factory.addAdvice(new SsoSecurityAdapter(beanFactory));
+ factory.addAdvice(new SsoSecurityAdapter(this.beanFactory));
bean = factory.getProxy();
}
return bean;
@@ -92,7 +92,7 @@ public class OAuth2SsoCustomConfiguration implements ImportAware, BeanPostProces
private SsoSecurityConfigurer configurer;
public SsoSecurityAdapter(BeanFactory beanFactory) {
- configurer = new SsoSecurityConfigurer(beanFactory);
+ this.configurer = new SsoSecurityConfigurer(beanFactory);
}
@Override
@@ -102,8 +102,8 @@ public class OAuth2SsoCustomConfiguration implements ImportAware, BeanPostProces
WebSecurityConfigurerAdapter.class, "getHttp");
ReflectionUtils.makeAccessible(method);
HttpSecurity http = (HttpSecurity) ReflectionUtils.invokeMethod(method,
- (WebSecurityConfigurerAdapter) invocation.getThis());
- configurer.configure(http);
+ invocation.getThis());
+ this.configurer.configure(http);
}
return invocation.proceed();
}
@@ -127,6 +127,7 @@ public class OAuth2SsoCustomConfiguration implements ImportAware, BeanPostProces
return ConditionOutcome
.noMatch("found no @EnableOAuth2Sso on a WebSecurityConfigurerAdapter");
}
+
}
}
diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2SsoDefaultConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2SsoDefaultConfiguration.java
index 6445a074d3..d8d509de66 100644
--- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2SsoDefaultConfiguration.java
+++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2SsoDefaultConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 the original author or authors.
+ * Copyright 2012-2015 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.
@@ -32,12 +32,13 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur
import org.springframework.util.ClassUtils;
/**
- * If the user only has @EnableOAuth2Sso but not on a
- * WebSecurityConfigurerAdapter then one is added with all paths secured and with an order
- * that puts it ahead of the default HTTP Basic security chain in Spring Boot.
- *
- * @author Dave Syer
+ * Configuration for OAuth2 Single Sign On (SSO). If the user only has
+ * {@code @EnableOAuth2Sso} but not on a {@code WebSecurityConfigurerAdapter} then one is
+ * added with all paths secured and with an order that puts it ahead of the default HTTP
+ * Basic security chain in Spring Boot.
*
+ * @author Dave Syer
+ * @since 1.3.0
*/
@Configuration
@EnableConfigurationProperties(OAuth2SsoProperties.class)
@@ -57,13 +58,13 @@ public class OAuth2SsoDefaultConfiguration {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/**").authorizeRequests().anyRequest().authenticated();
- new SsoSecurityConfigurer(beanFactory).configure(http);
+ new SsoSecurityConfigurer(this.beanFactory).configure(http);
}
@Override
public int getOrder() {
- if (sso.getFilterOrder() != null) {
- return sso.getFilterOrder();
+ if (this.sso.getFilterOrder() != null) {
+ return this.sso.getFilterOrder();
}
if (ClassUtils
.isPresent(
@@ -80,6 +81,7 @@ public class OAuth2SsoDefaultConfiguration {
}
private static class NeedsWebSecurityCondition extends SpringBootCondition {
+
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
@@ -95,6 +97,7 @@ public class OAuth2SsoDefaultConfiguration {
return ConditionOutcome
.match("found no @EnableOAuth2Sso on a WebSecurityConfigurerAdapter");
}
+
}
}
diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2SsoProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2SsoProperties.java
index d666fc22e8..ad3762ee5b 100644
--- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2SsoProperties.java
+++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2SsoProperties.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2014 the original author or authors.
+ * Copyright 2012-2015 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.
@@ -13,13 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.boot.autoconfigure.security.oauth2.client;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
- * @author Dave Syer
+ * Configuration properties for OAuth2 Single Sign On (SSO).
*
+ * @author Dave Syer
+ * @since 1.3.0
*/
@ConfigurationProperties("spring.oauth2.sso")
public class OAuth2SsoProperties {
@@ -39,7 +42,7 @@ public class OAuth2SsoProperties {
private Integer filterOrder;
public String getLoginPath() {
- return loginPath;
+ return this.loginPath;
}
public void setLoginPath(String loginPath) {
@@ -47,7 +50,7 @@ public class OAuth2SsoProperties {
}
public Integer getFilterOrder() {
- return filterOrder;
+ return this.filterOrder;
}
public void setFilterOrder(Integer filterOrder) {
diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/SsoSecurityConfigurer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/SsoSecurityConfigurer.java
index 4e5fe1515f..5c44a39c16 100644
--- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/SsoSecurityConfigurer.java
+++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/SsoSecurityConfigurer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 the original author or authors.
+ * Copyright 2012-2015 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.
@@ -36,7 +36,7 @@ class SsoSecurityConfigurer {
}
public void configure(HttpSecurity http) throws Exception {
- OAuth2SsoProperties sso = beanFactory.getBean(OAuth2SsoProperties.class);
+ OAuth2SsoProperties sso = this.beanFactory.getBean(OAuth2SsoProperties.class);
// Delay the processing of the filter until we know the
// SessionAuthenticationStrategy is available:
http.apply(new OAuth2ClientAuthenticationConfigurer(oauth2SsoFilter(sso)));
@@ -46,9 +46,9 @@ class SsoSecurityConfigurer {
private OAuth2ClientAuthenticationProcessingFilter oauth2SsoFilter(
OAuth2SsoProperties sso) {
- OAuth2RestOperations restTemplate = beanFactory
+ OAuth2RestOperations restTemplate = this.beanFactory
.getBean(OAuth2RestOperations.class);
- ResourceServerTokenServices tokenServices = beanFactory
+ ResourceServerTokenServices tokenServices = this.beanFactory
.getBean(ResourceServerTokenServices.class);
OAuth2ClientAuthenticationProcessingFilter filter = new OAuth2ClientAuthenticationProcessingFilter(
sso.getLoginPath());
@@ -59,6 +59,7 @@ class SsoSecurityConfigurer {
private static class OAuth2ClientAuthenticationConfigurer extends
SecurityConfigurerAdapter@EnableGlobalMethodSecurity).
+ * {@code @EnableGlobalMethodSecurity}).
*
* @author Greg Turnquist
* @author Dave Syer
+ * @since 1.3.0
*/
@Configuration
@ConditionalOnClass({ OAuth2AccessToken.class })
@ConditionalOnBean(GlobalMethodSecurityConfiguration.class)
-public class OAuth2MethodSecurityConfiguration implements
- BeanFactoryPostProcessor {
+public class OAuth2MethodSecurityConfiguration implements BeanFactoryPostProcessor {
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
throws BeansException {
- beanFactory
- .addBeanPostProcessor(new OAuth2ExpressionHandlerInjectionPostProcessor());
+ OAuth2ExpressionHandlerInjectionPostProcessor processor = new OAuth2ExpressionHandlerInjectionPostProcessor();
+ beanFactory.addBeanPostProcessor(processor);
}
private static class OAuth2ExpressionHandlerInjectionPostProcessor implements
diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/JwtAccessTokenConverterConfigurer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/JwtAccessTokenConverterConfigurer.java
index 2ebf2d7ce6..2e43ce43d4 100644
--- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/JwtAccessTokenConverterConfigurer.java
+++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/JwtAccessTokenConverterConfigurer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2015 the original author or authors.
+ * Copyright 2012-2015 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.
@@ -13,12 +13,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.springframework.boot.autoconfigure.security.oauth2.resource;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
+/**
+ * Callback interface that can be used to provide additional configuration to the
+ * {@link JwtAccessTokenConverter}.
+ *
+ * @author Dave Syer
+ * @since 1.3.0
+ */
public interface JwtAccessTokenConverterConfigurer {
+ /**
+ * Configure the {@link JwtAccessTokenConverter}.
+ * @param converter the converter to configure
+ */
void configure(JwtAccessTokenConverter converter);
}
diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/OAuth2ResourceServerConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/OAuth2ResourceServerConfiguration.java
index c70c0d92ab..156fac02f1 100644
--- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/OAuth2ResourceServerConfiguration.java
+++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/OAuth2ResourceServerConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2014 the original author or authors.
+ * Copyright 2012-2015 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.
@@ -16,6 +16,7 @@
package org.springframework.boot.autoconfigure.security.oauth2.resource;
+import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
@@ -27,13 +28,16 @@ import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.boot.autoconfigure.security.oauth2.resource.OAuth2ResourceServerConfiguration.ResourceServerCondition;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ConfigurationCondition;
import org.springframework.context.annotation.Import;
+import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;
+import org.springframework.core.type.StandardAnnotationMetadata;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerEndpointsConfiguration;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
@@ -50,6 +54,7 @@ import org.springframework.util.StringUtils;
*
* @author Greg Turnquist
* @author Dave Syer
+ * @since 1.3.0
*/
@Configuration
@Conditional(ResourceServerCondition.class)
@@ -91,10 +96,13 @@ public class OAuth2ResourceServerConfiguration {
}
- @ConditionalOnBean(AuthorizationServerEndpointsConfiguration.class)
protected static class ResourceServerCondition extends SpringBootCondition implements
ConfigurationCondition {
+ private static final String AUTHORIZATION_ANNOTATION = "org.springframework."
+ + "security.oauth2.config.annotation.web.configuration."
+ + "AuthorizationServerEndpointsConfiguration";
+
@Override
public ConfigurationPhase getConfigurationPhase() {
return ConfigurationPhase.REGISTER_BEAN;
@@ -104,31 +112,48 @@ public class OAuth2ResourceServerConfiguration {
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
Environment environment = context.getEnvironment();
- RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment);
+ RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment,
+ "spring.oauth2.resource.");
String client = environment
.resolvePlaceholders("${spring.oauth2.client.clientId:}");
if (StringUtils.hasText(client)) {
return ConditionOutcome.match("found client id");
}
- if (!resolver.getSubProperties("spring.oauth2.resource.jwt").isEmpty()) {
+ if (!resolver.getSubProperties("jwt").isEmpty()) {
return ConditionOutcome.match("found JWT resource configuration");
}
- if (StringUtils.hasText(resolver
- .getProperty("spring.oauth2.resource.userInfoUri"))) {
- return ConditionOutcome
- .match("found UserInfo URI resource configuration");
+ if (StringUtils.hasText(resolver.getProperty("user-info-uri"))) {
+ return ConditionOutcome.match("found UserInfo "
+ + "URI resource configuration");
}
- if (ClassUtils
- .isPresent(
- "org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerEndpointsConfiguration",
- null)) {
- if (SpringBootCondition.evaluateForClass(ResourceServerCondition.class, context)) {
- return ConditionOutcome
- .match("found authorization server endpoints configuration");
+ if (ClassUtils.isPresent(AUTHORIZATION_ANNOTATION, null)) {
+ if (AuthorizationServerEndpointsConfigurationBeanCondition
+ .matches(context)) {
+ return ConditionOutcome.match("found authorization "
+ + "server endpoints configuration");
}
}
- return ConditionOutcome
- .noMatch("found neither client id nor JWT resource nor authorization server");
+ return ConditionOutcome.noMatch("found neither client id nor "
+ + "JWT resource nor authorization server");
+ }
+
+ }
+
+ @ConditionalOnBean(AuthorizationServerEndpointsConfiguration.class)
+ private static class AuthorizationServerEndpointsConfigurationBeanCondition {
+
+ public static boolean matches(ConditionContext context) {
+ Class