重构用户角色类
This commit is contained in:
parent
acd127babd
commit
85e6dbf06f
@ -88,8 +88,8 @@ public class CustomAuthenticationProvider implements AuthenticationProvider {
|
|||||||
if (encryptPassword.equals(userEntity.getPassword())) {
|
if (encryptPassword.equals(userEntity.getPassword())) {
|
||||||
// 设置权限列表
|
// 设置权限列表
|
||||||
ArrayList<GrantedAuthority> permissions = new ArrayList<>();
|
ArrayList<GrantedAuthority> permissions = new ArrayList<>();
|
||||||
List<Integer> integers = customAuthenticationProvider.sysAuthorityService.selectAuthorityByUserId(userEntity.getId());
|
List<Long> longs = customAuthenticationProvider.sysAuthorityService.selectAuthorityByUserId(userEntity.getId());
|
||||||
List<SysAuthorityEntity> permissionList = customAuthenticationProvider.sysAuthorityService.findAllByIdIn(integers);
|
List<SysAuthorityEntity> permissionList = customAuthenticationProvider.sysAuthorityService.findAllByIdIn(longs);
|
||||||
for (SysAuthorityEntity sysAuthorityEntity : permissionList) {
|
for (SysAuthorityEntity sysAuthorityEntity : permissionList) {
|
||||||
permissions.add(new GrantedAuthorityImpl(sysAuthorityEntity.getAuthorityName()));
|
permissions.add(new GrantedAuthorityImpl(sysAuthorityEntity.getAuthorityName()));
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ public interface SysAuthorityService {
|
|||||||
*/
|
*/
|
||||||
List<SysAuthorityEntity> getSysAuthorityListByUserName(String userName);
|
List<SysAuthorityEntity> getSysAuthorityListByUserName(String userName);
|
||||||
|
|
||||||
List<SysAuthorityEntity> findAllByIdIn(List<Integer> id);
|
List<SysAuthorityEntity> findAllByIdIn(List<Long> id);
|
||||||
|
|
||||||
List<Integer> selectAuthorityByUserId(Long userId);
|
List<Long> selectAuthorityByUserId(Long userId);
|
||||||
}
|
}
|
||||||
|
@ -29,12 +29,12 @@ public class SysAuthorityServiceImpl implements SysAuthorityService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SysAuthorityEntity> findAllByIdIn(List<Integer> id) {
|
public List<SysAuthorityEntity> findAllByIdIn(List<Long> id) {
|
||||||
return sysAuthorityDao.findAllByIdIn(id);
|
return sysAuthorityDao.findAllByIdIn(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Integer> selectAuthorityByUserId(Long userId) {
|
public List<Long> selectAuthorityByUserId(Long userId) {
|
||||||
return relRoleAuthorityDao.selectAuthorityByUserId(userId);
|
return relRoleAuthorityDao.selectAuthorityByUserId(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,21 +8,12 @@ import org.springframework.data.repository.query.Param;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author XinYi Song
|
|
||||||
*/
|
|
||||||
public interface RelRoleAuthorityDao extends JpaRepository<RelRoleAuthorityEntity, Long>, JpaSpecificationExecutor<RelRoleAuthorityEntity> {
|
public interface RelRoleAuthorityDao extends JpaRepository<RelRoleAuthorityEntity, Long>, JpaSpecificationExecutor<RelRoleAuthorityEntity> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据userId查询出权限的id
|
* 根据userId查询出权限的id
|
||||||
*
|
|
||||||
* @param userId
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
@Query(value = "select authority_id from rel_role_authority where user_id = ?", nativeQuery = true)
|
@Query(value = "select authority_id from rel_role_authority where user_id = ?", nativeQuery = true)
|
||||||
List<Integer> selectAuthorityByUserId(@Param("userId") Long userId);
|
List<Long> selectAuthorityByUserId(@Param("userId") Long userId);
|
||||||
|
|
||||||
@Query(value = "SELECT * FROM rel_role_authority WHERE authority_id = ?1", nativeQuery = true)
|
|
||||||
List<RelRoleAuthorityEntity> selectByAuthorityId(Integer authorityId);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,6 @@ import com.xkrs.straw.model.entity.RelUserRoleEntity;
|
|||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author XinYi Song
|
|
||||||
*/
|
|
||||||
public interface RelUserRoleDao extends JpaRepository<RelUserRoleEntity, Long>, JpaSpecificationExecutor<RelUserRoleEntity> {
|
public interface RelUserRoleDao extends JpaRepository<RelUserRoleEntity, Long>, JpaSpecificationExecutor<RelUserRoleEntity> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,22 +8,16 @@ import org.springframework.data.repository.query.Param;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface SysAuthorityDao extends JpaRepository<SysAuthorityEntity, Integer>, JpaSpecificationExecutor<SysAuthorityEntity> {
|
public interface SysAuthorityDao extends JpaRepository<SysAuthorityEntity, Long>, JpaSpecificationExecutor<SysAuthorityEntity> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询权限实体列表根据用户名 Object[]
|
* 查询权限实体列表根据用户名 Object[]
|
||||||
*
|
|
||||||
* @param userName 用户名
|
|
||||||
* @return 用户实体
|
|
||||||
*/
|
*/
|
||||||
@Query(value = "SELECT a.id, a.authority_name, a.authority_name_zh, a.authority_desc FROM sys_authority a,rel_role_authority ra,sys_role r WHERE r.id = ra.role_id AND ra.authority_id = a.id AND r.id IN (SELECT r.id FROM sys_user u,sys_role r,rel_user_role ur WHERE u.user_name = :userName AND u.id = ur.user_id AND ur.role_id = r.id)", nativeQuery = true)
|
@Query(value = "SELECT a.id, a.authority_name, a.authority_name_zh, a.authority_desc FROM sys_authority a,rel_role_authority ra,sys_role r WHERE r.id = ra.role_id AND ra.authority_id = a.id AND r.id IN (SELECT r.id FROM sys_user u,sys_role r,rel_user_role ur WHERE u.user_name = :userName AND u.id = ur.user_id AND ur.role_id = r.id)", nativeQuery = true)
|
||||||
List<SysAuthorityEntity> selectByUserName(@Param("userName") String userName);
|
List<SysAuthorityEntity> selectByUserName(@Param("userName") String userName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据id批量查询权限信息
|
* 根据id批量查询权限信息
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
List<SysAuthorityEntity> findAllByIdIn(List<Integer> id);
|
List<SysAuthorityEntity> findAllByIdIn(List<Long> id);
|
||||||
}
|
}
|
||||||
|
@ -18,40 +18,40 @@ public class RelRoleAuthorityEntity implements Serializable {
|
|||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "rel_role_authority_seq_gen")
|
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "rel_role_authority_seq_gen")
|
||||||
@SequenceGenerator(name = "rel_role_authority_seq_gen", sequenceName = "rel_role_authority_id_seq", allocationSize = 1)
|
@SequenceGenerator(name = "rel_role_authority_seq_gen", sequenceName = "rel_role_authority_id_seq", allocationSize = 1)
|
||||||
private Integer id;
|
private Long id;
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private Integer roleId;
|
private Long roleId;
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private Integer authorityId;
|
private Long authorityId;
|
||||||
|
|
||||||
private Long userId;
|
private Long userId;
|
||||||
|
|
||||||
public RelRoleAuthorityEntity() {
|
public RelRoleAuthorityEntity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(Integer id) {
|
public void setId(Long id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getRoleId() {
|
public Long getRoleId() {
|
||||||
return roleId;
|
return roleId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRoleId(Integer roleId) {
|
public void setRoleId(Long roleId) {
|
||||||
this.roleId = roleId;
|
this.roleId = roleId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getAuthorityId() {
|
public Long getAuthorityId() {
|
||||||
return authorityId;
|
return authorityId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAuthorityId(Integer authorityId) {
|
public void setAuthorityId(Long authorityId) {
|
||||||
this.authorityId = authorityId;
|
this.authorityId = authorityId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,6 +65,11 @@ public class RelRoleAuthorityEntity implements Serializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "RelRoleAuthorityEntity{" + "id=" + id + ", roleId=" + roleId + ", authorityId=" + authorityId + ", userId=" + userId + '}';
|
return "RelRoleAuthorityEntity{" +
|
||||||
|
"id=" + id +
|
||||||
|
", roleId=" + roleId +
|
||||||
|
", authorityId=" + authorityId +
|
||||||
|
", userId=" + userId +
|
||||||
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,6 @@ package com.xkrs.straw.model.entity;
|
|||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
|
||||||
* RelUserRole 表实体类
|
|
||||||
*
|
|
||||||
* @author tajochen
|
|
||||||
*/
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "rel_user_role")
|
@Table(name = "rel_user_role")
|
||||||
public class RelUserRoleEntity implements Serializable {
|
public class RelUserRoleEntity implements Serializable {
|
||||||
@ -18,19 +13,22 @@ public class RelUserRoleEntity implements Serializable {
|
|||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "rel_user_role_seq_gen")
|
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "rel_user_role_seq_gen")
|
||||||
@SequenceGenerator(name = "rel_user_role_seq_gen", sequenceName = "rel_user_role_id_seq", allocationSize = 1)
|
@SequenceGenerator(name = "rel_user_role_seq_gen", sequenceName = "rel_user_role_id_seq", allocationSize = 1)
|
||||||
private Integer id;
|
private Long id;
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private Long userId;
|
private Long userId;
|
||||||
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private Integer roleId;
|
private Long roleId;
|
||||||
|
|
||||||
public Integer getId() {
|
public RelUserRoleEntity() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(Integer id) {
|
public void setId(Long id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,16 +40,20 @@ public class RelUserRoleEntity implements Serializable {
|
|||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getRoleId() {
|
public Long getRoleId() {
|
||||||
return roleId;
|
return roleId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRoleId(Integer roleId) {
|
public void setRoleId(Long roleId) {
|
||||||
this.roleId = roleId;
|
this.roleId = roleId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "RelUserRoleEntity{" + "id=" + id + ", userId=" + userId + ", roleId=" + roleId + '}';
|
return "RelUserRoleEntity{" +
|
||||||
|
"id=" + id +
|
||||||
|
", userId=" + userId +
|
||||||
|
", roleId=" + roleId +
|
||||||
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,6 @@ package com.xkrs.straw.model.entity;
|
|||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
|
||||||
* SysAuthority 表实体类
|
|
||||||
*
|
|
||||||
* @author tajochen
|
|
||||||
*/
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "sys_authority")
|
@Table(name = "sys_authority")
|
||||||
public class SysAuthorityEntity implements Serializable {
|
public class SysAuthorityEntity implements Serializable {
|
||||||
@ -18,7 +13,7 @@ public class SysAuthorityEntity implements Serializable {
|
|||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sys_authority_seq_gen")
|
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sys_authority_seq_gen")
|
||||||
@SequenceGenerator(name = "sys_authority_seq_gen", sequenceName = "sys_authority_id_seq", allocationSize = 1)
|
@SequenceGenerator(name = "sys_authority_seq_gen", sequenceName = "sys_authority_id_seq", allocationSize = 1)
|
||||||
private Integer id;
|
private Long id;
|
||||||
|
|
||||||
@Column(length = 64, nullable = false, unique = true, columnDefinition = "varchar(64)")
|
@Column(length = 64, nullable = false, unique = true, columnDefinition = "varchar(64)")
|
||||||
private String authorityName;
|
private String authorityName;
|
||||||
@ -29,11 +24,14 @@ public class SysAuthorityEntity implements Serializable {
|
|||||||
@Column(length = 128, columnDefinition = "varchar(128)")
|
@Column(length = 128, columnDefinition = "varchar(128)")
|
||||||
private String authorityDesc;
|
private String authorityDesc;
|
||||||
|
|
||||||
public Integer getId() {
|
public SysAuthorityEntity() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(Integer id) {
|
public void setId(Long id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +40,7 @@ public class SysAuthorityEntity implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setAuthorityName(String authorityName) {
|
public void setAuthorityName(String authorityName) {
|
||||||
this.authorityName = authorityName == null ? null : authorityName.trim();
|
this.authorityName = authorityName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAuthorityNameZh() {
|
public String getAuthorityNameZh() {
|
||||||
@ -50,7 +48,7 @@ public class SysAuthorityEntity implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setAuthorityNameZh(String authorityNameZh) {
|
public void setAuthorityNameZh(String authorityNameZh) {
|
||||||
this.authorityNameZh = authorityNameZh == null ? null : authorityNameZh.trim();
|
this.authorityNameZh = authorityNameZh;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAuthorityDesc() {
|
public String getAuthorityDesc() {
|
||||||
@ -58,11 +56,16 @@ public class SysAuthorityEntity implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setAuthorityDesc(String authorityDesc) {
|
public void setAuthorityDesc(String authorityDesc) {
|
||||||
this.authorityDesc = authorityDesc == null ? null : authorityDesc.trim();
|
this.authorityDesc = authorityDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "SysAuthorityEntity{" + "id=" + id + ", authorityName='" + authorityName + '\'' + ", authorityDesc='" + authorityDesc + '\'' + ", authorityNameZh='" + authorityNameZh + '\'' + '}';
|
return "SysAuthorityEntity{" +
|
||||||
|
"id=" + id +
|
||||||
|
", authorityName='" + authorityName + '\'' +
|
||||||
|
", authorityNameZh='" + authorityNameZh + '\'' +
|
||||||
|
", authorityDesc='" + authorityDesc + '\'' +
|
||||||
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user