Jump to content
We've recently updated our Privacy Statement, available here ×

Getting http cookie using PreAuth Token


srang

Recommended Posts

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)?

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

  • 10 months later...

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;[/code]

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    }[/code]
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...