当前位置: 首页 > 知识库问答 >
问题:

Spring Boot Oauth自定义登录表单

公西翼
2023-03-14

我学习了spring教程“SSOwith OAuth2:Angular JS和spring Security Part V”。

2016-05-18 11:14:53.667 DEBUG 22312---[nio-9999-exec-9]O.security.web.filterchainproxy:/login位于附加筛选器链中14的位置5;正在激发筛选器:“logoutfilter”2016-05-18 11:14:53.667 DEBUG 22312---[nio-9999-exec-9]O.s.s.w.u.matcher.antPathRequestMatcher:请求“get/login”与“post/logout 2016-05-18 11:14:53.667 DEBUG 22312---[nio-9999-exec-9]O.security.web.filterchainproxy:/login”不匹配,位于附加筛选器链中14的位置6;正在激发筛选器:“UsernamePasswordAuthenticationFilter”2016-05-18 11:14:53.667 DEBUG 22312---[nio-9999-exec-9]O.s.s.w.u.matcher.antPathRequestMatcher:请求“Get/login”与“Post/login 2016-05-18 11:14:53.667 DEBUG 22312---[nio-9999-exec-9]O.s.Security.web.FilterChainProxy:/login”在附加筛选器链中14个位置的第7处不匹配;激发筛选器:“DefaultLoginPageGeneratingFilter”2016-05-18 11:14:53.667 DEBUG 22312---[nio-9999-exec-9]W.C.httpsessionSecurityContextRepository:SecurityContext为空或内容为匿名-上下文将不会存储在HttpSession中。

OAuth2ServerConfiguration中的代码:

   @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(“AuthorizationRequest”)@EnableAutoConfiguration()@EnableConfigurationProperties({authProperties.class})公共类MainAuthserverApplication扩展WebMvcConfigurerAdapter{

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

共有1个答案

申屠飞
2023-03-14

我自己已经修复了这个问题:

看来这两种方法都得在一个档次上:

@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);
    }
}
 类似资料:
  • “入门Spring Security and Angular JS系列”中的oauth2 JWT项目有一个自定义登录名。为自定义登录页面添加相同的代码到oauth2-vanilla项目失败,因为登录响应中的授权代码始终为空。我还尝试将Sparklr2(https://github.com/spring-projects/spring-security-oauth/tree/master/sampl

  • 请参考一些wordpress post登录插件。我有3页的网站主页,关于正常工作和工作安全,我想显示工作安全页面,如果用户登录有电子邮件/只是虚拟id,我可以生成。找不到此登录模块的插件。带有自定义页面的自定义菜单 使用这个脚本,我可以创建菜单,但不能重定向单独的页面 函数my_wp_nav_menu_args($args=''){ 如果(用户是否已登录){ }否则{ } } 添加过滤器(“wp\

  • 我在我的JSF应用程序中使用容器管理的安全性,因此我有一个低于默认设置的登录页面。 现在在登录页面中,我想在登录按钮旁边添加一个按钮,以允许用户注册。 但我该如何将其转发到我的登记簿。我的注册按钮的xhtml页面?我用以下代码进行了尝试: 我也尝试将表单更改为h: form,以便我可以使用p:命令按钮,但正如我注意到的,我的登录页面不工作,当我单击提交按钮时什么也没有发生。 如何实现我想做的事?

  • 有人能告诉我一些资源吗?这些资源可以指导我如何实现一个定制的Spring Security身份验证,首先在ldap服务器上测试找到的用户的凭据,如果该用户的ldap用户名字段存在,如果无法进行身份验证(可能是因为ldap用户名不存在,或者给定的密码没有对服务器上的用户名进行身份验证),则会尝试根据本地数据库中散列的用户本地密码进行身份验证。 非常感谢。

  • 而且,再一次,即使键入正确的凭据,正如我在“userDetailsService”方法中指定的那样,我也无法登录,但这次我终于可以在控制台上看到错误消息: 显然我走了,但没有离开这个地方,因为现在我不知道我的代码有什么问题...

  • 我想知道我应该如何创建我自己的自定义登录页面?我尝试了https://docs.spring.io/spring-security/site/docs/current/guides/html5/form-javaconfig.html和http://www.baeldung.com/spring-mvc-tutorial#configviews等指南,但没有任何效果,因为我似乎无法使类工作。我一直