Flatten ServerHttpSecurity.oauth2()

Fixes: gh-5712
This commit is contained in:
Rob Winch 2018-08-21 15:48:21 -05:00
parent 59cdfc7d6e
commit 0dc80aed40
4 changed files with 156 additions and 207 deletions

View File

@ -207,7 +207,9 @@ public class ServerHttpSecurity {
private OAuth2LoginSpec oauth2Login;
private OAuth2Spec oauth2;
private OAuth2ResourceServerSpec resourceServer;
private OAuth2ClientSpec client;
private LogoutSpec logout = new LogoutSpec();
@ -572,41 +574,6 @@ public class ServerHttpSecurity {
private OAuth2LoginSpec() {}
}
/**
* Configures OAuth2 support. An example configuration is provided below:
*
* <pre class="code">
* &#064;Bean
* public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
* http
* // ...
* .oauth2()
* .resourceServer()
* .jwt()
* .jwkSetUri(jwkSetUri);
* return http.build();
* }
* </pre>
*
* @return the {@link HttpBasicSpec} to customize
*/
public OAuth2Spec oauth2() {
if (this.oauth2 == null) {
this.oauth2 = new OAuth2Spec();
}
return this.oauth2;
}
/**
* Configures OAuth2 Support
*
* @since 5.1
*/
public class OAuth2Spec {
private OAuth2ResourceServerSpec resourceServer;
private OAuth2ClientSpec client;
/**
* Configures the OAuth2 client.
*
@ -615,8 +582,7 @@ public class ServerHttpSecurity {
* public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
* http
* // ...
* .oauth2()
* .client()
* .oauth2Client()
* .clientRegistrationRepository(clientRegistrationRepository)
* .authorizedClientRepository(authorizedClientRepository);
* return http.build();
@ -626,7 +592,7 @@ public class ServerHttpSecurity {
*
* @return the {@link OAuth2ClientSpec} to customize
*/
public OAuth2ClientSpec client() {
public OAuth2ClientSpec oauth2Client() {
if (this.client == null) {
this.client = new OAuth2ClientSpec();
}
@ -705,7 +671,7 @@ public class ServerHttpSecurity {
private OAuth2ClientSpec() {}
}
public OAuth2ResourceServerSpec resourceServer() {
public OAuth2ResourceServerSpec oauth2ResourceServer() {
if (this.resourceServer == null) {
this.resourceServer = new OAuth2ResourceServerSpec();
}
@ -788,25 +754,9 @@ public class ServerHttpSecurity {
}
}
public OAuth2Spec and() {
return OAuth2Spec.this;
}
}
public ServerHttpSecurity and() {
return ServerHttpSecurity.this;
}
protected void configure(ServerHttpSecurity http) {
if (this.resourceServer != null) {
this.resourceServer.configure(http);
}
if (this.client != null) {
this.client.configure(http);
}
}
private OAuth2Spec() {}
}
/**
@ -1009,8 +959,11 @@ public class ServerHttpSecurity {
if (this.oauth2Login != null) {
this.oauth2Login.configure(this);
}
if (this.oauth2 != null) {
this.oauth2.configure(this);
if (this.resourceServer != null) {
this.resourceServer.configure(this);
}
if (this.client != null) {
this.client.configure(this);
}
this.loginPage.configure(this);
if(this.logout != null) {

View File

@ -95,8 +95,7 @@ public class OAuth2ClientSpecTests {
@Bean
SecurityWebFilterChain springSecurity(ServerHttpSecurity http) {
http
.oauth2()
.client();
.oauth2Client();
return http.build();
}

View File

@ -40,8 +40,7 @@ public class SecurityConfig {
.and()
.formLogin()
.and()
.oauth2()
.client();
.oauth2Client();
return http.build();
}

View File

@ -45,8 +45,7 @@ public class SecurityConfig {
.authorizeExchange()
.anyExchange().authenticated()
.and()
.oauth2()
.resourceServer()
.oauth2ResourceServer()
.jwt()
.jwkSetUri(jwkSetUri);
return http.build();
@ -59,8 +58,7 @@ public class SecurityConfig {
.authorizeExchange()
.anyExchange().authenticated()
.and()
.oauth2()
.resourceServer()
.oauth2ResourceServer()
.jwt()
.publicKey(publicKey());
return http.build();