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;
|
}
|
}
|