Skip to content

Commit 6efce64

Browse files
snicolldsyer
authored andcommitted
Generates useful metadata (spring-guides#36)
Prior to this commit, the generated metadata were mostly empty and did not really validate what was instructed in the guide. One reason was that `ClientResources` was treating the underlying types as mono value object so no meta-data were generated on them. The other reason was that the concrete type wasn't returned and the interface has no setter so no properties were found either. This commit fixes the infrastructure so that the generated metadata is valid.
1 parent a528aad commit 6efce64

File tree

6 files changed

+26
-9
lines changed

6 files changed

+26
-9
lines changed

auth-server/README.adoc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,13 @@ the `OAuth2ProtectedResourceDetails` and the
5151
----
5252
class ClientResources {
5353
54-
private OAuth2ProtectedResourceDetails client = new AuthorizationCodeResourceDetails();
54+
@NestedConfigurationProperty
55+
private AuthorizationCodeResourceDetails client = new AuthorizationCodeResourceDetails();
56+
57+
@NestedConfigurationProperty
5558
private ResourceServerProperties resource = new ResourceServerProperties();
5659
57-
public OAuth2ProtectedResourceDetails getClient() {
60+
public AuthorizationCodeResourceDetails getClient() {
5861
return client;
5962
}
6063
@@ -64,6 +67,10 @@ class ClientResources {
6467
}
6568
----
6669

70+
NOTE: the wrapper uses `@NestedConfigurationProperty` to instructs the annotation
71+
processor to crawl that type for meta-data as well since it does not represents
72+
a single value but a complete nested type.
73+
6774
With this wrapper in place we can use the same YAML configuration as
6875
before, but a single method for each provider:
6976

auth-server/src/main/java/com/example/SocialApplication.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties;
3030
import org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoTokenServices;
3131
import org.springframework.boot.context.properties.ConfigurationProperties;
32+
import org.springframework.boot.context.properties.NestedConfigurationProperty;
3233
import org.springframework.boot.web.servlet.FilterRegistrationBean;
3334
import org.springframework.context.annotation.Bean;
3435
import org.springframework.context.annotation.Configuration;
@@ -138,10 +139,14 @@ private Filter ssoFilter(ClientResources client, String path) {
138139
}
139140

140141
class ClientResources {
141-
private OAuth2ProtectedResourceDetails client = new AuthorizationCodeResourceDetails();
142+
143+
@NestedConfigurationProperty
144+
private AuthorizationCodeResourceDetails client = new AuthorizationCodeResourceDetails();
145+
146+
@NestedConfigurationProperty
142147
private ResourceServerProperties resource = new ResourceServerProperties();
143148

144-
public OAuth2ProtectedResourceDetails getClient() {
149+
public AuthorizationCodeResourceDetails getClient() {
145150
return client;
146151
}
147152

github/README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ supplemented with similar methods `github()` and `githubResource()`:
7272
----
7373
@Bean
7474
@ConfigurationProperties("github.client")
75-
public OAuth2ProtectedResourceDetails github() {
75+
public AuthorizationCodeResourceDetails github() {
7676
return new AuthorizationCodeResourceDetails();
7777
}
7878

github/src/main/java/com/example/SocialApplication.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties;
3030
import org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoTokenServices;
3131
import org.springframework.boot.context.properties.ConfigurationProperties;
32+
import org.springframework.boot.context.properties.NestedConfigurationProperty;
3233
import org.springframework.boot.web.servlet.FilterRegistrationBean;
3334
import org.springframework.context.annotation.Bean;
3435
import org.springframework.context.annotation.Configuration;
@@ -140,10 +141,14 @@ private Filter ssoFilter(ClientResources client, String path) {
140141
}
141142

142143
class ClientResources {
143-
private OAuth2ProtectedResourceDetails client = new AuthorizationCodeResourceDetails();
144+
145+
@NestedConfigurationProperty
146+
private AuthorizationCodeResourceDetails client = new AuthorizationCodeResourceDetails();
147+
148+
@NestedConfigurationProperty
144149
private ResourceServerProperties resource = new ResourceServerProperties();
145150

146-
public OAuth2ProtectedResourceDetails getClient() {
151+
public AuthorizationCodeResourceDetails getClient() {
147152
return client;
148153
}
149154

manual/README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ the filter also needs to know about the client registration with Facebook:
8383
8484
@Bean
8585
@ConfigurationProperties("facebook.client")
86-
public OAuth2ProtectedResourceDetails facebook() {
86+
public AuthorizationCodeResourceDetails facebook() {
8787
return new AuthorizationCodeResourceDetails();
8888
}
8989
----

manual/src/main/java/com/example/SocialApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private Filter ssoFilter() {
9191

9292
@Bean
9393
@ConfigurationProperties("facebook.client")
94-
public OAuth2ProtectedResourceDetails facebook() {
94+
public AuthorizationCodeResourceDetails facebook() {
9595
return new AuthorizationCodeResourceDetails();
9696
}
9797

0 commit comments

Comments
 (0)