我正在编写一个应用程序,我试图在其中配置不同端点的可见性。
我写了以下代码:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and().csrf().disable().authorizeRequests()
.antMatchers(HttpMethod.POST, SIGN_UP_URL).permitAll()
.antMatchers(HttpMethod.POST, "/login").permitAll()
.antMatchers(HttpMethod.GET, "/login").permitAll()
.antMatchers(HttpMethod.GET, "/").authenticated()
.antMatchers(HttpMethod.GET, UPVOTE_URL).authenticated()
.antMatchers(HttpMethod.GET, DOWNVOTE_URL).authenticated()
.antMatchers(HttpMethod.POST, LOG_OUT_URL).authenticated()
.antMatchers(HttpMethod.DELETE, DELETE_URL).authenticated()
.antMatchers(HttpMethod.POST, ADD_URL).authenticated()
.anyRequest().authenticated()
.and()
.addFilter(new JWTAuthenticationFilter(authenticationManager()))
.addFilter(new JWTAuthorizationFilter(authenticationManager()))
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.logout()
.and()
.exceptionHandling()
.authenticationEntryPoint(new Http401AuthenticationEntryPoint("No authorization"));
我的程序的行为很奇怪,因为当我试图到达“/login”或“/”端点时程序有时会抛出 401(如果用户没有登录,afaik 应该重定向到登录页面)。
之后我重新启动它,也许在其他地方做了一些小的改动,这似乎完全无关紧要,我的网站又可以工作了。
你们中有人遇到过这类问题吗?它的原因是什么?我在配置中做错了吗?
ABOUTYOU
相关分类