commit | author | age
|
c65695
|
1 |
package de.uhilger.um.api; |
U |
2 |
|
|
3 |
import de.uhilger.baselink.GenericRecord; |
|
4 |
import de.uhilger.baselink.Record; |
|
5 |
import de.uhilger.um.App; |
|
6 |
import de.uhilger.um.daten.User; |
87e382
|
7 |
import de.uhilger.um.daten.UserRole; |
725d10
|
8 |
import java.util.List; |
c65695
|
9 |
import org.apache.catalina.realm.RealmBase; |
U |
10 |
|
|
11 |
/** |
87e382
|
12 |
* Klasse zur Verwaltung von Benutzern und Rollen |
U |
13 |
* in einer Datenbank |
59f8b3
|
14 |
* |
c65695
|
15 |
* @author Ulrich Hilger |
U |
16 |
*/ |
|
17 |
public class UserMgr { |
|
18 |
|
|
19 |
private static final String MD5 = "MD5"; |
|
20 |
|
|
21 |
private static final Record UserMapper = new GenericRecord(User.class); |
87e382
|
22 |
private static final Record UserRoleMapper = new GenericRecord(UserRole.class); |
c65695
|
23 |
|
725d10
|
24 |
public static final String SQL_GET_USER_LIST = "getUserList"; |
U |
25 |
public static final String SQL_GET_USER_NAME_LIST = "getUserNameList"; |
87e382
|
26 |
public static final String SQL_GET_ROLE_LIST = "getRoleList"; |
c79c12
|
27 |
public static final String SQL_GET_USER_ROLES = "getUserRoles"; |
72c5c3
|
28 |
public static final String SQL_DELETE_USER = "deleteUser"; |
725d10
|
29 |
|
be9fa2
|
30 |
/* ----------- Benutzer -------------- */ |
U |
31 |
|
c65695
|
32 |
public User createUser(User user) { |
U |
33 |
String kw = user.getPw(); |
|
34 |
String digestedPw = RealmBase.Digest(kw, MD5, null); |
|
35 |
user.setPw(digestedPw); |
|
36 |
App.getDatabase().insert(user, UserMapper); |
|
37 |
return user; |
|
38 |
} |
|
39 |
|
725d10
|
40 |
public List getUserNameList() { |
U |
41 |
String sql = App.getSqlStatement(SQL_GET_USER_NAME_LIST); |
|
42 |
List userNames = App.getDatabase().select(sql, App.WITHOUT_BLOBS); |
|
43 |
return userNames; |
|
44 |
} |
|
45 |
|
72c5c3
|
46 |
public User deleteUser(User user) { |
U |
47 |
return (User) App.getDatabase().delete(user, UserMapper); |
|
48 |
} |
|
49 |
|
725d10
|
50 |
/* |
U |
51 |
public List getUserList() { |
|
52 |
String sql = App.getSqlStatement(SQL_GET_USER_LIST); |
|
53 |
List users = App.getDatabase().select(sql, UserMapper, App.WITHOUT_BLOBS); |
|
54 |
return users; |
|
55 |
} |
|
56 |
*/ |
|
57 |
|
be9fa2
|
58 |
/* ------------ Rollen ------------------ */ |
U |
59 |
|
87e382
|
60 |
public UserRole grantRole(String userId, String roleName) { |
U |
61 |
UserRole ur = new UserRole(); |
|
62 |
ur.setRole(roleName); |
|
63 |
ur.setUser(userId); |
|
64 |
App.getDatabase().insert(ur, UserRoleMapper); |
|
65 |
return ur; |
be9fa2
|
66 |
} |
U |
67 |
|
87e382
|
68 |
public UserRole revokeRole(String userId, String roleName) { |
U |
69 |
UserRole ur = new UserRole(); |
|
70 |
ur.setRole(roleName); |
|
71 |
ur.setUser(userId); |
|
72 |
App.getDatabase().delete(ur, UserRoleMapper); |
|
73 |
return ur; |
be9fa2
|
74 |
} |
U |
75 |
|
|
76 |
public List getRoleNamesGranted() { |
87e382
|
77 |
String sql = App.getSqlStatement(SQL_GET_ROLE_LIST); |
U |
78 |
List roleNames = App.getDatabase().select(sql, App.WITHOUT_BLOBS); |
|
79 |
return roleNames; |
be9fa2
|
80 |
} |
U |
81 |
|
c79c12
|
82 |
/** |
U |
83 |
* |
|
84 |
* |
|
85 |
* list.get(recordno).get(fieldno) |
|
86 |
* |
|
87 |
* @param userId ID des Benutzers |
|
88 |
* @return List<List<String>> Rollennamen des Benutzers |
|
89 |
*/ |
|
90 |
public List getUserRoleNames(String userId) { |
|
91 |
String sql = App.getSqlStatement(SQL_GET_USER_ROLES); |
|
92 |
List roleNames = App.getDatabase().select(sql, App.WITHOUT_BLOBS, userId); |
|
93 |
return roleNames; |
|
94 |
} |
|
95 |
|
be9fa2
|
96 |
/* ------------ sonstige Methoden -------------- */ |
U |
97 |
|
f8b605
|
98 |
public String hallo() { |
U |
99 |
return "Hallo Welt"; |
|
100 |
} |
|
101 |
|
c65695
|
102 |
} |