commit | author | age
|
e28ac1
|
1 |
/* |
U |
2 |
* Nutzerverwaltung - User and role management in your browser |
|
3 |
* Copyright (C) 2011-2017 Ulrich Hilger, http://uhilger.de |
|
4 |
* |
|
5 |
* This program is free software: you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation, either version 3 of the License, or |
|
8 |
* (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 General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program. If not, see http://www.gnu.org/licenses/ |
|
17 |
*/ |
|
18 |
|
70a614
|
19 |
package de.uhilger.um.pub; |
U |
20 |
|
|
21 |
import de.uhilger.um.api.Api; |
|
22 |
import static de.uhilger.um.api.UserMgr.MP_USER_DATA; |
|
23 |
import static de.uhilger.um.api.UserMgr.SQL_GET_USER_DATA; |
|
24 |
import static de.uhilger.um.api.UserMgr.WITHOUT_BLOBS; |
|
25 |
import de.uhilger.um.daten.UserData; |
|
26 |
import java.security.Principal; |
|
27 |
import java.util.List; |
1345f0
|
28 |
import java.util.logging.Logger; |
70a614
|
29 |
|
U |
30 |
/** |
|
31 |
* |
|
32 |
*/ |
|
33 |
public class SessionManager extends Api { |
1345f0
|
34 |
|
U |
35 |
private static final Logger logger = Logger.getLogger(SessionManager.class.getName()); |
70a614
|
36 |
|
U |
37 |
// /um/pub?c=de.uhilger.um.pub.SessionManager&m=getSessionUser |
|
38 |
public UserData getSessionUser() { |
|
39 |
UserData userData = new UserData(); |
|
40 |
userData.setFirstName("nicht angemeldet"); |
|
41 |
userData.setLastName("nicht angemeldet"); |
|
42 |
userData.setId("nicht angemeldet"); |
|
43 |
userData.setEmail("nicht angemeldet"); |
|
44 |
Object p = getRequest().getUserPrincipal(); |
|
45 |
if(p instanceof Principal) { |
|
46 |
String id = ((Principal) p).getName(); |
6fda23
|
47 |
logger.finer("User-ID: " + id); |
70a614
|
48 |
List userDataList = getDb().select(getSql(SQL_GET_USER_DATA), getMapper(MP_USER_DATA), WITHOUT_BLOBS, id); |
U |
49 |
if(userDataList != null && userDataList.size() > 0) { |
|
50 |
Object o = userDataList.get(0); |
|
51 |
if(o instanceof UserData) { |
|
52 |
userData = (UserData) o; |
|
53 |
} |
|
54 |
} |
1345f0
|
55 |
} else { |
6fda23
|
56 |
logger.finer("getUserPrincipal returned null or no Principal"); |
70a614
|
57 |
} |
U |
58 |
return userData; |
|
59 |
} |
|
60 |
|
1345f0
|
61 |
public String expireSession() { |
U |
62 |
getRequest().getSession().invalidate(); |
|
63 |
return "Die aktuelle Sitzung ist nicht mehr gueltig."; |
|
64 |
} |
|
65 |
|
70a614
|
66 |
|
U |
67 |
} |