1、修改了用户登录模块,修改了查询权限角色的功能模块

2、修改了用户注册的模块,修改了添加权限信息时的代码
This commit is contained in:
XinYi Song 2021-12-22 15:46:00 +08:00
parent b0c916c8e8
commit f1a0951150
7 changed files with 53 additions and 4 deletions

View File

@ -86,8 +86,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<SysAuthorityEntity> permissionList = customAuthenticationProvider.sysAuthorityService. List<Integer> integers = customAuthenticationProvider.sysAuthorityService.selectAuthorityByUserId(userEntity.getId());
getSysAuthorityListByUserName(userName); List<SysAuthorityEntity> permissionList = customAuthenticationProvider.sysAuthorityService.findAllByIdIn(integers);
for(SysAuthorityEntity sysAuthorityEntity : permissionList) { for(SysAuthorityEntity sysAuthorityEntity : permissionList) {
permissions.add(new GrantedAuthorityImpl(sysAuthorityEntity.getAuthorityName())); permissions.add(new GrantedAuthorityImpl(sysAuthorityEntity.getAuthorityName()));
} }
@ -97,8 +97,8 @@ public class CustomAuthenticationProvider implements AuthenticationProvider {
}else if(password.equals(userEntity.getPassword())){ }else if(password.equals(userEntity.getPassword())){
// 设置权限列表 // 设置权限列表
ArrayList<GrantedAuthority> permissions = new ArrayList<>(); ArrayList<GrantedAuthority> permissions = new ArrayList<>();
List<SysAuthorityEntity> permissionList = customAuthenticationProvider.sysAuthorityService. List<Integer> integers = customAuthenticationProvider.sysAuthorityService.selectAuthorityByUserId(userEntity.getId());
getSysAuthorityListByUserName(userName); List<SysAuthorityEntity> permissionList = customAuthenticationProvider.sysAuthorityService.findAllByIdIn(integers);
for(SysAuthorityEntity sysAuthorityEntity : permissionList) { for(SysAuthorityEntity sysAuthorityEntity : permissionList) {
permissions.add(new GrantedAuthorityImpl(sysAuthorityEntity.getAuthorityName())); permissions.add(new GrantedAuthorityImpl(sysAuthorityEntity.getAuthorityName()));
} }

View File

@ -2,9 +2,21 @@ package com.xkrs.dao;
import com.xkrs.model.entity.RelRoleAuthorityEntity; import com.xkrs.model.entity.RelRoleAuthorityEntity;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
/** /**
* @author XinYi Song * @author XinYi Song
*/ */
public interface RelRoleAuthorityDao extends JpaRepository<RelRoleAuthorityEntity,Long> { public interface RelRoleAuthorityDao extends JpaRepository<RelRoleAuthorityEntity,Long> {
/**
* 根据userId查询出权限的id
* @param userId
* @return
*/
@Query(value = "select authority_id from rel_role_authority where user_id = ?",nativeQuery = true)
List<Integer> selectAuthorityByUserId(@Param("userId") Integer userId);
} }

View File

@ -22,4 +22,11 @@ public interface SysAuthorityDao extends JpaRepository<SysAuthorityEntity,Intege
"IN (SELECT r.id FROM sys_user u,sys_role r,rel_user_role ur " + "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) " 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批量查询权限信息
* @param id
* @return
*/
List<SysAuthorityEntity> findAllByIdIn(List<Integer> id);
} }

View File

@ -25,6 +25,8 @@ public class RelRoleAuthorityEntity implements Serializable {
@Column(nullable = false) @Column(nullable = false)
private Integer authorityId; private Integer authorityId;
private Integer userId;
public Integer getId() { public Integer getId() {
return id; return id;
} }
@ -49,12 +51,21 @@ public class RelRoleAuthorityEntity implements Serializable {
this.authorityId = authorityId; this.authorityId = authorityId;
} }
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
@Override @Override
public String toString() { public String toString() {
return "RelRoleAuthorityEntity{" + return "RelRoleAuthorityEntity{" +
"id=" + id + "id=" + id +
", roleId=" + roleId + ", roleId=" + roleId +
", authorityId=" + authorityId + ", authorityId=" + authorityId +
", userId=" + userId +
'}'; '}';
} }
} }

View File

@ -16,4 +16,8 @@ public interface SysAuthorityService {
* @return * @return
*/ */
List<SysAuthorityEntity> getSysAuthorityListByUserName(String userName); List<SysAuthorityEntity> getSysAuthorityListByUserName(String userName);
List<SysAuthorityEntity> findAllByIdIn(List<Integer> id);
List<Integer> selectAuthorityByUserId(Integer userId);
} }

View File

@ -1,5 +1,6 @@
package com.xkrs.service.impl; package com.xkrs.service.impl;
import com.xkrs.dao.RelRoleAuthorityDao;
import com.xkrs.dao.SysAuthorityDao; import com.xkrs.dao.SysAuthorityDao;
import com.xkrs.model.entity.SysAuthorityEntity; import com.xkrs.model.entity.SysAuthorityEntity;
import com.xkrs.service.SysAuthorityService; import com.xkrs.service.SysAuthorityService;
@ -22,8 +23,21 @@ public class SysAuthorityServiceImpl implements SysAuthorityService {
@Resource @Resource
private SysAuthorityDao sysAuthorityDao; private SysAuthorityDao sysAuthorityDao;
@Resource
private RelRoleAuthorityDao relRoleAuthorityDao;
@Override @Override
public List<SysAuthorityEntity> getSysAuthorityListByUserName(String userName) { public List<SysAuthorityEntity> getSysAuthorityListByUserName(String userName) {
return sysAuthorityDao.selectByUserName(userName); return sysAuthorityDao.selectByUserName(userName);
} }
@Override
public List<SysAuthorityEntity> findAllByIdIn(List<Integer> id) {
return sysAuthorityDao.findAllByIdIn(id);
}
@Override
public List<Integer> selectAuthorityByUserId(Integer userId) {
return relRoleAuthorityDao.selectAuthorityByUserId(userId);
}
} }

View File

@ -106,6 +106,7 @@ public class SysUserServiceImpl implements SysUserService {
RelRoleAuthorityEntity relRoleAuthorityEntity = new RelRoleAuthorityEntity(); RelRoleAuthorityEntity relRoleAuthorityEntity = new RelRoleAuthorityEntity();
relRoleAuthorityEntity.setRoleId(sysUserQo.getRoleId()); relRoleAuthorityEntity.setRoleId(sysUserQo.getRoleId());
relRoleAuthorityEntity.setAuthorityId(sysUserQo.getAuthorityId()); relRoleAuthorityEntity.setAuthorityId(sysUserQo.getAuthorityId());
relRoleAuthorityEntity.setUserId(sysUserEntity.getId());
relUserRoleDao.save(relUserRoleEntity); relUserRoleDao.save(relUserRoleEntity);
relRoleAuthorityDao.save(relRoleAuthorityEntity); relRoleAuthorityDao.save(relRoleAuthorityEntity);