提交 9d131e30 作者: 洪东保

登录身份增加role: system/custom

父级 c8519f9e
...@@ -93,7 +93,8 @@ public class CustomAuthenticationProvider extends AbstractUserDetailsAuthenticat ...@@ -93,7 +93,8 @@ public class CustomAuthenticationProvider extends AbstractUserDetailsAuthenticat
try { try {
String uid = details.get("userId"); String uid = details.get("userId");
String tenantId = details.get("tenantId"); String tenantId = details.get("tenantId");
UserDetails loadedUser = this.getCustomUserDetailsService().loadUser(uid, tenantId); String role = details.get("role");
UserDetails loadedUser = this.getCustomUserDetailsService().loadUser(uid, tenantId, role);
if (loadedUser == null) { if (loadedUser == null) {
throw new InternalAuthenticationServiceException( throw new InternalAuthenticationServiceException(
"customUserDetailsService returned null, which is an interface contract violation"); "customUserDetailsService returned null, which is an interface contract violation");
......
...@@ -2,6 +2,7 @@ package com.cmeeting.ad.controller; ...@@ -2,6 +2,7 @@ package com.cmeeting.ad.controller;
import com.cmeeting.ad.service.UserService; import com.cmeeting.ad.service.UserService;
import com.cmeeting.ad.vo.UserVo; import com.cmeeting.ad.vo.UserVo;
import com.cmeeting.constant.RecordTemplateConstant;
import com.cmeeting.util.IPUtils; import com.cmeeting.util.IPUtils;
import com.cmeeting.util.R; import com.cmeeting.util.R;
import com.cmeeting.ad.vo.ApplicationUserVO; import com.cmeeting.ad.vo.ApplicationUserVO;
...@@ -33,7 +34,7 @@ public class UserController { ...@@ -33,7 +34,7 @@ public class UserController {
@PostMapping(value = "/auth") @PostMapping(value = "/auth")
public R auth(@Validated @RequestBody UserVo.Auth vo) { public R auth(@Validated @RequestBody UserVo.Auth vo) {
return R.ok(userService.auth(vo)); return R.ok(userService.auth(vo, RecordTemplateConstant.TEMPLATE_TYPE_SYSTEM));
} }
@PostMapping(value = "/tokenAuth") @PostMapping(value = "/tokenAuth")
......
...@@ -37,13 +37,16 @@ public class RobotSecurityUser implements UserDetails { ...@@ -37,13 +37,16 @@ public class RobotSecurityUser implements UserDetails {
private String password; private String password;
private String tenantId; private String tenantId;
/** /**
* system / custom
*/
private String role;
/**
* *
* 用户与租户区别字段 * 用户与租户区别字段
*/ */
private Integer type; private Integer type;
@JsonIgnore @JsonIgnore
private Collection<? extends GrantedAuthority> authorities; private Collection<? extends GrantedAuthority> authorities;
private RoleTree menus;
private SysPlatformSetting sysPlatformSetting; private SysPlatformSetting sysPlatformSetting;
......
...@@ -6,7 +6,7 @@ import org.springframework.security.core.userdetails.UserDetails; ...@@ -6,7 +6,7 @@ import org.springframework.security.core.userdetails.UserDetails;
* 写这个方法的目的是为了让业务实现层能够根据类型执行对应的业务逻辑 * 写这个方法的目的是为了让业务实现层能够根据类型执行对应的业务逻辑
*/ */
public interface CustomUserDetailsService { public interface CustomUserDetailsService {
UserDetails loadUser(String uid, String tenantId); UserDetails loadUser(String uid, String tenantId, String role);
} }
...@@ -13,7 +13,7 @@ import java.util.List; ...@@ -13,7 +13,7 @@ import java.util.List;
public interface UserService { public interface UserService {
R login(String agentId, String data, String ip); R login(String agentId, String data, String ip);
String auth(UserVo.Auth vo); String auth(UserVo.Auth vo, String role);
List<String> getRoleIdByUserId(String tenantId, String userId, String path); List<String> getRoleIdByUserId(String tenantId, String userId, String path);
......
...@@ -31,7 +31,7 @@ public class DetailsServiceImpl implements CustomUserDetailsService { ...@@ -31,7 +31,7 @@ public class DetailsServiceImpl implements CustomUserDetailsService {
* @throws UsernameNotFoundException 用户不存在 * @throws UsernameNotFoundException 用户不存在
*/ */
@Override @Override
public UserDetails loadUser(String uid, String tenantId) { public UserDetails loadUser(String uid, String tenantId, String role) {
RobotSecurityUser user = new RobotSecurityUser(); RobotSecurityUser user = new RobotSecurityUser();
user.setUserType(UserTypeConstant.SYNC); user.setUserType(UserTypeConstant.SYNC);
String url = userAdminConfig.getUserAdminDomain() + UserAdminRouteConstant.SyncUser.INFO + "?id=" + uid + "&tenantId=" + tenantId; String url = userAdminConfig.getUserAdminDomain() + UserAdminRouteConstant.SyncUser.INFO + "?id=" + uid + "&tenantId=" + tenantId;
...@@ -41,6 +41,7 @@ public class DetailsServiceImpl implements CustomUserDetailsService { ...@@ -41,6 +41,7 @@ public class DetailsServiceImpl implements CustomUserDetailsService {
user.setUsername(data.getString("name")); user.setUsername(data.getString("name"));
user.setNick(data.getString("nickName")); user.setNick(data.getString("nickName"));
user.setTenantId(data.getString("tenantId")); user.setTenantId(data.getString("tenantId"));
user.setRole(role);
return user; return user;
} }
} }
...@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; ...@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cmeeting.ad.entity.*; import com.cmeeting.ad.entity.*;
import com.cmeeting.ad.util.SecurityUtil; import com.cmeeting.ad.util.SecurityUtil;
import com.cmeeting.ad.vo.UserVo; import com.cmeeting.ad.vo.UserVo;
import com.cmeeting.constant.RecordTemplateConstant;
import com.cmeeting.dto.UserDTO; import com.cmeeting.dto.UserDTO;
import com.cmeeting.exception.RobotBaseException; import com.cmeeting.exception.RobotBaseException;
import com.cmeeting.mapper.primary.AuthMapper; import com.cmeeting.mapper.primary.AuthMapper;
...@@ -88,13 +89,14 @@ public class UserServiceImpl implements UserService { ...@@ -88,13 +89,14 @@ public class UserServiceImpl implements UserService {
} }
@Override @Override
public String auth(UserVo.Auth vo) { public String auth(UserVo.Auth vo, String role) {
String userId = vo.getId(); String userId = vo.getId();
String nick = vo.getNick(); String nick = vo.getNick();
HashMap<String, String> stringStringHashMap = new HashMap<>(); HashMap<String, String> stringStringHashMap = new HashMap<>();
SysTenant sysTenant = iTenantService.getById(permissionTenantId); SysTenant sysTenant = iTenantService.getById(permissionTenantId);
stringStringHashMap.put("userId", userId); stringStringHashMap.put("userId", userId);
stringStringHashMap.put("tenantId", permissionTenantId); stringStringHashMap.put("tenantId", permissionTenantId);
stringStringHashMap.put("role", role);
stringStringHashMap.put("language", sysTenant.getLanguage()); stringStringHashMap.put("language", sysTenant.getLanguage());
stringStringHashMap.put("nick", nick); stringStringHashMap.put("nick", nick);
UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = new UsernamePasswordAuthenticationToken(userId, permissionTenantId); UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = new UsernamePasswordAuthenticationToken(userId, permissionTenantId);
...@@ -225,7 +227,7 @@ public class UserServiceImpl implements UserService { ...@@ -225,7 +227,7 @@ public class UserServiceImpl implements UserService {
} }
UserVo.Auth authParams = UserVo.Auth.builder().id(userId).nick(robotSecurityUser.getNickName()).build(); UserVo.Auth authParams = UserVo.Auth.builder().id(userId).nick(robotSecurityUser.getNickName()).build();
String token = auth(authParams); String token = auth(authParams, RecordTemplateConstant.TEMPLATE_TYPE_CUSTOM);
return token; return token;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论