提交 033f7603 编写于 作者: pig_冷冷's avatar pig_冷冷

🐛 Fixing a bug. oauth server 用户ID没有注入,securityutils 不能获取

上级 51f95c7d
......@@ -19,6 +19,7 @@ package com.pig4cloud.pig.auth.config;
import com.pig4cloud.pig.common.core.constant.SecurityConstants;
import com.pig4cloud.pig.common.security.component.PigWebResponseExceptionTranslator;
import com.pig4cloud.pig.common.security.service.PigClientDetailsService;
import com.pig4cloud.pig.common.security.service.PigUser;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.context.annotation.Bean;
......@@ -95,7 +96,11 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
public TokenEnhancer tokenEnhancer() {
return (accessToken, authentication) -> {
final Map<String, Object> additionalInfo = new HashMap<>(1);
additionalInfo.put("license", SecurityConstants.PROJECT_LICENSE);
PigUser pigUser = (PigUser) authentication.getUserAuthentication().getPrincipal();
additionalInfo.put(SecurityConstants.DETAILS_LICENSE, SecurityConstants.PROJECT_LICENSE);
additionalInfo.put(SecurityConstants.DETAILS_USER_ID, pigUser.getId());
additionalInfo.put(SecurityConstants.DETAILS_USERNAME, pigUser.getUsername());
additionalInfo.put(SecurityConstants.DETAILS_DEPT_ID, pigUser.getDeptId());
((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(additionalInfo);
return accessToken;
};
......
......@@ -100,4 +100,24 @@ public interface SecurityConstants {
* 资源服务器默认bean名称
*/
String RESOURCE_SERVER_CONFIGURER = "resourceServerConfigurerAdapter";
/**
* 用户ID字段
*/
String DETAILS_USER_ID = "user_id";
/**
* 用户名字段
*/
String DETAILS_USERNAME = "username";
/**
* 用户部门字段
*/
String DETAILS_DEPT_ID = "dept_id";
/**
* 协议字段
*/
String DETAILS_LICENSE = "license";
}
......@@ -16,6 +16,7 @@
package com.pig4cloud.pig.common.security.component;
import com.pig4cloud.pig.common.core.constant.SecurityConstants;
import com.pig4cloud.pig.common.security.service.PigUser;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
......@@ -35,9 +36,6 @@ import java.util.Map;
* 根据checktoken 的结果转化用户信息
*/
public class PigUserAuthenticationConverter implements UserAuthenticationConverter {
private static final String USER_ID = "user_id";
private static final String DEPT_ID = "dept_id";
private static final String TENANT_ID = "tenant_id";
private static final String N_A = "N/A";
/**
......@@ -67,9 +65,9 @@ public class PigUserAuthenticationConverter implements UserAuthenticationConvert
if (map.containsKey(USERNAME)) {
Collection<? extends GrantedAuthority> authorities = getAuthorities(map);
String username = (String) map.get(USERNAME);
Integer id = (Integer) map.get(USER_ID);
Integer deptId = (Integer) map.get(DEPT_ID);
String username = (String) map.get(SecurityConstants.DETAILS_USERNAME);
Integer id = (Integer) map.get(SecurityConstants.DETAILS_USER_ID);
Integer deptId = (Integer) map.get(SecurityConstants.DETAILS_DEPT_ID);
PigUser user = new PigUser(id, deptId, username, N_A, true
, true, true, true, authorities);
return new UsernamePasswordAuthenticationToken(user, N_A, authorities);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册