Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2007 | es | 1 | package pt.estgp.es.exemplos.hibernate.security; |
2 | |||
3 | import java.util.HashMap; |
||
4 | import java.util.Map; |
||
5 | |||
6 | /** |
||
7 | * Created by jorgemachado on 23/10/18. |
||
8 | */ |
||
9 | public class SecurityContextProvider |
||
10 | { |
||
11 | |||
12 | private static SecurityContextProvider singletonInstance = new SecurityContextProvider(); |
||
13 | |||
14 | private Map<Thread,SecuritySessionContext> sessions = new HashMap<Thread,SecuritySessionContext>(); |
||
15 | |||
16 | private SecurityContextProvider(){} |
||
17 | |||
18 | public static SecurityContextProvider getInstance() |
||
19 | { |
||
20 | return singletonInstance; |
||
21 | } |
||
22 | |||
23 | |||
24 | public SecuritySessionContext getSecuritySessionContext() |
||
25 | { |
||
26 | SecuritySessionContext securitySessionContext = sessions.get(1.5.0/docs/api/java/lang/Thread.html">Thread.currentThread()); |
||
27 | if(securitySessionContext == null) |
||
28 | throw new 1.5.0/docs/api/java/lang/RuntimeException.html">RuntimeException("SecuritySessionContext not registered"); |
||
29 | return securitySessionContext; |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * O Requester pode ser um cookie |
||
34 | * @param requester |
||
35 | * @return |
||
36 | */ |
||
37 | public synchronized SecuritySessionContext registerSessionContext(1.5.0/docs/api/java/lang/String.html">String requester) |
||
38 | { |
||
39 | if(requester == null) |
||
40 | { |
||
41 | throw new 1.5.0/docs/api/java/lang/RuntimeException.html">RuntimeException("SecuritySessionContext must be registered with A VALID requester"); |
||
42 | } |
||
43 | SecuritySessionContext securitySessionContext = new SecuritySessionContext(); |
||
44 | securitySessionContext.setRequester(requester); |
||
45 | sessions.put(1.5.0/docs/api/java/lang/Thread.html">Thread.currentThread(),securitySessionContext); |
||
46 | return securitySessionContext; |
||
47 | } |
||
48 | |||
49 | |||
50 | public void unregisterSecuritySessionContext() |
||
51 | { |
||
52 | SecuritySessionContext securitySessionContext = getSecuritySessionContext(); |
||
53 | securitySessionContext.setRequester(null); |
||
54 | } |
||
55 | |||
56 | |||
57 | |||
58 | } |