Spring Security OAuth 2,带有表单登录

我正在尝试配置我的Spring启动应用程序以使用表单登录,并使用OAuth 2授权服务器validation凭据(将表单登录中的凭据发送到用户授权URL。

但是,当我使用以下SecurityConfig并且我转到资源时,而不是使用表单登录,它会重定向到授权服务器,询问我的凭据(使用基本身份validation),然后重定向回应用程序本身。

我正在使用以下SecurityConfig

 @Configuration @EnableOAuth2Sso public class SecurityConfig extends OAuth2SsoConfigurerAdapter { @Override public void configure(HttpSecurity http) throws Exception { http .logout() .and() .antMatcher("/**") .authorizeRequests() .anyRequest().authenticated() .and() .csrf() .csrfTokenRepository(csrfTokenRepository()).and() .addFilterAfter(csrfHeaderFilter(), CsrfFilter.class) .formLogin(); } // CSRF repository + filter } 

我将formLogin()提供给configure()方法,但这似乎不起作用。

以下配置位于我的application.yml文件中:

 spring: oauth2: client: clientId: test clientSecret: secret accessTokenUri: http://localhost:8081/uaa/oauth/token userAuthorizationUri: http://localhost:8081/uaa/oauth/authorize clientAuthenticationScheme: header resource: userInfoUri: http://localhost:8081/uaa/user 

这种配置确实有效,因为在重定向之后我获得了授权,但这并不是我希望它能够工作的方式(使用表单登录而不是重定向到OAuth2授权服务器)。

使用SSO,重点是用户使用auth服务器进行身份validation(在您的情况下为localhost:8081)。 如果您想要表单登录,那么您需要在其中实现它,而不是在客户端应用程序中。