2017-07-29 6 views
0

イメージが要求されたときに別のURLにリダイレクトするHTTPフィルタを開発していますが、私はすべての画像を保存するためにAEM DAMを使用しています。だから、コードをローカルの画像を要求すると、コードがダムとのログインにリダイレクトする必要がありますが、それが実装されているように私は、コードを使用してログインすることはできません。HTTPサーブレットの要求が別のURLにリダイレクトされ、Javaで自動的にログインする

@Override 
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) 
     throws IOException, ServletException { 

    HttpServletRequest req = (HttpServletRequest) request; 
    // ==> /images/path/my-image.png 
    // ==> /path1/path2/image.pngs 
    String servletPath = req.getServletPath(); 

    // The path to the root directory of the webapp (WebContent) 
    //String realRootPath = request.getServletContext().getRealPath(""); 
    String realRootPath = "http://localhost:4502/crx/de/index.jsp#/content/dam/"; 

    // Real path of Image. 
    String imageRealPath = realRootPath + servletPath; 

    System.out.println("imageRealPath = " + imageRealPath); 

    File file = new File(imageRealPath); 

    // Check image exists. 
    if (file.exists()) { 
     // Go to the next element (filter or servlet) in chain 
     chain.doFilter(request, response); 
    } else if (!servletPath.equals(this.notFoundImage)) { 
     // Redirect to 'image not found' image. 
     HttpServletResponse resp = (HttpServletResponse) response; 
     // ==> /ServletFilterTutorial + /images/image-not-found.png 
     resp.sendRedirect(req.getContextPath()+ this.notFoundImage); 
    } 
} 
+0

_crx/de/index.jsp#_は_realRootPath_で正しく表示されません。 AEMまたは別のアプリケーションでフィルタを開発していますか?最初のケースでは、サービスリソースリゾルバを使用して、DAMアセットを読み取り、応答してイメージデータを返す適切な権利を持つSlingFilterを記述することができます。 2番目のケースでは、AEMは[cURL](http://www.aemcq5tutorials.com/tutorials/adobe-cq5-aem-curl-commands/)と対応する[Java実装](https: //stackoverflow.com/questions/3283234/http-basic-authentication-in-java-using-httpclient)を使用してアセットにアクセスします。 –

答えて

0

AEM supports基本認証。したがって、DAMアセットURLを呼び出しているときに、ユーザー名/パスワードを渡します。

byte[] authEncBytes = Base64.encodeBase64("admin:admin".getBytes()); 
String authStringEnc = new String(authEncBytes);   
URL url = new URL("http://localhost:4502/content/dam/myassets/test.jpg"); 
     URLConnection urlConnection = url.openConnection(); 
     urlConnection.setRequestProperty("Authorization", "Basic " + 
     authStringEnc); 
     InputStream is = urlConnection.getInputStream(); 
関連する問題