IntelliJ+SpringBoot项目实战(十六)--在SpringBoot中整合SpringSecurity和JWT(下A)
五、开发登录认证需要的实体类
在上文中介绍了MD5、BCrypt和AES 三种密码加密方式。本文继续介绍SpringSecurity+JWT 整合,篇幅会比较长。现在我们先开发登录认证需要的实体类CommUser,此实体类需要实现SpringSecurity的UserDetails接口(在openjweb-core模块的org.openjweb.core.entity下创建CommUser实体类,此实体类同时也对应数据库表comm_user):
package org.openjweb.core.entity;
import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import java.util.Collection;
@Slf4j
@Data
@TableName("comm_user")
public class CommUser implements UserDetails {
/******* 非数据库属性开始 ******/
private final Collection<? extends GrantedAuthority> authorities;
private final boolean accountNonExpired;//账号是否过期
private final boolean accountNonLocked;//账号是否锁定
private final boolean credentialsNonExpired;//凭证是否过期
private final boolean enabled;//是否启用
/******* 非数据库属性结束 ******/
@TableId(type = IdType.ASSIGN_UUID)
private Long userId; //数字唯一主键
private String rowId;//32位唯一ID(因为项目中有所以保留32位UUID)
/* 登录必须属性开始 */
private String loginId;//业务系统登录账号,以后等同username
private final String username;//以后等同于loginId
private String password;//加密后的密码
/* 业务必填字段 */
private String comId; //所属公司ID
private String deptId; //所属部门
private String pwdType;//密码类型 MD5,AES,SM,BCR 默认为MD5
private String empNo; //员工工号
private String userEmail;//邮箱(如没有可随机一个)
private String userMobile;//手机(如没有可随机一个)
private String realName; //真实姓名
private String registMobile;//注册时填写的手机名称
/*重要字段*/
private String isInUse; //账号是否启用,未启动则不能登录
private String psnPhotoPath = "";//头像图片路径+文件名
private String isMobileValid;//是否手机认证通过
private String wxOpenId;//绑定的微信OpenID,以后放扩展表
/*时间戳 修改人 乐观锁等 */
private Long sortNo;//排序号
@TableField(fill = FieldFill.INSERT)
private String createDt;
@TableField(fill = FieldFill.INSERT_UPDATE)
private String updateDt;
@TableField(fill = FieldFill.INSERT)
private String createUid;
@TableField(fill = FieldFill.INSERT_UPDATE)
private String updateUid;
@Version
private Long recordVersion = 0L;//乐观锁
public CommUser(Long userId, String loginId, String password, Collection<? extends GrantedAuthority> authorities) {
this(userId, loginId, password, true, true, true, true, authorities);
}
public CommUser(Long userId, String loginId, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities) {
Assert.isTrue(loginId != null && !"".equals(loginId) && password != null, "Cannot pass null or empty values to constructor");
this.userId = userId;
this.username = loginId;
this.loginId = loginId;
this.password = password;
this.enabled = enabled;
this.accountNonExpired = accountNonExpired;
this.credentialsNonExpired = credentialsNonExpired;
this.accountNonLocked = accountNonLocked;
this.authorities = authorities;
}
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return this.authorities;
}
@Override
public String getPassword() {
return this.password;
}
@Override
public String getUsername() {
return this.loginId;
}
@Override
public boolean isAccountNonExpired() {
return this.accountNonExpired;
}
@Override
public boolean isAccountNonLocked() {
return this.accountNonLocked;
}
@Override
public boolean isCredentialsNonExpired() {
return this.credentialsNonExpired;
}
@Override
public boolean isEnabled() {
return this.enabled;
}
}
五、开发查询用户需要的Service和Mapper类
根据前面介绍的Mybatis-plus,我们现在开发用于查询用户的Service和Mapper类,先在openjweb-core的org.openjweb.core.mapper下开发一个Mapper接口类CommUserMapper.java:
package org.openjweb.core.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.openjweb.core.entity.CommUser;
import java.util.List;
@Mapper
public interface CommUserMapper extends BaseMapper<CommUser> {
//@Select("SELECT * FROM comm_user WHERE login_id = #{loginId}")
@Select("SELECT user_id,login_id,row_id,username,password,com_id,dept_id,pwd_type," +
"emp_no,user_email,user_mobile,real_name,regist_mobile,is_in_use ," +
"psn_photo_path,is_mobile_valid,wx_open_id,sort_no, create_dt,update_dt," +
"create_uid,update_uid FROM comm_user WHERE login_id = #{loginId}")
CommUser selectUserByLoginId(@Param("loginId") String loginId);
@Select("SELECT comm_code FROM v_user_auth WHERE login_id = #{loginId} order by comm_code ")
List<String> selectAuthorities(@Param("loginId") String loginId);
}
暂时先实现两个方法,以后再补充新的方法,为了简化起见,不使用Mapper.xml,直接使用@Select注解。第一个方式是根据登录账号查唯一用户,注意注解Select中的SQL,字段的数量是与CommUser中一个构造函数是参数匹配的,为此我们还需要在CommUser.java中完善一下,就是再增加一个构造函数,不然后面mybatis-plus会提示找不到对应的构造函数:
public CommUser(Long userId,String loginId,String rowId,String username,String password,
String comId,String deptId,String pwdType,String empNo,String userEmail,
String userMobile,String realName,String registMobile,String isInUse,String psnPhotoPath,
String isMobileValid,String wxOpenId,Long sortNo,String createDt,
String updateDt,String createUid,String updateUid){
this.userId = userId;
this.username = username;
this.rowId = rowId;
this.loginId = loginId;
this.password = password;
this.comId = comId;
this.deptId = deptId;
this.pwdType = pwdType;
this.empNo = empNo;
this.userEmail = userEmail;
this.userMobile = userMobile;
this.realName = realName;
this.registMobile = registMobile;
this.isInUse = isInUse;
this.enabled = "Y".equals(isInUse)?true:false;//
this.psnPhotoPath = psnPhotoPath;
this.isMobileValid = isMobileValid;
this.wxOpenId = wxOpenId;
this.sortNo = sortNo;
this.createDt = createDt;
this.updateDt = updateDt;
this.createUid = createUid;
this.updateUid = updateUid;//
//账号未过期需要增加一个判断,可以通过lastLoginDt与
this.accountNonExpired = this.enabled;//accountNonExpired;
this.credentialsNonExpired = false;//最好动态判断
this.accountNonLocked = enabled;
this.authorities = getAuthorities() ;//这里先设置下,否则提示authorities需要初始化
}
第二个方法是根据登录账号查询权限集合,是从v_user_auth这个视图中的comm_code字段获取权限。关于这个视图后面会介绍,我们先讲完代码开发。
然后在org.openjweb.core.service下创建一个CommUserService,并实现SpringSecurity的UserDetailService接口:
package org.openjweb.core.service;
import lombok.extern.slf4j.Slf4j;
import org.openjweb.core.entity.CommUser;
import org.openjweb.core.mapper.CommUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
@Slf4j
public class CommUserService implements UserDetailsService {
@Autowired
private CommUserMapper userMapper;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
CommUser user = this.userMapper.selectUserByLoginId(username);
//返回的时候如果不需要那么多信息可以重构一个对象
CommUser userDetail = null;
userDetail = new CommUser(user.getUserId(),user.getLoginId(),user.getPassword(),getUserAuthority(user.getLoginId()));
return userDetail;
}
/**
* 获取用户权限信息(角色、菜单权限)
* @param loginId
* @return
*/
public List<GrantedAuthority> getUserAuthority(String loginId) {
// 实际怎么写以数据表结构为准,这里只是写个例子
// 角色(比如ROLE_admin),菜单操作权限(比如sys:user:list)
List<String> authList = this.userMapper.selectAuthorities(loginId);
String auths = "";
if(authList!=null&&authList.size()>0){
auths = String.join(",",authList);
}
log.info("权限列表:"+auths);
return AuthorityUtils.commaSeparatedStringToAuthorityList(auths);
}
public List<String> getAuth(String loginId){
return this.userMapper.selectAuthorities(loginId);
}
}
在这个service中,loadUserByUsername是根据登录账号,通过userMapper.selectUserByLoginId查询用户,然后再返回通过构造函数,仅返回SpringSecurity必须的字段(返回所有也可以,因为CommUser是实现了UserDetails接口)。而getuserAuthority则是通过userMapper.selectAuthorities获取用户的所有的权限集合。
另外getAuth()方法是为了在API测试接口中检验userMapper调用是否正常。在org.openjweb.core.api下实现一个测试接口用于测试:
package org.openjweb.core.api;
import org.openjweb.core.entity.CommUser;
import org.openjweb.core.service.CommUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RequestMapping("/api/comm/auth")
@RestController
public class CommUserDemoApi {
//测试地址:localhost:8001/api/comm/auth/test?loginId=admin
@Autowired
CommUserService userService;
@RequestMapping("test")
public String testauth(String loginId){
List<String> authList = null;
String auth = "";
try {
authList = userService.getAuth(loginId);
auth = String.join(",",authList);
}
catch(Exception ex){
ex.printStackTrace();
}
return auth;
}
}
按照代码里的测试地址,测试后返回界面:
说明CommUserMapper.java的权限查询是正常的。
六、配置PasswordEncoder
在上一节讲到了几个PasswordEncoder,分别是MD5,BCrypt和AES。因为项目开发用的是AES,所以我们将AES配置到WebSecurityConfig中。我们先做些简单的改造,在上节中,AES使用的key和MD5的salt取的同一配置,但是AES的key是有特定格式的。所以需要分开设置,首先将AESPasswordEncoder的salt变量的注解改为@Value("${aes.key}"),然后在application-dev.yml中增加配置:
aes:
key: /Z3E1YW1mxM0BCluJdYaLHCnhTuzE8j0
然后我们再打开WebSecurityConfig.java,修改下代码:
@Autowired
MD5PasswordEncoder md5PasswordEncoder;
@Autowired
AESPasswordEncoder aesPasswordEncoder;
@Autowired
CommUserService userDetailService;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//auth.userDetailsService(userDetailService);
auth.userDetailsService(userDetailService).passwordEncoder(aesPasswordEncoder);
//auth.userDetailsService(userDetailService).passwordEncoder(new BCryptPasswordEncoder());
}
上节中使用的auth.userDetailsService(userDetailService),这里我们加上.passwordEncoder(aesPasswordEncoder),就是匹配一个aesPasswordEncoder,当然也可以匹配md5PasswordEncoder或BCryptPasswordEncoder()。
现在我们重启openjweb-sys的应用,启动后,我们看控制台,此时SpringSecurity不再自动生成登录密码了。此时我们先访问http://localhost:8001检查下登录:
输入数据库中有的用户账号和密码(comm_user表),测试账号admin 密码Hello0214@,不过现在大家还没有实际建表,稍后我把测试表和测试数据贴出来。如果密码输入错误,界面仍停留在当前页面,并有错误提示(Bad Credential),登录成功后,显示下面的页面:
这个页面是我们前面帖子里改造的页面,在resources/templates/index.html,以后有时间还需要改造下。当登录成功后,控制台会显示权限列表(CommUserService的log.info(" 权限列表:"),这里就不截屏了)。
到现在我们解决了SpringSecurity密码登录和获取权限列表的问题。接下来我们还要需要通过读取的权限列表来控制对应的URL访问权限。v_user_auth的每条记录除了COMM_CODE标识了权限编码,另外还有个字段auth_resource是URL,也就是说访问资源。下面我们先把数据库表和测试数据贴出来,以便后续的讲解。
七、数据库表及权限视图
openjweb平台中的comm_user字段比较多,而且有些关联外键,这里做下简化,去掉外键:
CREATE TABLE `comm_user` (
`user_id` bigint(20) NOT NULL,
`login_id` varchar(60) NOT NULL,
`emp_no` varchar(40) DEFAULT NULL,
`username` varchar(80) NOT NULL,
`password` varchar(80) NOT NULL,
`user_email` varchar(60) DEFAULT NULL,
`user_tel` varchar(30) DEFAULT NULL,
`user_mobile` varchar(40) NOT NULL,
`user_title` varchar(20) DEFAULT NULL,
`user_type` varchar(16) DEFAULT NULL,
`is_acct_non_expired` char(1) DEFAULT NULL,
`is_acct_non_locked` char(1) DEFAULT NULL,
`is_pwd_non_expired` char(1) DEFAULT NULL,
`is_in_use` char(1) DEFAULT NULL,
`row_id` varchar(40) NOT NULL,
`create_dt` varchar(23) DEFAULT NULL,
`update_dt` varchar(23) DEFAULT NULL,
`create_uid` varchar(40) DEFAULT NULL,
`update_uid` varchar(40) DEFAULT NULL,
`sort_no` bigint(20) DEFAULT NULL,
`com_id` varchar(40) NOT NULL,
`dept_id` varchar(40) DEFAULT NULL,
`com_name` varchar(100) DEFAULT NULL,
`real_name` varchar(255) DEFAULT NULL,
`position_name` varchar(150) DEFAULT NULL,
`msn_email` varchar(100) DEFAULT NULL,
`qq_no` varchar(20) DEFAULT NULL,
`is_portal_member` varchar(10) DEFAULT NULL,
`vip_start_dt` varchar(8) DEFAULT NULL,
`vip_end_dt` varchar(8) DEFAULT NULL,
`work_place` varchar(100) DEFAULT NULL,
`id_card` varchar(18) DEFAULT NULL,
`birth_day` varchar(100) DEFAULT NULL,
`user_sex` varchar(10) DEFAULT NULL,
`province_id` varchar(20) DEFAULT NULL,
`city_id` varchar(20) DEFAULT NULL,
`county_id` varchar(20) DEFAULT NULL,
`pwd_quest1` varchar(10) DEFAULT NULL,
`pwd_answer1` varchar(60) DEFAULT NULL,
`pwd_quest2` varchar(10) DEFAULT NULL,
`pwd_answer2` varchar(60) DEFAULT NULL,
`pwd_quest3` varchar(10) DEFAULT NULL,
`pwd_answer3` varchar(60) DEFAULT NULL,
`regist_ip` varchar(80) DEFAULT NULL,
`is_marry` varchar(10) DEFAULT NULL,
`indust_id` varchar(40) DEFAULT NULL,
`psn_photo_path` varchar(250) DEFAULT NULL,
`last_login_dt` varchar(23) DEFAULT NULL,
`md5_token` varchar(80) DEFAULT NULL,
`work_type` varchar(40) DEFAULT NULL,
`user_degree` varchar(40) DEFAULT NULL,
`zip_code` varchar(6) DEFAULT NULL,
`contact_addr` varchar(200) DEFAULT NULL,
`work_status` varchar(40) DEFAULT NULL,
`join_dt` varchar(23) DEFAULT NULL,
`curr_frame_code` varchar(10) DEFAULT NULL,
`curr_skin_code` varchar(40) DEFAULT NULL,
`theme_color` varchar(20) DEFAULT NULL,
`app_id` varchar(10) DEFAULT NULL,
`regist_com_name` varchar(300) DEFAULT NULL,
`regist_position` varchar(60) DEFAULT NULL,
`regist_mobile` varchar(20) DEFAULT NULL,
`zhou_id` varchar(10) DEFAULT NULL,
`cash_balance_amt` decimal(10,2) DEFAULT NULL,
`user_class` varchar(20) DEFAULT NULL,
`pk_id` varchar(40) DEFAULT NULL,
`live_addr` varchar(100) DEFAULT NULL,
`active_code` varchar(40) DEFAULT NULL,
`pay_pwd` varchar(80) DEFAULT NULL,
`is_mobile_valid` varchar(10) DEFAULT NULL,
`tel_ext` varchar(10) DEFAULT NULL,
`cc_group_code` varchar(6) DEFAULT NULL,
`allow_send_sms` varchar(10) DEFAULT NULL,
`test_mobile` varchar(100) DEFAULT NULL,
`test_email` varchar(100) DEFAULT NULL,
`is_email_valid` varchar(10) DEFAULT NULL,
`sub_com_id` varchar(40) DEFAULT NULL,
`reset_pwd` varchar(80) DEFAULT NULL,
`recommend_login_id` varchar(40) DEFAULT NULL,
`relation_type` varchar(10) DEFAULT NULL,
`first_channel_code` varchar(20) DEFAULT NULL,
`second_channel_code` varchar(10) DEFAULT NULL,
`nick_name` varchar(255) DEFAULT NULL,
`pinyin_code` varchar(100) DEFAULT NULL,
`domain_name` varchar(30) DEFAULT NULL,
`dynamic_url` varchar(200) DEFAULT NULL,
`static_url` varchar(200) DEFAULT NULL,
`qrcode_url` varchar(200) DEFAULT NULL,
`pro_style` varchar(60) DEFAULT NULL,
`real_com` varchar(40) DEFAULT NULL,
`sign_msg` varchar(255) DEFAULT NULL,
`rcmd_store_id` varchar(40) DEFAULT NULL,
`user_intro` varchar(300) DEFAULT NULL,
`nation_id` varchar(40) DEFAULT NULL,
`mobile_type` varchar(10) DEFAULT NULL,
`device_token` varchar(80) DEFAULT NULL,
`com_regist_capital` decimal(10,2) DEFAULT NULL,
`com_psn_count` bigint(20) DEFAULT NULL,
`com_year_sale_amt` decimal(13,2) DEFAULT NULL,
`is_com_member` varchar(10) DEFAULT NULL,
`mem_name` varchar(40) DEFAULT NULL,
`mem_start_dt` varchar(23) DEFAULT NULL,
`mem_end_dt` varchar(23) DEFAULT NULL,
`user_county_text` varchar(300) DEFAULT NULL,
`weixin_no` varchar(60) DEFAULT NULL,
`hist_pwd` varchar(900) DEFAULT NULL,
`pwd_update_dt` varchar(23) DEFAULT NULL,
`login_fail_count` bigint(20) DEFAULT NULL,
`last_fail_login_dt` varchar(23) DEFAULT NULL,
`alipay_no` varchar(80) DEFAULT NULL,
`alipay_name` varchar(80) DEFAULT NULL,
`block_chain_account` varchar(100) DEFAULT NULL,
`pri_key` varchar(255) DEFAULT NULL,
`id_image1` varchar(400) DEFAULT NULL,
`id_image2` varchar(400) DEFAULT NULL,
`is_valid_idcard` varchar(10) DEFAULT NULL,
`org_row_id` varchar(40) DEFAULT NULL,
`st_code` varchar(40) DEFAULT NULL,
`wx_open_id` varchar(80) DEFAULT NULL,
`init_pwd` varchar(40) DEFAULT NULL,
`msg_open_id` varchar(40) DEFAULT NULL,
`pwd_type` varchar(20) DEFAULT NULL,
`is_rand_skin` varchar(10) DEFAULT NULL,
PRIMARY KEY (`user_id`),
UNIQUE KEY `login_id` (`login_id`),
UNIQUE KEY `user_mobile` (`user_mobile`),
UNIQUE KEY `username` (`username`),
UNIQUE KEY `com_id` (`com_id`,`emp_no`),
UNIQUE KEY `user_email` (`user_email`),
KEY `idx_1730778572530000934` (`com_id`,`emp_no`),
KEY `idx_1730778572531000935` (`login_id`),
KEY `idx_1730778572531000936` (`user_email`),
KEY `idx_1730778572531000937` (`user_mobile`),
KEY `idx_1730778572532000938` (`username`),
KEY `idx_1730778572532000939` (`user_id`,`is_in_use`),
KEY `idx_1730778572533000940` (`login_id`,`is_in_use`),
KEY `idx_1730778572533000941` (`is_in_use`),
KEY `idx_1730778572534000942` (`dept_id`),
KEY `idx_1730778572534000943` (`is_in_use`,`dept_id`),
KEY `idx_1730778572535000944` (`user_id`,`com_id`,`is_in_use`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of comm_user
-- ----------------------------
INSERT INTO `comm_user` VALUES ('1', 'admin', 'admin', 'admin', 'A30AE30E32E678702B2967FAAA1B3E5B', 'aaa@qq.com', '432432432', '18600010001', null, null, null, null, null, 'Y', 'f7d6872cfa32415894d70a41d04066ed', '2009-03-09 12:06:25', '2024-01-12 14:06:44', 'admin', 'admin', '24', 'C0001', '29205', '本单位', '王保政', null, 'baozhengw@163.com,succ100@163.com', '29803446', null, null, null, '山东', null, '1971-10-04', 'F', '210000', '210600', '210624', '00', null, null, null, null, null, '0:0:0:0:0:0:0:1/0:0:0:0:0:0:0:1', 'Y', null, '/portal/upload/2024/04/24/57bdac0e280643338ae29a3ed1c749ba.jpg', '2024-11-05 11:45:40', null, null, null, null, '18600510596,13389710231', null, null, '06', 'skyThird', 'blue', ', , ,', null, null, '18600010001', null, null, null, '1', 'dsddsds', '861b70918e7942c68339dd341188bb9f', '25d55ad283aa400af464c76d713c07ad', 'N', null, null, 'Y', '18600510596,13389710231', 'baozhengw@163.com,succ100@163.com', 'Y', null, null, 'abao', '99', null, null, '超级管理员', 'abao', 'admin', 'http://www.openjweb.com/', 'http://admin.openjweb.com', null, null, null, '测试保存的备注', null, null, null, null, null, null, null, null, null, null, null, null, null, null, '6D9A2FAFBF4DADA9911213C662141C0A,6D432DEADF9B0E0765DD154B55AC3D0F,ACAFE307D6A1CE2A7205960F89ECD660,0748D35AEFCE465BB8ABA95B6DB1508E,7C08A224A54C61B671ECED8BE1DE9E86,961B6B9F044D4B12B5FAAE9CF0C58FEB,40ad44398de69db9709175bcafd2bc41,1d5a23ba2f9e35c87e1a5ba62a5d1ed9,e194c3daeab8e15a9b90f1a517725186,a2157d56ff005bb363182ce2aa998dc0,015a035abb3aa8ef0870c0b8e256a8b6,5b98597c2f341fa51bbfb9444fad4028,de9d848def0448cb065f2cb3289d5915,dbc92dfad8f93fd24e484ab9a17ccab3,DB95BBAD51C7D7D985CA2186B5D01036,21592453206BFD1CDB62FBAD49E6141F,0963B34FAFAF57AB0ED39F5B02168A53,3288688156DA4D44335B9E6B09199AD9,B9B23901BD54C7E196698AD658D20F71,0963B34FAFAF57AB0ED39F5B02168A53,5CB0444A6F799544E469E52007045225,A05E6C8E246E32F80D48178EADA4CC4C,cd7c8b9743792ec75df42c89fd2527d9,c47338cb87799abb3244fdeb51877cd6,9648a6ac0aecbe256f6e6d7e2d1719e9,c920033a5d33f90b58670982ef33043a,260b187d8573d8595f47b56e20894aac', '2024-10-21 09:56:12', '0', '2024-09-20 11:47:53', null, null, null, null, null, null, null, null, null, null, null, null, 'AES', null);
v_user_auth是个权限视图,这个权限视图比较复杂,是结合单位表,角色表,人员表,角色人员关系表,角色权限关系表等关联的视图,所以为了简单起见,我们针对v_user_auth创建一个测试的表叫demo_user_auth,然后把数据导进去 :
CREATE TABLE `demo_user_auth` (
`user_id` bigint(20) NOT NULL COMMENT '用户ID',
`login_id` varchar(80) DEFAULT NULL COMMENT '登录账号',
`auth_id` bigint(20) DEFAULT NULL COMMENT '权限ID',
`comm_code` varchar(80) DEFAULT NULL COMMENT '权限编码',
`auth_name` varchar(100) DEFAULT NULL COMMENT '权限名称',
`auth_resource` varchar(500) DEFAULT NULL COMMENT '资源URL',
`pic_file` varchar(255) DEFAULT NULL COMMENT '图片文件',
`sort_no` bigint(20) DEFAULT NULL COMMENT '顺序号',
`menu_url` varchar(500) DEFAULT NULL COMMENT '菜单URL',
`meu_sort_no` bigint(20) DEFAULT NULL COMMENT '菜单序号',
`layui_name` varchar(100) DEFAULT NULL COMMENT 'LAYUI菜单名',
`layui_jump` varchar(255) DEFAULT NULL COMMENT 'LAYUI跳转URL',
`is_layui` varchar(10) DEFAULT NULL COMMENT '是否LAYUI菜单',
KEY `idx_auth_view1` (`login_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of demo_user_auth
-- ----------------------------
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1330762709843001436', 'CRM_MENU45', 'SNS社区', '#', null, '999', '#', '999', null, null, 'N');
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1329708816625003018', 'CRM_MENU252102', '静态页生成配置', '/portal/listPortalConvertHtml*.action*', null, '20', '/portal/listPortalConvertHtml.action', '20', null, null, 'N');
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1687567698067001269', 'CRM_MENU3205', '系统管理', '#', 'layui-icon-set', '2', '#', '2', null, null, 'Y');
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1308314', 'CRM_MENU013402', '行业编码维护', '/comm/CommIndustryTree*.action*', null, '20', '/comm/CommIndustryTree.action?operate=showFrame', '20', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1679020246303000791', 'CRM_MENU014816', '公司信息编辑', '#', null, '11', '#', '11', 'ComEdit', null, 'N');
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1140365', 'CRM_MENU0904', '修改文章统计', '/comm/listCommReport!viewReport.action?repId=02', null, '40', '/comm/listCommReport!viewReport.action?repId=02', '40', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1531981412963002567', 'AUTH_BTN_CANCEL_RCMD', '取消新闻推荐', '#', null, '100', '#', '100', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1395898773515002755', 'CRM_MENU4902', '微信服务号菜单管理', '/weixin/listWeixinServiceMenu*.action*', null, '100', '/weixin/listWeixinServiceMenu.action ', '100', 'layweixinservicemenu', 'weixin/servicemenu/list', 'Y');
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1387116482042009039', 'CRM_MENU12140115', '库存明细查询', '/erp/listInvStockPro.action', null, '100', '/erp/listInvStockPro.action', '100', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1348149887398008768', 'AUTH_HR_FOLDER2', '暂存夹设置', '#', null, '20', '#', '20', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1331982116375001495', 'CRM_MENU1507', '短信帐户管理', '/sms/listSmsEntAccount*.action*', null, '100', '/sms/listSmsEntAccount.action', '100', 'Smsentaccount', 'sms/entaccount/list', 'Y');
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1329709154093003079', 'CRM_MENU252202', '网站流量统计', '/portal/listPortalVisitCounter*.action*', null, '20', '/portal/listPortalVisitCounter.action', '20', null, null, 'N');
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1687567875056002768', 'CRM_MENU320501', '数据字典', 'CommDictApi', null, '10', '#', '10', 'commdictjixiao', 'comm/dict/list', 'Y');
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1310693', 'CRM_MENU251702', '专家分类', '/comm/CommSpecialistClsTree*.action*', null, '20', '/comm/CommSpecialistClsTree.action?operate=showFrame', '20', null, null, 'N');
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1679021786586003827', 'CRM_MENU3858', '结算管理', '#', null, '11', '#', '11', 'B2cSettle', null, 'N');
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1303230', 'CRM_MENU28', '快速开发', '#', 'layui-icon-component', '10', '#', '21', 'Fastdev', null, 'Y');
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1545786087791004302', 'CRM_MENU3845', '电子秤PLU设置', '/b2c/listB2cPluSet.action*', null, '100', '/b2c/listB2cPluSet.action', '100', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1387201465821002801', 'CRM_MENU12140306', '销售出库', '/erp/listErpSaleCkHead.action', null, '100', '/erp/listErpSaleCkHead.action', '100', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1348150031339008794', 'AUTH_HR_ORG_SET2', '公司管理', '#', null, '20', '#', '20', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1332637180203001498', 'CRM_MENU0907', '信息访问日志', '/cms/listCmsVisitLog*.action*', null, '100', '/cms/listCmsVisitLog.action', '100', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1329973183609001367', 'CRM_MENU081901', '流程状态位定义', '/wf/listWfStatusDef.action', null, '10', '/wf/listWfStatusDef.action', '10', null, null, 'N');
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1371368', 'CRM_MENU200702', '收件箱', '/mail/listMailRecvBox*.action*', null, '20', '/mail/listMailRecvBox.action?selMail=&mailFlag=1', '20', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1681012324519000803', 'CRM_MENU9902', '我的系统', '#', null, '5', '#', '5', 'UserSysManager', null, 'N');
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1303293', 'CRM_MENU280102', '表字段定义', '/comm/listCommColumnDef*.action*', null, '30', '/comm/listCommColumnDef.action?operate=selectPageList', '30', 'commcolumndef', 'comm/columndef/list', 'Y');
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1555406269501004307', 'CRM_MENU011903', '异常日志管理', '/comm/listCommExceptionLog*.action*', null, '100', '/comm/listCommExceptionLog.action', '100', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1515120741603007089', 'CRM_MENU384301', '卡券模板管理(微信)', '/b2c/listB2cMemCardTempl*.action*', null, '100', '/b2c/listB2cMemCardTempl.action', '100', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1348150847758008822', 'AUTH_HR_REP4', '简历购买统计', '#', null, '40', '#', '40', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1330221498562002271', 'AUTH_PUB_GG', '站内公告发布权限', '/cms/listCmsInfo.action?cateTreeCode=001001', null, '11', '#', '11', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1452197', 'AUTH_TRIP_APPLY1', '项目经理审核', '#', null, '100', '#', '100', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1306115', 'CRM_MENU280304', '主明细表关系', '/comm/listCommMasterDetailRel*.action*', '/apps/skin/blue/icons/OAimg25.gif', '40', '/comm/listCommMasterDetailRel.action', '40', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1517441100959003004', 'CRM_MENU090901', '信息访问IP(PV) 时段统计', '/comm/listCommReport!myReport.action?repId=34', null, '100', '/comm/listCommReport!myReport.action?repId=34', '100', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1496805190934003110', 'CRM_MENU380415', '店铺日销售流水查询(按完成订单)', '/comm/listCommReport!myReport.action?*repId=31* ', null, '100', '/comm/listCommReport!myReport.action?repId=31', '100', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1348151040439008850', 'AUTH_HR_REP8', '所在城市统计', '#', null, '40', '#', '40', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1686483093857000860', 'CRM_MENU9906', '操作手册模板', '#', null, '1', '#', '1', 'MyWordTemplateList', null, 'N');
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1306182', 'CRM_MENU280308', '报表定义', '/comm/listCommReportDef*.action*', null, '80', '/comm/listCommReportDef.action', '80', 'reportdef', 'comm/reportdef/list', 'Y');
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1518167761927004977', 'CRM_MENU090903', '网站每日访问量统计', '/comm/listCommReport!myReport.action?repId=37', null, '100', '/comm/listCommReport!myReport.action?repId=37', '100', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1386736918631002693', 'CRM_MENU121308', '采购到货验收', '/erp/listPurRecvCheckHead.action', null, '100', '/erp/listPurRecvCheckHead.action', '100', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1348402291343002508', 'AUTH_HR_RESUME_PUR', '购买简历数', '/hr/listHrResumeDealDetail.action', null, '100', '/hr/listHrResumeDealDetail.action', '100', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1112842', 'AUTH_BTN_EXP_CMSINFO', '导出所有信息', '#', null, '100', '#', '100', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1328949409156001774', 'AUTH_SUPER_ADMIN', '超级管理员权限', '#', null, '11', '#', '11', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1452216047284003009', 'CRM_MENU383109', '销售大区管理', '/b2c/B2cAreaTree*.action?operate=showFrame', null, '100', '/b2c/B2cAreaTree.action?operate=showFrame', '100', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1379563796488004353', 'CRM_MENU3822', '规格值编码管理', '/b2c/listB2cProPropDict*.action*', null, '100', '/b2c/listB2cProPropDict.action', '100', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1348147915121007029', 'AUTH_HR_POS_LIST', '职位列表', '#', null, '20', '#', '20', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1342079652373002272', 'CRM_MENU252406', '充值卡卡号库管理', '/b2c/listB2cRechargeCard*.action*', null, '100', '/b2c/listB2cRechargeCard.action', '100', null, null, 'N');
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1637048607141001507', 'CRM_MENU3852', '会员实时分账', '#', null, '1010', '#', '1010', 'memrealprofit', 'forms/b2c/reprealtime_profit/list/repId=realtime_profit', 'Y');
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1468998674616003115', 'CRM_MENU383812', '个人佣金月汇总(报税)', '/b2c/listB2cCommissionSum*.action*', null, '100', '/b2c/listB2cCommissionSum.action', '100', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1452663289305003030', 'AUTH_MENU383110', '店铺收银管理', '/b2c/listB2cStoreCashier*.action*', null, '100', '/b2c/listB2cStoreCashier.action', '100', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1381667427066002645', 'CRM_MENU3823', '销售订单收款管理', '/b2c/listB2cOrderPay*.action*', null, '100', '/b2c/listB2cOrderPay.action ', '100', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1348148082473007054', 'AUTH_HR_FILTER', '过滤的简历', '#', null, '30', '#', '30', null, null, null);
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1719383826188001518', 'CRM_MENU102101', '外宣品订单', '/b2c/listB2cOrderHeadZd1111*.action*', null, '112', '/b2c/listB2cOrderHeadZd1111.action', '112', null, null, 'N');
INSERT INTO `demo_user_auth` VALUES ('1', 'admin', '1587467975853001403', 'CRM_MENU5603', '交易管理', '#', null, '3', '#', '3', null, null, 'Y');
注意使用这个demo_user_auth表,需要把上面介绍的CommUserMapper.java里的@Select注解里的v_user_auth改为demo_user_auth。替换后运行起来结果一样。
代码量比较大啊,本文先写到这里,明天基本可以结尾了。
示例代码下载见Github: https://github.com/openjweb/cloud/tree/masterhttps://github.com/openjweb/cloud/tree/master