mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-11 13:19:01 +08:00
1 parent
c617a8b7e2
commit
8d0faea641
1 file changed
+3
-9
@@ -26,7 +26,6 @@ import com.pig4cloud.pigx.admin.api.entity.SysTenant;
|
|||||||
import com.pig4cloud.pigx.admin.api.feign.RemoteClientDetailsService;
|
import com.pig4cloud.pigx.admin.api.feign.RemoteClientDetailsService;
|
||||||
import com.pig4cloud.pigx.admin.api.feign.RemoteTenantService;
|
import com.pig4cloud.pigx.admin.api.feign.RemoteTenantService;
|
||||||
import com.pig4cloud.pigx.admin.api.vo.TokenVO;
|
import com.pig4cloud.pigx.admin.api.vo.TokenVO;
|
||||||
import com.pig4cloud.pigx.auth.support.handler.PigxAuthenticationFailureEventHandler;
|
|
||||||
import com.pig4cloud.pigx.common.core.constant.CacheConstants;
|
import com.pig4cloud.pigx.common.core.constant.CacheConstants;
|
||||||
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
|
import com.pig4cloud.pigx.common.core.constant.CommonConstants;
|
||||||
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||||
@@ -55,7 +54,6 @@ import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
|
|||||||
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
|
import org.springframework.security.oauth2.server.authorization.OAuth2Authorization;
|
||||||
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
|
import org.springframework.security.oauth2.server.authorization.OAuth2AuthorizationService;
|
||||||
import org.springframework.security.oauth2.server.authorization.OAuth2TokenType;
|
import org.springframework.security.oauth2.server.authorization.OAuth2TokenType;
|
||||||
import org.springframework.security.oauth2.server.resource.InvalidBearerTokenException;
|
|
||||||
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
|
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@@ -78,8 +76,6 @@ import java.util.stream.Collectors;
|
|||||||
@RequestMapping("/token")
|
@RequestMapping("/token")
|
||||||
public class PigxTokenEndpoint {
|
public class PigxTokenEndpoint {
|
||||||
|
|
||||||
private final PigxAuthenticationFailureEventHandler authenticationFailureHandler;
|
|
||||||
|
|
||||||
private final OAuth2AuthorizationService authorizationService;
|
private final OAuth2AuthorizationService authorizationService;
|
||||||
|
|
||||||
private final RemoteClientDetailsService clientDetailsService;
|
private final RemoteClientDetailsService clientDetailsService;
|
||||||
@@ -153,16 +149,14 @@ public class PigxTokenEndpoint {
|
|||||||
|
|
||||||
if (StrUtil.isBlank(token)) {
|
if (StrUtil.isBlank(token)) {
|
||||||
httpResponse.setStatusCode(HttpStatus.UNAUTHORIZED);
|
httpResponse.setStatusCode(HttpStatus.UNAUTHORIZED);
|
||||||
this.authenticationFailureHandler.onAuthenticationFailure(request, response,
|
return R.failed(OAuth2ErrorCodesExpand.TOKEN_MISSING);
|
||||||
new InvalidBearerTokenException(OAuth2ErrorCodesExpand.TOKEN_MISSING));
|
|
||||||
return R.failed();
|
|
||||||
}
|
}
|
||||||
OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
|
OAuth2Authorization authorization = authorizationService.findByToken(token, OAuth2TokenType.ACCESS_TOKEN);
|
||||||
|
|
||||||
// 如果令牌不存在 返回401
|
// 如果令牌不存在 返回401
|
||||||
if (authorization == null || authorization.getAccessToken() == null) {
|
if (authorization == null || authorization.getAccessToken() == null) {
|
||||||
this.authenticationFailureHandler.onAuthenticationFailure(request, response,
|
httpResponse.setStatusCode(HttpStatus.UNAUTHORIZED);
|
||||||
new InvalidBearerTokenException(OAuth2ErrorCodesExpand.INVALID_BEARER_TOKEN));
|
return R.failed(OAuth2ErrorCodesExpand.INVALID_BEARER_TOKEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取令牌
|
// 获取令牌
|
||||||
|
|||||||
Reference in new issue
Block a user