1
zhujie
5 天以前 ec15861e14c66c38b1a8f5fffc6975d7da6c315c
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
package com.mzl.flower.config;
 
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.authentication.BearerTokenExtractor;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
 
import javax.servlet.http.HttpServletRequest;
 
public class TokenExtractor extends BearerTokenExtractor {
 
    private TokenStore tokenStore;
 
    public TokenExtractor(TokenStore tokenStore){
        this.tokenStore = tokenStore;
    }
 
    @Override
    public Authentication extract(HttpServletRequest request) {
        String tokenValue = extractToken(request);
        if (tokenValue != null) {
            OAuth2AccessToken accessToken = tokenStore.readAccessToken(tokenValue);
            if(accessToken == null){
                return null;
            }
 
            PreAuthenticatedAuthenticationToken authentication = new PreAuthenticatedAuthenticationToken(tokenValue, "");
            return authentication;
        }
        return null;
    }
}