@Override public void removeAccessToken(OAuth2AccessToken accessToken) { /*Query query = new Query(); query.addCriteria(Criteria.where("tokenId").is(accessToken.getValue())); OAuth2AuthenticationAccessToken token = mongoTemplate.findOne(query, OAuth2AuthenticationAccessToken.class, "oauth2_access_token");*/ OAuth2AuthenticationAccessToken token = oAuth2AccessTokenDao.findByTokenId(accessToken.getValue()); if (token != null) { oAuth2AccessTokenDao.delete(token); } }
@Override public void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication) { OAuth2AuthenticationAccessToken oAuth2AuthenticationAccessToken = new OAuth2AuthenticationAccessToken( token, authentication, authenticationKeyGenerator.extractKey(authentication)); oAuth2AccessTokenDao.save(oAuth2AuthenticationAccessToken); }
@Override public OAuth2Authentication readAuthentication(String tokenId) { /* Query query = new Query(); query.addCriteria(Criteria.where("tokenId").is(tokenId)); OAuth2AuthenticationAccessToken token = mongoTemplate.findOne(query, OAuth2AuthenticationAccessToken.class, "oauth2_access_token"); */ OAuth2AuthenticationAccessToken token = oAuth2AccessTokenDao.findByTokenId(tokenId); return null == token ? null : token.getAuthentication(); }
@Override public Collection<OAuth2AccessToken> findTokensByClientId(String clientId) { /*Query query = new Query(); query.addCriteria(Criteria.where("clientId").is(clientId)); List<OAuth2AuthenticationAccessToken> accessTokens = mongoTemplate.find(query, OAuth2AuthenticationAccessToken.class, "oauth2_access_token");*/ List<OAuth2AuthenticationAccessToken> accessTokens = oAuth2AccessTokenDao.findByClientId(clientId); return extractAccessTokens(accessTokens); }
@Override public OAuth2AccessToken readAccessToken(String tokenId) { /* Query query = new Query(); query.addCriteria(Criteria.where("tokenId").is(tokenId)); OAuth2AuthenticationAccessToken token = mongoTemplate.findOne(query, OAuth2AuthenticationAccessToken.class, "oauth2_access_token"); */ OAuth2AuthenticationAccessToken token = oAuth2AccessTokenDao.findByTokenId(tokenId); if (null == token) { throw new InvalidTokenException("Token not valid"); } return token.getoAuth2AccessToken(); }
@Override public OAuth2AccessToken getAccessToken(OAuth2Authentication authentication) { String authenticationId = authenticationKeyGenerator.extractKey(authentication); if (null == authenticationId) { return null; } /*Query query = new Query(); query.addCriteria(Criteria.where("authenticationId").is(authenticationId)); OAuth2AuthenticationAccessToken token = mongoTemplate.findOne(query, OAuth2AuthenticationAccessToken.class, "oauth2_access_token"); */ OAuth2AuthenticationAccessToken token = oAuth2AccessTokenDao.findByAuthenticationId(authenticationId); return token == null ? null : token.getoAuth2AccessToken(); }