Used Predicates to filter expired tokens and approved sites;
parent
b3bb43881d
commit
be97aedbc7
|
@ -85,9 +85,4 @@ public interface ApprovedSiteRepository {
|
||||||
*/
|
*/
|
||||||
public Collection<ApprovedSite> getByClientId(String clientId);
|
public Collection<ApprovedSite> getByClientId(String clientId);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all expired sites
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public Collection<ApprovedSite> getExpired();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +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.base.Predicate;
|
||||||
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;
|
||||||
|
@ -387,39 +387,39 @@ 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 = getExpiredAccessTokens();
|
Collection<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 = getExpiredRefreshTokens();
|
Collection<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() {
|
private Predicate<OAuth2AccessTokenEntity> isAccessTokenExpired = new Predicate<OAuth2AccessTokenEntity>() {
|
||||||
Collection<OAuth2AccessTokenEntity> accessTokens = tokenRepository.getAllAccessTokens();
|
@Override
|
||||||
List<OAuth2AccessTokenEntity> expired = Lists.newArrayList();
|
public boolean apply(OAuth2AccessTokenEntity input) {
|
||||||
for (OAuth2AccessTokenEntity a : accessTokens) {
|
return (input != null && input.isExpired());
|
||||||
if (a.isExpired()) {
|
|
||||||
expired.add(a);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return expired;
|
};
|
||||||
|
|
||||||
|
private Predicate<OAuth2RefreshTokenEntity> isRefreshTokenExpired = new Predicate<OAuth2RefreshTokenEntity>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(OAuth2RefreshTokenEntity input) {
|
||||||
|
return (input != null && input.isExpired());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private Collection<OAuth2AccessTokenEntity> getExpiredAccessTokens() {
|
||||||
|
return Sets.filter(Sets.newHashSet(tokenRepository.getAllAccessTokens()), isAccessTokenExpired);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<OAuth2RefreshTokenEntity> getExpiredRefreshTokens() {
|
private Collection<OAuth2RefreshTokenEntity> getExpiredRefreshTokens() {
|
||||||
Collection<OAuth2RefreshTokenEntity> refreshTokens = tokenRepository.getAllRefreshTokens();
|
return Sets.filter(Sets.newHashSet(tokenRepository.getAllRefreshTokens()), isRefreshTokenExpired);
|
||||||
List<OAuth2RefreshTokenEntity> expired = Lists.newArrayList();
|
|
||||||
for (OAuth2RefreshTokenEntity r : refreshTokens) {
|
|
||||||
if (r.isExpired()) {
|
|
||||||
expired.add(r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return expired;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|
|
@ -18,7 +18,6 @@ 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;
|
||||||
|
@ -34,7 +33,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;
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of the ApprovedSiteService
|
* Implementation of the ApprovedSiteService
|
||||||
|
@ -158,15 +158,15 @@ public class DefaultApprovedSiteService implements ApprovedSiteService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Collection<ApprovedSite> getExpired() {
|
private Predicate<ApprovedSite> isExpired = new Predicate<ApprovedSite>() {
|
||||||
Collection<ApprovedSite> sites = approvedSiteRepository.getAll();
|
@Override
|
||||||
List<ApprovedSite> expired = Lists.newArrayList();
|
public boolean apply(ApprovedSite input) {
|
||||||
for (ApprovedSite a : sites) {
|
return (input != null && input.isExpired());
|
||||||
if (a.isExpired()) {
|
|
||||||
expired.add(a);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return expired;
|
};
|
||||||
|
|
||||||
|
private Collection<ApprovedSite> getExpired() {
|
||||||
|
return Sets.filter(Sets.newHashSet(approvedSiteRepository.getAll()), isExpired);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue