在Alfresco中测试外部SSO

时间:2013-04-19 07:18:49

标签: single-sign-on alfresco alfresco-share

我将露天配置为使用外部SSO。 现在尝试通过在jsp页面中编写一个简单的java代码来测试它。 代码在这里发布;

        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); 
        %>

输出结果如下:

        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.

但是在通过response.sendRedirect(newUrl)重定向时; ,      它再次询问用户名和密码。我怎么能避免这个?     需要在此处获取登录用户的主页。

0 个答案:

没有答案