Angularjs Spring Oauth2+;用户注册
我对Spring Oauth2又有问题了。我知道这个主题不容易提出建议或检查代码,因为我们有太多的配置。 我的项目有3个不同的服务器,身份验证服务器、资源服务器和前端服务器。我想把register.html放到前端项目中的用户注册中(在Angularjs文件下),但是当我请求相关url()时,它会重定向到登录页面(),只需要一秒钟,我就可以看到我的register.html内容,但在那之后它会进入登录页面。 问题是,我应该把register.html放在哪里,它应该放在前端项目或身份验证服务器下 我的认证服务器和前端服务器代码为Angularjs Spring Oauth2+;用户注册,angularjs,spring-security,spring-boot,oauth2,Angularjs,Spring Security,Spring Boot,Oauth2,我对Spring Oauth2又有问题了。我知道这个主题不容易提出建议或检查代码,因为我们有太多的配置。 我的项目有3个不同的服务器,身份验证服务器、资源服务器和前端服务器。我想把register.html放到前端项目中的用户注册中(在Angularjs文件下),但是当我请求相关url()时,它会重定向到登录页面(),只需要一秒钟,我就可以看到我的register.html内容,但在那之后它会进入登录页面。 问题是,我应该把register.html放在哪里,它应该放在前端项目或身份验证服务器下
@Configuration
public class AuthServerSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
private AuthenticationManager authenticationManager;
@Override
protected void configure(AuthenticationManagerBuilder auth)
throws Exception {
auth.parentAuthenticationManager(authenticationManager);
auth.authenticationProvider(userAuthProviderService());
}
private CsrfMatcher csrfRequestMatcher = new CsrfMatcher();
@Override
protected void configure(final HttpSecurity http) throws Exception {
/*http.csrf().disable();*/
http.csrf().requireCsrfProtectionMatcher(csrfRequestMatcher);
http
.formLogin().loginPage("/login").defaultSuccessUrl("/")
/*.failureUrl("")*/.successHandler(new AuthSuccessHandler()).permitAll()
.and()
.requestMatchers().antMatchers("/login", "/oauth/authorize", "/oauth/confirm_access","/register")
.and()
.authorizeRequests().anyRequest().authenticated();
}
@Bean
public UserAuthProviderService userAuthProviderService(){
return new UserAuthProviderService();
}
private class CsrfMatcher implements RequestMatcher {
@Override
public boolean matches(HttpServletRequest request) {
return false;
}
}
}
}在您的UI服务器中,尝试在启用/register.hml的情况下创建Web安全性,如下所示
@Configuration
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.requestMatchers()
.antMatchers("/register.html")
.and()
.authorizeRequests()
.anyRequest().authenticated();
}
}
编辑:
或者在当前配置中删除.antMatcher(“/**”).authorizeRequests()
并添加和().authorizeRequests().anyRequest().authorized()
所以最后可能是这样的:
@Override
public void configure(HttpSecurity http) throws Exception {
http.logout().and()
.antMatchers("/index.html", "/home.html", "/", "/login","/register.html").permitAll().anyRequest()
.authenticated()
.and().csrf().disable();
http.headers().frameOptions().disable() //FOR EMBED MAP
.and()
.authorizeRequests()
.anyRequest().authenticated();
}
在您的UI服务器中,尝试在启用/register.hml的情况下创建Web安全性,如下所示
@Configuration
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.requestMatchers()
.antMatchers("/register.html")
.and()
.authorizeRequests()
.anyRequest().authenticated();
}
}
编辑:
或者在当前配置中删除.antMatcher(“/**”).authorizeRequests()
并添加和().authorizeRequests().anyRequest().authorized()
所以最后可能是这样的:
@Override
public void configure(HttpSecurity http) throws Exception {
http.logout().and()
.antMatchers("/index.html", "/home.html", "/", "/login","/register.html").permitAll().anyRequest()
.authenticated()
.and().csrf().disable();
http.headers().frameOptions().disable() //FOR EMBED MAP
.and()
.authorizeRequests()
.anyRequest().authenticated();
}
两件事:
- 我想不出一个好的理由不把你的*.html放在前端服务器以外的任何地方
- 此外,一般来说,您应该允许公开访问静态UI组件,如@bilak提到的:
.antMatchers(“/index.html”、“/home.html”、“/”、“/login”、“/register.html”).permitAll()
- 如果您能够看到
页面(假设未经身份验证的用户),那么它已经是公共的了register.html
- 也许,在触发身份验证流的Spring安全性后面的
加载事件上有一个webservice调用register.html
- 我想不出一个好的理由不把你的*.html放在前端服务器以外的任何地方
- 此外,一般来说,您应该允许公开访问静态UI组件,如@bilak提到的:
- 两件事:
.antMatchers(“/index.html”、“/home.html”、“/”、“/login”、“/register.html”).permitAll()
- 如果您能够看到
页面(假设未经身份验证的用户),那么它已经是公共的了register.html
- 也许,在触发身份验证流的Spring安全性后面的
加载事件上有一个webservice调用register.html