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)?
3 Answers:
Posted on January 27, 2016 at 11:25am
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 }