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.portlets.security.SecurityUtil;
31import org.apache.jetspeed.security.User;
32import org.apache.jetspeed.security.UserManager;
33import org.apache.jetspeed.security.UserPrincipal;
34import org.apache.portals.gems.browser.BrowserIterator;
35import org.apache.portals.gems.browser.DatabaseBrowserIterator;
3637/***38 * SSOBrowser39 * 40 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>41 * @version $Id: UserChooserPortlet.java 348264 2005-11-22 22:06:45Z taylor $42 */43publicclassUserChooserPortletextendsSecurityUtil44 {
45private UserManager userManager;
4647publicvoid init(PortletConfig config)
48 throws PortletException
49 {
50super.init(config);
51 userManager = (UserManager)
52 getPortletContext().getAttribute(CommonPortletServices.CPS_USER_MANAGER_COMPONENT);
53if (null == userManager)
54 {
55thrownew PortletException("Failed to find the User Manager on portlet initialization");
56 }
57 }
5859publicvoid getRows(RenderRequest request, String sql, int windowSize)
60 throws Exception
61 {
62 List resultSetTitleList = new ArrayList();
63 List resultSetTypeList = new ArrayList();
64try65 {
66 Iterator users = userManager.getUsers("");
676869 resultSetTypeList.add(String.valueOf(Types.VARCHAR));
70 resultSetTitleList.add("User");
7172// TODO: need to try to normalize List/Collection/Iterators73 List list = new ArrayList();
74while (users.hasNext())
75 {
76 User user = (User)users.next();
77 Principal principal = getPrincipal(user.getSubject(),
78 UserPrincipal.class);
79 list.add(principal.getName());
80 }
81 BrowserIterator iterator = new DatabaseBrowserIterator(
82 list, resultSetTitleList, resultSetTypeList,
83 windowSize);
84 setBrowserIterator(request, iterator);
85 iterator.sort("User");
86 }
87catch (Exception e)
88 {
89//log.error("Exception in CMSBrowserAction.getRows: ", e);90 e.printStackTrace();
91throw e;
92 }
93 }
9495 }