From 51b67ebc031dac77438c5d68d62fbb9e50bfc165 Mon Sep 17 00:00:00 2001 From: Justin Richer Date: Fri, 14 Dec 2012 17:00:42 -0500 Subject: [PATCH] added queries to get access token from id token --- .../mitre/oauth2/model/OAuth2AccessTokenEntity.java | 1 + .../oauth2/repository/OAuth2TokenRepository.java | 5 +++++ .../oauth2/service/OAuth2TokenEntityService.java | 6 ++++++ .../repository/impl/JpaOAuth2TokenRepository.java | 11 +++++++++++ .../impl/DefaultOAuth2ProviderTokenService.java | 8 ++++++++ 5 files changed, 31 insertions(+) diff --git a/openid-connect-common/src/main/java/org/mitre/oauth2/model/OAuth2AccessTokenEntity.java b/openid-connect-common/src/main/java/org/mitre/oauth2/model/OAuth2AccessTokenEntity.java index 67b6d3370..1968024db 100644 --- a/openid-connect-common/src/main/java/org/mitre/oauth2/model/OAuth2AccessTokenEntity.java +++ b/openid-connect-common/src/main/java/org/mitre/oauth2/model/OAuth2AccessTokenEntity.java @@ -58,6 +58,7 @@ import org.springframework.security.oauth2.common.OAuth2RefreshToken; @NamedQuery(name = "OAuth2AccessTokenEntity.getByClient", query = "select a from OAuth2AccessTokenEntity a where a.client = :client"), @NamedQuery(name = "OAuth2AccessTokenEntity.getExpired", query = "select a from OAuth2AccessTokenEntity a where a.expiration is not null and a.expiration < current_timestamp"), @NamedQuery(name = "OAuth2AccessTokenEntity.getByAuthentication", query = "select a from OAuth2AccessTokenEntity a where a.authenticationHolder.authentication = :authentication"), + @NamedQuery(name = "OAuth2AccessTokenEntity.getByIdToken", query = "select a from OAuth2AccessTokenEntity a where a.idToken = :idToken"), @NamedQuery(name = "OAuth2AccessTokenEntity.getByTokenValue", query = "select a from OAuth2AccessTokenEntity a where a.value = :tokenValue") }) //@JsonSerialize(using = OAuth2AccessTokenSerializer.class) diff --git a/openid-connect-common/src/main/java/org/mitre/oauth2/repository/OAuth2TokenRepository.java b/openid-connect-common/src/main/java/org/mitre/oauth2/repository/OAuth2TokenRepository.java index 63d2d5aed..b5b1622ce 100644 --- a/openid-connect-common/src/main/java/org/mitre/oauth2/repository/OAuth2TokenRepository.java +++ b/openid-connect-common/src/main/java/org/mitre/oauth2/repository/OAuth2TokenRepository.java @@ -53,5 +53,10 @@ public interface OAuth2TokenRepository { public List getExpiredRefreshTokens(); public OAuth2AccessTokenEntity getByAuthentication(OAuth2Authentication auth); + + /** + * @return + */ + public OAuth2AccessTokenEntity getAccessTokenForIdToken(OAuth2AccessTokenEntity idToken); } diff --git a/openid-connect-common/src/main/java/org/mitre/oauth2/service/OAuth2TokenEntityService.java b/openid-connect-common/src/main/java/org/mitre/oauth2/service/OAuth2TokenEntityService.java index 8b0dc9786..cdb25b6a7 100644 --- a/openid-connect-common/src/main/java/org/mitre/oauth2/service/OAuth2TokenEntityService.java +++ b/openid-connect-common/src/main/java/org/mitre/oauth2/service/OAuth2TokenEntityService.java @@ -45,5 +45,11 @@ public interface OAuth2TokenEntityService extends AuthorizationServerTokenServic public OAuth2RefreshTokenEntity saveRefreshToken(OAuth2RefreshTokenEntity refreshToken); public OAuth2AccessTokenEntity getAccessToken(OAuth2Authentication authentication); + + /** + * @param incomingToken + * @return + */ + public OAuth2AccessTokenEntity getAccessTokenForIdToken(OAuth2AccessTokenEntity idToken); } diff --git a/openid-connect-server/src/main/java/org/mitre/oauth2/repository/impl/JpaOAuth2TokenRepository.java b/openid-connect-server/src/main/java/org/mitre/oauth2/repository/impl/JpaOAuth2TokenRepository.java index 049cdd092..f6d89b37d 100644 --- a/openid-connect-server/src/main/java/org/mitre/oauth2/repository/impl/JpaOAuth2TokenRepository.java +++ b/openid-connect-server/src/main/java/org/mitre/oauth2/repository/impl/JpaOAuth2TokenRepository.java @@ -172,4 +172,15 @@ public class JpaOAuth2TokenRepository implements OAuth2TokenRepository { return JpaUtil.getSingleResult(accessTokens); } + /* (non-Javadoc) + * @see org.mitre.oauth2.repository.OAuth2TokenRepository#getAccessTokenForIdToken(org.mitre.oauth2.model.OAuth2AccessTokenEntity) + */ + @Override + public OAuth2AccessTokenEntity getAccessTokenForIdToken(OAuth2AccessTokenEntity idToken) { + TypedQuery queryA = manager.createNamedQuery("OAuth2AccessTokenEntity.getByIdToken", OAuth2AccessTokenEntity.class); + queryA.setParameter("idToken", idToken); + List accessTokens = queryA.getResultList(); + return JpaUtil.getSingleResult(accessTokens); + } + } diff --git a/openid-connect-server/src/main/java/org/mitre/oauth2/service/impl/DefaultOAuth2ProviderTokenService.java b/openid-connect-server/src/main/java/org/mitre/oauth2/service/impl/DefaultOAuth2ProviderTokenService.java index 5b0cf752f..71c0ca9f6 100644 --- a/openid-connect-server/src/main/java/org/mitre/oauth2/service/impl/DefaultOAuth2ProviderTokenService.java +++ b/openid-connect-server/src/main/java/org/mitre/oauth2/service/impl/DefaultOAuth2ProviderTokenService.java @@ -386,5 +386,13 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi public void setTokenEnhancer(TokenEnhancer tokenEnhancer) { this.tokenEnhancer = tokenEnhancer; } + + /* (non-Javadoc) + * @see org.mitre.oauth2.service.OAuth2TokenEntityService#getAccessTokenForIdToken(org.mitre.oauth2.model.OAuth2AccessTokenEntity) + */ + @Override + public OAuth2AccessTokenEntity getAccessTokenForIdToken(OAuth2AccessTokenEntity idToken) { + return tokenRepository.getAccessTokenForIdToken(idToken); + } }