Tomcat 9 中的 POST 请求禁止 Spring Boot 403

我是 Spring Boot 的新手,我正在创建一个 Web 应用程序。我在没有 JWT 令牌身份验证的情况下绕过“/auth/login”URL。


我创建了一个控制器来处理登录请求并给出响应。


当我使用http://localhost:9505/auth/login带有 body 参数的URL 在本地使用 URL 调用我的 Web 服务时


{

    "username":"abcd@g.l",

    "password" : "newPassword"

}

它工作正常,不检查令牌,但是当我导出它并创建 WAR 文件并部署在服务器上时,它给了我 403 Forbidden 错误。


下面是我在 tomcat 9 服务器上部署后用来调用 API 的 URL


http://localhost:9505/myapplicationame/auth/login

你能指导我会有什么问题吗?


下面是我的安全配置方法。


@Override

    protected void configure(HttpSecurity http) throws Exception {

    logger.info("SecurityConfig => configure : Configure in SecurityConfig");

    logger.info("http Request Path : ");


    logger.info("servletContext.getContextPath()) : " + servletContext.getContextPath());

    http

    .csrf()

        .disable()

   .exceptionHandling()

       .authenticationEntryPoint(unauthorizedHandler)

       .and()

   .sessionManagement()

       .sessionCreationPolicy(SessionCreationPolicy.STATELESS)

       .and()

   .authorizeRequests()

       .antMatchers("/",

           "/favicon.ico",

           "/**/*.png",

           "/**/*.gif",

           "/**/*.svg",

           "/**/*.jpg",

           "/**/*.html",

           "/**/*.css",

           "/**/*.js")

           .permitAll()

        .antMatchers("/auth/**")

           .permitAll()

        .antMatchers("/auth/login")

           .permitAll()

       .antMatchers("/permissions")

           .permitAll()

       .anyRequest()

           .authenticated();


    // Add our custom JWT security filter

    http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);

}


米脂
浏览 315回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java