Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 为什么OAuth2UserService没有在WebSecurityConfigureAdapter下的Spring引导中运行角色授权?_Spring Boot_Spring Security_Google Oauth_Spring Security Oauth2 - Fatal编程技术网

Spring boot 为什么OAuth2UserService没有在WebSecurityConfigureAdapter下的Spring引导中运行角色授权?

Spring boot 为什么OAuth2UserService没有在WebSecurityConfigureAdapter下的Spring引导中运行角色授权?,spring-boot,spring-security,google-oauth,spring-security-oauth2,Spring Boot,Spring Security,Google Oauth,Spring Security Oauth2,我试图通过以下方式使用Spring安全性实现角色,但我还无法运行OAuth2UserService 这是我拥有的配置文件和OAuth2UserService,它遵循它们的文档。终端打印的是ABC,但不是DEF,因此当我转到页面“/test”作为示例时,它不会运行。我在OAuth2中使用Google标识 身份验证是有效的,但不幸的是,这不起作用。我尝试过使用GrantedAuthoritesMapper和许多其他示例,但同样的情况也发生了 @配置 @启用Web安全性 @EnableGlobalMe

我试图通过以下方式使用Spring安全性实现角色,但我还无法运行OAuth2UserService

这是我拥有的配置文件和OAuth2UserService,它遵循它们的文档。终端打印的是
ABC
,但不是
DEF
,因此当我转到页面“/test”作为示例时,它不会运行。我在OAuth2中使用Google标识

身份验证是有效的,但不幸的是,这不起作用。我尝试过使用
GrantedAuthoritesMapper
和许多其他示例,但同样的情况也发生了

@配置
@启用Web安全性
@EnableGlobalMethodSecurity(securedEnabled=true,Prespenabled=true)
公共类WebSecurityConfig扩展了WebSecurityConfigureAdapter{
@凌驾
受保护的无效配置(HttpSecurity http)引发异常{
http
.注销(l->{
l、 logoutSuccessUrl(“/”).permitAll();})
.授权请求(a->a)
.antMatchers(“/”、“/js/**”、“/css/**”).permitAll()
.antMatchers(“/test”).hasRole(“管理员”)
.anyRequest().authenticated()
)
.csrf(c->c
.csrfTokenRepository(CookieCsrfTokenRepository.WithTpOnlyFalse())
)
.oauth2Login(oauth2->oauth2
.userInfoEndpoint(userInfo->userInfo)
.userService(this.oauth2UserService())
))
);
}
专用OAuth2UserService OAuth2UserService(){
最终DefaultOAuth2UserService委托=新的DefaultOAuth2UserService();
系统输出打印号(“ABC”);
返回(用户请求)->{
系统输出打印项次(“DEF”);
OAuth2User OAuth2User=delegate.loadUser(userRequest);
Set mappedAuthorities=new HashSet();
添加(新的SimpleGrantedAuthority(“角色管理”);
oauth2User=新的默认oauth2User(MappeAuthorities,
oauth2User.getAttributes(),oauth2User.getName();
返回oauth2User;
};
}

非常感谢您的帮助。谢谢。

当您转到页面“/test”时,不会调用
oauth2UserService
,因为它是在身份验证后调用的。是否看到
“DEF”
在用户登录后打印?另外,看起来您没有将正确的参数传递给
DefaultOAuth2User
构造函数。第三个参数是
nameAttributeKey
,用于从属性列表访问用户名的键。相反,您提供的是值,而不是键。