Skip to content

Commit 5c2333a

Browse files
author
Steve Riesenberg
committed
Add tests for OAuth 2.0 Device Authorization Grant
This commit adds tests for the following components: * AuthenticationConverters * AuthenticationProviders * Endpoint Filters Issue spring-projectsgh-44 Issue spring-projectsgh-1127
1 parent 8c63c7d commit 5c2333a

12 files changed

+3088
-0
lines changed

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

Lines changed: 405 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 315 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 424 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 305 additions & 0 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2020-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.security.oauth2.server.authorization.authentication;
17+
18+
import java.util.Map;
19+
import java.util.function.Consumer;
20+
21+
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
22+
23+
/**
24+
* @author Steve Riesenberg
25+
*/
26+
public final class OAuth2MetadataConsumers {
27+
private OAuth2MetadataConsumers() {
28+
}
29+
30+
public static Consumer<Map<String, Object>> accessGranted() {
31+
return withTrueValue(OAuth2Authorization.Token.ACCESS_GRANTED_METADATA_NAME);
32+
}
33+
34+
public static Consumer<Map<String, Object>> accessDenied() {
35+
return withTrueValue(OAuth2Authorization.Token.ACCESS_DENIED_METADATA_NAME);
36+
}
37+
38+
public static Consumer<Map<String, Object>> invalidated() {
39+
return withTrueValue(OAuth2Authorization.Token.INVALIDATED_METADATA_NAME);
40+
}
41+
42+
private static Consumer<Map<String, Object>> withTrueValue(String key) {
43+
return (metadata) -> metadata.put(key, true);
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2020-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.security.oauth2.server.authorization.authentication;
17+
18+
import java.util.function.Function;
19+
20+
import org.springframework.security.oauth2.core.OAuth2Token;
21+
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
22+
23+
/**
24+
* @author Steve Riesenberg
25+
*/
26+
public final class OAuth2TokenMetadataExtractors {
27+
private OAuth2TokenMetadataExtractors() {
28+
}
29+
30+
public static Function<OAuth2Authorization.Token<? extends OAuth2Token>, Boolean> accessGranted() {
31+
return extractBooleanValue(OAuth2Authorization.Token.ACCESS_GRANTED_METADATA_NAME);
32+
}
33+
34+
public static Function<OAuth2Authorization.Token<? extends OAuth2Token>, Boolean> accessDenied() {
35+
return extractBooleanValue(OAuth2Authorization.Token.ACCESS_DENIED_METADATA_NAME);
36+
}
37+
38+
public static Function<OAuth2Authorization.Token<? extends OAuth2Token>, Boolean> invalidated() {
39+
return extractBooleanValue(OAuth2Authorization.Token.INVALIDATED_METADATA_NAME);
40+
}
41+
42+
private static Function<OAuth2Authorization.Token<? extends OAuth2Token>, Boolean> extractBooleanValue(String key) {
43+
return (token) -> token.getMetadata(key);
44+
}
45+
}

0 commit comments

Comments
 (0)