如何解决Spring Security重定向到使用有效令牌登录
大家下午好,我是春季启动的新手,并使用jhipster创建了一个应用程序。但是现在,我试图在我的角度应用程序上使用授权服务器(Keycloak)进行身份验证,获取令牌,并且当我尝试获取任何资源时,它将我重定向到一种登录页面
从来源“ http:// localhost”访问“ http://myurl.com/oauth2/authorization/oidc”(从“ https://myurl.com/api/configuracaos/1”重定向)的XMLHttpRequest: 4200'已被CORS政策阻止:对飞行前请求的响应未通过访问控制检查:飞行前请求不允许重定向。
直接访问此URL后,它就像一个超级按钮。我想这个URL是由Spring自动实现的,并在内存中创建了会话,但是我找不到任何解决方法。
这是我的securityConfiguration:
@Override
public void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.csrf()
.disable()
.addFilterBefore(corsFilter,CsrfFilter.class)
.exceptionHandling()
.accessDeniedHandler(problemSupport)
.and()
.headers()
.contentSecurityPolicy("default-src 'self'; frame-src 'self' data:; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://storage.googleapis.com; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:")
.and()
.referrerPolicy(ReferrerPolicyHeaderWriter.ReferrerPolicy.STRICT_ORIGIN_WHEN_CROSS_ORIGIN)
.and()
.featurePolicy("geolocation 'none'; midi 'none'; sync-xhr 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope 'none'; speaker 'none'; fullscreen 'self'; payment 'none'")
.and()
.frameOptions()
.deny()
.and()
.authorizeRequests()
.antMatchers(HttpMethod.OPTIONS,"/**").permitAll()
.antMatchers("/api/auth-info").permitAll()
.antMatchers("/api/idiomas").permitAll()
.antMatchers("/api/**").authenticated()
.antMatchers("/management/health").permitAll()
.antMatchers("/management/info").permitAll()
.antMatchers("/management/prometheus").permitAll()
.antMatchers("/management/**").hasAuthority(AuthoritiesConstants.ADMIN)
.and()
.oauth2Login()
.and()
.oauth2ResourceServer()
.jwt()
.jwtAuthenticationConverter(jwtAuthorityExtractor)
.and()
.and()
.oauth2Client();
// @formatter:on
}
感谢您的宝贵时间!希望你能帮助我
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。