当我启用@EnableResourceServer和@EnableAuthorizationServer时,我遇到了登录页面的问题

时间:2017-05-31 14:21:04

标签: spring authentication oauth

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

我测试了并且使用由重定向触发的登录页面进行身份验证,使用授权代码创建令牌等都很好。

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

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

  

评估SpringEL表达式的异常:“_csrf.parameterName”   (登录:45)

建议的方法是什么?

此服务器的目的是: - 充当OAuth身份验证服务器,主要使用授权代码流,该流程将向用户显示登录后跟批准页面 - 还使用访问令牌托管OAuth客户端将连接到的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"));

登录页面是一个简单的百万美元登录页面。

2 个答案:

答案 0 :(得分:2)

我遇到了同样的问题

将@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

答案 1 :(得分:0)

我们现在似乎已经解决了这个问题。

我们必须设置WebSecurityConfigurerAdapter: @Order(org.springframework.boot.autoconfigure.security.SecurityProperties.ACCESS_OVERRIDE_ORDER)使事情正常运作。