2

私はJava-webappを持っています。webappはwarファイルとしてパッケージ化されています。これらのwarファイルは、HTTPを介して直接配信される静的コンテンツを許可します。この戦争のサーブレットの場合、HTTP認証を行うことができます(サーブレット自体で実装します)。ただし、静的コンテンツのHTTP認証も必要です。どうすればこれを実現できますか?

4

2 に答える 2

3

静的htmlファイルをディレクトリに配置し、web.xmlでセキュリティ制約を定義します。制約を適切な役割にマップします。

<security-constraint>
        <display-name>securedResources</display-name>
        <web-resource-collection>
            <web-resource-name>securedRes</web-resource-name>
            <url-pattern>/secured/*</url-pattern>
            <http-method>GET</http-method>
            <http-method>PUT</http-method>
            <http-method>HEAD</http-method>
            <http-method>TRACE</http-method>
            <http-method>POST</http-method>
            <http-method>DELETE</http-method>
            <http-method>OPTIONS</http-method>
        </web-resource-collection>
        <auth-constraint>
            <description>
            authenticatedUser_securedRes</description>
            <role-name>authenticatedUsed</role-name>
        </auth-constraint>
    </security-constraint>
于 2009-05-05T16:04:30.073 に答える
2

javax.servlet.Filterを実装するクラスを作成します。フィルタの要点を参照してください

主なメソッドは、ServletRequest、ServletResponse、およびFilterChainオブジェクトに渡されるdoFilterです。ここで認証を実施します。

次に、web.xmlでフィルターを宣言し、フィルターマッピングを次のように宣言します(すべてのリクエストにマップします)

    <filter>
            <filter-name>Authentication Filter</filter-name>
            <filter-class>
                    com.nfsdsystems.security.filters.AuthenticationFilter</filter-class>
    </filter>
    <filter-mapping>
            <filter-name>Authentication Filter</filter-name>
            <url-pattern>/*</url-pattern>
    </filter-mapping>
于 2009-05-05T15:18:40.120 に答える