1
yhj
2024-07-24 5e5d945e91568b973faa27d8ab0bcef99fc4a6c5
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
#region
 
using CSFrameworkV5.Common;
using CSFrameworkV5.Core;
using CSFrameworkV5.Core.SystemSecurity;
 
#endregion
 
namespace CSFrameworkV5.WCFContract
{
    /// <summary>
    ///     服务端:WCF服务层安全检查核心类
    /// </summary>
    public static class WebSecurity
    {
        /// <summary>
        ///     检查客户端恶意访问后台
        /// </summary>
        private static bool _AttackValidation;
 
        /// <summary>
        ///     是否检查客户端恶意攻击
        /// </summary>
        public static bool AttackValidation
        {
            get => _AttackValidation;
            set => _AttackValidation = value;
        }
 
        public static Loginer ValidateLoginer(byte[] loginTicket)
        {
            //是否连续攻击
            if (AttackValidation) AttackRecorder.IsAttack();
 
            //加密令牌解析成功
            var user = WebServiceSecurity.ValidateLoginer(loginTicket);
 
            //检查用户名及密码
            if (!ActivityUserCache.ValidateUser(user.Account, user.Password))
                throw new CustomException("用户名或密码不正确!");
 
            return user;
        }
 
        /// <summary>
        ///     检查用户登录凭证,并且检查两次访问时间
        /// </summary>
        /// <param name="loginer">用户登录凭证</param>
        /// <param name="checkAttack">检查连续调用方法攻击</param>
        /// <returns></returns>
        public static Loginer ValidateLoginer(byte[] loginTicket,
            bool checkAttack)
        {
            if (checkAttack) AttackRecorder.IsAttack();
 
            //加密令牌解析成功
            var user = WebServiceSecurity.ValidateLoginer(loginTicket);
 
            //检查用户名及密码
            if (!ActivityUserCache.ValidateUser(user.Account, user.Password))
                throw new CustomException("用户名或密码不正确!");
 
            return user;
        }
 
        /// <summary>
        ///     用户登录的验证码,防止用户恶意攻击Login接口.
        /// </summary>
        /// <param name="identity">验证码</param>
        /// <returns></returns>
        public static bool ValidateLoginIdentity(byte[] identity)
        {
            //是否连续攻击
            if (AttackValidation) AttackRecorder.IsAttack();
 
            var isIdentity = WebServiceSecurity.ValidateLoginIdentity(identity);
            return isIdentity;
        }
    }
}