在应用程序中禁用Google登录的弹簧安全性

问题描述 投票:0回答:1

我有一个具有默认级别spring安全性的spring boot应用程序,我使用auth.userDetailsS​​ervice(customuserservice)作为用户身份验证部分。除此之外,我们使用谷歌登录按钮。我的配置文件是

`http
            .authorizeRequests()
            .antMatchers("/","/securitylogin").permitAll()
            .antMatchers("/SecondMainPage")
            .hasAnyRole("SUPERADMIN","ADMIN","USER")
            .anyRequest()
            .authenticated()
            .and()
            .formLogin()
            .loginPage("/securitylogin") //login
            .usernameParameter("username") //optional
            .passwordParameter("password") //optional
            .defaultSuccessUrl("/loggedin")
            .permitAll()
            .and()
            .logout()
            .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
            .logoutSuccessUrl("/")
            .invalidateHttpSession(true)
            .permitAll();`

身份验证部分按预期工作,但不是Google登录部分。在谷歌登录后,我收到电子邮件并从服务器获取他的详细信息并重定向到一个控制器,但控制器重新加载n次。我不知道为什么单一方法会一次又一次地重新加载。

http.antMatcher( “/ loginwithgoogle / **”)匿名();

如果我使用上述行,Google登录部分工作非常好,但正常的登录身份验证无法访问。

web.ignoring()。antMatchers(HttpMethod.POST,“/ loginwithgoogle”);

我也尝试了上面的那个,但同一个控制器一次又一次地重新加载n次。请帮我继续前进。我还缺少其他什么,还是我走错了路?

spring spring-boot authentication spring-security spring-security-oauth2
1个回答
0
投票

实际上我之前尝试过同样的事情,但不知道为什么我没有成功,但以下的事情对我有用,如果对任何人都有帮助,更新相同。

http
            .authorizeRequests()
            .antMatchers("/loginwithgoogle/**").anonymous() //works this order
            .anyRequest().authenticated() // with this line too
            .antMatchers("/","/securitylogin").permitAll()

我不知道是否有单独的订单将在那里,但我分别尝试匿名()但没有工作。以上是完美的。

更新11.09.2018谷歌登录工作正常,但角色无法正常工作(即)用户可以访问管理页面,异常处理无法正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.