1   /* 
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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 }