package com.vci.client.framework.systemConfig.stafforgmanage; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Date; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.JPanel; import com.vci.client.LogonApplication; import com.vci.client.common.objects.DeptObject; import com.vci.client.common.objects.RoleObject; import com.vci.client.common.objects.UserObject; import com.vci.client.framework.delegate.RightManagementClientDelegate; import com.vci.client.framework.systemConfig.object.CombinationObject; import com.vci.client.framework.systemConfig.object.PasswordStrategyObject; import com.vci.client.ui.exception.VCIException; import com.vci.client.ui.swing.VCIOptionPane; import com.vci.common.utility.ObjectUtility; public class CommenListener extends JPanel implements ActionListener { private static final long serialVersionUID = 1L; private CombinationTablePanel combinationPanel; private CombinationDialog combinationDialog; private CombinationObject combinationObj; private RoleDialog roleDialog; private RoleTablePanel rolePanel; private DeptDialog deptDialog; private DeptObject parentDeptObj; private DeptObject deptObj; private DeptTablePanel deptPanel; private RoleObject roleObj; private PasswordSrategyDialog pwdStgDialog; private PasswordStrategyTablePanel pwdStgPanel; private PasswordStrategyObject pwdStgObj; private String optType; private UserObject logonUser = LogonApplication.getUserObject(); private String userName = LogonApplication.getUserEntityObject().getUserName(); public CommenListener(CombinationDialog combinationDialog, CombinationTablePanel combinationPanel, String optType, CombinationObject combinationObj) { this.combinationDialog = combinationDialog; this.combinationPanel = combinationPanel; this.optType = optType; this.combinationObj = combinationObj; } public CommenListener(RoleDialog roleDialog, RoleTablePanel rolePanel, String optType, RoleObject roleObj) { this.roleDialog = roleDialog; this.rolePanel = rolePanel; this.optType = optType; this.roleObj = roleObj; } public CommenListener(DeptDialog deptDialog, DeptTablePanel deptPanel, String optType, DeptObject parentDeptObj, DeptObject deptObj) { this.deptDialog = deptDialog; this.deptPanel = deptPanel; this.optType = optType; this.parentDeptObj = parentDeptObj; this.deptObj = deptObj; } public CommenListener(PasswordSrategyDialog pwdStgDialog, PasswordStrategyTablePanel pwdStgPanel, String optType, PasswordStrategyObject pwdStgObj) { this.pwdStgDialog = pwdStgDialog; this.pwdStgPanel = pwdStgPanel; this.optType = optType; this.pwdStgObj = pwdStgObj; } public void actionPerformed(ActionEvent e) { if (optType.equals("addDept")) { addDept_actionPerformed(); } else if (optType.equals("addRole")) { addRole_actionPerformed(); } else if (optType.equals("editDept")) { editDept_actionPerformed(); } else if (optType.equals("editRole")) { editRole_actionPerformed(); } else if (optType.equals("addPwdStg")) { addPwdStg_actionPerformed(); } else if (optType.equals("editPwdStg")) { editPwdStg_actionPerformed(); } else if (optType.equals("addCombination")) { addCombination_actionPerformed(); } else if (optType.equals("editCombination")) { editCombination_actionPerformed(); } } /** * 添加密码组合方式 *

* Description: *

* * @author wangxl * @time 2013-1-3 */ private void addCombination_actionPerformed() { boolean rs = checkCombination(); if (!rs) { return; } CombinationObject combObj = getCombinationInfo(); try { String id = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()) .saveCombination(combObj); combObj.setId(id); } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e); return; } combinationDialog.dispose(); combinationPanel.tablePanel.refreshTableData(); } /** * 修改密码组合方式 *

* Description: *

* * @author wangxl * @time 2013-1-3 */ private void editCombination_actionPerformed() { boolean rs = checkCombination(); if (!rs) { return; } CombinationObject combObj = getCombinationInfo(); try { new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).updateCombination(combObj); } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e); return; } combinationDialog.dispose(); combinationPanel.tablePanel.refreshTableData(); } /** * 注册部门添加事件 */ private void addDept_actionPerformed() { boolean rs = checkDept(); if (!rs) { return; } DeptObject departmentInfo = getDepartmentInfo(); try { String id = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()) .saveDepartment(departmentInfo); departmentInfo.setId(id); } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e); return; } deptDialog.dispose(); deptPanel.insertNewDeptObjToTree(departmentInfo); } /** *

* Description: 添加角色 *

* * @author wangxl * @time 2012-5-11 */ private void addRole_actionPerformed() { boolean rs = checkRole(); if (!rs) { return; } RoleObject roleInfo = getRoleInfo(); try { String id = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).saveRole(roleInfo); roleInfo.setId(id); } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e); return; } roleDialog.dispose(); rolePanel.tablePanel.refreshTableData(); } /** * 注册编辑部门事件 */ private void editDept_actionPerformed() { boolean rs = checkDept(); if (!rs) { return; } DeptObject departmentInfo = getDepartmentInfo(); try { new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).updateDepartment(departmentInfo); } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e); return; } deptDialog.dispose(); deptPanel.updateCurrentDeptObjForTree(departmentInfo); } /** *

* Description: 注册角色修改事件 *

* * @author wangxl * @time 2012-5-11 */ private void editRole_actionPerformed() { boolean rs = checkRole(); if (!rs) { return; } RoleObject roleInfo = getRoleInfo(); try { new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).updateRole(roleInfo); } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e); return; } roleDialog.dispose(); rolePanel.tablePanel.refreshTableData(); } /** * 得到部门 * * @return */ private DeptObject getDepartmentInfo() { DeptObject departmentInfo = new DeptObject(); departmentInfo.setNum(deptDialog.getNumText()); departmentInfo.setName(deptDialog.getNameText()); departmentInfo.setCode(deptDialog.getCodeText()); departmentInfo.setSpecialties(deptDialog.getSpecialtiesText()); departmentInfo.setDescription(deptDialog.getDescriptionArea()); String parentId = parentDeptObj.getId(); departmentInfo.setParentId(parentId); // 增加,状态为未同步 if (optType.equalsIgnoreCase("addDept")) { departmentInfo.setStatus((short) 0); } else { if (deptObj.getStatus() == 0) { departmentInfo.setStatus((short) 0); } else if (deptObj.getStatus() == 1 || deptObj.getStatus() == 2) { departmentInfo.setStatus((short) 1); } } departmentInfo.setCreateTime(System.currentTimeMillis()); departmentInfo.setCreateUser(userName); departmentInfo.setUpdateTime(System.currentTimeMillis()); departmentInfo.setUpdateUser(userName); if ("editDept".equalsIgnoreCase(optType)) { departmentInfo.setId(deptObj.getId()); departmentInfo.setGrantor(deptObj.getGrantor()); } return departmentInfo; } private boolean checkDept() { String name = deptDialog.getNameText(); if ("".equals(name)) { VCIOptionPane.showMessageDialog(deptDialog, "部门名称不能为空,请填写!"); return false; } if (name.getBytes().length > 128) { VCIOptionPane.showMessageDialog(deptDialog, "名称过长,不能大于128个字节!"); return false; } String num = deptDialog.getNumText(); if (!"".equals(num)) { if (num.getBytes().length > 64) { VCIOptionPane.showMessageDialog(roleDialog, "编号过长,不能大于64个字节!"); return false; } } String specialties = deptDialog.getSpecialtiesText(); if (!"".equals(specialties)) { if (specialties.getBytes().length > 255) { VCIOptionPane.showMessageDialog(roleDialog, "编号过长,不能大于255个字节!"); return false; } } String parentId = parentDeptObj.getId() == null ? "" : parentDeptObj.getId(); DeptObject[] deptObjs = null; try { deptObjs = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()) .fetchDepartmentInfoByParentId(parentId); if (deptObjs != null) { int size = deptObjs.length; for (int i = 0; i < size; i++) { if (name.equals(deptObjs[i].getName())) { if ("editDept".equalsIgnoreCase(optType)) { if (deptObj.getId().equals(deptObjs[i].getId())) { continue; } } VCIOptionPane.showMessageDialog(roleDialog, "同级部门不能存在相同名称的部门,请修改名称!"); return false; } if (!"".equals(num)) { if (num.equals(deptObjs[i].getNum())) { if ("editDept".equalsIgnoreCase(optType)) { if (deptObj.getId().equals(deptObjs[i].getId())) { continue; } } VCIOptionPane.showMessageDialog(roleDialog, "部门编号在已经存在,请修改!"); return false; } } } } } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e); return false; } return true; } /** *

* Description:得到角色 *

* * @author wangxl * @time 2012-5-11 * @return */ private RoleObject getRoleInfo() { RoleObject roleInfo = new RoleObject(); roleInfo.setName(roleDialog.getNameText()); roleInfo.setDescription(roleDialog.getDescriptionArea()); roleInfo.setType(logonUser.getUserType()); if ("editRole".equalsIgnoreCase(optType)) { roleInfo.setId(roleObj.getId()); } roleInfo.setCreateTime(System.currentTimeMillis()); roleInfo.setCreateUser(userName); roleInfo.setUpdateTime(System.currentTimeMillis()); roleInfo.setUpdateUser(userName); return roleInfo; } private boolean checkRole() { String name = roleDialog.getNameText(); if ("".equalsIgnoreCase(name)) { VCIOptionPane.showMessageDialog(roleDialog, "角色名称不能为空,请填写!"); return false; } if (name.getBytes().length > 128) { VCIOptionPane.showMessageDialog(roleDialog, "名称过长,不能大于128个字节!"); return false; } if (roleDialog.getDescriptionArea().getBytes().length > 255) { VCIOptionPane.showMessageDialog(roleDialog, "描述过长,不能大于255个字节!"); return false; } RoleObject[] roleObjs = null; try { roleObjs = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).fetchRoleInfo(); int size = roleObjs.length; for (int i = 0; i < size; i++) { if (name.equals(roleObjs[i].getName())) { if ("editRole".equalsIgnoreCase(optType)) { if (roleObj.getId().equals(roleObjs[i].getId())) { continue; } } VCIOptionPane.showMessageDialog(roleDialog, "该角色名称已经存在,请修改!"); return false; } } } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e); return false; } return true; } /** * 得到密码组合方式对象 *

* Description: *

* * @author wangxl * @time 2013-1-3 * @return */ private CombinationObject getCombinationInfo() { CombinationObject combinationInfo = new CombinationObject(); combinationInfo.setName(combinationDialog.getNameText()); combinationInfo.setDescription(combinationDialog.getDescriptionArea()); if ("editCombination".equalsIgnoreCase(optType)) { combinationInfo.setId(combinationObj.getId()); } combinationInfo.setCreateTime(System.currentTimeMillis()); combinationInfo.setCreateUser(userName); combinationInfo.setUpdateTime(System.currentTimeMillis()); combinationInfo.setUpdateUser(userName); return combinationInfo; } private boolean checkCombination() { String name = combinationDialog.getNameText(); if ("".equalsIgnoreCase(name)) { VCIOptionPane.showMessageDialog(roleDialog, "密码组合方式名称不能为空,请填写!"); return false; } if (name.getBytes().length > 128) { VCIOptionPane.showMessageDialog(roleDialog, "名称过长,不能大于128个字节!"); return false; } if (combinationDialog.getDescriptionArea().getBytes().length > 255) { VCIOptionPane.showMessageDialog(roleDialog, "描述过长,不能大于255个字节!"); return false; } CombinationObject[] combinationObjs = null; try { combinationObjs = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()) .fetchAllCombinations(); int size = combinationObjs.length; for (int i = 0; i < size; i++) { if (name.equals(combinationObjs[i].getName())) { if ("editCombination".equalsIgnoreCase(optType)) { if (combinationObj.getId().equals(combinationObjs[i].getId())) { continue; } } VCIOptionPane.showMessageDialog(roleDialog, "该密码组合方式名称已经存在,请修改!"); return false; } } } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e); return false; } return true; } /** *

* Description:增加密码策略 *

* * @author wangxl * @time 2012-5-23 */ public void addPwdStg_actionPerformed() { if (!checkPwdStg()) { return; } PasswordStrategyObject obj = getPasswordStrategyObj(); if (obj == null) { return; } // String[] combinationIds = pwdStgDialog.getCombinationId(); try { new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).savePasswordStrategy(obj); } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e); return; } pwdStgDialog.dispose(); pwdStgPanel.tablePanel.refreshTableData(); } /** *

* Description:修改密码策略 *

* * @author wangxl * @time 2012-5-23 */ public void editPwdStg_actionPerformed() { if (!checkPwdStg()) { return; } PasswordStrategyObject obj = getPasswordStrategyObj(); if (obj == null) { return; } // String[] combinationIds = pwdStgDialog.getCombinationId(); try { new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).editPasswordStrategy(obj); } catch (VCIException e) { VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e); return; } pwdStgDialog.dispose(); pwdStgPanel.tablePanel.refreshTableData(); } private boolean checkPwdStg() { String name = pwdStgDialog.getName(); String passwordLen = pwdStgDialog.getPasswordLen(); String passwordMaxLen = pwdStgDialog.getPasswordMaxLen(); // String[] combinationIds = pwdStgDialog.getCombinationId(); short containsTypes = pwdStgDialog.getContainsTypes(); short requiredType = pwdStgDialog.getRequiredType(); String overDay = pwdStgDialog.getOverDay(); String remideDay = pwdStgDialog.getRemideDay(); String lockCount = pwdStgDialog.getLockCount(); String lockTime = pwdStgDialog.getLockTime(); boolean isDefault = pwdStgDialog.getIsDefault(); String desc = pwdStgDialog.getDescriptionArea(); int typeCount = 0; for (int i = 0; i < 4; i++) { int type = (int) Math.pow(2, i); if ((containsTypes & type) == type) typeCount++; } if ("".equals(name)) { VCIOptionPane.showMessageDialog(this, "名称不能为空!"); return false; } if (name.length() > 128) { VCIOptionPane.showMessageDialog(this, "名称长度不能超过128个字节!"); return false; } if ("".equals(passwordLen)) { VCIOptionPane.showMessageDialog(this, "密码最小长度不能为空!"); return false; } if (!checkPattern(passwordLen)) { VCIOptionPane.showMessageDialog(this, "密码最小长度只能输入(0-9)的数字!"); return false; } if (Integer.valueOf(passwordLen) == 0) { VCIOptionPane.showMessageDialog(this, "密码最小长度不能为0!"); return false; } if ("".equals(passwordMaxLen)) { VCIOptionPane.showMessageDialog(this, "密码最大长度不能为空!"); return false; } if (!checkPattern(passwordMaxLen)) { VCIOptionPane.showMessageDialog(this, "密码最大长度只能输入(0-9)的数字!"); return false; } if (Integer.valueOf(passwordMaxLen) == 0) { VCIOptionPane.showMessageDialog(this, "密码最大长度不能为0!"); return false; } if (Integer.valueOf(passwordLen) > Integer.valueOf(passwordMaxLen)) { VCIOptionPane.showMessageDialog(this, "密码最小长度不能大于最大长度!"); return false; } if (containsTypes == 0) { VCIOptionPane.showMessageDialog(this, "请选择密码组合方式!"); return false; } if (requiredType == 0) { VCIOptionPane.showMessageDialog(this, "请选择密码必填种类!"); return false; } if (requiredType > typeCount) { VCIOptionPane.showMessageDialog(this, "密码必填种类不能大于所选择的密码组合方式的个数"); return false; } if ("".equals(overDay)) { VCIOptionPane.showMessageDialog(this, "过期时间不能为空!"); return false; } if (!checkPattern(overDay)) { VCIOptionPane.showMessageDialog(this, "过期时间只能输入(0-9)的数字!"); return false; } if (Integer.valueOf(overDay) == 0) { VCIOptionPane.showMessageDialog(this, "过期时间不能为0!"); return false; } if ("".equals(remideDay)) { VCIOptionPane.showMessageDialog(this, "提醒时间不能为空!"); return false; } if (!checkPattern(remideDay)) { VCIOptionPane.showMessageDialog(this, "提醒时间只能输入(0-9)的数字!"); return false; } if (Integer.valueOf(remideDay) == 0) { VCIOptionPane.showMessageDialog(this, "提醒时间不能为0!"); return false; } if (Integer.parseInt(overDay) < Integer.valueOf(remideDay)) { VCIOptionPane.showMessageDialog(this, "过期时间不能小于提醒时间!"); return false; } if ("".equals(lockCount)) { VCIOptionPane.showMessageDialog(this, "锁定次数不能为空!"); return false; } if (!checkPattern(lockCount)) { VCIOptionPane.showMessageDialog(this, "锁定次数只能输入(0-9)的数字!"); return false; } if (Integer.valueOf(lockCount) == 0) { VCIOptionPane.showMessageDialog(this, "锁定次数不能为0!"); return false; } if ("".equals(lockTime)) { VCIOptionPane.showMessageDialog(this, "锁定时间不能为空!"); return false; } if (!checkPattern(lockTime)) { VCIOptionPane.showMessageDialog(this, "锁定时间只能输入(0-9)的数字!"); return false; } if (Integer.valueOf(lockTime) == 0) { VCIOptionPane.showMessageDialog(this, "锁定时间不能为0!"); return false; } if (desc.length() > 255) { VCIOptionPane.showMessageDialog(this, "描述长度不能超过255个字节!"); return false; } try { PasswordStrategyObject[] psdStgObjs = new RightManagementClientDelegate( LogonApplication.getUserEntityObject()).fetchAllPasswordStrategy(); // 判断名称是否存在 for (PasswordStrategyObject info : psdStgObjs) { if (info.getName().equals(pwdStgDialog.getName())) { if ("editPwdStg".equalsIgnoreCase(optType)) { if (pwdStgObj.getId().equals(info.getId())) { continue; } } VCIOptionPane.showMessageDialog(this, "策略名称已经存在,请进行修改!"); return false; } if (info.getIsDefault() && isDefault) { if ("editPwdStg".equalsIgnoreCase(optType)) { if (pwdStgObj.getId().equals(info.getId())) { continue; } } int ok = VCIOptionPane.showQuestion(LogonApplication.frame, "系统中已经存在了默认密码策略,确定要更改默认密码策略吗?"); if (ok == 1) { return false; } } } } catch (VCIException re) { VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", re); return false; } return true; } // 正则表达式校验 public boolean checkPattern(String input) { String str = "^[0-9]*$"; Pattern p = Pattern.compile(str); Matcher m = p.matcher(input); return m.matches(); } private PasswordStrategyObject getPasswordStrategyObj() { PasswordStrategyObject obj = new PasswordStrategyObject(); String name = pwdStgDialog.getName(); String passwordLen = pwdStgDialog.getPasswordLen(); String passwordMaxLen = pwdStgDialog.getPasswordMaxLen(); short containsTypes = pwdStgDialog.getContainsTypes(); short requiredType = pwdStgDialog.getRequiredType(); // String charSpeci = pwdStgDialog.getCharspeci(); String overDay = pwdStgDialog.getOverDay(); String remideDay = pwdStgDialog.getRemideDay(); String lockCount = pwdStgDialog.getLockCount(); String lockTime = pwdStgDialog.getLockTime(); boolean isDefault = pwdStgDialog.getIsDefault(); String desc = pwdStgDialog.getDescriptionArea(); // 当密码长度大于密码策略的时候 if (Integer.valueOf(passwordLen) >= requiredType) { obj.setName(name); obj.setPasswordLen(Short.valueOf(passwordLen)); obj.setPasswordMaxLen(Short.valueOf(passwordMaxLen)); obj.setCharTypes(containsTypes); obj.setRequiredType(requiredType); // obj.setCharSpeics(charSpeci); obj.setOverdueDay(Short.valueOf(overDay)); obj.setRemideDay(Short.valueOf(remideDay)); obj.setRetryTime(Short.valueOf(lockCount)); obj.setLockTime(Short.valueOf(lockTime)); obj.setIsDefault(isDefault); obj.setDesc(desc); if ("addPwdStg".equals(optType)) { String id = ObjectUtility.getNewObjectID36(); obj.setId(id); } else if ("editPwdStg".equals(optType)) { obj.setId(pwdStgObj.getId()); } obj.setCreateTime(System.currentTimeMillis()); obj.setCreateUser(userName); obj.setUpdateTime(System.currentTimeMillis()); obj.setUpdateUser(userName); } else { VCIOptionPane.showMessageDialog(this, "密码最小长度不能小于秘密策略的值!"); return null; } return obj; } }