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

Spring Oauth2登录重定向如何工作?

漆雕稳
2023-03-14

我一直在研究Spring Boot Oauth2教程,但似乎找不到一个非常关键的元素:

protected void configure(HttpSecurity http) throws Exception {
    http
      .antMatcher("/**")
      .authorizeRequests()
        .antMatchers("/", "/login**", "/webjars/**")
        .permitAll()
      .anyRequest()
        .authenticated()
        .and().logout().logoutSuccessUrl("/").permitAll()
        .and().csrf().csrfTokenRepository(csrfTokenRepository())
        .and().addFilterAfter(csrfHeaderFilter(), CsrfFilter.class)
        .addFilterBefore(ssoFilter(), BasicAuthenticationFilter.class);
}

我可以通过添加以下内容来让它工作:

        .and().formLogin().loginPage("/")

...但在前进之前,我真的想知道这是否是教程或我的实现或其他问题。Oauth安全系统决定什么是“登录”页面的机制是什么?

共有1个答案

封永嘉
2023-03-14

解决方案是向SecurityConfig.Configure调用添加以下内容:

@Override
protected void configure(HttpSecurity http) throws Exception {
    AuthenticationEntryPoint aep = new AuthenticationEntryPoint() {

        @Override
        public void commence(HttpServletRequest request,
                HttpServletResponse response,
                AuthenticationException authException) throws IOException,
                ServletException {
            response.sendRedirect("/login");
        }
    };

    http.exceptionHandling()
            .authenticationEntryPoint(aep)

它将身份验证流重定向到一个特定的URL(在本例中,我将它发送到“/login”,但它也与“/”或其他我选择的任何东西一起工作)。我不知道如果不显式地添加这一行,教程应该如何进行重定向。

 类似资料:
  • 我在Laravel5.2中使用了php artisan函数。 我想重定向的客人登录页面,若客人点击链接,只有用户并没有客人。 我想在登录后将用户重定向到后面的页面。 我怎么能这么做?请详细展示一些文件名示例。 ///////编辑 路线 控制器 Kernel.php

  • 我正在将DNN应用程序从07.00.02升级到07.03.04并在安装后将所有门户重定向到登录页面。所有门户都配置有一个登陆页面,该页面被配置为允许“所有用户”角色视图访问。还有人在升级后遇到过这个问题吗? 2015-02-05 05:45:01 127.0.0.1 GET/-80-127.0.0.1 Mozilla/5.0+(Windows+NT+6.3;+WOW64)+AppleWebKit/

  • 记录器文件中的日志- org.springframework.Security.Access.event.loggerlistener-安全授权失败,原因是:org.springframework.Security.Access.accessdeniedexception:访问被拒绝;通过身份验证的主体:org.springframework.security.authentication.ano

  • MvcConfig方法如下所示:

  • 我想在成功登录后为特定页面重定向用户。 我不希望用户在登录后导航到上次查看的页面。 我试过以下网址,但它显示我的错误。 错误:

  • Reducer.js 我想在成功登录后重定向/主页。我如何重定向?