springsecurity前后端分离
时间: 2023-08-20 19:05:52 浏览: 50
对于Spring Security,您可以使用用户名和密码进行登录。您需要配置相应的认证提供者和用户存储来实现基本身份验证。
以下是一个简单的示例,演示了如何使用用户名和密码进行登录:
首先,在您的Spring Boot项目的pom.xml文件中,添加Spring Security依赖项:
```xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
```
然后,在您的应用程序的配置类中,启用基于表单的身份验证,并配置一个用户存储:
```java
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("admin").password("{noop}password").roles("USER");
}
@Override
protected void configure(HttpSecurity http) throws Exception {