# security-learn
**Repository Path**: chenlixin/security-learn
## Basic Information
- **Project Name**: security-learn
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2021-08-09
- **Last Updated**: 2021-09-15
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
## 集成spring security
```xml
org.springframework.boot
spring-boot-starter-web
2.1.1.RELEASE
org.springframework.boot
spring-boot-dependencies
2.1.1.RELEASE
pom
import
org.springframework.boot
spring-boot-starter-security
2.1.1.RELEASE
```
默认用户名:user
密码控制台随机生成
```$xslt
2021-08-09 09:40:09.564 INFO 1428 --- [ main] .s.s.UserDetailsServiceAutoConfiguration :
Using generated security password: dc8e6aba-cb88-4997-857f-31668ecf18cc
```
可自定义配置用户名密码和角色,在application.yml中添加
```yaml
spring:
security:
user:
name: cg
password: 123456
roles: admin
```
---
```sql
CREATE TABLE `user` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(255) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
`enabled` tinyint(2) DEFAULT NULL,
`locked` tinyint(2) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `user`(`id`, `username`, `password`, `enabled`, `locked`) VALUES (1, 'root', '123', 1, 0);
INSERT INTO `user`(`id`, `username`, `password`, `enabled`, `locked`) VALUES (2, 'admin', '123', 1, 0);
INSERT INTO `user`(`id`, `username`, `password`, `enabled`, `locked`) VALUES (3, 'hangge', '123', 1, 0);
CREATE TABLE `role` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(32) DEFAULT NULL,
`nameZh` varchar(32) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `role`(`id`, `name`, `nameZh`) VALUES (1, 'ROLE_dba', '数据库管理员');
INSERT INTO `role`(`id`, `name`, `nameZh`) VALUES (2, 'ROLE_admin', '系统管理员');
INSERT INTO `role`(`id`, `name`, `nameZh`) VALUES (3, 'ROLE_user', '用户');
CREATE TABLE `user_role` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`uid` int(11) DEFAULT NULL,
`rid` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `user_role`(`id`, `uid`, `rid`) VALUES (1, 1, 1);
INSERT INTO `user_role`(`id`, `uid`, `rid`) VALUES (2, 1, 2);
INSERT INTO `user_role`(`id`, `uid`, `rid`) VALUES (3, 2, 2);
INSERT INTO `user_role`(`id`, `uid`, `rid`) VALUES (4, 3, 3);
CREATE TABLE `product` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`item_code` varchar(55) DEFAULT NULL COMMENT '商品码',
`product_desc` varchar(255) DEFAULT NULL COMMENT '商品描述',
`product_url` varchar(255) DEFAULT NULL COMMENT '商品链接',
`stock` int(11) DEFAULT NULL COMMENT '库存',
`monitor_num` int(10) unsigned DEFAULT NULL COMMENT '监控数量',
`monitor_type` char(5) DEFAULT NULL COMMENT '监控类型:1 大于 2 小于',
`status` char(1) DEFAULT NULL COMMENT '脚本运行状态',
`is_proxy` char(1) DEFAULT NULL COMMENT '代理状态',
`msg` varchar(255) DEFAULT NULL COMMENT '消息日志',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `security`.`product`(`id`, `item_code`, `product_desc`, `product_url`, `stock`, `monitor_num`, `monitor_type`, `status`, `is_proxy`, `msg`, `create_time`, `update_time`) VALUES (1, NULL, NULL, 'https://www.ti.com/store/ti/zh/p/product/?p=UAF42AP', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
```
### 参考资料
https://github.com/aaronlinv/springsecurity-jwt-demo