Add integration tests for How-to: Implement core services with Redis

Issue gh-1019
This commit is contained in:
Joe Grandja
2024-09-20 11:54:47 -04:00
parent 20f1048079
commit 00f3874a80
4 changed files with 233 additions and 13 deletions

View File

@@ -27,24 +27,26 @@ import org.springframework.stereotype.Repository;
public interface OAuth2AuthorizationGrantAuthorizationRepository
extends CrudRepository<OAuth2AuthorizationGrantAuthorization, String> {
<T extends OAuth2AuthorizationCodeGrantAuthorization> T findByState(String token);
<T extends OAuth2AuthorizationCodeGrantAuthorization> T findByState(String state);
<T extends OAuth2AuthorizationCodeGrantAuthorization> T findByAuthorizationCode_TokenValue(String token);
<T extends OAuth2AuthorizationCodeGrantAuthorization> T findByAuthorizationCode_TokenValue(String authorizationCode);
<T extends OAuth2AuthorizationGrantAuthorization> T findByAccessToken_TokenValue(String token);
<T extends OAuth2AuthorizationCodeGrantAuthorization> T findByStateOrAuthorizationCode_TokenValue(String state, String authorizationCode);
<T extends OAuth2AuthorizationGrantAuthorization> T findByRefreshToken_TokenValue(String token);
<T extends OAuth2AuthorizationGrantAuthorization> T findByAccessToken_TokenValue(String accessToken);
<T extends OidcAuthorizationCodeGrantAuthorization> T findByIdToken_TokenValue(String token);
<T extends OAuth2AuthorizationGrantAuthorization> T findByRefreshToken_TokenValue(String refreshToken);
<T extends OAuth2DeviceCodeGrantAuthorization> T findByDeviceState(String token);
<T extends OAuth2AuthorizationGrantAuthorization> T findByAccessToken_TokenValueOrRefreshToken_TokenValue(String accessToken, String refreshToken);
<T extends OAuth2DeviceCodeGrantAuthorization> T findByDeviceCode_TokenValue(String token);
<T extends OidcAuthorizationCodeGrantAuthorization> T findByIdToken_TokenValue(String idToken);
<T extends OAuth2DeviceCodeGrantAuthorization> T findByUserCode_TokenValue(String token);
<T extends OAuth2DeviceCodeGrantAuthorization> T findByDeviceState(String deviceState);
<T extends OAuth2AuthorizationGrantAuthorization> T findByStateOrAuthorizationCode_TokenValueOrAccessToken_TokenValueOrRefreshToken_TokenValueOrIdToken_TokenValueOrDeviceStateOrDeviceCode_TokenValueOrUserCode_TokenValue(
String state, String authorizationCode, String accessToken, String refreshToken, String idToken,
String deviceState, String deviceCode, String userCode);
<T extends OAuth2DeviceCodeGrantAuthorization> T findByDeviceCode_TokenValue(String deviceCode);
<T extends OAuth2DeviceCodeGrantAuthorization> T findByUserCode_TokenValue(String userCode);
<T extends OAuth2DeviceCodeGrantAuthorization> T findByDeviceStateOrDeviceCode_TokenValueOrUserCode_TokenValue(String deviceState, String deviceCode, String userCode);
}

View File

@@ -73,8 +73,19 @@ public class RedisOAuth2AuthorizationService implements OAuth2AuthorizationServi
OAuth2AuthorizationGrantAuthorization authorizationGrantAuthorization = null;
if (tokenType == null) {
authorizationGrantAuthorization = this.authorizationGrantAuthorizationRepository
.findByStateOrAuthorizationCode_TokenValueOrAccessToken_TokenValueOrRefreshToken_TokenValueOrIdToken_TokenValueOrDeviceStateOrDeviceCode_TokenValueOrUserCode_TokenValue(
token, token, token, token, token, token, token, token);
.findByStateOrAuthorizationCode_TokenValue(token, token);
if (authorizationGrantAuthorization == null) {
authorizationGrantAuthorization = this.authorizationGrantAuthorizationRepository
.findByAccessToken_TokenValueOrRefreshToken_TokenValue(token, token);
}
if (authorizationGrantAuthorization == null) {
authorizationGrantAuthorization = this.authorizationGrantAuthorizationRepository
.findByIdToken_TokenValue(token);
}
if (authorizationGrantAuthorization == null) {
authorizationGrantAuthorization = this.authorizationGrantAuthorizationRepository
.findByDeviceStateOrDeviceCode_TokenValueOrUserCode_TokenValue(token, token, token);
}
}
else if (OAuth2ParameterNames.STATE.equals(tokenType.getValue())) {
authorizationGrantAuthorization = this.authorizationGrantAuthorizationRepository.findByState(token);