1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 BaseHierarchyResolver implements HierarchyResolver
44 {
45
46 /***
47 * @see org.apache.jetspeed.security.HierarchyResolver#resolve(Preferences)
48 */
49 public String[] resolve(Preferences prefs)
50 {
51 ArgUtil.notNull(new Object[] { prefs }, new String[] { "preferences" }, "resolve(java.util.prefs.Preferences)");
52
53 List list = new ArrayList();
54 Preferences preferences = prefs;
55 while ((preferences.parent() != null) && (preferences.parent().parent() != null))
56 {
57 list.add(preferences.absolutePath());
58 preferences = preferences.parent();
59 }
60 return (String[]) list.toArray(new String[0]);
61 }
62
63 }