Initial commit
This commit is contained in:
@@ -2,7 +2,7 @@ package com.atguigu.auth.controller;
|
||||
|
||||
import com.atguigu.auth.service.SysMenuService;
|
||||
import com.atguigu.auth.service.SysUserService;
|
||||
import com.atguigu.common.execption.GuiguException;
|
||||
import com.atguigu.common.config.execption.GuiguException;
|
||||
import com.atguigu.common.jwt.JwtHelper;
|
||||
import com.atguigu.common.result.Result;
|
||||
import com.atguigu.common.utils.MD5;
|
||||
|
@@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -63,11 +64,11 @@ public class SysRoleController {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation("查询所有角色")
|
||||
@GetMapping("findAll")
|
||||
public Result findAll() {
|
||||
return Result.ok(sysRoleService.list());
|
||||
}
|
||||
// @ApiOperation("查询所有角色")
|
||||
// @GetMapping("findAll")
|
||||
// public Result findAll() {
|
||||
// return Result.ok(sysRoleService.list());
|
||||
// }
|
||||
|
||||
/**
|
||||
* 条件分页查询
|
||||
@@ -76,6 +77,7 @@ public class SysRoleController {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("hasAuthority('bnt.sysRole.list')")
|
||||
@ApiOperation("条件分页查询")
|
||||
@GetMapping("{page}/{limit}")
|
||||
public Result pageQueryRole(@PathVariable Long page,
|
||||
@@ -105,6 +107,7 @@ public class SysRoleController {
|
||||
* @param role
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("hasAuthority('bnt.sysRole.add')")
|
||||
@ApiOperation("添加角色")
|
||||
@PostMapping("save")
|
||||
public Result save(@RequestBody SysRole role) {
|
||||
@@ -123,6 +126,7 @@ public class SysRoleController {
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("hasAuthority('bnt.sysRole.list')")
|
||||
@ApiOperation("根据id查询")
|
||||
@GetMapping("get/{id}")
|
||||
public Result get(@PathVariable Long id) {
|
||||
@@ -136,6 +140,7 @@ public class SysRoleController {
|
||||
* @param role
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("hasAuthority('bnt.sysRole.update')")
|
||||
@ApiOperation("修改角色")
|
||||
@PutMapping("update")
|
||||
public Result update(@RequestBody SysRole role) {
|
||||
@@ -154,6 +159,7 @@ public class SysRoleController {
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("hasAuthority('bnt.sysRole.remove')")
|
||||
@ApiOperation("根据id删除")
|
||||
@DeleteMapping("remove/{id}")
|
||||
public Result remove(@PathVariable Long id) {
|
||||
@@ -172,6 +178,7 @@ public class SysRoleController {
|
||||
* @param idList
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("hasAuthority('bnt.sysRole.remove')")
|
||||
@ApiOperation("批量删除")
|
||||
@DeleteMapping("batchRemove")
|
||||
public Result batchRemove(@RequestBody List<Long> idList) {
|
||||
|
@@ -4,7 +4,7 @@ import com.atguigu.auth.mapper.SysMenuMapper;
|
||||
import com.atguigu.auth.service.SysMenuService;
|
||||
import com.atguigu.auth.service.SysRoleMenuService;
|
||||
import com.atguigu.auth.utils.MenuHelper;
|
||||
import com.atguigu.common.execption.GuiguException;
|
||||
import com.atguigu.common.config.execption.GuiguException;
|
||||
import com.atguigu.model.system.SysMenu;
|
||||
import com.atguigu.model.system.SysRoleMenu;
|
||||
import com.atguigu.vo.system.AssginMenuVo;
|
||||
|
@@ -1,15 +1,18 @@
|
||||
package com.atguigu.auth.service.impl;
|
||||
|
||||
import com.atguigu.auth.service.SysMenuService;
|
||||
import com.atguigu.auth.service.SysUserService;
|
||||
import com.atguigu.model.system.SysUser;
|
||||
import com.atguigu.security.custom.CustomUser;
|
||||
import com.atguigu.security.custom.UserDetailsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ClassName: UserDetailsServiceImpl
|
||||
@@ -24,16 +27,26 @@ public class UserDetailsServiceImpl implements UserDetailsService {
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
|
||||
@Autowired
|
||||
private SysMenuService sysMenuService;
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
SysUser sysUser = sysUserService.getByUsername(username);
|
||||
if(null == sysUser) {
|
||||
if (null == sysUser) {
|
||||
throw new UsernameNotFoundException("用户名不存在!");
|
||||
}
|
||||
|
||||
if(sysUser.getStatus() == 0) {
|
||||
if (sysUser.getStatus() == 0) {
|
||||
throw new RuntimeException("账号已停用");
|
||||
}
|
||||
return new CustomUser(sysUser, Collections.emptyList());
|
||||
//根据用户id查询用户操作权限
|
||||
List<String> userPermsList = sysMenuService.findUserPermsByUserId(sysUser.getId());
|
||||
//创建List集合,封装权限数据
|
||||
ArrayList<SimpleGrantedAuthority> authList = new ArrayList<>();
|
||||
for (String perm : userPermsList) {
|
||||
authList.add(new SimpleGrantedAuthority(perm.trim()));
|
||||
}
|
||||
return new CustomUser(sysUser, authList);
|
||||
}
|
||||
}
|
||||
|
@@ -16,3 +16,15 @@ spring:
|
||||
jackson:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
time-zone: GMT+8
|
||||
redis:
|
||||
host: localhost
|
||||
port: 6379
|
||||
database: 0
|
||||
timeout: 1800000
|
||||
password:
|
||||
jedis:
|
||||
pool:
|
||||
max-active: 20 #最大连接数
|
||||
max-wait: -1 #最大阻塞等待时间(负数表示没限制)
|
||||
max-idle: 5 #最大空闲
|
||||
min-idle: 0 #最小空闲
|
||||
|
Reference in New Issue
Block a user