Spring security 将Spring安全认证与Oauth2服务器集成
对于Spring Boot(1.3.0)上托管的AngularJS应用程序,我有以下web安全配置类:Spring security 将Spring安全认证与Oauth2服务器集成,spring-security,oauth-2.0,spring-security-oauth2,Spring Security,Oauth 2.0,Spring Security Oauth2,对于Spring Boot(1.3.0)上托管的AngularJS应用程序,我有以下web安全配置类: 我如何简单地替换configureGlobal方法,以使用仅具有“refresh\u token”和“password”授权类型的Oauth2服务器进行身份验证 我认为我不理解这个问题(或者如果我理解了,那就是OAuth2的一个相当不寻常的应用)。您想提供一个AuthenticationManager,使用password grant对OAuth2身份验证服务器进行远程调用?@DaveSyer
我如何简单地替换configureGlobal方法,以使用仅具有“refresh\u token”和“password”授权类型的Oauth2服务器进行身份验证 我认为我不理解这个问题(或者如果我理解了,那就是OAuth2的一个相当不寻常的应用)。您想提供一个
AuthenticationManager
,使用password grant对OAuth2身份验证服务器进行远程调用?@DaveSyer是的,假设我们有一个OAuth2服务器位于此应用程序的外部。是否可以通过AuthenticationManager将Spring Security链接到该服务器?我最初的方法是创建一个自定义AuthenticationProvider,然后使用RestTemplate调用Oauth2服务,但我不知道这是否会有问题。感谢您回答我的问题,现在我正在评估Spring Security的Oauth项目的特性和灵活性。我认为这没有任何问题,但有点奇怪。你为什么不直接发布到登录表单上呢?
@Configuration
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.httpBasic().and().authorizeRequests()
.antMatchers("/index.html", "/", "/js/**", "/css/**", "/img/**", "/bower_components/**", "/templates/login/**",
"/fonts/**", "/user")
.permitAll().anyRequest().authenticated().and()
.addFilterAfter(new CsrfHeaderFilter(), CsrfFilter.class)
.csrf().csrfTokenRepository(csrfTokenRepository()).and().logout().logoutSuccessUrl("/");
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("myuser").password("password").roles("USER");
}
private CsrfTokenRepository csrfTokenRepository() {
HttpSessionCsrfTokenRepository repository = new HttpSessionCsrfTokenRepository();
repository.setHeaderName("X-XSRF-TOKEN");
return repository;
}
}