KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > security > UserItem


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.security;
21
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26
27 import com.sslexplorer.core.CoreUtil;
28 import com.sslexplorer.policyframework.PolicyUtil;
29 import com.sslexplorer.table.TableItem;
30
31 /**
32  * Implementation of a {@link com.sslexplorer.table.TableItem} that wraps a
33  * {@link com.sslexplorer.security.User} for display in a pager.
34  *
35  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
36  */

37 public class UserItem implements TableItem {
38     
39     final static Log log = LogFactory.getLog(UserItem.class);
40
41     // Private instance variables
42
private User user;
43     private int numberRoles;
44
45     /**
46      * Constructor
47      *
48      * @param user user to wrap
49      */

50     public UserItem(User user) {
51         this.user = user;
52         this.numberRoles = this.user.getRoles().length;
53     }
54
55     /**
56      * Get the user status. See {@link LogonController#getUserStatus(User)}
57      * for more details.
58      *
59      * @return user status
60      */

61     public int getStatus() {
62         try {
63             return LogonControllerFactory.getInstance().getUserStatus(user);
64         }
65         catch(Exception JavaDoc e) {
66             log.error("Failed to determine user status.", e);
67             return LogonController.ACCOUNT_UNKNOWN;
68         }
69     }
70
71     /**
72      * Get if this user is the super user.
73      *
74      * @return is super user
75      */

76     public boolean getAdministrator() {
77         return LogonControllerFactory.getInstance().isAdministrator(user);
78     }
79
80     /**
81      * Get the user object this item wraps
82      *
83      * @return user object
84      */

85     public User getUser() {
86         return user;
87     }
88
89     /**
90      * Get if this user is enabled
91      *
92      * @return enabled
93      * @throws Exception on any error
94      */

95     public boolean getEnabled() throws Exception JavaDoc {
96         return PolicyUtil.isEnabled(user);
97     }
98
99     /*
100      * (non-Javadoc)
101      *
102      * @see com.sslexplorer.table.TableItem#getColumnValue(int)
103      */

104     public Object JavaDoc getColumnValue(int col) {
105         if(col == 0) {
106             return getUser().getPrincipalName();
107         }
108         return "";
109     }
110
111     /**
112      * @return String
113      */

114     public String JavaDoc getLink() {
115         return "#";
116     }
117     
118     /**
119      * @return String
120      */

121     public String JavaDoc getOnClick() {
122         return "";
123     }
124     
125     /**
126      * @return int
127      */

128     public int getNumberRoles() {
129         return numberRoles;
130     }
131
132     /**
133      * @param numberRoles
134      */

135     public void setNumberRoles(int numberRoles) {
136         this.numberRoles = numberRoles;
137     }
138
139     /**
140      * @param request
141      * @return String
142      */

143     public String JavaDoc getSmallIconPath(HttpServletRequest JavaDoc request) {
144         switch (getStatus()) {
145             case LogonController.ACCOUNT_GRANTED:
146                 return CoreUtil.getThemePath(request.getSession()) + "/images/actions/userActive.gif";
147             case LogonController.ACCOUNT_DISABLED:
148                 return CoreUtil.getThemePath(request.getSession()) + "/images/actions/userDisabled.gif";
149             case LogonController.ACCOUNT_LOCKED:
150                 return CoreUtil.getThemePath(request.getSession()) + "/images/actions/userLocked.gif";
151             case LogonController.ACCOUNT_REVOKED:
152                 return CoreUtil.getThemePath(request.getSession()) + "/images/actions/userInactive.gif";
153             case LogonController.ACCOUNT_ACTIVE:
154                 return CoreUtil.getThemePath(request.getSession()) + "/images/actions/userOnLine.gif";
155             default:
156                 return CoreUtil.getThemePath(request.getSession()) + "/images/actions/userError.gif";
157         }
158     }
159 }
Popular Tags