gpt4 book ai didi

spring - 当我启用@EnableResourceServer 和@EnableAuthorizationServer 时,登录页面出现问题

转载 作者:行者123 更新时间:2023-12-04 22:56:52 27 4
gpt4 key购买 nike

我正在研究组合身份验证和资源服务器。

我测试了身份验证,并使用由重定向触发的登录页面、使用授权码创建 token 等一切正常。

但是,当我打开资源服务器时,redirct 登录页面会停止工作,并出现不同的安全设置相关问题。我认为这与 ResourceServerConfigurerAdapterWebSecurityConfigurerAdapter 都有一个要覆盖的 configure(HttpSecurity http) 方法有关。我尝试只使用其中一个,甚至尝试让它们都设置相同的设置等,但无法使其正常工作。

例如,我遇到的问题之一是模型中缺少 csrf:

Exception evaluating SpringEL expression: "_csrf.parameterName" (login:45)

推荐的做法是什么?

此服务器的目的是:- 充当OAuth认证服务器,主要是授权代码流程,向用户显示登录后的批准页面- 还托管 OAuth 客户端将使用访问 token 连接到的 REST API 以访问已登录用户的资源

安全配置如下所示:

 http
.authorizeRequests()
.antMatchers("/login", "/logout.do").permitAll()
.antMatchers("/oauth/**").permitAll()
.antMatchers("/myservice/api/**").authenticated()
.and()
.formLogin()
.loginProcessingUrl("/login.do")
.usernameParameter("name")
.loginPage("/login")
.and()
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout.do"));

登录页面是一个简单的 thymeleaf 登录页面。

最佳答案

我遇到了同样的问题

将 @Order(org.springframework.boot.autoconfigure.security.SecurityProperties.ACCESS_OVERRIDE_ORDER) 添加到我的 WebSecurityConfigurerAdapter 解决了我的问题。

https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-security.html

关于spring - 当我启用@EnableResourceServer 和@EnableAuthorizationServer 时,登录页面出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44287316/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com