mirror of
https://github.com/sismics/docs.git
synced 2025-12-13 17:56:20 +00:00
List and delete active tokens (server)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.sismics.docs.core.dao.jpa;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
@@ -96,4 +97,31 @@ public class AuthenticationTokenDao {
|
||||
q.setParameter("id", id);
|
||||
q.executeUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all authentication tokens of an user.
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<AuthenticationToken> getByUserId(String userId) {
|
||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||
Query q = em.createQuery("select a from AuthenticationToken a where a.userId = :userId");
|
||||
q.setParameter("userId", userId);
|
||||
return q.getResultList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all authentication tokens of an user.
|
||||
*
|
||||
* @param userId
|
||||
*/
|
||||
public void deleteByUserId(String userId, String id) {
|
||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||
Query q = em.createQuery("delete AuthenticationToken a where a.userId = :userId and a.id != :id");
|
||||
q.setParameter("userId", userId);
|
||||
q.setParameter("id", id);
|
||||
q.executeUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,12 +91,8 @@ public class FileDao {
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<File> getByDocumentId(String documentId) {
|
||||
EntityManager em = ThreadLocalContext.get().getEntityManager();
|
||||
|
||||
// Get the files
|
||||
Query q = em.createQuery("select f from File f where f.documentId = :documentId and f.deleteDate is null");
|
||||
q.setParameter("documentId", documentId);
|
||||
List<File> files = (List<File>) q.getResultList();
|
||||
|
||||
return files;
|
||||
return q.getResultList();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user