웹 컨테이너에서 JAX-RS 애플리케이션 보안 설정
웹 컨테이너에서 사용 가능한 보안 서비스를 사용하여 REST(Representational State Transfer) 자원을 보안 설정할 수 있습니다. 역할 맵핑에 대해 사용자 인증, 전송 보안, 권한 제어 및 사용자를 정의하는 보안 메커니즘을 구성할 수 있습니다.
시작하기 전에
보안 제한조건을 올바르게 정의하려면 애플리케이션 및 애플리케이션이 노출시키는 RESTful 자원에 익숙해야 합니다. 이러한 지식을 통해 애플리케이션 및 애플리케이션이 노출시키는 개별 자원에 필요한 적합한 보안 역할을 판별할 수 있습니다.
REST 애플리케이션을 보안 설정하는 방법을 보여주기 위해 이 주제에서는 AddressBookApp이라고 하는 샘플 REST 애플리케이션을 사용합니다.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app id="WebApp_1255468655347">
<display-name>Sample REST Web Application</display-name>
<servlet>
<servlet-name>AddressBookApp</servlet-name>
<servlet-class>com.ibm.websphere.jaxrs.server.IBMRestServlet</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.test.AddressBookApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AddressBookApp</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
이 예제에서 서블릿 맵핑은
REST 자원이 /app_root_context/rest 디렉토리에서 제공됨을 나타냅니다.
여기서, app_root_context는 애플리케이션 설치 중 구성한
것입니다. 기본 루트 컨텍스트는 /입니다. WebSphere Application Server에 대해 보안을 사용으로 설정해야 합니다.
이 태스크 정보
웹 컨테이너를 사용하여 인증 및 권한 부여 제한조건을 애플리케이션 서버 환경에서 실행되고 있는 REST 애플리케이션에 적용할 수 있습니다. 인증은 최소 레벨의 보안이 필요하고 호출자의 ID를 기반으로 하여 추가로 보호해야 하는 비즈니스 REST 자원의 기본 보안 요구사항입니다.
- 사용자는 HTTP 기본 인증 또는 양식 로그인을 사용하여 애플리케이션에 대해 인증해야 합니다.
- REST 자원 호출 시 전송에 SSL 채널을 사용하도록 애플리케이션을 구성합니다.
- REST 자원 패턴에서 역할 기반 권한 부여 제한조건을 정의합니다.
- 사용자 ID 및 역할을 판별하기 위해 어노테이션이 있는 SecurityContext 오브젝트의 프로그래밍 방식 사용을 구현합니다.
프로시저
결과
보안 제한조건을 정의한 후 애플리케이션에서 정의되는 REST 자원에 대한 액세스는 사용자 인증에 성공한 경우에만 가능합니다. 또한 다양한 자원 URL 패턴에 역할 제한조건을 적용했으므로 이러한 자원에 대한 역할 기반 액세스가 가능합니다.
예
<web-app id="WebApp_1255468655347">
<display-name>Sample REST Web Application</display-name>
<servlet>
<servlet-name>AddressBookApp</servlet-name>
<servlet-class>com.ibm.websphere.jaxrs.server.IBMRestServlet</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.test.AddressBookApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AddressBookApp</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<security-constraint id="SecurityConstraint_1">
<web-resource-collection id="WebResourceCollection_1">
<web-resource-name>AddressBookApp</web-resource-name>
<description>Protection area for Rest Servlet</description>
<url-pattern>/rest/addresses</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint id="AuthConstraint_1">
<description>Role1 for this rest servlet</description>
<role-name>Role1</role-name>
</auth-constraint>
<user-data-constraint id="UserDataConstraint_1">
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<security-constraint id="SecurityConstraint_2">
<web-resource-collection id="WebResourceCollection_2">
<web-resource-name>AddressBookApp</web-resource-name>
<description>Protection area for Rest Servlet</description>
<url-pattern>/rest/addresses/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint id="AuthConstraint_2">
<description>Role2 for this rest servlet</description>
<role-name>Role2</role-name>
</auth-constraint>
<user-data-constraint id="UserDataConstraint_1">
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<security-role id="SecurityRole_1">
<description>This is Role1</description>
<role-name>Role1</role-name>
</security-role>
<security-role id="SecurityRole_2">
<description>This is Role2</description>
<role-name>Role2</role-name>
</security-role>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/logon.jsp</form-login-page>
<form-error-page>/logonError.jsp</form-error-page>
</form-login-config>
</login-config>
</web-app>
다음에 수행할 작업
관리 콘솔을 사용하여 JAX-RS 애플리케이션에 대한 보안을 관리할 수 있습니다.