dangsn
2024-12-26 4e9ff2ce6a830bb2340d7c8612c72eea0c5a553e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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);
    }
}