Skip to content
Snippets Groups Projects
Commit f59dec43 authored by Dominik František Bučík's avatar Dominik František Bučík
Browse files

chore: merge branch 'fix_clear_orphaned' into 'main'

fix: :bug: unused param, introduce constants

See merge request perun-proxy-aai/java/lsaai-oidc-mock!58
parents a713dfee 9dd97fd0
No related tags found
1 merge request!58fix: 🐛 unused param, introduce constants
Pipeline #397692 passed with warnings
...@@ -4,6 +4,7 @@ import cz.muni.ics.oauth2.model.AuthorizationCodeEntity; ...@@ -4,6 +4,7 @@ import cz.muni.ics.oauth2.model.AuthorizationCodeEntity;
import cz.muni.ics.oauth2.model.DeviceCode; import cz.muni.ics.oauth2.model.DeviceCode;
import cz.muni.ics.oauth2.model.OAuth2AccessTokenEntity; import cz.muni.ics.oauth2.model.OAuth2AccessTokenEntity;
import cz.muni.ics.oauth2.model.OAuth2RefreshTokenEntity; import cz.muni.ics.oauth2.model.OAuth2RefreshTokenEntity;
import cz.muni.ics.openid.connect.model.ApprovedSite;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
...@@ -18,6 +19,8 @@ public class CustomClearTasks { ...@@ -18,6 +19,8 @@ public class CustomClearTasks {
@PersistenceContext(unitName = "defaultPersistenceUnit") @PersistenceContext(unitName = "defaultPersistenceUnit")
private EntityManager manager; private EntityManager manager;
public static final String HINT_TIMEOUT = "javax.persistence.query.timeout";
public int clearExpiredTokens(long timeout) { public int clearExpiredTokens(long timeout) {
int count = 0; int count = 0;
count += this.clearExpiredAccessTokens(timeout); count += this.clearExpiredAccessTokens(timeout);
...@@ -34,7 +37,7 @@ public class CustomClearTasks { ...@@ -34,7 +37,7 @@ public class CustomClearTasks {
"WHERE a.expiration <= :" + OAuth2AccessTokenEntity.PARAM_DATE); "WHERE a.expiration <= :" + OAuth2AccessTokenEntity.PARAM_DATE);
query1.setParameter(OAuth2AccessTokenEntity.PARAM_DATE, new Date()); query1.setParameter(OAuth2AccessTokenEntity.PARAM_DATE, new Date());
if (timeout > 0) { if (timeout > 0) {
query1.setHint("javax.persistence.query.timeout", timeout); query1.setHint(HINT_TIMEOUT, timeout);
} }
try { try {
count += query1.executeUpdate(); count += query1.executeUpdate();
...@@ -52,7 +55,7 @@ public class CustomClearTasks { ...@@ -52,7 +55,7 @@ public class CustomClearTasks {
"WHERE r.expiration <= :" + OAuth2RefreshTokenEntity.PARAM_DATE); "WHERE r.expiration <= :" + OAuth2RefreshTokenEntity.PARAM_DATE);
query2.setParameter(OAuth2RefreshTokenEntity.PARAM_DATE, new Date()); query2.setParameter(OAuth2RefreshTokenEntity.PARAM_DATE, new Date());
if (timeout > 0) { if (timeout > 0) {
query2.setHint("javax.persistence.query.timeout", timeout); query2.setHint(HINT_TIMEOUT, timeout);
} }
try { try {
count += query2.executeUpdate(); count += query2.executeUpdate();
...@@ -71,7 +74,7 @@ public class CustomClearTasks { ...@@ -71,7 +74,7 @@ public class CustomClearTasks {
"a.id NOT IN (SELECT r.authenticationHolder.id FROM OAuth2RefreshTokenEntity r) AND " + "a.id NOT IN (SELECT r.authenticationHolder.id FROM OAuth2RefreshTokenEntity r) AND " +
"a.id NOT IN (SELECT c.authenticationHolder.id FROM AuthorizationCodeEntity c)"); "a.id NOT IN (SELECT c.authenticationHolder.id FROM AuthorizationCodeEntity c)");
if (timeout > 0) { if (timeout > 0) {
query3.setHint("javax.persistence.query.timeout", timeout); query3.setHint(HINT_TIMEOUT, timeout);
} }
try { try {
count += query3.executeUpdate(); count += query3.executeUpdate();
...@@ -85,10 +88,12 @@ public class CustomClearTasks { ...@@ -85,10 +88,12 @@ public class CustomClearTasks {
manager.flush(); manager.flush();
manager.clear(); manager.clear();
int count = 0; int count = 0;
Query query = manager.createQuery("DELETE FROM ApprovedSite a WHERE a.timeoutDate <= :date"); Query query = manager.createQuery(
query.setParameter("date", new Date()); "DELETE FROM ApprovedSite a WHERE a.timeoutDate <= :" + ApprovedSite.PARAM_DATE
);
query.setParameter(ApprovedSite.PARAM_DATE, new Date());
if (timeout > 0) { if (timeout > 0) {
query.setHint("javax.persistence.query.timeout", timeout); query.setHint(HINT_TIMEOUT, timeout);
} }
try { try {
count += query.executeUpdate(); count += query.executeUpdate();
...@@ -106,7 +111,7 @@ public class CustomClearTasks { ...@@ -106,7 +111,7 @@ public class CustomClearTasks {
"WHERE a.expiration <= :" + AuthorizationCodeEntity.PARAM_DATE); "WHERE a.expiration <= :" + AuthorizationCodeEntity.PARAM_DATE);
query.setParameter(AuthorizationCodeEntity.PARAM_DATE, new Date()); query.setParameter(AuthorizationCodeEntity.PARAM_DATE, new Date());
if (timeout > 0) { if (timeout > 0) {
query.setHint("javax.persistence.query.timeout", timeout); query.setHint(HINT_TIMEOUT, timeout);
} }
try { try {
count += query.executeUpdate(); count += query.executeUpdate();
...@@ -123,7 +128,7 @@ public class CustomClearTasks { ...@@ -123,7 +128,7 @@ public class CustomClearTasks {
Query query = manager.createQuery("DELETE FROM DeviceCode d WHERE d.expiration <= :" + DeviceCode.PARAM_DATE); Query query = manager.createQuery("DELETE FROM DeviceCode d WHERE d.expiration <= :" + DeviceCode.PARAM_DATE);
query.setParameter(DeviceCode.PARAM_DATE, new Date()); query.setParameter(DeviceCode.PARAM_DATE, new Date());
if (timeout > 0) { if (timeout > 0) {
query.setHint("javax.persistence.query.timeout", timeout); query.setHint(HINT_TIMEOUT, timeout);
} }
try { try {
count += query.executeUpdate(); count += query.executeUpdate();
...@@ -141,7 +146,7 @@ public class CustomClearTasks { ...@@ -141,7 +146,7 @@ public class CustomClearTasks {
"WHERE sa.id NOT IN (SELECT ah.userAuth FROM AuthenticationHolderEntity ah)"); "WHERE sa.id NOT IN (SELECT ah.userAuth FROM AuthenticationHolderEntity ah)");
query.setParameter(DeviceCode.PARAM_DATE, new Date()); query.setParameter(DeviceCode.PARAM_DATE, new Date());
if (timeout > 0) { if (timeout > 0) {
query.setHint("javax.persistence.query.timeout", timeout); query.setHint(HINT_TIMEOUT, timeout);
} }
try { try {
count += query.executeUpdate(); count += query.executeUpdate();
......
...@@ -82,6 +82,8 @@ public class ApprovedSite { ...@@ -82,6 +82,8 @@ public class ApprovedSite {
public static final String PARAM_CLIENT_ID = "clientId"; public static final String PARAM_CLIENT_ID = "clientId";
public static final String PARAM_USER_ID = "userId"; public static final String PARAM_USER_ID = "userId";
public static final String PARAM_DATE = "date";
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id") @Column(name = "id")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment