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.util.Iterator;
2122import javax.faces.context.FacesContext;
23import javax.portlet.PortletConfig;
24import javax.portlet.PortletException;
25import javax.security.auth.Subject;
2627import org.apache.jetspeed.CommonPortletServices;
28import org.apache.jetspeed.security.SecurityException;
29import org.apache.jetspeed.security.User;
30import org.apache.jetspeed.security.UserManager;
31import org.apache.jetspeed.security.UserPrincipal;
32import org.apache.portals.bridges.jsf.FacesPortlet;
3334/***35 * Provides maintenance capabilities for User Administration.36 * 37 * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>38 * @version $Id: UserManagerPortlet.java 348264 2005-11-22 22:06:45Z taylor $39 */40publicclassUserManagerPortletextends FacesPortlet {
41private UserManager userManager;
4243publicvoid init(PortletConfig config) throws PortletException {
44super.init(config);
45 userManager = (UserManager) getPortletContext().getAttribute(
46 CommonPortletServices.CPS_USER_MANAGER_COMPONENT);
47if (null == userManager) {
48thrownew PortletException(
49"Failed to find the User Manager on portlet initialization");
50 }
51// System.out.println("user manager = " + userManager);52try {
53 Iterator users = userManager.getUsers("");
54while (users.hasNext()) {
55 User user = (User) users.next();
56// System.out.println("++++ User = " + user);57 getPrincipal(user.getSubject(), UserPrincipal.class);
58// System.out.println("principal = " + principal.getName());59 }
60 } catch (SecurityException se) {
61thrownew PortletException(se);
62 }
63 }
6465protectedvoid preProcessFaces(FacesContext context) {
66// System.out.println("*** pre processing faces for user manager: " + context);67 }
6869public Principal getPrincipal(Subject subject, Class classe) {
70 Principal principal = null;
71 Iterator principals = subject.getPrincipals().iterator();
72while (principals.hasNext()) {
73 Principal p = (Principal) principals.next();
74if (classe.isInstance(p)) {
75 principal = p;
76break;
77 }
78 }
79return principal;
80 }
8182 }