1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.security.spi.ldap;
18
19 import org.apache.jetspeed.security.GroupPrincipal;
20 import org.apache.jetspeed.security.RolePrincipal;
21 import org.apache.jetspeed.security.UserPrincipal;
22 import org.apache.jetspeed.security.impl.GroupPrincipalImpl;
23 import org.apache.jetspeed.security.impl.RolePrincipalImpl;
24 import org.apache.jetspeed.security.impl.UserPrincipalImpl;
25 import org.apache.jetspeed.security.spi.CredentialHandler;
26 import org.apache.jetspeed.security.spi.GroupSecurityHandler;
27 import org.apache.jetspeed.security.spi.RoleSecurityHandler;
28 import org.apache.jetspeed.security.spi.UserSecurityHandler;
29
30 /***
31 * <p>
32 * Utility class for LDAP test data.
33 * </p>
34 *
35 * @author <a href="mailto:dlestrat@apache.org">David Le Strat</a>
36 */
37 public class LdapDataHelper
38 {
39 /*** The {@link UserSecurityHandler}. */
40 private static UserSecurityHandler userHandler;
41
42 /*** The {@link CredentialHandler}. */
43 private static CredentialHandler crHandler;
44
45 /*** The {@link GroupSecurityHandler}. */
46 private static GroupSecurityHandler grHandler;
47
48 /*** The {@link RoleSecurityHandler}. */
49 private static RoleSecurityHandler roleHandler;
50
51 public static void seedUserData(String uid, String password) throws Exception
52 {
53 UserPrincipal up = new UserPrincipalImpl(uid);
54 userHandler.addUserPrincipal(up);
55 crHandler.setPassword(uid, "", password);
56 }
57
58 public static void seedGroupData(String gpUid) throws Exception
59 {
60 GroupPrincipal gp = new GroupPrincipalImpl(gpUid);
61 grHandler.setGroupPrincipal(gp);
62 }
63
64 public static void seedRoleData(String roleUid) throws Exception
65 {
66 RolePrincipal rp = new RolePrincipalImpl(roleUid);
67 roleHandler.setRolePrincipal(rp);
68 }
69
70 public static void removeUserData(String uid) throws Exception
71 {
72 UserPrincipal up = new UserPrincipalImpl(uid);
73 userHandler.removeUserPrincipal(up);
74 }
75
76 public static void removeGroupData(String gpUid) throws Exception
77 {
78 GroupPrincipal gp = new GroupPrincipalImpl(gpUid);
79 grHandler.removeGroupPrincipal(gp);
80 }
81
82 public static void removeRoleData(String roleUid) throws Exception
83 {
84 RolePrincipal rp = new RolePrincipalImpl(roleUid);
85 roleHandler.removeRolePrincipal(rp);
86 }
87
88 public static void setUserSecurityHandler(UserSecurityHandler userHandlerVar)
89 {
90 userHandler = userHandlerVar;
91 }
92
93 public static void setCredentialHandler(CredentialHandler crHandlerVar)
94 {
95 crHandler = crHandlerVar;
96 }
97
98 public static void setGroupSecurityHandler(GroupSecurityHandler grHandlerVar)
99 {
100 grHandler = grHandlerVar;
101 }
102
103 public static void setRoleSecurityHandler(RoleSecurityHandler roleHandlerVar)
104 {
105 roleHandler = roleHandlerVar;
106 }
107 }