【发布时间】:2020-05-12 17:00:11
【问题描述】:
【问题讨论】:
-
请检查我对另一个类似问题的回答 - 可能对一些人有所帮助...stackoverflow.com/a/66107609/57033
标签: java spring-boot principal
【问题讨论】:
标签: java spring-boot principal
这样的东西可以工作。获得这些属性总是有点讨厌。
@RequestMapping("/user")
public void user(Authentication authentication) {
LinkedHashMap<String, Object> properties = (LinkedHashMap<String, Object>) authentication.getDetails();
String loginProperty = properties.get("login");
//Do what you want to do with your property
}
【讨论】:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: Current user principal is not of type [org.springframework.security.oauth2.provider.OAuth2Authentication]: org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken@28f0d859: Principal: Name: [...], Granted Authorities: [[...]], User Attributes: [{...}]
Unchecked cast: 'java.lang.Object' to 'java.util.LinkedHashMap<java.lang.String,java.lang.Object>' 并返回 properties.get("login"); Incompatible types. Required: org.springframework.security.core.Authentication Found: java.lang.ObjectCannot resolve method 'getUserAuthentication()'