package com.vci.client.logon.client; import java.text.SimpleDateFormat; import java.util.Date; import com.vci.client.common.ConfigUtils; import com.vci.client.common.objects.UserObject; import com.vci.client.framework.delegate.RightManagementClientDelegate; import com.vci.client.logon.base.EncryptData; import com.vci.client.ui.exception.VCIException; public class SingleLogon { public SingleLogon() { } /** * 判断用户是否存在 * @param userName, 用户名 * @return */ public boolean verifyUserExist(String userName) { boolean isExist = false; try { UserObject userObject = new RightManagementClientDelegate().getUserObjToLock(userName); if (userObject != null && userObject.getId() != null && !userObject.getId().equals("")) { isExist = true; } } catch (VCIException e) { e.printStackTrace(); } return isExist; } /** * 解密 * * @param input,输入的加密字符串 * @return,解密字符串 */ public String getDecryptData(String input) { String key = ConfigUtils.getConfigValue("encrypt.key"); if (key == null || key.equals("")) { return ""; } EncryptData data = new EncryptData(key); return data.decrypt(input); } /** * 根据间隔时间判断登录是否有效 * @param inputTime, 输入的字符串 * @param space * @return */ /** * 根据间隔时间判断登录是否有效 * * @param inputTime, 输入的字符串 * @param dateFormate, 输入日期格式, 如yyyy-MM-dd HH:mm:ss * @param space,间隔时间,在间隔时间内为有效,单位:分钟 * @return,有效返回true,无效范围false */ public boolean isLogonValidByTime(String inputTime, String dateFormat, int space) { boolean isValid = false; try { SimpleDateFormat formatter = new SimpleDateFormat (dateFormat); java.util.Date itime = formatter.parse(inputTime); java.util.Date ctime = new Date(); long timeSpan = ctime.getTime() - itime.getTime(); if (timeSpan >= 0 && timeSpan <= space * 60 * 1000) { return true; } else if (timeSpan < 0 && -timeSpan <= space * 60 * 1000) { return true; } } catch (Exception e) { e.printStackTrace(); } return isValid; } public static void main(String[] args) { SingleLogon logon = new SingleLogon(); boolean is = logon.isLogonValidByTime("2013-03-28 16:02:00", "yyyy-MM-dd HH:mm:ss", 5); System.out.println(is); } }