0
我想添加一個過濾器bean,以便我可以驗證對特定網址的請求。在這種情況下,我試圖添加網址前綴/api/v1/*
,以便所有具有此前綴的網址都通過身份驗證。Spring FilterRegistrationBean註冊所有的URL而不是我定義的URL?
@EnableAutoConfiguration
@ComponentScan
@Configuration
public class Application {
@Bean
public FilterRegistrationBean jwtFilter() {
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
registrationBean.setFilter(new JwtFilter());
registrationBean.addUrlPatterns("/api/v1/*");
return registrationBean;
}
....
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
但是,這似乎註冊所有網址,而不是/api/v1
的一個前綴。
如果我發送POST請求,我會得到如下回應:
{
"timestamp": 1466406709295,
"status": 401,
"error": "Unauthorized",
"message": "Full authentication is required to access this resource",
"path": "/user/login/email"
}
我POM,如果它可以幫助:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>