认证用户

把这个功能找回来所需要做的就是在 configure(HttpSecurity) 方法中,调用 formLogin(),如下面的程序清单所示。

如果我们访问应用的 “/login” 链接或者导航到需要认证的页面,那么将会在浏览器中展现登录页面。

@Override
protected void configure(HttpSecurity http) throws Exception {
  http
    .formLogin()
    .and()
    .authorizeRequests()
    .antMatchers("/spitter/me").hasRole("SPITTER")
    .antMatchers(HttpMethod.POST, "/spittles").hasRole("SPITTER")
    .anyRequest().permitAll()
    .and()
    .requeresChannel()
    .antMatchers("/spitter/form").requiresSecure();
}

Last updated