Moved getExpired to service layers
parent
eea37cf79c
commit
b3bb43881d
|
@ -50,15 +50,8 @@ public interface OAuth2TokenRepository {
|
||||||
|
|
||||||
public List<OAuth2RefreshTokenEntity> getRefreshTokensForClient(ClientDetailsEntity client);
|
public List<OAuth2RefreshTokenEntity> getRefreshTokensForClient(ClientDetailsEntity client);
|
||||||
|
|
||||||
public List<OAuth2AccessTokenEntity> getExpiredAccessTokens();
|
|
||||||
|
|
||||||
public List<OAuth2RefreshTokenEntity> getExpiredRefreshTokens();
|
|
||||||
|
|
||||||
public OAuth2AccessTokenEntity getByAuthentication(OAuth2Authentication auth);
|
public OAuth2AccessTokenEntity getByAuthentication(OAuth2Authentication auth);
|
||||||
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public OAuth2AccessTokenEntity getAccessTokenForIdToken(OAuth2AccessTokenEntity idToken);
|
public OAuth2AccessTokenEntity getAccessTokenForIdToken(OAuth2AccessTokenEntity idToken);
|
||||||
|
|
||||||
public Set<OAuth2AccessTokenEntity> getAllAccessTokens();
|
public Set<OAuth2AccessTokenEntity> getAllAccessTokens();
|
||||||
|
|
|
@ -33,8 +33,6 @@ import org.springframework.security.oauth2.provider.OAuth2Authentication;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public class JpaOAuth2TokenRepository implements OAuth2TokenRepository {
|
public class JpaOAuth2TokenRepository implements OAuth2TokenRepository {
|
||||||
|
|
||||||
|
@ -162,38 +160,6 @@ public class JpaOAuth2TokenRepository implements OAuth2TokenRepository {
|
||||||
return refreshTokens;
|
return refreshTokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.mitre.oauth2.repository.OAuth2TokenRepository#getExpiredAccessTokens()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<OAuth2AccessTokenEntity> getExpiredAccessTokens() {
|
|
||||||
TypedQuery<OAuth2AccessTokenEntity> queryA = manager.createNamedQuery("OAuth2AccessTokenEntity.getAll", OAuth2AccessTokenEntity.class);
|
|
||||||
List<OAuth2AccessTokenEntity> accessTokens = queryA.getResultList();
|
|
||||||
List<OAuth2AccessTokenEntity> expired = Lists.newArrayList();
|
|
||||||
for (OAuth2AccessTokenEntity a : accessTokens) {
|
|
||||||
if (a.isExpired()) {
|
|
||||||
expired.add(a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return expired;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.mitre.oauth2.repository.OAuth2TokenRepository#getExpiredRefreshTokens()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<OAuth2RefreshTokenEntity> getExpiredRefreshTokens() {
|
|
||||||
TypedQuery<OAuth2RefreshTokenEntity> queryR = manager.createNamedQuery("OAuth2RefreshTokenEntity.getAll", OAuth2RefreshTokenEntity.class);
|
|
||||||
List<OAuth2RefreshTokenEntity> refreshTokens = queryR.getResultList();
|
|
||||||
List<OAuth2RefreshTokenEntity> expired = Lists.newArrayList();
|
|
||||||
for (OAuth2RefreshTokenEntity r : refreshTokens) {
|
|
||||||
if (r.isExpired()) {
|
|
||||||
expired.add(r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return expired;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OAuth2AccessTokenEntity getByAuthentication(OAuth2Authentication auth) {
|
public OAuth2AccessTokenEntity getByAuthentication(OAuth2Authentication auth) {
|
||||||
TypedQuery<OAuth2AccessTokenEntity> queryA = manager.createNamedQuery("OAuth2AccessTokenEntity.getByAuthentication", OAuth2AccessTokenEntity.class);
|
TypedQuery<OAuth2AccessTokenEntity> queryA = manager.createNamedQuery("OAuth2AccessTokenEntity.getByAuthentication", OAuth2AccessTokenEntity.class);
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
*/
|
*/
|
||||||
package org.mitre.oauth2.service.impl;
|
package org.mitre.oauth2.service.impl;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -49,6 +50,7 @@ import org.springframework.security.oauth2.provider.TokenRequest;
|
||||||
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
|
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.nimbusds.jwt.JWTClaimsSet;
|
import com.nimbusds.jwt.JWTClaimsSet;
|
||||||
import com.nimbusds.jwt.PlainJWT;
|
import com.nimbusds.jwt.PlainJWT;
|
||||||
|
@ -385,19 +387,41 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi
|
||||||
public void clearExpiredTokens() {
|
public void clearExpiredTokens() {
|
||||||
logger.info("Cleaning out all expired tokens");
|
logger.info("Cleaning out all expired tokens");
|
||||||
|
|
||||||
List<OAuth2AccessTokenEntity> accessTokens = tokenRepository.getExpiredAccessTokens();
|
List<OAuth2AccessTokenEntity> accessTokens = getExpiredAccessTokens();
|
||||||
logger.info("Found " + accessTokens.size() + " expired access tokens");
|
logger.info("Found " + accessTokens.size() + " expired access tokens");
|
||||||
for (OAuth2AccessTokenEntity oAuth2AccessTokenEntity : accessTokens) {
|
for (OAuth2AccessTokenEntity oAuth2AccessTokenEntity : accessTokens) {
|
||||||
revokeAccessToken(oAuth2AccessTokenEntity);
|
revokeAccessToken(oAuth2AccessTokenEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<OAuth2RefreshTokenEntity> refreshTokens = tokenRepository.getExpiredRefreshTokens();
|
List<OAuth2RefreshTokenEntity> refreshTokens = getExpiredRefreshTokens();
|
||||||
logger.info("Found " + refreshTokens.size() + " expired refresh tokens");
|
logger.info("Found " + refreshTokens.size() + " expired refresh tokens");
|
||||||
for (OAuth2RefreshTokenEntity oAuth2RefreshTokenEntity : refreshTokens) {
|
for (OAuth2RefreshTokenEntity oAuth2RefreshTokenEntity : refreshTokens) {
|
||||||
revokeRefreshToken(oAuth2RefreshTokenEntity);
|
revokeRefreshToken(oAuth2RefreshTokenEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<OAuth2AccessTokenEntity> getExpiredAccessTokens() {
|
||||||
|
Collection<OAuth2AccessTokenEntity> accessTokens = tokenRepository.getAllAccessTokens();
|
||||||
|
List<OAuth2AccessTokenEntity> expired = Lists.newArrayList();
|
||||||
|
for (OAuth2AccessTokenEntity a : accessTokens) {
|
||||||
|
if (a.isExpired()) {
|
||||||
|
expired.add(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return expired;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<OAuth2RefreshTokenEntity> getExpiredRefreshTokens() {
|
||||||
|
Collection<OAuth2RefreshTokenEntity> refreshTokens = tokenRepository.getAllRefreshTokens();
|
||||||
|
List<OAuth2RefreshTokenEntity> expired = Lists.newArrayList();
|
||||||
|
for (OAuth2RefreshTokenEntity r : refreshTokens) {
|
||||||
|
if (r.isExpired()) {
|
||||||
|
expired.add(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return expired;
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.mitre.oauth2.service.OAuth2TokenEntityService#saveAccessToken(org.mitre.oauth2.model.OAuth2AccessTokenEntity)
|
* @see org.mitre.oauth2.service.OAuth2TokenEntityService#saveAccessToken(org.mitre.oauth2.model.OAuth2AccessTokenEntity)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -19,7 +19,6 @@ package org.mitre.openid.connect.repository.impl;
|
||||||
import static org.mitre.util.jpa.JpaUtil.saveOrUpdate;
|
import static org.mitre.util.jpa.JpaUtil.saveOrUpdate;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.PersistenceContext;
|
import javax.persistence.PersistenceContext;
|
||||||
|
@ -30,8 +29,6 @@ import org.mitre.openid.connect.repository.ApprovedSiteRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JPA ApprovedSite repository implementation
|
* JPA ApprovedSite repository implementation
|
||||||
*
|
*
|
||||||
|
@ -104,18 +101,4 @@ public class JpaApprovedSiteRepository implements ApprovedSiteRepository {
|
||||||
|
|
||||||
return query.getResultList();
|
return query.getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional
|
|
||||||
public Collection<ApprovedSite> getExpired() {
|
|
||||||
TypedQuery<ApprovedSite> query = manager.createNamedQuery("ApprovedSite.getAll", ApprovedSite.class);
|
|
||||||
List<ApprovedSite> sites = query.getResultList();
|
|
||||||
List<ApprovedSite> expired = Lists.newArrayList();
|
|
||||||
for (ApprovedSite a : sites) {
|
|
||||||
if (a.isExpired()) {
|
|
||||||
expired.add(a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return expired;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ package org.mitre.openid.connect.service.impl;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.mitre.oauth2.model.OAuth2AccessTokenEntity;
|
import org.mitre.oauth2.model.OAuth2AccessTokenEntity;
|
||||||
|
@ -33,6 +34,8 @@ import org.springframework.security.oauth2.provider.ClientDetails;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of the ApprovedSiteService
|
* Implementation of the ApprovedSiteService
|
||||||
*
|
*
|
||||||
|
@ -147,7 +150,7 @@ public class DefaultApprovedSiteService implements ApprovedSiteService {
|
||||||
|
|
||||||
logger.info("Clearing expired approved sites");
|
logger.info("Clearing expired approved sites");
|
||||||
|
|
||||||
Collection<ApprovedSite> expiredSites = approvedSiteRepository.getExpired();
|
Collection<ApprovedSite> expiredSites = getExpired();
|
||||||
if (expiredSites != null) {
|
if (expiredSites != null) {
|
||||||
for (ApprovedSite expired : expiredSites) {
|
for (ApprovedSite expired : expiredSites) {
|
||||||
approvedSiteRepository.remove(expired);
|
approvedSiteRepository.remove(expired);
|
||||||
|
@ -155,4 +158,15 @@ public class DefaultApprovedSiteService implements ApprovedSiteService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Collection<ApprovedSite> getExpired() {
|
||||||
|
Collection<ApprovedSite> sites = approvedSiteRepository.getAll();
|
||||||
|
List<ApprovedSite> expired = Lists.newArrayList();
|
||||||
|
for (ApprovedSite a : sites) {
|
||||||
|
if (a.isExpired()) {
|
||||||
|
expired.add(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return expired;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue