Commit c83eadb1 authored by Matija Obreza's avatar Matija Obreza

Updated oauth tokens cleanup for production

parent 89b231b4
......@@ -45,7 +45,7 @@ public interface OAuthAccessTokenPersistence extends JpaRepository<OAuthAccessTo
void deleteByRefreshToken(String value);
@Query("select tokenId from OAuthAccessToken where createdDate < ?1")
List<String> getIdsOlderThen(Date date);
List<String> getIdsOlderThan(Date date);
@Query("select refreshToken from OAuthAccessToken where tokenId in (:ids)")
List<String> getRefreshTokensByIds(@Param("ids") List<String> tokenIds);
......
package org.genesys2.server.service.impl;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.genesys2.server.persistence.domain.OAuthAccessTokenPersistence;
import org.genesys2.server.persistence.domain.OAuthRefreshTokenPersistence;
import org.genesys2.server.service.TokensCleanupService;
......@@ -7,13 +11,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
@Service("tokensCleanupService")
public class TokensCleanupServiceImpl implements TokensCleanupService{
......@@ -28,15 +27,14 @@ public class TokensCleanupServiceImpl implements TokensCleanupService{
@Autowired
private OAuthRefreshTokenPersistence refreshTokenPersistence;
@Scheduled(cron = "${scheduler.tokens.cleanup.expression}")
@Override
public void cleanupAccessAndRefreshTokens() {
_logger.info("Start cleanup of tokens");
//calculate date
Date olderThen = new Date(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(cleanupHours));
Date olderThan = new Date(System.currentTimeMillis() - TimeUnit.HOURS.toMillis(cleanupHours));
//get "old" access token ids
List<String> accessTokensIds = accessTokenPersistence.getIdsOlderThen(olderThen);
List<String> accessTokensIds = accessTokenPersistence.getIdsOlderThan(olderThan);
_logger.debug("Access tokens IDs ready to cleanup {}", accessTokensIds);
if (!accessTokensIds.isEmpty()){
......
......@@ -103,3 +103,5 @@ hazelcast.aws.security-group=sg-hazelcast
# Theme
theme.defaultThemeName=dev
scheduler.tokens.cleanup.hours=1
#Hibernate specific properties
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.connection.autocommit=false
hibernate.hbm2ddl.auto=update
hibernate.search.default.indexBase=./lucene/
hibernate.search.default.exclusive_index_use=false
hibernate.search.default.worker.execution=async
......@@ -45,3 +45,5 @@ cdn.flags.url=${cdn.base}/flags
# Content creation on startup
auto.createContent=false
scheduler.tokens.cleanup.hours=1
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment