📄 usersession.java
字号:
package com.pegasus.framework.acl.pojo;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import com.pegasus.framework.acl.pojo.vo.User;
import com.pegasus.framework.castor.menu.MenuItem;
import com.pegasus.framework.castor.menu.WebMenu;
import com.pegasus.framework.util.StringUtil;
import com.pegasus.framework.web.tree.HTMLTree;
import com.pegasus.framework.web.tree.TreeNode;
public class UserSession implements Serializable {
/**
* Comment for <code>serialVersionUID</code>
*/
private static final long serialVersionUID = 10000L;
private Logger logger = LogManager.getLogger(UserSession.class);
public static final String USERSESSION_KEY = "userSession";
private WebUser webUser;
private boolean isLocale = false;
private Map attribute = new HashMap();
/**
* 检测用户的口令是否正确
*
* @param user 用户对象
* @param password 为加密的口令
* @return 如果密码正确返回true,否则返回false
*/
public static boolean verifyPasword(User user, String password) {
if (user == null) {
return false;
}
if (StringUtil.isEmpty(user.getPassword())) {
return StringUtil.isEmpty(password);
}
//return user.getPassword().equals(Crypt.encodeByMD5(password));
return user.getPassword().equals(password);
}
/**
* @return .
*/
public Map getAttribute() {
return attribute;
}
/**
*
*/
public void clearAttribute() {
attribute.clear();
}
/**
* @return .
*/
public int attributersSize() {
return attribute.size();
}
/**
* @param key .
* @return .
*/
public Object getAttribute(Object key) {
return attribute.get(key);
}
/**
* @param key .
* @return .
*/
public Object removeAttribute(Object key) {
return attribute.remove(key);
}
/**
* @param key .
* @return .
*/
public boolean containsAttribute(Object key) {
return attribute.containsKey(key);
}
/**
* @param value .
* @return .
*/
public boolean containsAttributeValue(Object value) {
return attribute.containsValue(value);
}
/**
* @param key .
* @param value .
* @return .
*/
public Object setAttribute(Object key, Object value) {
return attribute.put(key, value);
}
private static final String HOSTNAME = "host_name";
/**
* @return host name
*/
public String getHost_name() {
return (String) getAttribute(HOSTNAME);
}
/**
* @param host_name .
*/
public void setHost_name(String host_name) {
setAttribute(HOSTNAME, host_name);
}
private static final String USERIP = "user_ip";
/**
* @return user ip
*/
public String getUser_ip() {
return (String) getAttribute(USERIP);
}
/**
* @param user_ip .
*/
public void setUser_ip(String user_ip) {
setAttribute(USERIP, user_ip);
}
private static final String LASTACTNAME = "lastActName";
/**
* @return .
*/
public String getLastActName() {
return (String) getAttribute(LASTACTNAME);
}
/**
* @param lastActName .
*/
public void setLastActName(String lastActName) {
setAttribute(LASTACTNAME, lastActName);
}
private static final String LOGINDATE = "loginDate";
/**
* @return .
*/
public java.util.Date getLoginDate() {
return (java.util.Date) attribute.get(LOGINDATE);
}
/**
* @param loginDate .
*/
public void setLoginDate(java.util.Date loginDate) {
setAttribute(LOGINDATE, loginDate);
}
private static final String LASTVISITDATE = "lastVisitDate";
/**
* @return .
*/
public java.util.Date getLastVisitDate() {
return (java.util.Date) getAttribute(LASTVISITDATE);
}
/**
* @param lastVisitDate .
*/
public void setLastVisitDate(java.util.Date lastVisitDate) {
setAttribute(LASTVISITDATE, lastVisitDate);
}
/**
* @return .
*/
public static long getSerialVersionUID() {
return serialVersionUID;
}
/**
* @return selfService URl
* @deprecated 不建议使用,将来使用配置文件代替,目前仅仅为了年中项目验收。
*/
public String getSelfServiceURL() {
return webUser.getUser().getDescription();
}
/**
* @return is locale
*/
public boolean isLocale() {
return isLocale;
}
/**
* @param isLocale
* isLocale
*/
public void setLocale(boolean isLocale) {
this.isLocale = isLocale;
}
/**
* .
*/
public UserSession() {
}
/**
* @param user
* user
*/
public UserSession(WebUser user) {
super();
webUser = user;
}
/**
* @return webuser
*/
public WebUser getWebUser() {
return webUser;
}
/**
* @return .
*/
public Set getUserPrivilege() {
return webUser.getUserPrivilege();
}
/**
* @return .
*/
public Map getUserPrivilegeMap() {
return webUser.getUserPrivilegeMap();
}
/**
* @param webUser .
*/
public void setWebUser(WebUser webUser) {
this.webUser = webUser;
}
/**
* @return loginName
*/
public String getLoginname() {
return webUser.getUser().getLoginname();
}
/**
* @param code
* code
* @return if can visit return true
*/
public boolean canVisit(String code) {
return webUser.canVisit(code);
}
/**
* @return userid
*/
public Long getUserID() {
return webUser.getUser().getId();
}
/**
* @return username
*/
public String getUserName() {
return StringUtil.getText(webUser.getUser().getName());
}
/**
* 得到用户从属的公司
*
* @return 。
*/
public Long getBelongCorpID() {
return webUser.getUser().getCorpId();
}
/**
* 得到用户从属的公司
*
* @return 。
*/
public String getBelongCorpName() {
return webUser.getUser().getCorpName();
}
/**
* @return corpid
*/
public Long getCorp_id() {
return webUser.getCurrentCompany();
}
/**
* @return corpname
*/
public String getCorp_name() {
return webUser.getCurrentCompanyName();
}
/**
* @return deptid
*/
public Long getDept_id() {
return webUser.getUser().getDeptId();
}
/**
* @return .
*/
public String getDept_code() {
return webUser.getUser().getDeptCode();
}
/**
* @return deptname
*/
public String getDept_name() {
return webUser.getUser().getDeptName();
}
/**
* @return 返回用户对应的员工的ID
*/
public Long getEmployeeId() {
return webUser.getUser().getEmployeeid();
}
/**
* @return 工号
*/
public String getEmployeeCode() {
return webUser.getUser().getLoginname();
}
/**
* @return employ name
*/
public String getEmployeeName() {
return webUser.getUser().getName();
}
/**
* 得到用户的菜单
*
* @return .
*/
public WebMenu getUserWebMenu() {
return webUser.getWebMenu();
}
/**
* 得到用户的菜单
*
* @return 。
*/
public HTMLTree getUserMenuHTMLTree() {
WebMenu menu = getUserWebMenu();
HTMLTree htmlTree = new HTMLTree();
htmlTree.setRootid(menu.getId());
htmlTree.setRoot_title(menu.getCaption());
for (int index = 0; index < menu.getMenuItemCount(); index++) {
MenuItem item = menu.getMenuItem(index);
TreeNode node = new TreeNode();
node.setParentid(menu.getId());
node.setNode_id(item.getId());
node.setNode_title(item.getCaption());
node.setUrl(item.getUrl());
htmlTree.addTreeNode(node);
makeTreeNode(item, htmlTree);
}
logger.info(" htmlTree : " + htmlTree.toString());
return htmlTree;
}
/**
* @param parentItem .
* @param tree .
*/
private void makeTreeNode(MenuItem parentItem, HTMLTree tree) {
for (int i = 0; i < parentItem.getMenuItemCount(); i++) {
MenuItem item = parentItem.getMenuItem(i);
TreeNode node = new TreeNode();
node.setParentid(parentItem.getId());
node.setNode_id(item.getId());
node.setNode_title(item.getCaption());
node.setUrl(item.getUrl());
tree.addTreeNode(node);
makeTreeNode(item, tree);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -