srang Posted March 13, 2015 Posted March 13, 2015 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 Posted March 20, 2015 Author Posted March 20, 2015 So weirdly enough I solved this problem by switching from spring rest template to apache HttpClient and it completely solved the problem for me.
zhitao_yan Posted January 21, 2016 Posted January 21, 2016 could you please detail what you have done for this?thanks in advance
srang Posted January 27, 2016 Author Posted January 27, 2016 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]
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now