java - Spring RestTemplate unable to get JSESSIONID cookie -
in spring boot/spring security application i'm trying login spring resttemplate.
this code:
final keystore keystore = keystore.getinstance("pkcs12"); keystore.load(new fileinputstream(new file("keystore.p12")), "changeit".tochararray()); final sslcontext sslcontext = new sslcontextbuilder().loadtrustmaterial(null, new trustselfsignedstrategy()).loadkeymaterial(keystore, "changeit".tochararray()).build(); final sslconnectionsocketfactory socketfactory = new sslconnectionsocketfactory(sslcontext, noophostnameverifier.instance); final httpclient httpclient = httpclientbuilder.create().setsslsocketfactory(socketfactory).setredirectstrategy(new laxredirectstrategy()).build(); final clienthttprequestfactory requestfactory = new httpcomponentsclienthttprequestfactory(httpclient); final resttemplate resttemplate = new resttemplate(requestfactory); final httpheaders headers = new httpheaders(); headers.add("cookie", "jsessionid=" + loginresponse.getjsessionid()); headers.add("x-xsrf-token", loginresponse.getcsrf()); final multivaluemap<string, string> body = new linkedmultivaluemap<string, string>(); body.add("username", "username"); body.add("password", "password"); final httpentity<?> requestentity = new httpentity<object>(body, headers); final responseentity<string> responseentity = resttemplate.exchange("https://localhost:" + port + "/api/login", httpmethod.post, requestentity, string.class);
this i'm receiving in responseentity
headers:
server = [apache-coyote/1.1] x-content-type-options = [nosniff] x-xss-protection = [1; mode=block] cache-control = [no-cache, no-store, max-age=0, must-revalidate] pragma = [no-cache] expires = [0] strict-transport-security = [max-age=31536000 ; includesubdomains] set-cookie = [xsrf-token=cf1968b0-068b-455b-be8f-10e39e0e44a4; path=/] x-application-context = [application:0] content-type = [text/plain;charset=iso-8859-1] content-length = [12] date = [thu, 21 apr 2016 19:32:34 gmt]
as can see - there xsrf-token
cookie no jsessionid
.
i think possible issue can in redirect after successful authentication @ https://localhost/api/login https://localhost/api/
what doing wrong ? how receive jsessionid
cookie ?
i have fixed issue following statefulresttemplate
Comments
Post a Comment