保誠-保戶業務員媒合平台
wayne
2022-03-10 e8241decc705f9db3e46aed7b3a3f8b3188cf820
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
package com.pollex.pam.security.provider;
 
import com.pollex.pam.config.ApplicationProperties;
import com.pollex.pam.business.security.token.EServiceAuthenticationToken;
import com.pollex.pam.security.token.OtpAuthenticationToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.stereotype.Component;
 
 
@Component
public class CustomAuthenticationProvider implements AuthenticationProvider {
 
    @Autowired
    EServiceAuthenticationProvider eServiceAuthenticationProvider;
 
    @Autowired
    OtpAuthenticationProvider otpAuthenticationProvider;
 
    @Autowired
    ApplicationProperties applicationProperty;
 
    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        if(authentication instanceof OtpAuthenticationToken) {
            return otpAuthenticationProvider.authenticate((OtpAuthenticationToken) authentication);
        }
        else if(authentication instanceof EServiceAuthenticationToken) {
            return eServiceAuthenticationProvider.authenticate((EServiceAuthenticationToken) authentication);
        }
        return null;
    }
 
    @Override
    public boolean supports(Class<?> authentication) {
        return AbstractAuthenticationToken.class.isAssignableFrom(authentication);
    }
}