[英]File upload not working from Angular 8 front-end to the Spring Boot back-end after adding Spring Security
[英]Spring Boot Back-End with Angular Front-End getting status and metrics from prometheus and health endpoint but 401
在集群上部署时遇到 401 错误问题。 请注意在本地开发期间未发生的问题。 只有在测试集群上部署后才会出现问题。 目前该项目仅处于开发/测试阶段。
后端配置(Spring 属性文件):
server.port=8085 management.health.defaults.enabled=false management.endpoint.health.show-details="ALWAYS" management.server.port=${management.port:1234} management.endpoints.enabled-by-default=true management.endpoints.web.base-path=/ management.endpoints.web.exposure.include=health, prometheus
Angular:登录成功(使用相对 url 到端口 8085 一旦部署在集群上)但登录后我的仪表板页面调用执行器健康和普罗米修斯端点:
这些是 URL: healthUrl: "http://localhost:1234/health" metricsUrl: "http://localhost:1234/prometheus"
弹簧安全:
@Configuration @EnableWebSecurity public class ActuatorWebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .csrf().disable() .cors().configurationSource(corsConfigurationSource()) .and() .authorizeRequests() .requestMatchers(EndpointRequest.to(HealthEndpoint.class, InfoEndpoint.class)).permitAll() .antMatchers("/**").authenticated() .and().httpBasic() .and() .addFilterBefore(new ForwardedHeaderFilter(), UsernamePasswordAuthenticationFilter.class); } @Bean CorsConfigurationSource corsConfigurationSource() { CorsConfiguration configuration = new CorsConfiguration(); configuration.setAllowedOrigins(Arrays.asList("*")); configuration.setAllowCredentials(true); configuration.setAllowedMethods(Arrays.asList("GET","POST","OPTIONS")); configuration.setAllowedHeaders(Collections.singletonList("*")); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", configuration); return source; } }
请为整个类提供安全配置,包括所有注释,以便我们更好地理解它。
以下是一些深入研究的建议
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.