在Spring Security中配置用户认证和授权,配置文件可以放置在application.properties或application.yml文件中
时间: 2023-06-01 18:03:04 浏览: 272
Spring Security 配置
。在application.properties文件中,可以使用以下配置:
```
# basic authentication
spring.security.user.name=user
spring.security.user.password=password
# jdbc authentication
spring.datasource.url=jdbc:mysql://localhost:3306/dbname
spring.datasource.username=username
spring.datasource.password=password
spring.queries.users-query=select username,password,enabled from users where username=?
spring.queries.roles-query=select u.username, r.name from users u inner join user_role ur on(u.id=ur.user_id) inner join roles r on(ur.role_id=r.id) where u.username=?
```
在application.yml文件中,可以使用以下配置:
```
# basic authentication
spring:
security:
user:
name: user
password: password
# jdbc authentication
spring:
datasource:
url: jdbc:mysql://localhost:3306/dbname
username: username
password: password
security:
user:
name: user
password: password
jdbc:
users-by-username-query: select username,password,enabled from users where username=?
authorities-by-username-query: select u.username, r.name from users u inner join user_role ur on(u.id=ur.user_id) inner join roles r on(ur.role_id=r.id) where u.username=?
```
阅读全文