【问题标题】:Integrating Angular 5 App and Spring boot. Spring security blocks the app集成 Angular 5 应用程序和 Spring Boot。 Spring 安全阻止应用程序
【发布时间】:2018-10-31 21:42:33
【问题描述】:

我已将构建的 Angular 应用程序添加到资源下的静态文件夹中。当我转到localhost:8080 时,该应用程序未显示。如何配置 Spring Security 以仅允许 Angular 5 应用程序通过。

我的Http配置:

http
            .cors()
                .and()
            .csrf()
                .disable()
            .exceptionHandling()
                .authenticationEntryPoint(unauthorizedHandler)
                .and()
            .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
            .authorizeRequests()
                .antMatchers("/auth/**").permitAll()
                .antMatchers("/h2-console/**").permitAll()
                .antMatchers("/users/checkUsernameAvailability",
                        "/users/checkEmailAvailability")
                    .permitAll()
                .anyRequest().authenticated();

【问题讨论】:

  • 你得到什么回应?有任何错误消息或 HTTP 状态吗?您的日志中的消息是什么?
  • @dur 我收到 401 Not Authenticated 消息

标签: spring angular spring-boot spring-security


【解决方案1】:

你有以下:

.anyRequest().authenticated();

所以如果你没有登录,访问 http://localhost:8080 是 root 将被 Spring Security 阻止。

尝试登录添加以下行。

.antMatchers("/**").permitAll()

以上行必须仅用于测试。

【讨论】:

    猜你喜欢
    • 2018-09-27
    • 2019-09-25
    • 1970-01-01
    • 2019-10-09
    • 1970-01-01
    • 1970-01-01
    • 2019-08-31
    • 2018-05-17
    • 2017-01-13
    相关资源
    最近更新 更多