|
|
@@ -1,15 +1,13 @@
|
|
|
package com.kxs.common.security.component;
|
|
|
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
-import com.kxs.common.core.constant.SecurityConstants;
|
|
|
import com.kxs.common.security.model.KxsUser;
|
|
|
import com.kxs.common.security.service.KxsUserDetailsService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.core.Ordered;
|
|
|
-import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
|
+import org.springframework.security.core.Authentication;
|
|
|
import org.springframework.security.core.authority.AuthorityUtils;
|
|
|
-import org.springframework.security.core.userdetails.UserDetails;
|
|
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
|
|
import org.springframework.security.oauth2.core.AuthorizationGrantType;
|
|
|
import org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal;
|
|
|
@@ -57,12 +55,13 @@ public class SkyCustomOpaqueTokenIntrospector implements OpaqueTokenIntrospector
|
|
|
oldAuthorization.getAuthorizationGrantType().getValue()))
|
|
|
.max(Comparator.comparingInt(Ordered::getOrder));
|
|
|
|
|
|
- UserDetails userDetails = null;
|
|
|
try {
|
|
|
+
|
|
|
+ //获取用户信息
|
|
|
Object principal = Objects.requireNonNull(oldAuthorization).getAttributes().get(Principal.class.getName());
|
|
|
- UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = (UsernamePasswordAuthenticationToken) principal;
|
|
|
- Object tokenPrincipal = usernamePasswordAuthenticationToken.getPrincipal();
|
|
|
- userDetails = optional.get().loadUserByUser((KxsUser) tokenPrincipal);
|
|
|
+ Authentication authentication = (Authentication) principal;
|
|
|
+
|
|
|
+ return (KxsUser) authentication.getPrincipal();
|
|
|
}
|
|
|
catch (UsernameNotFoundException notFoundException) {
|
|
|
log.warn("用户不不存在 {}", notFoundException.getLocalizedMessage());
|
|
|
@@ -70,14 +69,8 @@ public class SkyCustomOpaqueTokenIntrospector implements OpaqueTokenIntrospector
|
|
|
}
|
|
|
catch (Exception ex) {
|
|
|
log.error("资源服务器 introspect Token error {}", ex.getLocalizedMessage());
|
|
|
+ throw new RuntimeException(ex);
|
|
|
}
|
|
|
-
|
|
|
- // 注入客户端信息,方便上下文中获取
|
|
|
- KxsUser kxsUser = (KxsUser) userDetails;
|
|
|
- Objects.requireNonNull(kxsUser)
|
|
|
- .getAttributes()
|
|
|
- .put(SecurityConstants.CLIENT_ID, oldAuthorization.getRegisteredClientId());
|
|
|
- return kxsUser;
|
|
|
}
|
|
|
|
|
|
}
|