1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.portlets.security.users;
18
19 import java.security.Principal;
20 import java.util.Iterator;
21
22 import javax.faces.context.FacesContext;
23 import javax.portlet.PortletConfig;
24 import javax.portlet.PortletException;
25 import javax.security.auth.Subject;
26
27 import org.apache.jetspeed.CommonPortletServices;
28 import org.apache.jetspeed.security.SecurityException;
29 import org.apache.jetspeed.security.User;
30 import org.apache.jetspeed.security.UserManager;
31 import org.apache.jetspeed.security.UserPrincipal;
32 import org.apache.portals.bridges.jsf.FacesPortlet;
33
34 /***
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 */
40 public class UserManagerPortlet extends FacesPortlet {
41 private UserManager userManager;
42
43 public void init(PortletConfig config) throws PortletException {
44 super.init(config);
45 userManager = (UserManager) getPortletContext().getAttribute(
46 CommonPortletServices.CPS_USER_MANAGER_COMPONENT);
47 if (null == userManager) {
48 throw new PortletException(
49 "Failed to find the User Manager on portlet initialization");
50 }
51
52 try {
53 Iterator users = userManager.getUsers("");
54 while (users.hasNext()) {
55 User user = (User) users.next();
56
57 getPrincipal(user.getSubject(), UserPrincipal.class);
58
59 }
60 } catch (SecurityException se) {
61 throw new PortletException(se);
62 }
63 }
64
65 protected void preProcessFaces(FacesContext context) {
66
67 }
68
69 public Principal getPrincipal(Subject subject, Class classe) {
70 Principal principal = null;
71 Iterator principals = subject.getPrincipals().iterator();
72 while (principals.hasNext()) {
73 Principal p = (Principal) principals.next();
74 if (classe.isInstance(p)) {
75 principal = p;
76 break;
77 }
78 }
79 return principal;
80 }
81
82 }