抱歉,原先没有发表,是因为一直在参考
http://blog.csdn.net/j754379117/article/details/70176974
http://blog.csdn.net/j754379117/article/details/70175198
https://spring.io/guides/tutorials/spring-boot-oauth2/
现在配置好,运行报
PreparedStatementCallback; bad SQL grammar [select username,password,enabled from users where username = ?]; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'users' doesn't exist
不难看出在Spring Security源码中导数据库中查询用户名密码,及其用户对应的权限是其固定写在代码里面的,这就是为什么网上的一些小的demo中数据库为什么这么创建的原因。下面给出MySQL创建这两张的SQL语句及其插入数据的相关语句:
- create table users(
- username varchar(50) not null primary key,
- password varchar(50) not null,
- enabled boolean not null
- );
- create table authorities (
- username varchar(50) not null,
- authority varchar(50) not null,
- constraint fk_authorities_users foreign key(username) references users(username)
- );
- create unique index ix_auth_username on authorities (username,authority);
- insert into users(username,password,enabled) values('admin','admin',true);
- insert into users(username,password,enabled) values('user','user',true);
- insert into authorities(username,authority) values('admin','ROLE_ADMIN');
- insert into authorities(username,authority) values('admin','ROLE_USER');
- insert into authorities(username,authority) values('user','ROLE_USER');