0

Spring Web とセキュリティ 3.1 を実行しています。セキュア エリア内のセキュア エリアから別のローカル ページをダウンロードする必要があります。次のコードがあるとします。

@Controller
@RequestMapping("/secure")
public class SecureArea {

    @RequestMapping("/downloadMe.xhtml")
    public String downloadMe(HttpServletRequest request, HttpServletResponse response) throws Exception {
        // do stuff
        return "myJsp";
    }

    @RequestMapping("/viewStuff")
    public void viewStuff(HttpServletRequest request, HttpServletResponse response) throws Exception {
        InputStream in = (new URL("http://"+request.getServerName()+":"+request.getServerPort()+"/secure/downloadMe.xhtml").openStream());
        // read the input stream and do stuff with it, obviously returns my 401 page
    }
}

春のセキュリティのため、viewStuff メソッドは /downloadMe.xhtml ページを表示できません。リクエストのセキュリティ認証情報を新しいリクエストに入れ、downloadMe.xhtml をダウンロードする方法はありますか。

*この方法または同じ結果が得られる同様の方法で行う必要があります。単に downloadMe(request, response) を呼び出すことはできません。myJsp から返されたデータとそれに付随するすべてのロジックが必要です。

4

1 に答える 1

1

私自身の質問を解決しました!リクエストで JSESSIONID を Cookie として渡すことで、これを機能させることができました。私の質問のコードから行くと、次のようになります。

@Controller
@RequestMapping("/secure")
public class SecureArea {

    @RequestMapping("/downloadMe.xhtml")
    public String downloadMe(HttpServletRequest request, HttpServletResponse response) throws Exception {
        // do stuff
        return "myJsp";
    }

    @RequestMapping("/viewStuff")
    public void viewStuff(HttpServletRequest request, HttpServletResponse response) throws Exception {
        URL url = new URL("http://"+request.getServerName()+":"+request.getServerPort()+"/secure/downloadMe.xhtml");
        URLConnection con = url.openConnection();
        con.setDoOutput(true);
        // attach the session ID in the request
        con.setRequestProperty("Cookie", "JSESSIONID="+request.getSession().getId());
        con.connect();

        InputStream in = con.getInputStream();  
        // read the input stream and do stuff with it, obviously returns my 401 page
    }
}
于 2013-08-17T22:54:17.043 に答える