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

View File

@ -2,9 +2,21 @@ package com.xkrs.dao;
import com.xkrs.model.entity.RelRoleAuthorityEntity;
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
*/
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 " +
" 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);
/**
* 根据id批量查询权限信息
* @param id
* @return
*/
List<SysAuthorityEntity> findAllByIdIn(List<Integer> id);
}

View File

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

View File

@ -16,4 +16,8 @@ public interface SysAuthorityService {
* @return
*/
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;
import com.xkrs.dao.RelRoleAuthorityDao;
import com.xkrs.dao.SysAuthorityDao;
import com.xkrs.model.entity.SysAuthorityEntity;
import com.xkrs.service.SysAuthorityService;
@ -22,8 +23,21 @@ public class SysAuthorityServiceImpl implements SysAuthorityService {
@Resource
private SysAuthorityDao sysAuthorityDao;
@Resource
private RelRoleAuthorityDao relRoleAuthorityDao;
@Override
public List<SysAuthorityEntity> getSysAuthorityListByUserName(String 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.setRoleId(sysUserQo.getRoleId());
relRoleAuthorityEntity.setAuthorityId(sysUserQo.getAuthorityId());
relRoleAuthorityEntity.setUserId(sysUserEntity.getId());
relUserRoleDao.save(relUserRoleEntity);
relRoleAuthorityDao.save(relRoleAuthorityEntity);