新增当前用户角色列表
This commit is contained in:
parent
3181b8b632
commit
53ca1699fa
@ -45,12 +45,13 @@ public class ClientUserAuthConverter implements UserAuthenticationConverter {
|
|||||||
Object principal = map.get("user_name");
|
Object principal = map.get("user_name");
|
||||||
if (!Objects.isNull(principal)) {
|
if (!Objects.isNull(principal)) {
|
||||||
Collection<GrantedAuthority> authorities;
|
Collection<GrantedAuthority> authorities;
|
||||||
if("admin".equals(principal.toString())) {
|
List<RoleBO> roles = new ArrayList<>();
|
||||||
|
if ("admin".equals(principal.toString())) {
|
||||||
authorities = new LinkedHashSet<>();
|
authorities = new LinkedHashSet<>();
|
||||||
authorities.add(new RoleGrantedAuthority("ROLE_ALL"));
|
authorities.add(new RoleGrantedAuthority("ROLE_ALL"));
|
||||||
authorities.add(new RoleGrantedAuthority("ROLE_GROUP_ALL"));
|
authorities.add(new RoleGrantedAuthority("ROLE_GROUP_ALL"));
|
||||||
} else {
|
} else {
|
||||||
authorities = getAuthorities(map);
|
authorities = getAuthorities(roles, map);
|
||||||
}
|
}
|
||||||
// 包含用户信息,则直接抽取其中的用户信息
|
// 包含用户信息,则直接抽取其中的用户信息
|
||||||
Map<String, Object> userInfo = (Map<String, Object>) map.get("user_info");
|
Map<String, Object> userInfo = (Map<String, Object>) map.get("user_info");
|
||||||
@ -59,6 +60,7 @@ public class ClientUserAuthConverter implements UserAuthenticationConverter {
|
|||||||
userInfoBO.setUserUsername(userInfo.get("username").toString());
|
userInfoBO.setUserUsername(userInfo.get("username").toString());
|
||||||
userInfoBO.setUserName(userInfo.get("userName").toString());
|
userInfoBO.setUserName(userInfo.get("userName").toString());
|
||||||
userInfoBO.setUserPhone(userInfo.get("userPhone") == null ? "" : userInfo.get("userPhone").toString());
|
userInfoBO.setUserPhone(userInfo.get("userPhone") == null ? "" : userInfo.get("userPhone").toString());
|
||||||
|
userInfoBO.setRoles(roles);
|
||||||
principal = userInfoBO;
|
principal = userInfoBO;
|
||||||
LOG.debug("获取用户权限");
|
LOG.debug("获取用户权限");
|
||||||
return new UsernamePasswordAuthenticationToken(principal, "N/A", authorities);
|
return new UsernamePasswordAuthenticationToken(principal, "N/A", authorities);
|
||||||
@ -67,13 +69,13 @@ public class ClientUserAuthConverter implements UserAuthenticationConverter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Collection<GrantedAuthority> getAuthorities(Map<String, ?> map) {
|
private Collection<GrantedAuthority> getAuthorities(List<RoleBO> roles, Map<String, ?> map) {
|
||||||
Collection authorities = (Collection) map.get("authorities");
|
Collection authorities = (Collection) map.get("authorities");
|
||||||
if(authorities.isEmpty()) {
|
if (authorities.isEmpty()) {
|
||||||
authorities = new LinkedHashSet();
|
authorities = new LinkedHashSet();
|
||||||
authorities.add(new RoleGrantedAuthority("ROLE_ALL"));
|
authorities.add(new RoleGrantedAuthority("ROLE_ALL"));
|
||||||
authorities.add(new RoleGrantedAuthority("ROLE_GROUP_ALL"));
|
authorities.add(new RoleGrantedAuthority("ROLE_GROUP_ALL"));
|
||||||
return authorities;
|
return authorities;
|
||||||
}
|
}
|
||||||
Map<String, Object> params = new HashMap<>(1);
|
Map<String, Object> params = new HashMap<>(1);
|
||||||
params.put(IApiConsts.ACCESS_TOKEN, ClientTokenManager.getInstance().getClientToken().getAccessToken());
|
params.put(IApiConsts.ACCESS_TOKEN, ClientTokenManager.getInstance().getClientToken().getAccessToken());
|
||||||
@ -88,6 +90,7 @@ public class ClientUserAuthConverter implements UserAuthenticationConverter {
|
|||||||
RoleBO roleBO = resultObj.toJavaObject(RoleBO.class);
|
RoleBO roleBO = resultObj.toJavaObject(RoleBO.class);
|
||||||
RoleGrantedAuthority roleGrantedAuthority = new RoleGrantedAuthority(roleBO.getRoleId(), roleBO);
|
RoleGrantedAuthority roleGrantedAuthority = new RoleGrantedAuthority(roleBO.getRoleId(), roleBO);
|
||||||
roleGrantedAuthoritySet.add(roleGrantedAuthority);
|
roleGrantedAuthoritySet.add(roleGrantedAuthority);
|
||||||
|
roles.add(roleBO);
|
||||||
}
|
}
|
||||||
return roleGrantedAuthoritySet;
|
return roleGrantedAuthoritySet;
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import org.springframework.stereotype.Component;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName: SecurityCompontent
|
* @ClassName: SecurityCompontent
|
||||||
@ -48,9 +49,11 @@ public class SecurityComponent {
|
|||||||
userInfoBO.setDataAuthority(userBO.getDataAuthority());
|
userInfoBO.setDataAuthority(userBO.getDataAuthority());
|
||||||
userInfoBO.setDataAuthorityUserIds(userBO.getDataAuthorityUserIds());
|
userInfoBO.setDataAuthorityUserIds(userBO.getDataAuthorityUserIds());
|
||||||
userInfoBO.setBaseDepartmentIds(userBO.getBaseDepartmentIds());
|
userInfoBO.setBaseDepartmentIds(userBO.getBaseDepartmentIds());
|
||||||
|
userInfoBO.setRoles(userBO.getRoles());
|
||||||
}
|
}
|
||||||
if (user instanceof UserInfoBO) {
|
if (user instanceof UserInfoBO) {
|
||||||
userInfoBO = (UserInfoBO) user;
|
userInfoBO = (UserInfoBO) user;
|
||||||
|
|
||||||
}
|
}
|
||||||
return userInfoBO;
|
return userInfoBO;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.cm.common.pojo.bos;
|
package com.cm.common.pojo.bos;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -19,6 +20,7 @@ public class UserInfoBO {
|
|||||||
private List<String> dataAuthorityUserIds;
|
private List<String> dataAuthorityUserIds;
|
||||||
private List<String> baseDepartmentIds;
|
private List<String> baseDepartmentIds;
|
||||||
private List<DepartmentBO> departments;
|
private List<DepartmentBO> departments;
|
||||||
|
private List<RoleBO> roles;
|
||||||
|
|
||||||
public String getUserId() {
|
public String getUserId() {
|
||||||
return userId == null ? "" : userId.trim();
|
return userId == null ? "" : userId.trim();
|
||||||
@ -84,25 +86,38 @@ public class UserInfoBO {
|
|||||||
this.departments = departments;
|
this.departments = departments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<RoleBO> getRoles() {
|
||||||
|
if (roles == null) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoles(List<RoleBO> roles) {
|
||||||
|
this.roles = roles;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuilder sb = new StringBuilder("{");
|
final StringBuilder sb = new StringBuilder("{");
|
||||||
sb.append("\"userId\":")
|
sb.append("\"userId\":\"")
|
||||||
.append("\"").append(userId).append("\"");
|
.append(userId).append('\"');
|
||||||
sb.append(",\"userUsername\":")
|
sb.append(",\"userUsername\":\"")
|
||||||
.append("\"").append(userUsername).append("\"");
|
.append(userUsername).append('\"');
|
||||||
sb.append(",\"userName\":")
|
sb.append(",\"userName\":\"")
|
||||||
.append("\"").append(userName).append("\"");
|
.append(userName).append('\"');
|
||||||
sb.append(",\"userPhone\":")
|
sb.append(",\"userPhone\":\"")
|
||||||
.append("\"").append(userPhone).append("\"");
|
.append(userPhone).append('\"');
|
||||||
sb.append(",\"dataAuthority\":")
|
sb.append(",\"dataAuthority\":\"")
|
||||||
.append("\"").append(dataAuthority).append("\"");
|
.append(dataAuthority).append('\"');
|
||||||
sb.append(",\"dataAuthorityUserIds\":")
|
sb.append(",\"dataAuthorityUserIds\":")
|
||||||
.append(dataAuthorityUserIds);
|
.append(dataAuthorityUserIds);
|
||||||
sb.append(",\"baseDepartmentIds\":")
|
sb.append(",\"baseDepartmentIds\":")
|
||||||
.append(baseDepartmentIds);
|
.append(baseDepartmentIds);
|
||||||
sb.append(",\"departments\":")
|
sb.append(",\"departments\":")
|
||||||
.append(departments);
|
.append(departments);
|
||||||
|
sb.append(",\"roles\":")
|
||||||
|
.append(roles);
|
||||||
sb.append('}');
|
sb.append('}');
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user