0

I configured my alfresco to use External SSO. Now trying to test it by writing a simple java code in a jsp page. Code is 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);
        for (int i = 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 the 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");
        for (int i = 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 is getting like :

        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">  ....... the full html content of logged in user home page goes here.

But while redirecting by response.sendRedirect(newUrl); , its again asking user name and password. How can I avoid this? Need to get Home page of logged in user here.

Boat
  • 515
  • 2
  • 8
  • 28
  • 1
    How did you configure the SSO? That bit is quite important to figuring out why it isn't working! – Gagravarr Apr 19 '13 at 08:31
  • Please have a look into https://forums.alfresco.com/forum/installation-upgrades-configuration-integration/authentication-ldap-sso/external-sso-alfresco see the steps which I did. – Boat Apr 19 '13 at 09:54
  • Can you tell me how can I get the ticket here? – Boat Apr 19 '13 at 10:19

0 Answers0