1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 *9 * http://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * 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 and15 * limitations under the License.16 */17packageorg.apache.jetspeed.security.impl;
1819import java.util.ArrayList;
20import java.util.List;
21import java.util.prefs.Preferences;
2223import org.apache.jetspeed.security.HierarchyResolver;
24import org.apache.jetspeed.util.ArgUtil;
2526/***27 * <p>28 * Implementation for "is a" hierarchy. For Example: if a user has the role29 * [roleA.roleB.roleC] than30 * </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:5841 * dlestrat Exp $42 */43publicclassGeneralizationHierarchyResolverextendsBaseHierarchyResolver implements HierarchyResolver
44 {
4546/***47 * @see org.apache.jetspeed.security.HierarchyResolver#resolve(Preferences)48 */49public String[] resolve(Preferences prefs)
50 {
51 ArgUtil.notNull(new Object[] { prefs }, new String[] { "preferences" }, "resolve(java.util.prefs.Preferences)");
5253 List list = new ArrayList();
54 Preferences preferences = prefs;
55while ((preferences.parent() != null) && (preferences.parent().parent() != null))
56 {
57 list.add(preferences.absolutePath());
58 preferences = preferences.parent();
59 }
60return (String[]) list.toArray(new String[0]);
61 }
6263 }