java - 确认 oauth2 批准流程后,service/oauth/authorize 中的主体为空(approveR Deny 中的 http post)

标签 java spring-security-oauth2

我正在使用 spring security oauth2 批准页面,当我授权请求时,该页面会作为“post”发送到“/oauth/authorize”(AuthorizationEndpoint 类中的approveOrDeny 方法),但是此服务的参数之一为 null,这将是“主要”。

spring oauth 页面,当我点击授权时 (/image/aCIKZ.jpg)

有人知道为什么这个参数(Principalprincipal)为空吗?

这是 spring 方法,其主体为 null

    public View approveOrDeny(@RequestParam Map<String, String> approvalParameters, Map<String, ?> model,
            SessionStatus sessionStatus, Principal principal) {

        if (!(principal instanceof Authentication)) {
            sessionStatus.setComplete();
            throw new InsufficientAuthenticationException(
                    "User must be authenticated with Spring Security before authorizing an access token.");
        }

         ...
         ...

最佳答案

我发现了问题,我有一个扩展 DefaultRedirectResolver 的类,并且在我调用的重写方法中resolveRedirect SecurityContextHolder.clearContext()

只需删除 SecurityContextHolder.clearContext() 即可填充主体。

关于java - 确认 oauth2 批准流程后,service/oauth/authorize 中的主体为空(approveR Deny 中的 http post),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58450340/

相关文章:

java - JMS 有队列查看的概念吗?

spring-security-oauth2 - 用于 Postgres 的 Spring Security Oauth2 SQL 模式?

java - 在没有servlet api的webflux项目中使用OAuth2与Spring Security OAuth2和reactor netty

java - 如何用 jetty.port 覆盖 jetty.xml

java - Spring security中使用rest服务进行身份验证和授权

Spring Boot - 使用 JWT、OAuth 以及单独的资源和身份验证服务器

spring - 从 Spring 4.3 升级到 5.0 后 Spring Security OAuth 中的 "NoClassDefFoundError: org/springframework/web/method/HandlerMethodSelector"

java - 尝试用数据填充 View 时 AsyncLayoutInflater 崩溃

java - 绑定(bind)到 Maven 中的生命周期不适用于故障安全和集成测试

java - 一个迭代器,它改变并返回相同的对象。不好的做法?