Added task scheduling for deleting expired tokens and approved sites. Configuration is all done in application-context.xml so that it is easy to configure
parent
6e8ab7736e
commit
2d3f43e3b8
|
@ -42,6 +42,7 @@ import javax.persistence.Transient;
|
||||||
@NamedQuery(name = "ApprovedSite.getAll", query = "select a from ApprovedSite a"),
|
@NamedQuery(name = "ApprovedSite.getAll", query = "select a from ApprovedSite a"),
|
||||||
@NamedQuery(name = "ApprovedSite.getByUserId", query = "select a from ApprovedSite a where a.userId = :userId"),
|
@NamedQuery(name = "ApprovedSite.getByUserId", query = "select a from ApprovedSite a where a.userId = :userId"),
|
||||||
@NamedQuery(name = "ApprovedSite.getByClientId", query = "select a from ApprovedSite a where a.clientId = :clientId"),
|
@NamedQuery(name = "ApprovedSite.getByClientId", query = "select a from ApprovedSite a where a.clientId = :clientId"),
|
||||||
|
@NamedQuery(name = "ApprovedSite.getExpired", query = "select a from ApprovedSite a where a.timeoutDate is not null and a.timeoutDate < current_timestamp"),
|
||||||
@NamedQuery(name = "ApprovedSite.getByClientIdAndUserId", query = "select a from ApprovedSite a where a.clientId = :clientId and a.userId = :userId")
|
@NamedQuery(name = "ApprovedSite.getByClientIdAndUserId", query = "select a from ApprovedSite a where a.clientId = :clientId and a.userId = :userId")
|
||||||
})
|
})
|
||||||
public class ApprovedSite {
|
public class ApprovedSite {
|
||||||
|
|
|
@ -84,4 +84,10 @@ public interface ApprovedSiteRepository {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Collection<ApprovedSite> getByClientId(String clientId);
|
public Collection<ApprovedSite> getByClientId(String clientId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all expired sites
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Collection<ApprovedSite> getExpired();
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,4 +96,10 @@ public interface ApprovedSiteService {
|
||||||
* @param client
|
* @param client
|
||||||
*/
|
*/
|
||||||
public void clearApprovedSitesForClient(ClientDetails client);
|
public void clearApprovedSitesForClient(ClientDetails client);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all expired approved sites fromt he data store.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public void clearExpiredSites();
|
||||||
}
|
}
|
||||||
|
|
|
@ -319,7 +319,6 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Scheduled(fixedRate = 5 * 60 * 1000) // schedule this task every five minutes
|
|
||||||
public void clearExpiredTokens() {
|
public void clearExpiredTokens() {
|
||||||
logger.info("Cleaning out all expired tokens");
|
logger.info("Cleaning out all expired tokens");
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.mitre.openid.connect.repository.impl;
|
package org.mitre.openid.connect.repository.impl;
|
||||||
|
|
||||||
|
import static org.mitre.util.jpa.JpaUtil.saveOrUpdate;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
@ -27,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 static org.mitre.util.jpa.JpaUtil.saveOrUpdate;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JPA ApprovedSite repository implementation
|
* JPA ApprovedSite repository implementation
|
||||||
*
|
*
|
||||||
|
@ -101,4 +101,11 @@ public class JpaApprovedSiteRepository implements ApprovedSiteRepository {
|
||||||
|
|
||||||
return query.getResultList();
|
return query.getResultList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public Collection<ApprovedSite> getExpired() {
|
||||||
|
TypedQuery<ApprovedSite> query = manager.createNamedQuery("ApprovedSite.getExpired", ApprovedSite.class);
|
||||||
|
return query.getResultList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,8 @@ import org.mitre.openid.connect.model.ApprovedSite;
|
||||||
import org.mitre.openid.connect.model.WhitelistedSite;
|
import org.mitre.openid.connect.model.WhitelistedSite;
|
||||||
import org.mitre.openid.connect.repository.ApprovedSiteRepository;
|
import org.mitre.openid.connect.repository.ApprovedSiteRepository;
|
||||||
import org.mitre.openid.connect.service.ApprovedSiteService;
|
import org.mitre.openid.connect.service.ApprovedSiteService;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.oauth2.provider.ClientDetails;
|
import org.springframework.security.oauth2.provider.ClientDetails;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -39,6 +41,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
@Transactional
|
@Transactional
|
||||||
public class DefaultApprovedSiteService implements ApprovedSiteService {
|
public class DefaultApprovedSiteService implements ApprovedSiteService {
|
||||||
|
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(DefaultApprovedSiteService.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApprovedSiteRepository approvedSiteRepository;
|
private ApprovedSiteRepository approvedSiteRepository;
|
||||||
|
|
||||||
|
@ -121,5 +125,18 @@ public class DefaultApprovedSiteService implements ApprovedSiteService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearExpiredSites() {
|
||||||
|
|
||||||
|
logger.info("Clearing expired approved sites");
|
||||||
|
|
||||||
|
Collection<ApprovedSite> expiredSites = approvedSiteRepository.getExpired();
|
||||||
|
if (expiredSites != null) {
|
||||||
|
for (ApprovedSite expired : expiredSites) {
|
||||||
|
approvedSiteRepository.remove(expired);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@Service("defaultNonceService")
|
@Service("defaultNonceService")
|
||||||
|
@ -111,7 +110,9 @@ public class DefaultNonceService implements NonceService, InitializingBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Scheduled(fixedRate = 5 * 60 * 1000) // schedule this task every five minutes
|
//We are eventually deleting this class, but if we weren't,
|
||||||
|
//this would have been moved to application-context.xml for easier configuration.
|
||||||
|
//@Scheduled(fixedRate = 5 * 60 * 1000) // schedule this task every five minutes
|
||||||
public void clearExpiredNonces() {
|
public void clearExpiredNonces() {
|
||||||
|
|
||||||
logger.info("Clearing expired nonces");
|
logger.info("Clearing expired nonces");
|
||||||
|
|
|
@ -240,9 +240,14 @@
|
||||||
<!-- End view configuration -->
|
<!-- End view configuration -->
|
||||||
|
|
||||||
<!-- scheduled tasks -->
|
<!-- scheduled tasks -->
|
||||||
<!-- <task:scheduler id="taskScheduler" pool-size="10" /> -->
|
<task:scheduler id="taskScheduler" pool-size="10" />
|
||||||
<!-- <task:executor id="taskExecutor" pool-size="5" /> -->
|
<task:executor id="taskExecutor" pool-size="5" />
|
||||||
<!-- <task:annotation-driven scheduler="taskScheduler" executor="taskExecutor" /> -->
|
<task:annotation-driven scheduler="taskScheduler" executor="taskExecutor" />
|
||||||
|
|
||||||
|
<task:scheduled-tasks scheduler="taskScheduler">
|
||||||
|
<task:scheduled ref="defaultOAuth2ProviderTokenService" method="clearExpiredTokens" fixed-rate="300000"/>
|
||||||
|
<task:scheduled ref="defaultApprovedSiteService" method="clearExpiredSites" fixed-rate="300000"/>
|
||||||
|
</task:scheduled-tasks>
|
||||||
|
|
||||||
<!-- import application-local configuration information (such as bean definitions) -->
|
<!-- import application-local configuration information (such as bean definitions) -->
|
||||||
<import resource="local-config.xml" />
|
<import resource="local-config.xml" />
|
||||||
|
|
Loading…
Reference in New Issue