001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.security.spi.ldap;
018:
019: import org.apache.jetspeed.security.GroupPrincipal;
020: import org.apache.jetspeed.security.RolePrincipal;
021: import org.apache.jetspeed.security.UserPrincipal;
022: import org.apache.jetspeed.security.impl.GroupPrincipalImpl;
023: import org.apache.jetspeed.security.impl.RolePrincipalImpl;
024: import org.apache.jetspeed.security.impl.UserPrincipalImpl;
025: import org.apache.jetspeed.security.spi.CredentialHandler;
026: import org.apache.jetspeed.security.spi.GroupSecurityHandler;
027: import org.apache.jetspeed.security.spi.RoleSecurityHandler;
028: import org.apache.jetspeed.security.spi.UserSecurityHandler;
029:
030: /**
031: * <p>
032: * Utility class for LDAP test data.
033: * </p>
034: *
035: * @author <a href="mailto:dlestrat@apache.org">David Le Strat</a>
036: */
037: public class LdapDataHelper {
038: /** The {@link UserSecurityHandler}. */
039: private static UserSecurityHandler userHandler;
040:
041: /** The {@link CredentialHandler}. */
042: private static CredentialHandler crHandler;
043:
044: /** The {@link GroupSecurityHandler}. */
045: private static GroupSecurityHandler grHandler;
046:
047: /** The {@link RoleSecurityHandler}. */
048: private static RoleSecurityHandler roleHandler;
049:
050: public static void seedUserData(String uid, String password)
051: throws Exception {
052: UserPrincipal up = new UserPrincipalImpl(uid);
053: userHandler.addUserPrincipal(up);
054: crHandler.setPassword(uid, "", password);
055: }
056:
057: public static void seedGroupData(String gpUid) throws Exception {
058: GroupPrincipal gp = new GroupPrincipalImpl(gpUid);
059: grHandler.setGroupPrincipal(gp);
060: }
061:
062: public static void seedRoleData(String roleUid) throws Exception {
063: RolePrincipal rp = new RolePrincipalImpl(roleUid);
064: roleHandler.setRolePrincipal(rp);
065: }
066:
067: public static void removeUserData(String uid) throws Exception {
068: UserPrincipal up = new UserPrincipalImpl(uid);
069: userHandler.removeUserPrincipal(up);
070: }
071:
072: public static void removeGroupData(String gpUid) throws Exception {
073: GroupPrincipal gp = new GroupPrincipalImpl(gpUid);
074: grHandler.removeGroupPrincipal(gp);
075: }
076:
077: public static void removeRoleData(String roleUid) throws Exception {
078: RolePrincipal rp = new RolePrincipalImpl(roleUid);
079: roleHandler.removeRolePrincipal(rp);
080: }
081:
082: public static void setUserSecurityHandler(
083: UserSecurityHandler userHandlerVar) {
084: userHandler = userHandlerVar;
085: }
086:
087: public static void setCredentialHandler(
088: CredentialHandler crHandlerVar) {
089: crHandler = crHandlerVar;
090: }
091:
092: public static void setGroupSecurityHandler(
093: GroupSecurityHandler grHandlerVar) {
094: grHandler = grHandlerVar;
095: }
096:
097: public static void setRoleSecurityHandler(
098: RoleSecurityHandler roleHandlerVar) {
099: roleHandler = roleHandlerVar;
100: }
101: }
|