Skip to content
Snippets Groups Projects
Verified Commit 61ab061c authored by Dominik Frantisek Bucik's avatar Dominik Frantisek Bucik
Browse files

fix: :bug: scheduled tasks, missing constant and non-used param

parent 134a1bc8
No related branches found
No related tags found
1 merge request!376fix: 🐛 scheduled tasks, missing constant and non-used param
Pipeline #397687 passed
......@@ -4,6 +4,7 @@ import cz.muni.ics.oauth2.model.AuthorizationCodeEntity;
import cz.muni.ics.oauth2.model.DeviceCode;
import cz.muni.ics.oauth2.model.OAuth2AccessTokenEntity;
import cz.muni.ics.oauth2.model.OAuth2RefreshTokenEntity;
import cz.muni.ics.openid.connect.model.ApprovedSite;
import org.springframework.stereotype.Repository;
import javax.persistence.EntityManager;
......@@ -17,6 +18,8 @@ public class CustomClearTasks {
@PersistenceContext(unitName = "defaultPersistenceUnit")
private EntityManager manager;
public static final String HINT_TIMEOUT = "javax.persistence.query.timeout";
public int clearExpiredTokens(long timeout) {
int count = 0;
......@@ -34,7 +37,7 @@ public class CustomClearTasks {
"WHERE a.expiration <= :" + OAuth2AccessTokenEntity.PARAM_DATE);
query1.setParameter(OAuth2AccessTokenEntity.PARAM_DATE, new Date());
if (timeout > 0) {
query1.setHint("javax.persistence.query.timeout", timeout);
query1.setHint(HINT_TIMEOUT, timeout);
}
try {
count += query1.executeUpdate();
......@@ -52,7 +55,7 @@ public class CustomClearTasks {
"WHERE r.expiration <= :" + OAuth2RefreshTokenEntity.PARAM_DATE);
query2.setParameter(OAuth2RefreshTokenEntity.PARAM_DATE, new Date());
if (timeout > 0) {
query2.setHint("javax.persistence.query.timeout", timeout);
query2.setHint(HINT_TIMEOUT, timeout);
}
try {
count += query2.executeUpdate();
......@@ -71,7 +74,7 @@ public class CustomClearTasks {
"a.id NOT IN (SELECT r.authenticationHolder.id FROM OAuth2RefreshTokenEntity r) AND " +
"a.id NOT IN (SELECT c.authenticationHolder.id FROM AuthorizationCodeEntity c)");
if (timeout > 0) {
query3.setHint("javax.persistence.query.timeout", timeout);
query3.setHint(HINT_TIMEOUT, timeout);
}
try {
count += query3.executeUpdate();
......@@ -85,10 +88,12 @@ public class CustomClearTasks {
manager.flush();
manager.clear();
int count = 0;
Query query = manager.createQuery("DELETE FROM ApprovedSite a WHERE a.timeoutDate <= :date");
query.setParameter("date", new Date());
Query query = manager.createQuery(
"DELETE FROM ApprovedSite a WHERE a.timeoutDate <= :" + ApprovedSite.PARAM_DATE
);
query.setParameter(ApprovedSite.PARAM_DATE, new Date());
if (timeout > 0) {
query.setHint("javax.persistence.query.timeout", timeout);
query.setHint(HINT_TIMEOUT, timeout);
}
try {
count += query.executeUpdate();
......@@ -106,7 +111,7 @@ public class CustomClearTasks {
"WHERE a.expiration <= :" + AuthorizationCodeEntity.PARAM_DATE);
query.setParameter(AuthorizationCodeEntity.PARAM_DATE, new Date());
if (timeout > 0) {
query.setHint("javax.persistence.query.timeout", timeout);
query.setHint(HINT_TIMEOUT, timeout);
}
try {
count += query.executeUpdate();
......@@ -123,7 +128,7 @@ public class CustomClearTasks {
Query query = manager.createQuery("DELETE FROM DeviceCode d WHERE d.expiration <= :" + DeviceCode.PARAM_DATE);
query.setParameter(DeviceCode.PARAM_DATE, new Date());
if (timeout > 0) {
query.setHint("javax.persistence.query.timeout", timeout);
query.setHint(HINT_TIMEOUT, timeout);
}
try {
count += query.executeUpdate();
......@@ -138,10 +143,9 @@ public class CustomClearTasks {
manager.clear();
int count = 0;
Query query = manager.createQuery("DELETE FROM SavedUserAuthentication sa " +
"WHERE sa.id NOT IN (SELECT ah.userAuth FROM AuthenticationHolderEntity ah)");
query.setParameter(DeviceCode.PARAM_DATE, new Date());
"WHERE sa.id NOT IN (SELECT ah.userAuth FROM AuthenticationHolderEntity ah)");
if (timeout > 0) {
query.setHint("javax.persistence.query.timeout", timeout);
query.setHint(HINT_TIMEOUT, timeout);
}
try {
count += query.executeUpdate();
......
......@@ -82,6 +82,8 @@ public class ApprovedSite {
public static final String PARAM_CLIENT_ID = "clientId";
public static final String PARAM_USER_ID = "userId";
public static final String PARAM_DATE = "date";
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment