Getting http cookie using PreAuth Token

0

So I've set up my jasper server to accept PreAuth tokens for authentication and I've verified its working by entering the url with token into my browser and getting into the server. However what I really want to do is be able to embed this in an application using the rest api. The problem I've run into is that while the rest/login service always reaturns the Set-Cookie/JSessionID, using a preauth token only sometimes returns the cookie. Is there a way to use preauth token the same way as the login rest service to get the cookie (consistently)?

srang's picture
206
Joined: Oct 28 2014 - 11:52am
Last seen: 3 years 1 month ago

3 Answers:

0

So weirdly enough I solved this problem by switching from spring rest template to apache HttpClient and it completely solved the problem for me.

srang's picture
206
Joined: Oct 28 2014 - 11:52am
Last seen: 3 years 1 month ago
0

could you please detail what you have done for this?

thanks in advance

zhitao_yan's picture
Joined: Mar 25 2015 - 8:07pm
Last seen: 1 year 11 months ago
0

Yeah sure. So what I ended up getting working is using the apache packages for authentication, specifically:

org.apache.http.HttpResponse;
org.apache.http.client.HttpClient;
org.apache.http.client.methods.HttpGet;
org.apache.http.impl.client.DefaultHttpClient;

Using those packages I did something like this:

    public String init(Integer userId) {
        server = cfg.getString("server");
        String target = server + "/";
        String token = reportAuthorizer.buildToken(userId); // builds my preauth token with user id
        String ret = "cookie";
        URI uri = UriComponentsBuilder.fromHttpUrl(target).queryParam("pp", token).build().toUri();
        HttpClient client = new DefaultHttpClient();
        HttpGet req = new HttpGet(uri);
        try {
            HttpResponse resp = client.execute(req);
            ret = resp.getHeaders("Set-Cookie")[0].getValue();
        } catch (IOException e) {
            LOGGER.error("Error with jasper cookie");
            LOGGER.error(e.toString());
        }
        return ret; //sessionid
    }
srang's picture
206
Joined: Oct 28 2014 - 11:52am
Last seen: 3 years 1 month ago
Feedback
randomness