single sign on - Testing External SSO in Alfresco -
i configured alfresco use external sso. trying test writing simple java code in jsp page. code posting here;
url url1 = new url("http://localhost:8080/share/page"); httpurlconnection conn = (httpurlconnection) url1.openconnection(); conn.setrequestproperty("x-alfresco-remote-user", "admin"); system.out.println("request url ... " + url1); (int = 0;; i++) { string headername = conn.getheaderfieldkey(i); string headervalue = conn.getheaderfield(i); system.out.println(headername + "==="); system.out.println(headervalue); if (headername == null && headervalue == null) { break; } } string sessionvalue = conn.getheaderfield("set-cookie").substring(0,conn.getheaderfield("set-cookie").indexof(";")); sessionvalue = sessionvalue.substring(sessionvalue.indexof("=")+1); conn.setinstancefollowredirects(false); httpurlconnection.setfollowredirects(false); string newurl = conn.getheaderfield("location"); string cookies = conn.getheaderfield("set-cookie"); // open new connnection again conn = (httpurlconnection) new url(newurl).openconnection(); conn.setrequestproperty("jsessionid", sessionvalue); conn.addrequestproperty("_alftest", "_alftest"); conn.addrequestproperty("_alftest", "_alftest"); conn.addrequestproperty("alfusername3", "admin"); system.out.println("second"); (int = 0;; i++) { string headername = conn.getheaderfieldkey(i); string headervalue = conn.getheaderfield(i); system.out.println(headername + "==="); system.out.println(headervalue); if (headername == null && headervalue == null) { break; } } conn.connect(); dis = new bufferedreader( new inputstreamreader( conn.getinputstream())); while ((mystring = dis.readline()) != null) { system.out.println(mystring); } response.setheader("jsessionid", sessionvalue); response.setheader("_alftest", "_alftest"); response.setheader("alfusername3", "admin"); response.sendredirect(newurl); %> the output getting :
request url ... http://localhost:8080/share/page null=== http/1.1 302 found server=== apache-coyote/1.1 set-cookie=== jsessionid=7f9dcde35b45b91d245e3b544b29f8d2; path=/share/; httponly cache-control=== no-cache location=== http://localhost:8080/share/page/user/admin/dashboard content-type=== text/html;charset=utf-8 content-language=== en-us content-length=== 0 date=== fri, 19 apr 2013 07:03:04 gmt null=== null http://localhost:8080/share/page/user/admin/dashboard second null=== http/1.1 200 ok server=== apache-coyote/1.1 set-cookie=== jsessionid=334d167d21b0910981804ecd14619d66; path=/share/; httponly cache-control=== no-cache content-type=== text/html;charset=utf-8 content-language=== en-us transfer-encoding=== chunked date=== fri, 19 apr 2013 07:03:04 gmt null=== null <!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"> ....... full html content of logged in user home page goes here. but while redirecting response.sendredirect(newurl); , again asking user name , password. how can avoid this? need home page of logged in user here.
Comments
Post a Comment