Java-webapp(war)에서 정적 콘텐츠에 HTTP 인증을 어떻게 사용할 수 있나요?

StackOverflow https://stackoverflow.com/questions/825142

문제

Java-webapp이 있습니다.웹앱은 war 파일로 패키지됩니다.이러한 war 파일은 HTTP를 통해 직접 전달되는 정적 콘텐츠를 허용합니다.이 전쟁에서 서블릿의 경우 HTTP 인증을 수행할 수 있습니다(서블릿 자체로 구현).하지만 정적 콘텐츠에 대한 HTTP 인증도 원합니다.이것을 어떻게 깨달을 수 있습니까?

도움이 되었습니까?

해결책

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>

다른 팁

정적 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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top