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.portlets.security.users;
1819import java.security.Principal;
20import java.sql.Types;
21import java.util.ArrayList;
22import java.util.Iterator;
23import java.util.List;
2425import javax.portlet.PortletConfig;
26import javax.portlet.PortletException;
27import javax.portlet.RenderRequest;
2829import org.apache.jetspeed.CommonPortletServices;
30import org.apache.jetspeed.security.Role;
31import org.apache.jetspeed.security.RoleManager;
32import org.apache.portals.gems.browser.BrowserIterator;
33import org.apache.portals.gems.browser.DatabaseBrowserIterator;
34import org.apache.portals.gems.browser.BrowserPortlet;
3536/***37 * RoleChooserPortlet38 * 39 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>40 * @version $Id: RoleChooserPortlet.java 348264 2005-11-22 22:06:45Z taylor $41 */42publicclassRoleChooserPortletextends BrowserPortlet
43 {
44private RoleManager roleManager;
4546publicvoid init(PortletConfig config)
47 throws PortletException
48 {
49super.init(config);
50 roleManager = (RoleManager)
51 getPortletContext().getAttribute(CommonPortletServices.CPS_GROUP_MANAGER_COMPONENT);
52if (null == roleManager)
53 {
54thrownew PortletException("Failed to find the User Manager on portlet initialization");
55 }
56 }
5758publicvoid getRows(RenderRequest request, String sql, int windowSize)
59 throws Exception
60 {
61 List resultSetTitleList = new ArrayList();
62 List resultSetTypeList = new ArrayList();
63try64 {
65 Iterator roles = roleManager.getRoles("");
666768 resultSetTypeList.add(String.valueOf(Types.VARCHAR));
69 resultSetTitleList.add("Role");
7071// TODO: need to try to normalize List/Collection/Iterators72 List list = new ArrayList();
73while (roles.hasNext())
74 {
75 Role role = (Role)roles.next();
7677 Principal principal = role.getPrincipal();
78 list.add(principal.getName());
79 }
80 BrowserIterator iterator = new DatabaseBrowserIterator(
81 list, resultSetTitleList, resultSetTypeList,
82 windowSize);
83 setBrowserIterator(request, iterator);
84 iterator.sort("Role");
85 }
86catch (Exception e)
87 {
88//log.error("Exception in CMSBrowserAction.getRows: ", e);89 e.printStackTrace();
90throw e;
91 }
92 }
9394 }