7

JSF と PrettyFaces は初めてです。だから今では、リクエストを正しい.xhtmlファイルに「転送」するようにPrettyFacesを構成できることがわかりました。問題は、私 (またはユーザーが私のフォルダー構造を知っている場合) もファイルを要求できることです。これは私のサンプルです:

ファイル: webbapp/mypage.xhtml

次の行を pretty-config.xml に追加しました。

<url-mapping id="myPageId">
    <pattern value="/prettyurltomypage" />
    <view-id value="/mypage.xhtml" /> 
</url-mapping>

PrettyFaces フィルターは、「/ 」でインターセプトするように構成されています。Faces Front Controller は、すべての「 .xhtml」リクエストを処理するように構成されています。お願いしたら…

http://localhost:8080/myapp/prettyurltomypage

・・・なんでもいいです。私の問題は、私もリクエストできることです...

http://localhost:8080/myapp/mypage.xhtml

.xhtml リクエストを制限するにはどうすればよいですか? 私の目標は、jsf/server がデフォルトの 404 ページを配信するようにすることです。

私の解決策 (これまでのところ) は、pretty-config.xml で書き換えルールを定義することでした。

<rewrite match="/mypage.xhtml" substitute="/prettyurltomypage" redirect="301" />

他の(よりスマートな)方法はありますか?

4

3 に答える 3

6

これは、デプロイメント記述子で XHTML ファイルを Web リソースとしてマークすることで実行できます。
これを行うには、次のようなものをweb.xmlに追加します。

<security-constraint>
    <display-name>Restrict direct access to XHTML files</display-name>
    <web-resource-collection>
        <web-resource-name>XHTML files</web-resource-name>
        <url-pattern>*.xhtml</url-pattern>
    </web-resource-collection>
    <auth-constraint/>
</security-constraint>

セキュリティ上の制約について詳しく知りたい場合は、Javalobby に関する簡単な記事があります。

于 2011-08-03T13:51:51.483 に答える
3

ええ、直接ページへのアクセスをブロックしたいだけなら、カスタム セキュリティ パッケージのようなものを使わずに行くのがおそらく最善の方法です。実際には、faces サーブレット マッピングを .xhtml に変更するだけで済みます。これは、人々がページにアクセスしたときにソースが公開されないことを意味します。

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
</servlet-mapping>

ページを実際にロックダウンするために、より複雑な書き換えルールを実行したい場合は、カスタムの書き換えプロセッサを使用して Processor インターフェースを実装することを検討できます。

http://ocpsoft.com/docs/prettyfaces/3.3.0/en-US/html_single/#inbound_rewriting.options

カスタム プロセッサは HttpServletRequest と HttpServletResponse にアクセスでき、インバウンドとアウトバウンドの両方のリライトで呼び出します。このインターフェイスを使用すると、より複雑なことを行うことができます。

/**
 * Perform a rewrite operation on a given URL, utilizing any necessary information from the given {@link RewriteRule}
 * configuration object from which the processor was invoked.
 * 
 * @author Lincoln Baxter, III <lincoln@ocpsoft.com>
 */
public interface Processor
{
   /**
    * Process an inbound URL Rewrite request. This takes place when the request first comes in to the server and passes
    * through {@link RewriteFilter}
    */
   String processInbound(HttpServletRequest request, HttpServletResponse response, RewriteRule rule, String url);

   /**
    * Process an outbound URL Rewrite request. This takes place when a URL is passed in to
    * {@link HttpServletResponse#encodeRedirectURL(String)}, and since most frameworks ensure the call to
    * 'encodeRedirectUrl()' occurs automatically, can be assumed to occur whenever a URL would be rendered to HTML
    * output.
    */
   String processOutbound(HttpServletRequest request, HttpServletResponse response, RewriteRule rule, String url);
}

それ以外の場合は、OCPSoft Rewrite https://github.com/ocpsoft/rewrite ( PrettyFaces の背後にもいる) がリリースされるまで、あなたがしていることはうまくいきます。

package com.example;
public class ExampleConfigurationProvider extends HttpConfigurationProvider
{

   @Override
   public int priority()
   {
     return 10;
   }

   @Override
   public Configuration getConfiguration(final ServletContext context)
   {
     return ConfigurationBuilder.begin()
       .defineRule()
         .when(Direction.isInbound().and(DispatchType.isRequest()).and(Path.matches(".*\\.xhtml")).andNot(Path.matches(".*javax.faces.resource.*")))
         .perform(SendStatus.code(404));
    }
}

この書き換えルールは、.XHTML ファイルのインバウンド HTTP 要求へのアクセスをブロックしますが、転送、エラー、または非同期要求は引き続き許可します。また、JSF2 リソース API を機能状態のままにします。これは、別の回答で提案されているように Java EE セキュリティ制約を使用する場合には当てはまりません。

これが役に立てば幸いです、リンカーン

于 2011-08-03T20:40:09.477 に答える
0

次の問題を参照してください: http ://code.google.com/p/prettyfaces/issues/detail?id = 116

これがお役に立てば幸いです

于 2011-08-03T13:01:14.880 に答える