- 修改database sql
- 增加Security配置
This commit is contained in:
yulinling 2025-06-10 22:48:56 +08:00 committed by 雨霖铃
parent 84c77b0b50
commit 474c9499f6
11 changed files with 237 additions and 44 deletions

View File

@ -28,6 +28,7 @@
</scm> </scm>
<properties> <properties>
<java.version>17</java.version> <java.version>17</java.version>
<jjwt.veersion>0.9.1</jjwt.veersion>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
@ -106,6 +107,10 @@
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -0,0 +1,24 @@
package asia.yulinling.workflow.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(authorize -> authorize
.requestMatchers("/users", "/users/**").permitAll()
.anyRequest().authenticated())
.formLogin(formLogin -> formLogin
.loginPage("/login")
.permitAll())
.rememberMe(Customizer.withDefaults());
return http.build();
}
}

View File

@ -72,4 +72,9 @@ public class TestController {
public ApiResponse<PageResult<UserVO>> usersPage(PageParam pageParam) { public ApiResponse<PageResult<UserVO>> usersPage(PageParam pageParam) {
return userService.getUserListByPage(pageParam); return userService.getUserListByPage(pageParam);
} }
@GetMapping("/login")
public ApiResponse<String> login() {
return ApiResponse.ofSuccess("登录成功");
}
} }

View File

@ -13,7 +13,7 @@ import java.util.Date;
/** /**
* <p> * <p>
* 用户实体类 * 用户实体类
* </p> * </p>
* *
* @author yulinling * @author yulinling
@ -23,7 +23,7 @@ import java.util.Date;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Builder @Builder
@TableName("`orm_user`") @TableName("`wk_user`")
public class User { public class User {
/** /**
* 主键id * 主键id
@ -34,7 +34,12 @@ public class User {
/** /**
* 用户名 * 用户名
*/ */
private String name; private String username;
/**
* 昵称
*/
private String nickname;
/** /**
* 加密后的密码 * 加密后的密码
@ -51,6 +56,16 @@ public class User {
*/ */
private String email; private String email;
/**
* 生日
*/
private String birthday;
/**
* 性别,-1,-2
*/
private Integer sex;
/** /**
* 手机号 * 手机号
*/ */
@ -67,15 +82,16 @@ public class User {
@TableField("create_time") @TableField("create_time")
private Date createTime; private Date createTime;
/**
* 上次更新时间
*/
@TableField("update_time")
private Date updateTime;
/** /**
* 上次登录时间 * 上次登录时间
*/ */
@TableField("last_login_time") @TableField("last_login_time")
private Date lastLoginTime; private Date lastLoginTime;
/**
* 上次更新时间
*/
@TableField("last_update_time")
private Date lastUpdateTime;
} }

View File

@ -15,7 +15,7 @@ public class UserVO {
/** /**
* 用户名 * 用户名
*/ */
private String name; private String username;
/** /**
* 邮箱 * 邮箱

View File

@ -42,7 +42,7 @@ public class UserServiceImpl implements UserService {
if (ArrayUtil.isNotEmpty(users)) { if (ArrayUtil.isNotEmpty(users)) {
for (User user : users) { for (User user : users) {
UserVO userVO = new UserVO(); UserVO userVO = new UserVO();
userVO.setName(user.getName()); userVO.setUsername(user.getUsername());
userVO.setEmail(user.getEmail()); userVO.setEmail(user.getEmail());
userVO.setPhone(user.getPhone()); userVO.setPhone(user.getPhone());
userVO.setStatus(user.getStatus()); userVO.setStatus(user.getStatus());

View File

@ -1,7 +1,7 @@
# ???? # 服务端配置
server.port=8080 server.port=8080
server.servlet.context-path=/demo server.servlet.context-path=/demo
# mysql?? # mysql配置
spring.datasource.url=jdbc:mysql://122.152.201.90:9912/workflow?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&failOverReadOnly=false&serverTimezone=GMT%2B8 spring.datasource.url=jdbc:mysql://122.152.201.90:9912/workflow?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&failOverReadOnly=false&serverTimezone=GMT%2B8
spring.datasource.username=root spring.datasource.username=root
spring.datasource.password=0andrx spring.datasource.password=0andrx
@ -10,7 +10,7 @@ spring.sql.init.mode=always
spring.sql.init.continue-on-error=true spring.sql.init.continue-on-error=true
spring.sql.init.schema-locations=classpath:db/schema.sql spring.sql.init.schema-locations=classpath:db/schema.sql
spring.sql.init.data-locations=classpath:db/data.sql spring.sql.init.data-locations=classpath:db/data.sql
# ??????? # 连接池配置
spring.datasource.hikari.minimum-idle=5 spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.connection-test-query=SELECT 1 spring.datasource.hikari.connection-test-query=SELECT 1
spring.datasource.hikari.maximum-pool-size=20 spring.datasource.hikari.maximum-pool-size=20
@ -19,10 +19,10 @@ spring.datasource.hikari.idle-timeout=30000
spring.datasource.hikari.pool-name=MyAppHikariCP spring.datasource.hikari.pool-name=MyAppHikariCP
spring.datasource.hikari.max-lifetime=300000 spring.datasource.hikari.max-lifetime=300000
spring.datasource.hikari.connection-timeout=30000 spring.datasource.hikari.connection-timeout=30000
# log?? # log配置
logging.level.asia.yulinling=debug logging.level.asia.yulinling=debug
logging.level.asia.yulinling.workflow.mapper=trace logging.level.asia.yulinling.workflow.mapper=trace
# mail?? # mail配置
spring.mail.host=smtp.qq.com spring.mail.host=smtp.qq.com
spring.mail.port=587 spring.mail.port=587
spring.mail.username=2712495353@qq.com spring.mail.username=2712495353@qq.com
@ -35,5 +35,5 @@ spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.ssl.enable=false spring.mail.properties.mail.smtp.ssl.enable=false
spring.mail.properties.mail.display.sendmail=spring-boot-demo spring.mail.properties.mail.display.sendmail=spring-boot-demo
# Jasypt?? # Jasypt配置
jasypt.encryptor.password=abc jasypt.encryptor.password=abc

View File

@ -1,2 +1,93 @@
INSERT INTO `orm_user`(`id`,`name`,`password`,`salt`,`email`,`phone`) VALUES (1, 'user_1', 'ff342e862e7c3285cdc07e56d6b8973b', '412365a109674b2dbb1981ed561a4c70', 'user1@xkcoding.com', '17300000001'); BEGIN;
INSERT INTO `orm_user`(`id`,`name`,`password`,`salt`,`email`,`phone`) VALUES (2, 'user_2', '6c6bf02c8d5d3d128f34b1700cb1e32c', 'fcbdd0e8a9404a5585ea4e01d0e4d7a0', 'user2@xkcoding.com', '17300000002'); INSERT INTO `wk_permission`
VALUES (1072806379288399872, '测试页面', '/test', 1, 'page:test', NULL, 1, 0);
INSERT INTO `wk_permission`
VALUES (1072806379313565696, '测试页面-查询', '/**/test', 2, 'btn:test:query', 'GET', 1, 1072806379288399872);
INSERT INTO `wk_permission`
VALUES (1072806379330342912, '测试页面-添加', '/**/test', 2, 'btn:test:insert', 'POST', 2, 1072806379288399872);
INSERT INTO `wk_permission`
VALUES (1072806379342925824, '监控在线用户页面', '/monitor', 1, 'page:monitor:online', NULL, 2, 0);
INSERT INTO `wk_permission`
VALUES (1072806379363897344, '在线用户页面-查询', '/**/api/monitor/online/user', 2, 'btn:monitor:online:query', 'GET',
1,
1072806379342925824);
INSERT INTO `wk_permission`
VALUES (1072806379384868864, '在线用户页面-踢出', '/**/api/monitor/online/user/kickout', 2,
'btn:monitor:online:kickout',
'DELETE', 2, 1072806379342925824);
COMMIT;
BEGIN;
INSERT INTO `wk_role`
VALUES (1072806379208708096, '管理员', '超级管理员', '2018-12-12 14:52:27', '2018-12-12 14:52:27');
INSERT INTO `wk_role`
VALUES (1072806379238068224, '普通用户', '普通用户', '2018-12-12 14:52:27', '2018-12-12 14:52:27');
COMMIT;
BEGIN;
INSERT INTO `wk_role_permission`
VALUES (1072806379208708096, 1072806379288399872);
INSERT INTO `wk_role_permission`
VALUES (1072806379208708096, 1072806379313565696);
INSERT INTO `wk_role_permission`
VALUES (1072806379208708096, 1072806379330342912);
INSERT INTO `wk_role_permission`
VALUES (1072806379208708096, 1072806379342925824);
INSERT INTO `wk_role_permission`
VALUES (1072806379208708096, 1072806379363897344);
INSERT INTO `wk_role_permission`
VALUES (1072806379208708096, 1072806379384868864);
INSERT INTO `wk_role_permission`
VALUES (1072806379238068224, 1072806379288399872);
INSERT INTO `wk_role_permission`
VALUES (1072806379238068224, 1072806379313565696);
COMMIT;
BEGIN;
INSERT INTO `wk_user` (
id, username, nickname, password, salt, email, birthday, sex, phone, status,
create_time, update_time, last_login_time
) VALUES (
1072806377661009920,
'admin',
'管理员',
'ff342e862e7c3285cdc07e56d6b8973b',
'412365a109674b2dbb1981ed561a4c70',
'admin@xkcoding.com',
'1994-11-28 00:00:00', -- birthday: 785433600000 → 1994-11-28
1,
'17300000000',
1,
'2018-12-12 14:52:27', -- create_time
'2018-12-12 14:52:27', -- update_time
'2018-12-12 14:52:27' -- last_login_time
);
INSERT INTO `wk_user` (
id, username, nickname, password, salt, email, birthday, sex, phone, status,
create_time, update_time, last_login_time
) VALUES (
1072806378780889088,
'user',
'普通用户',
'6c6bf02c8d5d3d128f34b1700cb1e32c',
'fcbdd0e8a9404a5585ea4e01d0e4d7a0',
'user@xkcoding.com',
'1994-11-28 00:00:00', -- birthday: 785433600000 → 1994-11-28
1,
'17300001111',
1,
'2018-12-12 14:52:27', -- create_time
'2018-12-12 14:52:27', -- update_time
'2018-12-12 14:52:27' -- last_login_time
);
COMMIT;
BEGIN;
INSERT INTO `wk_role_user`
VALUES (1072806379208708096, 1072806377661009920);
INSERT INTO `wk_role_user`
VALUES (1072806379238068224, 1072806378780889088);
COMMIT;

View File

@ -1,13 +1,61 @@
DROP TABLE IF EXISTS `orm_user`; DROP TABLE IF EXISTS `wk_user`;
CREATE TABLE `orm_user` ( CREATE TABLE `wk_user`
`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT '主键', (
`name` VARCHAR(32) NOT NULL UNIQUE COMMENT '用户名', `id` bigint(64) NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT '主键',
`password` VARCHAR(32) NOT NULL COMMENT '加密后的密码', `username` VARCHAR(32) NOT NULL UNIQUE COMMENT '用户名',
`salt` VARCHAR(32) NOT NULL COMMENT '加密使用的盐', `nickname` VARCHAR(32) NOT NULL UNIQUE COMMENT '昵称',
`email` VARCHAR(32) NOT NULL UNIQUE COMMENT '邮箱', `password` VARCHAR(32) NOT NULL COMMENT '加密后的密码',
`phone` VARCHAR(15) NOT NULL UNIQUE COMMENT '手机号码', `salt` VARCHAR(32) NOT NULL COMMENT '加密使用的盐',
`status` INT(2) NOT NULL DEFAULT 1 COMMENT '状态,-1逻辑删除0禁用1启用', `email` VARCHAR(32) NOT NULL UNIQUE COMMENT '邮箱',
`create_time` DATETIME NOT NULL DEFAULT NOW() COMMENT '创建时间', `birthday` DATETIME DEFAULT NULL COMMENT '生日',
`last_login_time` DATETIME DEFAULT NULL COMMENT '上次登录时间', `sex` INT(2) DEFAULT NULL COMMENT '性别,男-1,女-2',
`last_update_time` DATETIME NOT NULL DEFAULT NOW() COMMENT '上次更新时间' `phone` VARCHAR(15) DEFAULT NULL UNIQUE COMMENT '手机号',
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Spring Boot Demo Orm 系列示例表'; `status` INT(2) NOT NULL DEFAULT 1 COMMENT '状态 -1删除 0警用 1启用',
`create_time` DATETIME NOT NULL DEFAULT NOW() COMMENT '创建时间',
`update_time` DATETIME NOT NULL DEFAULT NOW() COMMENT '上次更新时间',
`last_login_time` DATETIME DEFAULT NULL COMMENT '上次登录时间'
) ENGINE = INNODB
DEFAULT CHARSET = UTF8 COMMENT '用户表';
DROP TABLE IF EXISTS `wk_role`;
CREATE TABLE `wk_role`
(
`id` BIGINT(64) NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT '主键',
`name` VARCHAR(32) NOT NULL UNIQUE COMMENT '角色名',
`description` VARCHAR(100) DEFAULT NULL COMMENT '描述',
`create_time` DATETIME NOT NULL DEFAULT NOW() COMMENT '创建时间',
`update_time` DATETIME NOT NULL DEFAULT NOW() COMMENT '更新时间'
) ENGINE = INNODB
DEFAULT CHARSET = UTF8 COMMENT '角色表';
DROP TABLE IF EXISTS `wk_permission`;
CREATE TABLE `wk_permission`
(
`id` BIGINT(64) NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT '主键',
`name` VARCHAR(32) NOT NULL UNIQUE COMMENT '权限名',
`url` VARCHAR(1000) DEFAULT NULL COMMENT '类型为页面时,代表前端路由地址,类型为按钮时,代表后端接口地址',
`type` INT(2) NOT NULL COMMENT '权限类型,页面-1,按钮-2',
`permission` VARCHAR(50) DEFAULT NULL COMMENT '权限表达式',
`method` VARCHAR(50) DEFAULT NULL COMMENT '后端接口访问方式',
`sort` INT(11) NOT NULL COMMENT '排序',
`parent_id` BIGINT(64) NOT NULL COMMENT '父级ID'
) ENGINE = INNODB
DEFAULT CHARSET = UTF8 COMMENT '权限表';
DROP TABLE IF EXISTS `wk_role_permission`;
CREATE TABLE `wk_role_permission`
(
`role_id` BIGINT(64) NOT NULL COMMENT '',
`permission_id` BIGINT(64) NOT NULL COMMENT '',
PRIMARY KEY (`role_id`, `permission_id`)
) ENGINE = INNODB
DEFAULT CHARSET = UTF8 COMMENT '角色权限表';
DROP TABLE IF EXISTS `wk_role_user`;
CREATE TABLE `wk_role_user`
(
`role_id` BIGINT(64) NOT NULL COMMENT '',
`user_id` BIGINT(64) NOT NULL COMMENT '',
PRIMARY KEY (`role_id`, `user_id`)
) ENGINE = INNODB
DEFAULT CHARSET = UTF8 COMMENT '角色用户表';

View File

@ -2,16 +2,18 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="asia.yulinling.workflow.mapper.UserMapper"> <mapper namespace="asia.yulinling.workflow.mapper.UserMapper">
<insert id="saveUser"> <insert id="saveUser">
INSERT INTO `orm_user` (`name`, INSERT INTO `wk_user` (`username`,
`password`, `nickname`,
`salt`, `password`,
`email`, `salt`,
`phone`, `email`,
`status`, `phone`,
`create_time`, `status`,
`last_login_time`, `create_time`,
`last_update_time`) `last_login_time`,
`update_time`)
VALUES (#{user.name}, VALUES (#{user.name},
#{user.nickname},
#{user.password}, #{user.password},
#{user.salt}, #{user.salt},
#{user.email}, #{user.email},
@ -19,10 +21,12 @@
#{user.status}, #{user.status},
#{user.createTime}, #{user.createTime},
#{user.lastLoginTime}, #{user.lastLoginTime},
#{user.lastUpdateTime}) #{user.updateTime})
</insert> </insert>
<delete id="deleteById"> <delete id="deleteById">
DELETE FROM `orm_user` WHERE id = #{id} DELETE
FROM `wk_user`
WHERE id = #{id}
</delete> </delete>
</mapper> </mapper>

View File

@ -57,7 +57,7 @@ public class UserMapperTest {
public void saveUser() { public void saveUser() {
String salt = IdUtil.simpleUUID(); String salt = IdUtil.simpleUUID();
User user = User.builder() User user = User.builder()
.name("yulinling_test") .username("yulinling_test")
.password(SecureUtil.md5("123456" + salt)) .password(SecureUtil.md5("123456" + salt))
.salt(salt) .salt(salt)
.email("2712495353@qq.com") .email("2712495353@qq.com")
@ -65,7 +65,7 @@ public class UserMapperTest {
.status(1) .status(1)
.lastLoginTime(new DateTime()) .lastLoginTime(new DateTime())
.createTime(new DateTime()) .createTime(new DateTime())
.lastUpdateTime(new DateTime()) .updateTime(new DateTime())
.build(); .build();
// int i = userMapper.saveUser(user); // int i = userMapper.saveUser(user);