如何在Java Spring Boot安全性中允许所有HTTP重定向?

问题描述 投票:0回答:1

我正在编写一个Java Spring Boot应用程序,该程序在pom.xml中包含了Spring Boot Security。但是,当我从登录名重定向到我的/home时,它起作用。虽然当我再次更改页面或执行简单的ajax调用时,却遇到了403错误。我认为这与安全性有关,并且该页面没有适当的访问权限。我正在寻找解决此问题的最佳方法,同时又保持安全状态。

Java安全性:

    @Override
      protected void configure(HttpSecurity http) throws Exception {
        http
          .authorizeRequests()
            .anyRequest().fullyAuthenticated()
            .and()
          .formLogin()
          .successHandler(new CustomAuthenticationSuccessHandler())                 // On authentication success custom handler    
          .and()
          .logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")).logoutSuccessUrl("/login");


    }

Java成功处理程序:

@Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
            Authentication authentication) throws IOException, ServletException {
        String principal = authentication.getName();

        System.out.println("Successful login: principal " + principal);
        ADID = principal;
        response.sendRedirect("/dashboard");

    }

控制器错误:

Error 403 : http://localhost:8080/edit/ajax/doesSomething

因此/dashboard是登录成功后进入的第一页,然后客户端输入一些字段,并移至另一个调用另一个URL路径的页面。我认为当它调用不是/dashboard

的其他路径时,它会失败
java spring spring-boot
1个回答
0
投票

您的问题是CSRF令牌。您可以在安全性配置中禁用它,但最好使用它。有关更多信息,请参见this网站。

© www.soinside.com 2019 - 2024. All rights reserved.