Commit 80ff602268101f2cef2f63b867d9660d948b1a4e
1 parent
8f05ee77
Classe Session
Showing
4 changed files
with
81 additions
and
0 deletions
Show diff stats
.gitignore
... | ... | @@ -0,0 +1,10 @@ |
1 | +<component name="InspectionProjectProfileManager"> | |
2 | + <profile version="1.0"> | |
3 | + <option name="myName" value="Project Default" /> | |
4 | + <inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false"> | |
5 | + <option name="processCode" value="true" /> | |
6 | + <option name="processLiterals" value="true" /> | |
7 | + <option name="processComments" value="true" /> | |
8 | + </inspection_tool> | |
9 | + </profile> | |
10 | +</component> | |
0 | 11 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,60 @@ |
1 | +package etunicorn; | |
2 | + | |
3 | +import javax.persistence.Entity; | |
4 | +import javax.persistence.Id; | |
5 | +import javax.persistence.ManyToOne; | |
6 | +import java.math.BigInteger; | |
7 | +import java.security.SecureRandom; | |
8 | +import java.util.Date; | |
9 | + | |
10 | +/** | |
11 | + * Created by geoffrey on 04/02/17. | |
12 | + */ | |
13 | +@Entity | |
14 | +public class Session { | |
15 | + | |
16 | + // Durée par défaut d'une session en secondes | |
17 | + private static final int SESSION_DURATION = 10 * 60; | |
18 | + private static SecureRandom random = new SecureRandom(); | |
19 | + @ManyToOne | |
20 | + private Personne personne; | |
21 | + @Id | |
22 | + private String token; | |
23 | + // TODO Vérifier si c'est bien initialisé qu'une seule fois par éxecution car c'est lourd à initialiser | |
24 | + private Date validity; | |
25 | + | |
26 | + | |
27 | + public Session() { | |
28 | + } | |
29 | + | |
30 | + public Session(Personne personne) { | |
31 | + this.personne = personne; | |
32 | + // From http://stackoverflow.com/a/41156 | |
33 | + this.token = new BigInteger(130, random).toString(32); | |
34 | + this.validity = new Date(new Date().getTime() + SESSION_DURATION * 1000); | |
35 | + } | |
36 | + | |
37 | + public Personne getPersonne() { | |
38 | + return personne; | |
39 | + } | |
40 | + | |
41 | + public void setPersonne(Personne personne) { | |
42 | + this.personne = personne; | |
43 | + } | |
44 | + | |
45 | + public String getToken() { | |
46 | + return token; | |
47 | + } | |
48 | + | |
49 | + public void setToken(String token) { | |
50 | + this.token = token; | |
51 | + } | |
52 | + | |
53 | + public Date getValidity() { | |
54 | + return validity; | |
55 | + } | |
56 | + | |
57 | + public void setValidity(Date validity) { | |
58 | + this.validity = validity; | |
59 | + } | |
60 | +} | ... | ... |
... | ... | @@ -0,0 +1,10 @@ |
1 | +package etunicorn; | |
2 | + | |
3 | +import org.springframework.data.repository.CrudRepository; | |
4 | + | |
5 | +/** | |
6 | + * Created by geoffrey on 04/02/17. | |
7 | + */ | |
8 | +public interface SessionRepository extends CrudRepository<Session, Long> { | |
9 | + Session findByToken(String token); | |
10 | +} | ... | ... |