如何在 play 框架中的 pac4j 中从自定义授权方获取请求正文

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

我正在尝试使用带有 pac4j 的播放框架在我的 Web 应用程序中实现自定义 authorizer。正在调用我的自定义授权方,但我无法使用 WebContext 的

getRequestContent()
方法将请求负载作为字符串访问。它是空的。我能够正确访问请求标头。

我的自定义授权者

package v2;

import org.pac4j.core.authorization.authorizer.ProfileAuthorizer;
import org.pac4j.core.context.WebContext;
import org.pac4j.core.context.session.SessionStore;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.play.PlayWebContext;

import java.util.List;

public class OPAAuthorizer extends ProfileAuthorizer {
    @Override
    public boolean isAuthorized(WebContext context, SessionStore sessionStore, List<UserProfile> profiles) {
        System.out.println(context.getRequestHeader("Authorization"));
        System.out.println(context.getRequestContent());
        return true;
    }

    @Override
    protected boolean isProfileAuthorized(WebContext context, SessionStore sessionStore, UserProfile profile) {
        
        return false;
    }
}

playframework pac4j
1个回答
0
投票

以前,getRequestContent() 方法有一个只能调用一次的错误。它应该在最新的 pac4j 版本中得到修复。 如果是,请在这个方法中打个断点,看看是否为同一个

PlayWebContext
对象调用了多次。

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