Skip to content

Commit 022004d

Browse files
committed
Merge pull request #35460 from sjohnr
* pr/35460: Polish "Add property defaults for Spring Authorization Server" Add property defaults for Spring Authorization Server Closes gh-35460
2 parents 3b1f4e6 + d7b4353 commit 022004d

File tree

2 files changed

+60
-21
lines changed

2 files changed

+60
-21
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/server/servlet/OAuth2AuthorizationServerProperties.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,37 +97,37 @@ public static class Endpoint {
9797
/**
9898
* Authorization Server's OAuth 2.0 Authorization Endpoint.
9999
*/
100-
private String authorizationUri;
100+
private String authorizationUri = "/oauth2/authorize";
101101

102102
/**
103103
* Authorization Server's OAuth 2.0 Device Authorization Endpoint.
104104
*/
105-
private String deviceAuthorizationUri;
105+
private String deviceAuthorizationUri = "/oauth2/device_authorization";
106106

107107
/**
108108
* Authorization Server's OAuth 2.0 Device Verification Endpoint.
109109
*/
110-
private String deviceVerificationUri;
110+
private String deviceVerificationUri = "/oauth2/device_verification";
111111

112112
/**
113113
* Authorization Server's OAuth 2.0 Token Endpoint.
114114
*/
115-
private String tokenUri;
115+
private String tokenUri = "/oauth2/token";
116116

117117
/**
118118
* Authorization Server's JWK Set Endpoint.
119119
*/
120-
private String jwkSetUri;
120+
private String jwkSetUri = "/oauth2/jwks";
121121

122122
/**
123123
* Authorization Server's OAuth 2.0 Token Revocation Endpoint.
124124
*/
125-
private String tokenRevocationUri;
125+
private String tokenRevocationUri = "/oauth2/revoke";
126126

127127
/**
128128
* Authorization Server's OAuth 2.0 Token Introspection Endpoint.
129129
*/
130-
private String tokenIntrospectionUri;
130+
private String tokenIntrospectionUri = "/oauth2/introspect";
131131

132132
/**
133133
* OpenID Connect 1.0 endpoints.
@@ -205,17 +205,17 @@ public static class OidcEndpoint {
205205
/**
206206
* Authorization Server's OpenID Connect 1.0 Logout Endpoint.
207207
*/
208-
private String logoutUri;
208+
private String logoutUri = "/connect/logout";
209209

210210
/**
211211
* Authorization Server's OpenID Connect 1.0 Client Registration Endpoint.
212212
*/
213-
private String clientRegistrationUri;
213+
private String clientRegistrationUri = "/connect/register";
214214

215215
/**
216216
* Authorization Server's OpenID Connect 1.0 UserInfo Endpoint.
217217
*/
218-
private String userInfoUri;
218+
private String userInfoUri = "/userinfo";
219219

220220
public String getLogoutUri() {
221221
return this.logoutUri;
@@ -258,12 +258,12 @@ public static class Client {
258258
* Whether the client is required to provide a proof key challenge and verifier
259259
* when performing the Authorization Code Grant flow.
260260
*/
261-
private boolean requireProofKey;
261+
private boolean requireProofKey = false;
262262

263263
/**
264264
* Whether authorization consent is required when the client requests access.
265265
*/
266-
private boolean requireAuthorizationConsent;
266+
private boolean requireAuthorizationConsent = false;
267267

268268
/**
269269
* URL for the client's JSON Web Key Set.
@@ -444,17 +444,17 @@ public static class Token {
444444
/**
445445
* Time-to-live for an authorization code.
446446
*/
447-
private Duration authorizationCodeTimeToLive;
447+
private Duration authorizationCodeTimeToLive = Duration.ofMinutes(5);
448448

449449
/**
450450
* Time-to-live for an access token.
451451
*/
452-
private Duration accessTokenTimeToLive;
452+
private Duration accessTokenTimeToLive = Duration.ofMinutes(5);
453453

454454
/**
455455
* Token format for an access token.
456456
*/
457-
private String accessTokenFormat;
457+
private String accessTokenFormat = "self-contained";
458458

459459
/**
460460
* Time-to-live for a device code.
@@ -465,17 +465,17 @@ public static class Token {
465465
* Whether refresh tokens are reused or a new refresh token is issued when
466466
* returning the access token response.
467467
*/
468-
private boolean reuseRefreshTokens;
468+
private boolean reuseRefreshTokens = true;
469469

470470
/**
471471
* Time-to-live for a refresh token.
472472
*/
473-
private Duration refreshTokenTimeToLive;
473+
private Duration refreshTokenTimeToLive = Duration.ofMinutes(60);
474474

475475
/**
476476
* JWS algorithm for signing the ID Token.
477477
*/
478-
private String idTokenSignatureAlgorithm;
478+
private String idTokenSignatureAlgorithm = "RS256";
479479

480480
public Duration getAuthorizationCodeTimeToLive() {
481481
return this.authorizationCodeTimeToLive;

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/server/servlet/OAuth2AuthorizationServerPropertiesTests.java

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import org.junit.jupiter.api.Test;
2020

21+
import org.springframework.security.oauth2.server.authorization.settings.AuthorizationServerSettings;
22+
import org.springframework.security.oauth2.server.authorization.settings.ClientSettings;
2123
import org.springframework.security.oauth2.server.authorization.settings.TokenSettings;
2224

2325
import static org.assertj.core.api.Assertions.assertThat;
@@ -73,9 +75,46 @@ void authorizationGrantTypesEmptyThrowsException() {
7375
}
7476

7577
@Test
76-
void defaultDeviceCodeTimeToLiveMatchesBuilderDefault() {
77-
assertThat(new OAuth2AuthorizationServerProperties.Client().getToken().getDeviceCodeTimeToLive())
78-
.isEqualTo(TokenSettings.builder().build().getDeviceCodeTimeToLive());
78+
void defaultEndpointPropertiesMatchBuilderDefaults() {
79+
OAuth2AuthorizationServerProperties.Endpoint properties = new OAuth2AuthorizationServerProperties.Endpoint();
80+
AuthorizationServerSettings defaults = AuthorizationServerSettings.builder().build();
81+
assertThat(properties.getAuthorizationUri()).isEqualTo(defaults.getAuthorizationEndpoint());
82+
assertThat(properties.getDeviceAuthorizationUri()).isEqualTo(defaults.getDeviceAuthorizationEndpoint());
83+
assertThat(properties.getDeviceVerificationUri()).isEqualTo(defaults.getDeviceVerificationEndpoint());
84+
assertThat(properties.getTokenUri()).isEqualTo(defaults.getTokenEndpoint());
85+
assertThat(properties.getJwkSetUri()).isEqualTo(defaults.getJwkSetEndpoint());
86+
assertThat(properties.getTokenRevocationUri()).isEqualTo(defaults.getTokenRevocationEndpoint());
87+
assertThat(properties.getTokenIntrospectionUri()).isEqualTo(defaults.getTokenIntrospectionEndpoint());
88+
OAuth2AuthorizationServerProperties.OidcEndpoint oidc = properties.getOidc();
89+
assertThat(oidc.getLogoutUri()).isEqualTo(defaults.getOidcLogoutEndpoint());
90+
assertThat(oidc.getClientRegistrationUri()).isEqualTo(defaults.getOidcClientRegistrationEndpoint());
91+
assertThat(oidc.getUserInfoUri()).isEqualTo(defaults.getOidcUserInfoEndpoint());
92+
}
93+
94+
@Test
95+
void defaultClientPropertiesMatchBuilderDefaults() {
96+
OAuth2AuthorizationServerProperties.Client properties = new OAuth2AuthorizationServerProperties.Client();
97+
ClientSettings defaults = ClientSettings.builder().build();
98+
assertThat(properties.isRequireProofKey()).isEqualTo(defaults.isRequireProofKey());
99+
assertThat(properties.isRequireAuthorizationConsent()).isEqualTo(defaults.isRequireAuthorizationConsent());
100+
assertThat(properties.getJwkSetUri()).isEqualTo(defaults.getJwkSetUrl());
101+
assertThat(properties.getTokenEndpointAuthenticationSigningAlgorithm())
102+
.isEqualTo((defaults.getTokenEndpointAuthenticationSigningAlgorithm() != null)
103+
? defaults.getTokenEndpointAuthenticationSigningAlgorithm().getName() : null);
104+
}
105+
106+
@Test
107+
void defaultTokenPropertiesMatchBuilderDefaults() {
108+
OAuth2AuthorizationServerProperties.Token properties = new OAuth2AuthorizationServerProperties.Token();
109+
TokenSettings defaults = TokenSettings.builder().build();
110+
assertThat(properties.getAuthorizationCodeTimeToLive()).isEqualTo(defaults.getAuthorizationCodeTimeToLive());
111+
assertThat(properties.getAccessTokenTimeToLive()).isEqualTo(defaults.getAccessTokenTimeToLive());
112+
assertThat(properties.getAccessTokenFormat()).isEqualTo(defaults.getAccessTokenFormat().getValue());
113+
assertThat(properties.getDeviceCodeTimeToLive()).isEqualTo(defaults.getDeviceCodeTimeToLive());
114+
assertThat(properties.isReuseRefreshTokens()).isEqualTo(defaults.isReuseRefreshTokens());
115+
assertThat(properties.getRefreshTokenTimeToLive()).isEqualTo(defaults.getRefreshTokenTimeToLive());
116+
assertThat(properties.getIdTokenSignatureAlgorithm())
117+
.isEqualTo(defaults.getIdTokenSignatureAlgorithm().getName());
79118
}
80119

81120
}

0 commit comments

Comments
 (0)