Skip to content

Commit

Permalink
Add tests for OAuth 2.0 Device Authorization Grant
Browse files Browse the repository at this point in the history
This commit adds tests for the following components:
* AuthenticationConverters
* AuthenticationProviders
* Endpoint Filters

Issue spring-projectsgh-44
Issue spring-projectsgh-1127
  • Loading branch information
sjohnr committed Apr 10, 2023
1 parent 8c63c7d commit 5c2333a
Show file tree
Hide file tree
Showing 12 changed files with 3,088 additions and 0 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2020-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.security.oauth2.server.authorization.authentication;

import java.util.Map;
import java.util.function.Consumer;

import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;

/**
* @author Steve Riesenberg
*/
public final class OAuth2MetadataConsumers {
private OAuth2MetadataConsumers() {
}

public static Consumer<Map<String, Object>> accessGranted() {
return withTrueValue(OAuth2Authorization.Token.ACCESS_GRANTED_METADATA_NAME);
}

public static Consumer<Map<String, Object>> accessDenied() {
return withTrueValue(OAuth2Authorization.Token.ACCESS_DENIED_METADATA_NAME);
}

public static Consumer<Map<String, Object>> invalidated() {
return withTrueValue(OAuth2Authorization.Token.INVALIDATED_METADATA_NAME);
}

private static Consumer<Map<String, Object>> withTrueValue(String key) {
return (metadata) -> metadata.put(key, true);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2020-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.security.oauth2.server.authorization.authentication;

import java.util.function.Function;

import org.springframework.security.oauth2.core.OAuth2Token;
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;

/**
* @author Steve Riesenberg
*/
public final class OAuth2TokenMetadataExtractors {
private OAuth2TokenMetadataExtractors() {
}

public static Function<OAuth2Authorization.Token<? extends OAuth2Token>, Boolean> accessGranted() {
return extractBooleanValue(OAuth2Authorization.Token.ACCESS_GRANTED_METADATA_NAME);
}

public static Function<OAuth2Authorization.Token<? extends OAuth2Token>, Boolean> accessDenied() {
return extractBooleanValue(OAuth2Authorization.Token.ACCESS_DENIED_METADATA_NAME);
}

public static Function<OAuth2Authorization.Token<? extends OAuth2Token>, Boolean> invalidated() {
return extractBooleanValue(OAuth2Authorization.Token.INVALIDATED_METADATA_NAME);
}

private static Function<OAuth2Authorization.Token<? extends OAuth2Token>, Boolean> extractBooleanValue(String key) {
return (token) -> token.getMetadata(key);
}
}
Loading

0 comments on commit 5c2333a

Please sign in to comment.