01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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.impl;
18:
19: import java.util.ArrayList;
20: import java.util.List;
21: import java.util.prefs.Preferences;
22:
23: import org.apache.jetspeed.security.HierarchyResolver;
24: import org.apache.jetspeed.util.ArgUtil;
25:
26: /**
27: * <p>
28: * Implementation for "is a" hierarchy. For Example: if a user has the role
29: * [roleA.roleB.roleC] than
30: * </p>
31: * <code>user.getSubject().getPrincipals()</code> returns:
32: * <ul>
33: * <li>/role/roleA</li>
34: * <li>/role/roleA/roleB</li>
35: * <li>/role/roleA/roleB/roleC</li>
36: * </ul>
37: * </p>
38: *
39: * @author <a href="mailto:Artem.Grinshtein@t-systems.com">Artem Grinshtein </a>
40: * @version $Id: GeneralizationHierarchyResolver.java,v 1.2 2004/09/18 19:33:58
41: * dlestrat Exp $
42: */
43: public class GeneralizationHierarchyResolver extends
44: BaseHierarchyResolver implements HierarchyResolver {
45:
46: /**
47: * @see org.apache.jetspeed.security.HierarchyResolver#resolve(Preferences)
48: */
49: public String[] resolve(Preferences prefs) {
50: ArgUtil.notNull(new Object[] { prefs },
51: new String[] { "preferences" },
52: "resolve(java.util.prefs.Preferences)");
53:
54: List list = new ArrayList();
55: Preferences preferences = prefs;
56: while ((preferences.parent() != null)
57: && (preferences.parent().parent() != null)) {
58: list.add(preferences.absolutePath());
59: preferences = preferences.parent();
60: }
61: return (String[]) list.toArray(new String[0]);
62: }
63:
64: }
|