shikeyin
2024-01-11 65da8373531677b1c37a98f53eaa30c892f35e5a
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
package com.iplatform.security.util;
 
import com.iplatform.base.captcha.JigsawCaptchaProvider;
import com.iplatform.base.captcha.NoneCaptchaProvider;
import com.iplatform.security.config.SecurityProperties;
import com.walker.web.CaptchaProvider;
import com.walker.web.CaptchaResult;
import com.walker.web.CaptchaType;
import com.walker.web.ClientType;
import com.walker.web.captcha.SlideCaptchaProvider;
 
public class SecurityConfigUtils {
 
    /**
     * 根据设备类型,返回token失效时间(分钟)
     * @param clientType
     * @param securityProperties
     * @return
     * @date 2023-03-28
     */
    public static final long getTokenExpireMinutes(String clientType, SecurityProperties securityProperties){
        if(clientType.equals(ClientType.INDEX_PC)){
            return securityProperties.getTokenExpireWeb();
        } else {
            return securityProperties.getTokenExpireMobile();
        }
    }
 
    /**
     * 根据'登录回调方式'查找需要装配的'验证码类型'。
     * @param loginCaptchaUserPass
     * @param smsCaptchaProvider
     * @param imageCaptchaProvider
     * @return
     * @date 2023-03-14
     */
    public static final CaptchaProvider<CaptchaResult> findCaptchaProvider(String loginCaptchaUserPass
            , CaptchaProvider<CaptchaResult> smsCaptchaProvider
            , CaptchaProvider<CaptchaResult> imageCaptchaProvider
            , JigsawCaptchaProvider jigsawCaptchaProvider){
        CaptchaProvider<CaptchaResult> captchaProvider = null;
        CaptchaType captchaType = CaptchaType.getType(loginCaptchaUserPass);
        if(captchaType == CaptchaType.InputCode){
            captchaProvider = imageCaptchaProvider;
        } else if(captchaType == CaptchaType.SmsCode){
            captchaProvider = smsCaptchaProvider;
        } else if(captchaType == CaptchaType.Slide){
            captchaProvider = new SlideCaptchaProvider();
        } else if(captchaType == CaptchaType.Jigsaw){
            captchaProvider = jigsawCaptchaProvider;
        } else if(captchaType == CaptchaType.None){
            captchaProvider = new NoneCaptchaProvider();
        } else {
            throw new UnsupportedOperationException("不支持的CaptchaType:" + loginCaptchaUserPass);
        }
        return captchaProvider;
    }
}