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"; |
72c5c3
|
27 |
public static final String SQL_DELETE_USER = "deleteUser"; |
725d10
|
28 |
|
be9fa2
|
29 |
/* ----------- Benutzer -------------- */ |
U |
30 |
|
c65695
|
31 |
public User createUser(User user) { |
U |
32 |
String kw = user.getPw(); |
|
33 |
String digestedPw = RealmBase.Digest(kw, MD5, null); |
|
34 |
user.setPw(digestedPw); |
|
35 |
App.getDatabase().insert(user, UserMapper); |
|
36 |
return user; |
|
37 |
} |
|
38 |
|
725d10
|
39 |
public List getUserNameList() { |
U |
40 |
String sql = App.getSqlStatement(SQL_GET_USER_NAME_LIST); |
|
41 |
List userNames = App.getDatabase().select(sql, App.WITHOUT_BLOBS); |
|
42 |
return userNames; |
|
43 |
} |
|
44 |
|
72c5c3
|
45 |
public User deleteUser(User user) { |
U |
46 |
return (User) App.getDatabase().delete(user, UserMapper); |
|
47 |
} |
|
48 |
|
725d10
|
49 |
/* |
U |
50 |
public List getUserList() { |
|
51 |
String sql = App.getSqlStatement(SQL_GET_USER_LIST); |
|
52 |
List users = App.getDatabase().select(sql, UserMapper, App.WITHOUT_BLOBS); |
|
53 |
return users; |
|
54 |
} |
|
55 |
*/ |
|
56 |
|
be9fa2
|
57 |
/* ------------ Rollen ------------------ */ |
U |
58 |
|
87e382
|
59 |
public UserRole grantRole(String userId, String roleName) { |
U |
60 |
UserRole ur = new UserRole(); |
|
61 |
ur.setRole(roleName); |
|
62 |
ur.setUser(userId); |
|
63 |
App.getDatabase().insert(ur, UserRoleMapper); |
|
64 |
return ur; |
be9fa2
|
65 |
} |
U |
66 |
|
87e382
|
67 |
public UserRole revokeRole(String userId, String roleName) { |
U |
68 |
UserRole ur = new UserRole(); |
|
69 |
ur.setRole(roleName); |
|
70 |
ur.setUser(userId); |
|
71 |
App.getDatabase().delete(ur, UserRoleMapper); |
|
72 |
return ur; |
be9fa2
|
73 |
} |
U |
74 |
|
|
75 |
public List getRoleNamesGranted() { |
87e382
|
76 |
String sql = App.getSqlStatement(SQL_GET_ROLE_LIST); |
U |
77 |
List roleNames = App.getDatabase().select(sql, App.WITHOUT_BLOBS); |
|
78 |
return roleNames; |
be9fa2
|
79 |
} |
U |
80 |
|
|
81 |
/* ------------ sonstige Methoden -------------- */ |
|
82 |
|
f8b605
|
83 |
public String hallo() { |
U |
84 |
return "Hallo Welt"; |
|
85 |
} |
|
86 |
|
c65695
|
87 |
} |