commit | author | age
|
9ee357
|
1 |
/* |
c7d492
|
2 |
http-auth - Authentication Extensions to jdk.httpserver |
9ee357
|
3 |
Copyright (C) 2021 Ulrich Hilger |
U |
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU Affero General Public License as |
|
7 |
published by the Free Software Foundation, either version 3 of the |
|
8 |
License, or (at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU Affero General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU Affero General Public License |
|
16 |
along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
package de.uhilger.httpserver.auth.session; |
|
19 |
|
|
20 |
import java.util.HashMap; |
|
21 |
import java.util.Iterator; |
|
22 |
import java.util.Map; |
|
23 |
|
|
24 |
/** |
|
25 |
* |
|
26 |
* @author Ulrich Hilger |
|
27 |
* @version 1, 29.05.2021 |
|
28 |
*/ |
|
29 |
public class Sessions implements SessionManager { |
|
30 |
|
|
31 |
/** zur Zeit im Gange befindliche Sessions authentifizierter Nutzer */ |
|
32 |
private final Map<String, Session> sessions; |
|
33 |
|
|
34 |
public Sessions() { |
|
35 |
sessions = new HashMap(); |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
public void add(Session session) { |
|
40 |
sessions.put(session.getId(), session); |
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
public void remove(String sessionId) { |
|
45 |
sessions.remove(sessionId); |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
public void modify(String sessionId, Session session) { |
|
50 |
sessions.remove(sessionId); |
|
51 |
sessions.put(sessionId, session); |
|
52 |
} |
|
53 |
|
|
54 |
@Override |
|
55 |
public Session get(String sessionId) { |
|
56 |
Object o = sessions.get(sessionId); |
|
57 |
if(o instanceof Session) { |
|
58 |
return (Session) o; |
|
59 |
} else { |
|
60 |
return null; |
|
61 |
} |
|
62 |
} |
|
63 |
|
|
64 |
@Override |
|
65 |
public Iterator sessions() { |
|
66 |
return sessions.values().iterator(); |
|
67 |
} |
|
68 |
|
|
69 |
} |