From 80ff602268101f2cef2f63b867d9660d948b1a4e Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Sat, 4 Feb 2017 10:50:32 +0100 Subject: [PATCH] Classe Session --- .gitignore | 1 + .idea/inspectionProfiles/Project_Default.xml | 10 ++++++++++ src/main/java/etunicorn/Session.java | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/etunicorn/SessionRepository.java | 10 ++++++++++ 4 files changed, 81 insertions(+), 0 deletions(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 src/main/java/etunicorn/Session.java create mode 100644 src/main/java/etunicorn/SessionRepository.java diff --git a/.gitignore b/.gitignore index c4a4981..4f896c7 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ .idea/libraries/ target/ demo*/ +.idea/dictionaries/ diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..146ab09 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/src/main/java/etunicorn/Session.java b/src/main/java/etunicorn/Session.java new file mode 100644 index 0000000..e44d66a --- /dev/null +++ b/src/main/java/etunicorn/Session.java @@ -0,0 +1,60 @@ +package etunicorn; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import java.math.BigInteger; +import java.security.SecureRandom; +import java.util.Date; + +/** + * Created by geoffrey on 04/02/17. + */ +@Entity +public class Session { + + // Durée par défaut d'une session en secondes + private static final int SESSION_DURATION = 10 * 60; + private static SecureRandom random = new SecureRandom(); + @ManyToOne + private Personne personne; + @Id + private String token; + // TODO Vérifier si c'est bien initialisé qu'une seule fois par éxecution car c'est lourd à initialiser + private Date validity; + + + public Session() { + } + + public Session(Personne personne) { + this.personne = personne; + // From http://stackoverflow.com/a/41156 + this.token = new BigInteger(130, random).toString(32); + this.validity = new Date(new Date().getTime() + SESSION_DURATION * 1000); + } + + public Personne getPersonne() { + return personne; + } + + public void setPersonne(Personne personne) { + this.personne = personne; + } + + public String getToken() { + return token; + } + + public void setToken(String token) { + this.token = token; + } + + public Date getValidity() { + return validity; + } + + public void setValidity(Date validity) { + this.validity = validity; + } +} diff --git a/src/main/java/etunicorn/SessionRepository.java b/src/main/java/etunicorn/SessionRepository.java new file mode 100644 index 0000000..324ef0f --- /dev/null +++ b/src/main/java/etunicorn/SessionRepository.java @@ -0,0 +1,10 @@ +package etunicorn; + +import org.springframework.data.repository.CrudRepository; + +/** + * Created by geoffrey on 04/02/17. + */ +public interface SessionRepository extends CrudRepository { + Session findByToken(String token); +} -- libgit2 0.21.2