SAMLResponse null in ACS request url :using onelog

2019-09-13 19:28发布

I am using Onelogin 2.0 toolkit . Instead of having Login and ACS as jsp files I have added them as rest services. I am getting this error when my IdP redirects to ACS Service Url.

SAML Response not found, Only supported HTTP_POST Binding

In request to ACS service SAMLResponse parameter is coming as null. How can I fix this ?

@Path("/saml")
public class SAMLAuthService {
    @Context
    HttpServletRequest request;

    @Context
    HttpServletResponse response;

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/dologin")
    public void SAMLLogin(){
        try {
            Auth auth = new Auth(CommonUtils.samlPropertyFileName,request, response);
            System.out.println("Calling SAML Login::");
            auth.login();
        } catch (Exception e) {
            e.printStackTrace();

        }
    }

    @POST
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/acs")
    public Response SAMLACS()
            throws ExecException {
        Response samlResponse = null;
        try {
            System.out.println("Calling SAML ACS::");
            Auth auth = new Auth(CommonUtils.samlPropertyFileName,request, response);
            auth.processResponse();
            if (!auth.isAuthenticated()) {
                System.out.println("Not Authenticated");
            }

            List<String> errors = auth.getErrors();
            if (!errors.isEmpty()) {
                if (auth.isDebugActive()) {
                    String errorReason = auth.getLastErrorReason();
                    if (errorReason != null && !errorReason.isEmpty()) {
                        System.out.println(errorReason);
                    }
                }
            } else {
                Map<String, List<String>> attributes = auth.getAttributes();
                String nameId = auth.getNameId();
                System.out.println("NameId::"+nameId);
                if (attributes.isEmpty()) {
                    System.out.println("No Attributes");
                }
                else {
                    Collection<String> keys = attributes.keySet();
                    for(String name :keys){
                        List<String> values = attributes.get(name);
                        System.out.println(name+"::");
                        for(String value :values) {
                            System.out.print(value);
                        }

                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return samlResponse;
    }

}

1条回答
smile是对你的礼貌
2楼-- · 2019-09-13 20:28

The Auth constructor that you are using expects a HttpServletRequest request object with a SAMLResponse POST parameter

If you don't have that HttpServletRequest object, you can build it using the makeHttpRequest

You can use the SAML Tracer to analyze the SAML flow between the IdP and the SP. You may be sure that the IdP is sending a SAMLResponse. I'm not familiar with the "Rest approach" you are using, but you may see the way to get the SAMLResponse and build the HttpServletRequest object injecting that parameter.

查看更多
登录 后发表回答