Skip to content

Commit ceb75e3

Browse files
committed
Merge branch '1.4.x' into 1.5.x
Closes gh-2216
2 parents 4f83ac2 + 4a3a1ba commit ceb75e3

File tree

5 files changed

+49
-7
lines changed

5 files changed

+49
-7
lines changed

docs/src/test/java/sample/jpa/JpaTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2024 the original author or authors.
2+
* Copyright 2020-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -63,6 +63,7 @@
6363
import org.springframework.util.StringUtils;
6464

6565
import static org.assertj.core.api.Assertions.assertThat;
66+
import static sample.util.RegisteredClients.deviceMessagingClient;
6667
import static sample.util.RegisteredClients.messagingClient;
6768

6869
/**
@@ -140,7 +141,7 @@ public void deviceAuthorizationWhenJpaCoreServicesAutowiredThenSuccess() throws
140141
assertThat(this.authorizationService).isInstanceOf(JpaOAuth2AuthorizationService.class);
141142
assertThat(this.authorizationConsentService).isInstanceOf(JpaOAuth2AuthorizationConsentService.class);
142143

143-
RegisteredClient registeredClient = messagingClient();
144+
RegisteredClient registeredClient = deviceMessagingClient();
144145
this.registeredClientRepository.save(registeredClient);
145146

146147
DeviceAuthorizationGrantFlow deviceAuthorizationGrantFlow = new DeviceAuthorizationGrantFlow(this.mockMvc);

docs/src/test/java/sample/redis/RedisTests.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2024 the original author or authors.
2+
* Copyright 2020-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -63,6 +63,8 @@
6363
public class RedisTests {
6464
private static final RegisteredClient TEST_MESSAGING_CLIENT = RegisteredClients.messagingClient();
6565

66+
private static final RegisteredClient TEST_DEVICE_MESSAGING_CLIENT = RegisteredClients.deviceMessagingClient();
67+
6668
@Autowired
6769
private MockMvc mockMvc;
6870

@@ -126,7 +128,7 @@ public void deviceAuthorizationWhenRedisCoreServicesAutowiredThenUsed() throws E
126128
assertThat(this.authorizationService).isInstanceOf(RedisOAuth2AuthorizationService.class);
127129
assertThat(this.authorizationConsentService).isInstanceOf(RedisOAuth2AuthorizationConsentService.class);
128130

129-
RegisteredClient registeredClient = TEST_MESSAGING_CLIENT;
131+
RegisteredClient registeredClient = TEST_DEVICE_MESSAGING_CLIENT;
130132

131133
DeviceAuthorizationGrantFlow deviceAuthorizationGrantFlow = new DeviceAuthorizationGrantFlow(this.mockMvc);
132134
deviceAuthorizationGrantFlow.setUsername("user");
@@ -194,6 +196,7 @@ static class RedisServerConfig {
194196
void postConstruct() throws IOException {
195197
this.redisServer.start();
196198
this.registeredClientRepository.save(TEST_MESSAGING_CLIENT);
199+
this.registeredClientRepository.save(TEST_DEVICE_MESSAGING_CLIENT);
197200
}
198201

199202
@PreDestroy

docs/src/test/java/sample/util/RegisteredClients.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 the original author or authors.
2+
* Copyright 2020-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,4 +46,20 @@ public static RegisteredClient messagingClient() {
4646
.build();
4747
}
4848
// @formatter:on
49+
50+
// @formatter:off
51+
public static RegisteredClient deviceMessagingClient() {
52+
return RegisteredClient.withId(UUID.randomUUID().toString())
53+
.clientId("device-messaging-client")
54+
.clientSecret("{noop}secret")
55+
.clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC)
56+
.authorizationGrantType(AuthorizationGrantType.DEVICE_CODE)
57+
.authorizationGrantType(AuthorizationGrantType.REFRESH_TOKEN)
58+
.scope("message.read")
59+
.scope("message.write")
60+
.clientSettings(ClientSettings.builder().requireAuthorizationConsent(true).build())
61+
.build();
62+
}
63+
// @formatter:on
64+
4965
}

oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/authentication/OAuth2DeviceAuthorizationRequestAuthenticationProvider.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2024 the original author or authors.
2+
* Copyright 2020-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,6 +39,7 @@
3939
import org.springframework.security.oauth2.core.OAuth2ErrorCodes;
4040
import org.springframework.security.oauth2.core.OAuth2UserCode;
4141
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
42+
import org.springframework.security.oauth2.core.oidc.OidcScopes;
4243
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
4344
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
4445
import org.springframework.security.oauth2.server.authorization.OAuth2TokenType;
@@ -120,6 +121,9 @@ public Authentication authenticate(Authentication authentication) throws Authent
120121
throwError(OAuth2ErrorCodes.INVALID_SCOPE, OAuth2ParameterNames.SCOPE);
121122
}
122123
}
124+
if (requestedScopes.contains(OidcScopes.OPENID)) {
125+
throwError(OAuth2ErrorCodes.INVALID_SCOPE, OAuth2ParameterNames.SCOPE);
126+
}
123127
}
124128

125129
if (this.logger.isTraceEnabled()) {

oauth2-authorization-server/src/test/java/org/springframework/security/oauth2/server/authorization/authentication/OAuth2DeviceAuthorizationRequestAuthenticationProviderTests.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 the original author or authors.
2+
* Copyright 2020-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,6 +34,7 @@
3434
import org.springframework.security.oauth2.core.OAuth2ErrorCodes;
3535
import org.springframework.security.oauth2.core.OAuth2UserCode;
3636
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
37+
import org.springframework.security.oauth2.core.oidc.OidcScopes;
3738
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
3839
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
3940
import org.springframework.security.oauth2.server.authorization.client.RegisteredClient;
@@ -165,6 +166,23 @@ public void authenticateWhenInvalidScopesThenThrowOAuth2AuthenticationException(
165166
// @formatter:on
166167
}
167168

169+
@Test
170+
public void authenticateWhenOpenIdScopeThenThrowOAuth2AuthenticationException() {
171+
RegisteredClient registeredClient = TestRegisteredClients.registeredClient()
172+
.authorizationGrantType(AuthorizationGrantType.DEVICE_CODE)
173+
.scope(OidcScopes.OPENID)
174+
.build();
175+
Authentication authentication = createAuthentication(registeredClient);
176+
// @formatter:off
177+
assertThatExceptionOfType(OAuth2AuthenticationException.class)
178+
.isThrownBy(() -> this.authenticationProvider.authenticate(authentication))
179+
.withMessageContaining(OAuth2ParameterNames.SCOPE)
180+
.extracting(OAuth2AuthenticationException::getError)
181+
.extracting(OAuth2Error::getErrorCode)
182+
.isEqualTo(OAuth2ErrorCodes.INVALID_SCOPE);
183+
// @formatter:on
184+
}
185+
168186
@Test
169187
public void authenticateWhenDeviceCodeIsNullThenThrowOAuth2AuthenticationException() {
170188
@SuppressWarnings("unchecked")

0 commit comments

Comments
 (0)