Spring Boot Oauth自定义登录表单

Spring Boot Oauth自定义登录表单,spring,security,login,spring-boot,oauth2,Spring,Security,Login,Spring Boot,Oauth2,我遵循了spring教程“带OAuth2的SSO:Angular JS和spring安全第五部分” 在自定义登录表单不再工作之后,我将“authserver”项目从maven转换为gradle 登录表单工作是否需要pom.xml中的wro任务 我也尝试过本教程,但在我的场景中也不起作用: 我希望你能帮助我 日志文件: 2016-05-18 11:14:53.667调试22312---[nio-9999-exec-9]o.s.security.web.FilterChainProxy::在附加过

我遵循了spring教程“带OAuth2的SSO:Angular JS和spring安全第五部分”

在自定义登录表单不再工作之后,我将“authserver”项目从maven转换为gradle

登录表单工作是否需要pom.xml中的wro任务

我也尝试过本教程,但在我的场景中也不起作用:

我希望你能帮助我

日志文件:

2016-05-18 11:14:53.667调试22312---[nio-9999-exec-9]o.s.security.web.FilterChainProxy::在附加过滤器链中14个位置中的第5个位置登录;正在启动筛选器:“注销筛选器” 2016-05-18 11:14:53.667调试22312---[nio-9999-exec-9]o.s.s.w.u.matcher.AntPathRequestMatcher:请求“获取/登录”与“发布/注销”不匹配 2016-05-18 11:14:53.667调试22312---[nio-9999-exec-9]o.s.security.web.FilterChainProxy:/login位于附加过滤器链中14位中的第6位;正在启动筛选器:“UsernamePasswordAuthenticationFilter” 2016-05-18 11:14:53.667调试22312---[nio-9999-exec-9]o.s.s.w.u.matcher.AntPathRequestMatcher:请求“获取/登录”与“发布/登录”不匹配 2016-05-18 11:14:53.667调试22312---[nio-9999-exec-9]o.s.security.web.FilterChainProxy::在附加过滤器链中14个位置中的第7个位置登录;触发筛选器:'DefaultLoginPageGeneratingFilter' 2016-05-18 11:14:53.667调试22312---[nio-9999-exec-9]w.c.HttpSessionSecurityContextRepository:SecurityContext为空或内容为匿名-上下文不会存储在HttpSession中

OAuth2Server配置中的代码:

   @Override
    public void configure(HttpSecurity http) throws Exception {
        http.formLogin().loginPage("/login").permitAll()
            .and().requestMatchers()
                .antMatchers("/login", "/oauth/authorize", "/oauth/confirm_access")
            .and().authorizeRequests()
                .anyRequest().authenticated();
    }
MainAuthserverApplication.java
@ComponentScan
@SessionAttributes(“授权请求”)
@EnableAutoConfiguration()
@EnableConfigurationProperties({AuthProperties.class})

公共类MainAuthserverApplication扩展WebMVCConfigureAdapter{

@Override
public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/login").setViewName("login");
    registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
    registry.addViewController("/oauth/confirm_access").setViewName("authorize");
}

我已经自己解决了这个问题:

似乎这两种方法必须在同一个类中:

@Configuration
@Order(-20)
protected static class LoginConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private AuthenticationManager authenticationManager;

    @Override
    protected void configure(HttpSecurity http) throws Exception {


        // @formatter:off
        http.formLogin().loginPage("/login").permitAll().and().requestMatchers()
            .antMatchers("/login", "/oauth/authorize", "/oauth/confirm_access").and().authorizeRequests()
            .anyRequest().authenticated();
        // @formatter:on
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.parentAuthenticationManager(authenticationManager);
    }
}

我已经自己解决了这个问题:

似乎这两种方法必须在同一个类中:

@Configuration
@Order(-20)
protected static class LoginConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private AuthenticationManager authenticationManager;

    @Override
    protected void configure(HttpSecurity http) throws Exception {


        // @formatter:off
        http.formLogin().loginPage("/login").permitAll().and().requestMatchers()
            .antMatchers("/login", "/oauth/authorize", "/oauth/confirm_access").and().authorizeRequests()
            .anyRequest().authenticated();
        // @formatter:on
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.parentAuthenticationManager(authenticationManager);
    }
}

嗨,jens,你能分享你在github上的工作吗?我也做了同样的工作,但我的工作不起作用。嗨,jens,你能分享你在github上的工作吗?我也做了同样的工作,但我的工作不起作用