📄 useritem.java
字号:
/*
* SSL-Explorer
*
* Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package com.sslexplorer.security;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.policyframework.PolicyUtil;
import com.sslexplorer.table.TableItem;
/**
* Implementation of a {@link com.sslexplorer.table.TableItem} that wraps a
* {@link com.sslexplorer.security.User} for display in a pager.
*
* @author Brett Smith <a href="mailto: brett@3sp.com"><brett@3sp.com></a>
* @version $Revision: 1.12 $
*/
public class UserItem implements TableItem {
final static Log log = LogFactory.getLog(UserItem.class);
// Private instance variables
private User user;
private int numberRoles;
private String firstRoleName;
/**
* Constructor
*
* @param user user to wrap
*/
public UserItem(User user) {
this.user = user;
this.numberRoles = this.user.getRoles().length;
}
/**
* Get the user status. See {@link LogonController#getUserStatus(String)}
* for more details.
*
* @return user status
*/
public int getStatus() {
try {
return CoreServlet.getServlet().getLogonController().getUserStatus(user.getPrincipalName());
}
catch(Exception e) {
log.error("Failed to determine user status.", e);
return LogonController.ACCOUNT_UNKNOWN;
}
}
/**
* Get if this user is the super user.
*
* @return is super user
*/
public boolean getAdministrator() {
return CoreServlet.getServlet().getLogonController().isAdministrator(user);
}
/**
* Get the user object this item wraps
*
* @return user object
*/
public User getUser() {
return user;
}
/**
* Get if this user is enabled
*
* @return enabled
* @throws Exception on any error
*/
public boolean getEnabled() throws Exception {
return PolicyUtil.isEnabled(user);
}
/*
* (non-Javadoc)
*
* @see com.sslexplorer.table.TableItem#getColumnValue(int)
*/
public Object getColumnValue(int col) {
switch (col) {
case 0:
try {
return new Integer(getStatus());
} catch (Exception e) {
return new Integer(0);
}
case 1:
return getUser().getPrincipalName();
case 2:
return getUser().getFullname();
case 3:
return Boolean.valueOf(getAdministrator());
case 4:
return Boolean.FALSE;
}
return null;
}
public String getFirstRoleName() {
if (this.user.getRoles().length > 0){
return this.user.getRoles()[0].getPrincipalName();
}
else{
return "";
}
}
public int getNumberRoles() {
return numberRoles;
}
public void setNumberRoles(int numberRoles) {
this.numberRoles = numberRoles;
}
public void setFirstRoleName(String firstRoleName) {
this.firstRoleName = firstRoleName;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -