ええ、直接ページへのアクセスをブロックしたいだけなら、カスタム セキュリティ パッケージのようなものを使わずに行くのがおそらく最善の方法です。実際には、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 セキュリティ制約を使用する場合には当てはまりません。
これが役に立てば幸いです、リンカーン