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.impl;
018:
019: import org.apache.jetspeed.security.UserPrincipal;
020:
021: /**
022: * <p>{@link UserPrincipal} interface implementation.</p>
023: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
024: * @version $Id: UserPrincipalImpl.java 592149 2007-11-05 21:05:25Z taylor $
025: */
026: public class UserPrincipalImpl extends BasePrincipalImpl implements
027: UserPrincipal {
028:
029: /** The serial version uid. */
030: private static final long serialVersionUID = 4134905654850335230L;
031:
032: private static boolean hiearchicalNames = true;
033:
034: public static final Object useHierarchicalNames(
035: boolean hierarchicalNames) {
036: UserPrincipalImpl.hiearchicalNames = hierarchicalNames;
037: return null;
038: }
039:
040: /**
041: * <p>The user principal constructor.</p>
042: * @param userName The user principal name.
043: */
044: public UserPrincipalImpl(String userName) {
045: this (userName, true, false);
046: }
047:
048: public UserPrincipalImpl(String userName, boolean isMapping) {
049: this (userName, true, isMapping);
050: }
051:
052: public UserPrincipalImpl(String userName, boolean isEnabled,
053: boolean isMapping) {
054: super (userName, PREFS_USER_ROOT, hiearchicalNames, isEnabled,
055: isMapping);
056: }
057:
058: /**
059: * <p>Compares this principal to the specified object. Returns true
060: * if the object passed in matches the principal represented by
061: * the implementation of this interface.</p>
062: * @param another Principal to compare with.
063: * @return True if the principal passed in is the same as that
064: * encapsulated by this principal, and false otherwise.
065:
066: */
067: public boolean equals(Object another) {
068: if (!(another instanceof UserPrincipalImpl))
069: return false;
070: UserPrincipalImpl principal = (UserPrincipalImpl) another;
071: return this .getName().equals(principal.getName());
072: }
073:
074: /**
075: * <p>Gets the principal implementation full path from the principal name.</p>
076: * <p>Prepends PREFS_USER_ROOT if not prepended.</p>
077: * @param name The principal name.
078: * @return The preferences full path / principal name.
079: */
080: public static String getFullPathFromPrincipalName(String name) {
081: return BasePrincipalImpl.getFullPathFromPrincipalName(name,
082: PREFS_USER_ROOT, hiearchicalNames);
083: }
084:
085: /**
086: * <p>Gets the principal name from the principal implementation full path.</p>
087: * <p>Remove prepended PREFS_GROUP_ROOT if present.</p>
088: * @param fullPath The principal full path.
089: * @return The principal name.
090: */
091: public static String getPrincipalNameFromFullPath(String fullPath) {
092: return BasePrincipalImpl.getPrincipalNameFromFullPath(fullPath,
093: PREFS_USER_ROOT, hiearchicalNames);
094: }
095:
096: public static String getFullPathFromPrincipalName(String name,
097: String prefsRoot) {
098: return BasePrincipalImpl.getFullPathFromPrincipalName(name,
099: prefsRoot, hiearchicalNames);
100: }
101:
102: }
|