浏览代码

新增APP用户Shiro模块

master
鲲鹏 4 年前
父节点
当前提交
46721ed021
共有 23 个文件被更改,包括 350 次插入10 次删除
  1. +2
    -0
      log.path_IS_UNDEFINED/log_info.log
  2. +21
    -0
      src/main/java/com/taauav/api/controller/AppAdminController.java
  3. +150
    -0
      src/main/java/com/taauav/api/entity/AppAdmin.java
  4. +16
    -0
      src/main/java/com/taauav/api/mapper/AppAdminMapper.java
  5. +5
    -0
      src/main/java/com/taauav/api/mapper/AppAdminMapper.xml
  6. +24
    -0
      src/main/java/com/taauav/api/service/IAppAdminService.java
  7. +46
    -0
      src/main/java/com/taauav/api/service/impl/AppAdminServiceImpl.java
  8. +2
    -5
      src/main/java/com/taauav/api/service/impl/InspectLogsServiceImpl.java
  9. +2
    -3
      src/main/java/com/taauav/api/service/impl/InspectQuestionServiceImpl.java
  10. +4
    -2
      src/main/java/com/taauav/api/service/impl/LoginServiceImpl.java
  11. +27
    -0
      src/main/java/com/taauav/api/utils/LoginUtils.java
  12. +15
    -0
      src/main/java/com/taauav/common/config/AppUserToken.java
  13. +32
    -0
      src/main/java/com/taauav/common/config/MyShiroRealm.java
  14. +4
    -0
      src/main/java/com/taauav/common/util/ShiroUtils.java
  15. 二进制
      upload/425e5e925aaa43fda531d8eb18e0c0c5_1.png
  16. 二进制
      upload/425e5e925aaa43fda531d8eb18e0c0c5_2.png
  17. 二进制
      upload/8cb636165b0848e7800a6a8de8a64acf_1.png
  18. 二进制
      upload/8cb636165b0848e7800a6a8de8a64acf_2.png
  19. 二进制
      upload/beddc08f2ebf4d04b36ff7996da2c3d4_1.png
  20. 二进制
      upload/beddc08f2ebf4d04b36ff7996da2c3d4_2.png
  21. 二进制
      upload/file/file/2020819/425e5e925aaa43fda531d8eb18e0c0c5.png
  22. 二进制
      upload/file/file/2020819/8cb636165b0848e7800a6a8de8a64acf.png
  23. 二进制
      upload/file/file/2020819/beddc08f2ebf4d04b36ff7996da2c3d4.png

+ 2
- 0
log.path_IS_UNDEFINED/log_info.log 查看文件

@@ -4,3 +4,5 @@
2020-08-18 10:46:34.098 [SessionValidationThread-1] INFO o.a.s.s.m.AbstractValidatingSessionManager - [validateSessions,308] - Finished session validation. No sessions were stopped.
2020-08-18 10:50:37.500 [SpringContextShutdownHook] INFO o.s.s.c.ThreadPoolTaskScheduler - [shutdown,208] - Shutting down ExecutorService 'taskScheduler'
2020-08-18 10:50:37.809 [SpringContextShutdownHook] INFO c.a.d.p.DruidDataSource - [close,1825] - {dataSource-1} closed
2020-08-18 15:05:11.530 [SpringContextShutdownHook] INFO o.s.s.c.ThreadPoolTaskScheduler - [shutdown,208] - Shutting down ExecutorService 'taskScheduler'
2020-08-18 15:05:11.785 [SpringContextShutdownHook] INFO c.a.d.p.DruidDataSource - [close,1825] - {dataSource-1} closed

+ 21
- 0
src/main/java/com/taauav/api/controller/AppAdminController.java 查看文件

@@ -0,0 +1,21 @@
package com.taauav.api.controller;


import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.taauav.api.controller.ApiBaseController;

/**
* <p>
* 外包人员表 前端控制器
* </p>
*
* @author zongjl
* @since 2020-08-18
*/
@RestController
@RequestMapping("/app-admin")
public class AppAdminController extends ApiBaseController {

}

+ 150
- 0
src/main/java/com/taauav/api/entity/AppAdmin.java 查看文件

@@ -0,0 +1,150 @@
package com.taauav.api.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.taauav.common.domain.Entity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotEmpty;
import java.math.BigInteger;
import java.util.Date;

/**
* <p>
* 外包人员表
* </p>
*
* @author 鲲鹏
* @since 2020-05-14
*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("user_admin")
public class AppAdmin extends Entity {

private static final long serialVersionUID = 1L;

/**
* 编号
*/
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
/**
* 姓名
*/
@NotEmpty(message = "姓名不能为空")
@Length(min = 2, max = 10, message = "姓名长度为2-10")
private String realname;

/**
* 用户名
*/
@NotEmpty(message = "用户名不能为空")
@Length(min = 2, max = 20, message = "用户名长度为2-20个字符")
private String username;

/**
* 密码
*/
private String password;

/**
* 管理员拥有的规则id, 多个规则","隔开'
*/
private String rules;

/**
* 公司
*/
private String company;

/**
* 部门ID
*/
private Integer depId;

/**
* 头像
*/
private String avatar;

/**
* 性别:1男 2女 3保密
*/
private Integer gender;

/**
* 联系方式(手机号码)
*/
private String mobile;

/**
* 邮箱
*/
private String email;

/**
* 河长等级:1一级 2二级 3三级
*/
private Integer level;

/**
* 区划ID
*/
private BigInteger driverArea;

/**
* 职务
*/
private String duty;

/**
* 角色编号
*/
private String authGroup;

/**
* 备注
*/
private String note;

/**
* 最近登录时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date lastTime;

/**
* 登录次数
*/
private Integer loginNum;

/**
* 上次登录IP
*/
private Long lastIp;

/**
* 排序
*/
private Integer sort;

/**
* 角色描述
*/
@TableField(exist = false)
private String authGroupText;

/**
* 状态描述
*/
@TableField(exist = false)
private String statusText;


}

+ 16
- 0
src/main/java/com/taauav/api/mapper/AppAdminMapper.java 查看文件

@@ -0,0 +1,16 @@
package com.taauav.api.mapper;

import com.taauav.api.entity.AppAdmin;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
* <p>
* 外包人员表 Mapper 接口
* </p>
*
* @author zongjl
* @since 2020-08-18
*/
public interface AppAdminMapper extends BaseMapper<AppAdmin> {

}

+ 5
- 0
src/main/java/com/taauav/api/mapper/AppAdminMapper.xml 查看文件

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.taauav.api.mapper.AppAdminMapper">

</mapper>

+ 24
- 0
src/main/java/com/taauav/api/service/IAppAdminService.java 查看文件

@@ -0,0 +1,24 @@
package com.taauav.api.service;

import com.taauav.api.entity.AppAdmin;
import com.baomidou.mybatisplus.extension.service.IService;

/**
* <p>
* 外包人员表 服务类
* </p>
*
* @author zongjl
* @since 2020-08-18
*/
public interface IAppAdminService extends IService<AppAdmin> {

/**
* 根据用户获取数据
*
* @param username
* @return
*/
AppAdmin findByUsername(String username);

}

+ 46
- 0
src/main/java/com/taauav/api/service/impl/AppAdminServiceImpl.java 查看文件

@@ -0,0 +1,46 @@
package com.taauav.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.taauav.api.entity.AppAdmin;
import com.taauav.api.mapper.AppAdminMapper;
import com.taauav.api.service.IAppAdminService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.taauav.front.entity.UserAdmin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
* <p>
* 外包人员表 服务实现类
* </p>
*
* @author zongjl
* @since 2020-08-18
*/
@Service
public class AppAdminServiceImpl extends ServiceImpl<AppAdminMapper, AppAdmin> implements IAppAdminService {

@Autowired
private AppAdminMapper appAdminMapper;
@Value("${server.IMAGE_URL}")
private String imageUrl;

/**
* 获取用户信息
*
* @param username 用户名
* @return
*/
@Override
public AppAdmin findByUsername(String username) {
QueryWrapper wrapper = new QueryWrapper();
wrapper.eq("username", username);
wrapper.eq("mark", 1);
AppAdmin admin = appAdminMapper.selectOne(wrapper);
if (admin != null && !"".equals(admin.getAvatar())) {
admin.setAvatar(imageUrl + admin.getAvatar());
}
return admin;
}
}

+ 2
- 5
src/main/java/com/taauav/api/service/impl/InspectLogsServiceImpl.java 查看文件

@@ -8,10 +8,7 @@ import com.taauav.api.mapper.InspectLogsMapper;
import com.taauav.api.service.IInspectLogsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.taauav.common.bean.Response;
import com.taauav.common.util.DateUtil;
import com.taauav.common.util.FileUtil;
import com.taauav.common.util.ImageUtil;
import com.taauav.common.util.StringUtils;
import com.taauav.common.util.*;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -102,7 +99,7 @@ public class InspectLogsServiceImpl extends ServiceImpl<InspectLogsMapper, TauvI
entity.setQuestionId(inspectLogsDto.getQuestionId());
entity.setInspectResult(inspectLogsDto.getInspectResult());
entity.setInspectImage(filePath);
entity.setCreateUser(1);
entity.setCreateUser(ShiroUtils.getAdminId());
entity.setCreateTime(DateUtil.now());
Integer result = inspectLogsMapper.insert(entity);
if (result == 0) {

+ 2
- 3
src/main/java/com/taauav/api/service/impl/InspectQuestionServiceImpl.java 查看文件

@@ -1,6 +1,5 @@
package com.taauav.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -185,7 +184,7 @@ public class InspectQuestionServiceImpl extends ServiceImpl<InspectQuestionMappe
String filePath = destNewFileUrl.replace(uploadFolder, "");
inspectFile.setSrc(filePath);
inspectFile.setOriginalImg(filePath);
inspectFile.setCreateUser(1);
inspectFile.setCreateUser(ShiroUtils.getAdminId());
inspectFile.setCreateTime(DateUtil.now());
inspectFile.setThumbImg(thumbImg);
Integer result = inspectFileMapper.insert(inspectFile);
@@ -200,7 +199,7 @@ public class InspectQuestionServiceImpl extends ServiceImpl<InspectQuestionMappe
inspectQuestion.setQuestionId(inspectQuestionDto.getQuestionId());
inspectQuestion.setQuestionNo(createQuestionNo());
inspectQuestion.setNote(inspectQuestionDto.getQuestionNote());
inspectQuestion.setCreateUser(1);
inspectQuestion.setCreateUser(ShiroUtils.getAdminId());
inspectQuestion.setCreateTime(DateUtil.now());
Integer result2 = inspectQuestionMapper.insert(inspectQuestion);
if (result2 == 0) {

+ 4
- 2
src/main/java/com/taauav/api/service/impl/LoginServiceImpl.java 查看文件

@@ -2,9 +2,11 @@ package com.taauav.api.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.taauav.api.dto.LoginDto;
import com.taauav.api.entity.AppAdmin;
import com.taauav.api.service.ILoginService;
import com.taauav.common.bean.CacheUser;
import com.taauav.common.bean.Response;
import com.taauav.common.config.AppUserToken;
import com.taauav.common.config.FrontUserToken;
import com.taauav.common.util.StringUtils;
import com.taauav.front.entity.UserAdmin;
@@ -51,14 +53,14 @@ public class LoginServiceImpl extends ServiceImpl<UserAdminMapper, UserAdmin> im
Subject currentUser = SecurityUtils.getSubject();

// 将用户名和密码封装到UsernamePasswordToken
UsernamePasswordToken token = new FrontUserToken(loginDto.getUsername(), loginDto.getPassword());
UsernamePasswordToken token = new AppUserToken(loginDto.getUsername(), loginDto.getPassword());
CacheUser cacheUser;
// 4、认证
try {
// 传到 MyShiroRealm 类中的方法进行认证
currentUser.login(token);
// 构建缓存用户信息返回给前端
UserAdmin user = (UserAdmin) currentUser.getPrincipals().getPrimaryPrincipal();
AppAdmin user = (AppAdmin) currentUser.getPrincipals().getPrimaryPrincipal();
cacheUser = CacheUser.builder()
.token(currentUser.getSession().getId().toString())
.build();

+ 27
- 0
src/main/java/com/taauav/api/utils/LoginUtils.java 查看文件

@@ -0,0 +1,27 @@
package com.taauav.api.utils;

import com.taauav.common.util.JwtUtil;
import com.taauav.common.util.StringUtils;
import com.taauav.front.utils.ServletUtils;
import io.jsonwebtoken.Claims;

/**
* 封路信息工具类
*/
public class LoginUtils {

/**
* 获取登录用户ID
*
* @return
*/
public static Integer getAdminId() {
String token = ServletUtils.getRequest().getHeader("token");
Claims data = JwtUtil.parseJWT(token);
if (!StringUtils.isEmpty(data.get("id").toString())) {
return Integer.valueOf(data.get("id").toString());
}
return 0;
}

}

+ 15
- 0
src/main/java/com/taauav/common/config/AppUserToken.java 查看文件

@@ -0,0 +1,15 @@
package com.taauav.common.config;

import org.apache.shiro.authc.UsernamePasswordToken;

/**
* 前台用户token
* @author dyg
*/
public class AppUserToken extends UsernamePasswordToken {

public AppUserToken(String username, String password)
{
super(username, password);
}
}

+ 32
- 0
src/main/java/com/taauav/common/config/MyShiroRealm.java 查看文件

@@ -4,6 +4,8 @@ import com.taauav.admin.entity.SysAdmin;
import com.taauav.admin.entity.SysAuthRule;
import com.taauav.admin.service.ISysAdminService;
import com.taauav.admin.service.ISysAuthRuleService;
import com.taauav.api.entity.AppAdmin;
import com.taauav.api.service.IAppAdminService;
import com.taauav.common.domain.Entity;
import com.taauav.common.util.ShiroUtils;
import com.taauav.front.entity.UserAdmin;
@@ -37,6 +39,8 @@ public class MyShiroRealm extends AuthorizingRealm {
private ISysAdminService iSysAdminService;
@Autowired
private IUserAdminService userAdminService;
@Autowired
private IAppAdminService appAdminService;
@Resource
private ISysAuthRuleService iSysAuthRuleService;
@Resource
@@ -90,6 +94,9 @@ public class MyShiroRealm extends AuthorizingRealm {
}
}
return authorizationInfo;
} else if (principals.getPrimaryPrincipal() instanceof AppAdmin) {
// APP 用户
authorizationInfo.addStringPermission("*:*:*");
}
return null;
}
@@ -154,6 +161,31 @@ public class MyShiroRealm extends AuthorizingRealm {
// realm name
getName()
);
} else if (authenticationToken instanceof AppUserToken) {
// APP用户认证
UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken;
//获取用户的输入的账号.
String userName = (String) token.getPrincipal();
//通过username从数据库中查找 User对象.
//实际项目中,这里可以根据实际情况做缓存,如果不做,Shiro自己也是有时间间隔机制,2分钟内不会重复执行该方法
AppAdmin user = appAdminService.findByUsername(userName);
if (Objects.isNull(user)) {
throw new UnknownAccountException("用户名或密码错误");
}
String status = "1";
if (!(status.equals(user.getStatus().toString()))) {
throw new UnknownAccountException("账号已被锁定,请联系管理员!");
}
return new SimpleAuthenticationInfo(
// 这里传入的是user对象,比对的是用户名,直接传入用户名也没错,但是在授权部分就需要自己重新从数据库里取权限
user,
// 密码
user.getPassword(),
// salt = username + salt
ByteSource.Util.bytes(""),
// realm name
getName()
);
} else {
throw new UnknownAccountException("用户名或密码错误");
}

+ 4
- 0
src/main/java/com/taauav/common/util/ShiroUtils.java 查看文件

@@ -1,6 +1,7 @@
package com.taauav.common.util;
import com.taauav.admin.entity.SysAdmin;
import com.taauav.api.entity.AppAdmin;
import com.taauav.common.domain.Entity;
import com.taauav.front.entity.UserAdmin;
import lombok.extern.slf4j.Slf4j;
@@ -57,6 +58,9 @@ public class ShiroUtils {
} else if (object instanceof UserAdmin) {
UserAdmin admin = (UserAdmin) SecurityUtils.getSubject().getPrincipal();
adminId = admin.getId();
} else if (object instanceof AppAdmin) {
AppAdmin admin = (AppAdmin) SecurityUtils.getSubject().getPrincipal();
adminId = admin.getId();
}
return adminId;
}

二进制
upload/425e5e925aaa43fda531d8eb18e0c0c5_1.png 查看文件

之前 之后
宽度: 100  |  高度: 100  |  大小: 2.1KB

二进制
upload/425e5e925aaa43fda531d8eb18e0c0c5_2.png 查看文件

之前 之后
宽度: 650  |  高度: 365  |  大小: 6.2KB

二进制
upload/8cb636165b0848e7800a6a8de8a64acf_1.png 查看文件

之前 之后
宽度: 100  |  高度: 100  |  大小: 2.1KB

二进制
upload/8cb636165b0848e7800a6a8de8a64acf_2.png 查看文件

之前 之后
宽度: 650  |  高度: 365  |  大小: 6.2KB

二进制
upload/beddc08f2ebf4d04b36ff7996da2c3d4_1.png 查看文件

之前 之后
宽度: 100  |  高度: 100  |  大小: 2.1KB

二进制
upload/beddc08f2ebf4d04b36ff7996da2c3d4_2.png 查看文件

之前 之后
宽度: 650  |  高度: 365  |  大小: 6.2KB

二进制
upload/file/file/2020819/425e5e925aaa43fda531d8eb18e0c0c5.png 查看文件

之前 之后
宽度: 128  |  高度: 128  |  大小: 5.4KB

二进制
upload/file/file/2020819/8cb636165b0848e7800a6a8de8a64acf.png 查看文件

之前 之后
宽度: 128  |  高度: 128  |  大小: 5.4KB

二进制
upload/file/file/2020819/beddc08f2ebf4d04b36ff7996da2c3d4.png 查看文件

之前 之后
宽度: 128  |  高度: 128  |  大小: 5.4KB

正在加载...
取消
保存