有一个包含用户权限的 Oauth2Authentication 对象。当我想获得它的权威并将其设置为User对象的权威时,如下所示:
OAuth2Authentication oAuth2Authentication = (OAuth2Authentication) SecurityContextHolder.getContext().getAuthentication();
LinkedHashMap linkedHashMap = (LinkedHashMap) oAuth2Authentication.getUserAuthentication().getDetails();
user.setAuthorities((Set<GrantedAuthority>) oAuth2Authentication.getAuthorities());
引发以下异常:
java.lang.ClassCastException: java.util.Collections$UnmodifiableRandomAccessList 不能 cast to java.util.Set
我该如何修复它?
注:
用户权限对象的类型为Set<GrantedAuthority>
芜湖不芜
相关分类