0

I am trying to implement a custom authorizer in my web application using play framework with pac4j. My custom authorizer is getting called but I am not able to access request payload as string using WebContext's getRequestContent() method. It is coming as null. I am able to access request headers properly.

My custom authorizer

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;
    }
}

Bill Goldberg
  • 1,699
  • 5
  • 26
  • 50

1 Answers1

0

In the past, there was a bug on the getRequestContent() method which could only be called once. It should be fixed in the latest pac4j versions. If so, please put a breakpoint in this method to see if it is called many times for the same PlayWebContext object.

jleleu
  • 2,309
  • 1
  • 13
  • 9