View Javadoc

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.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  }