|
|
|
@ -3,7 +3,6 @@ package com.xit.core.oauth2.utils;
|
|
|
|
|
import com.xit.core.constant.XitConstants;
|
|
|
|
|
import com.xit.core.constant.ErrorCode;
|
|
|
|
|
import com.xit.core.exception.TokenAuthException;
|
|
|
|
|
//import com.xit.core.oauth2.oauth.token.JwtToken;
|
|
|
|
|
import com.xit.core.oauth2.oauth.JwtTokenProvider;
|
|
|
|
|
import com.xit.core.util.Checks;
|
|
|
|
|
import com.xit.core.util.SpringUtils;
|
|
|
|
@ -14,21 +13,26 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
|
|
public class HeaderUtil {
|
|
|
|
|
|
|
|
|
|
//private static String sAccessToken;
|
|
|
|
|
|
|
|
|
|
public static String getAccessToken(){
|
|
|
|
|
return getAccessToken(((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String getAccessToken(HttpServletRequest request) {
|
|
|
|
|
String headerValue = request.getHeader(XitConstants.JwtToken.HEADER_NAME.getCode());
|
|
|
|
|
return extractAccessToken(request.getHeader(XitConstants.JwtToken.HEADER_NAME.getCode()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (headerValue == null) {
|
|
|
|
|
/**
|
|
|
|
|
* get access token
|
|
|
|
|
* @param tokenStr String
|
|
|
|
|
* @return String
|
|
|
|
|
*/
|
|
|
|
|
public static String extractAccessToken(String tokenStr) {
|
|
|
|
|
if (tokenStr == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (headerValue.startsWith(XitConstants.JwtToken.GRANT_TYPE.getCode())) {
|
|
|
|
|
return headerValue.substring(XitConstants.JwtToken.GRANT_TYPE.getCode().length());
|
|
|
|
|
if (tokenStr.startsWith(XitConstants.JwtToken.GRANT_TYPE.getCode())) {
|
|
|
|
|
return tokenStr.substring(XitConstants.JwtToken.GRANT_TYPE.getCode().length() + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|