웹 애플리케이션용 프로그램 보안 API 개발

이 정보를 사용하면 웹 애플리케이션을 위해 API를 프로그래밍 방식으로 보안할 수 있습니다.

시작하기 전에

프로그램 보안은 선언적 보안 단독으로는 애플리케이션의 보안 모델을 표시하기에 충분하지 않는 경우에 보안 인지 애플리케이션에 의해 사용됩니다.

인증, 로그인, 로그아웃, getRemoteUser, isUserInRole 및 getAuthType 서블릿 보안 메소드는 javax.servlet.http.HttpServletRequest 인터페이스의 메소드입니다. 이러한 서블릿 보안 메소드에 대한 보다 자세한 정보는 서블릿 보안 메소드 기사를 읽으십시오.
참고:

로그아웃, 로그인 및 인증 API는 WebSphere® Application Server의 이 릴리스에서 Java™ Servlet 3.0의 새로운 사항입니다.

웹 클라이언트가 보호 및 보호되지 않은 URI(Uniform Resource Identifier)와 상호 작용하는 방법을 판별하는 웹 인증의 몇몇 옵션을 구성할 수 있습니다. 또한 WebSphere Application Server가 HTTPS 클라이언트의 인증서 인증이 실패하는 경우 웹 클라이언트에서 기본 인증 정보를 확인하는지 여부를 지정할 수 있습니다. 자세한 정보는 인증 메커니즘 선택 기사를 참조하십시오.

[z/OS]어떤 프린시펄 클래스가 이러한 셀에 의해서 보호되는지를 나타내기 위해 로그인 모듈을 사용 가능으로 설정할 수 있습니다. 자세한 정보는 JAAS(Java Authentication and Authorization Service) 로그인 모듈을 사용하여 레지스트리 프린시펄을 SAF(System Authorization Facility) 사용자 ID에 맵핑에 대한 주제를 참조하십시오.

isUserInRole 메소드가 사용되면 이 메소드에 전달되는 역할 이름을 포함하는 role-name 하위 요소를 사용하여 배치 디스크립터에서 security-role-ref 요소를 선언하거나 @DeclareRoles 어노테이션을 사용하십시오. 애플리케이션의 어셈블리 단계 동안에 실제 역할이 작성되면 논리 역할을 역할 이름으로서 사용하고 해당 역할을 실제 역할에 링크하기 위해 security-role-ref 요소의 설명에 어셈블러에 대한 충분한 힌트를 제공할 수 있습니다. 어셈블리 동안에 어셈블러는 role-link 하위 요소를 작성하여 역할 이름을 실제 역할에 링크합니다. Rational® Application Developer 등과 같은 어셈블리 도구가 사용되는 경우에는 security-role-ref 요소 작성이 가능합니다. 어셈블리 도구를 사용하여 어셈블리 단계 동안에 security-role-ref 요소를 작성할 수도 있습니다.

프로시저

  1. 서블릿 코드에서 필수 보안 메소드를 추가하십시오.
  2. role-name 필드를 사용하여 security-role-ref 요소를 작성하십시오. 개발 동안에 security-role-ref 요소가 작성되지 않은 경우에는 어셈블리 단계 동안에 작성되는지 확인하십시오.

결과

프로그래밍 방식으로 보안된 서블릿 애플리케이션.

이러한 단계는 애플리케이션을 프로그램으로 보안하기 위해 필요합니다. 이 조치는 웹 애플리케이션이 외부 자원에 액세스해야 하고 자체 권한 부여 테이블을 사용하여 외부 자원에 대한 액세스를 제어하고 싶은 경우(external-resource 대 remote-user 맵핑)에 특히 유용합니다. 이 경우 getUserPrincipal 또는 getRemoteUser 메소드를 사용하여 원격 사용자를 가져온 다음 애플리케이션은 자체 권한 부여 테이블을 참조하여 권한 부여를 수행할 수 있습니다. 원격 사용자 정보는 또한 데이터베이스 등과 같은 외부 소스 또는 엔터프라이즈 Bean으로부터 해당하는 사용자 정보를 검색하는 데 도움이 될 수도 있습니다. isUserInRole 메소드를 유사한 방법으로 사용할 수 있습니다.
개발 후에 security-role-ref 요소를 작성할 수 있습니다.
<security-role-ref>
   <description>Provide hints to assembler for linking this role 
                name to an actual role here<\description>
   <role-name>Mgr<\role-name>
</security-role-ref>
어셈블리 동안 어셈블러는 role-link 요소를 작성합니다.
<security-role-ref>
   <description>Hints provided by developer to map the role 
                name to the role-link</description>
   <role-name>Mgr</role-name>
   <role-link>Manager</role-link>
</security-role-ref>
프로그램 서블릿 보안 메소드를 서블릿 doGet, doPost, doPut 및 doDelete 서비스 메소드 내에 추가할 수 있습니다. 다음 예는 프로그램 보안 API의 사용을 묘사합니다.
public void doGet(HttpServletRequest request, 
HttpServletResponse response) {

   ....
   // to logoff the current user
	 request.logout();
    
   // to login with a new user
   request.login(“bob”,”bobpwd”)

   // to get remote user using getUserPrincipal()
   java.security.Principal principal = request.getUserPrincipal();
   String remoteUser = principal.getName();
 
   // to get remote user using getRemoteUser()
   remoteUser = request.getRemoteUser();

   // to check if remote user is granted Mgr role
   boolean isMgr = request.isUserInRole("Mgr");

   // use this information in any way as needed by 
   // the application 
   ....
                  
}
사용자 ID 및 비밀번호를 사용하여 서블릿 doGet, doPost, doPut 및 doDelete 서비스 메소드 내 프로그램 로그인할 수 있습니다. 다음 예는 프로그램 로그인/로그아웃 API의 사용을 묘사합니다.
public void doGet(HttpServletRequest request, 
HttpServletResponse response) {

   ....
   // to logout the current user. If you are not already authenticate, then no need to call the logout() method.
   request.logout();
    
   // to login with a new user
   request.login(“utle”,”mypwd”)

   // the user utle subject now set on the thread and the LTPA SSO cookie is set in the response
   ....
                  
}
서블릿 doGet, doPost, doPut 및 doDelete 서비스 메소드 내에서 다른 ID로 프로그래밍 방식으로 인증할 수 있습니다. 이 예에서 웹 서블릿이 basicAuth를 사용하기로 구성된 경우에는 웹 서버는 응답 코드 401을 리턴하고, 로그인 프롬프트가 표시되고, 인증하기 위해 사용자 ID와 비밀번호를 입력할 수 있습니다. 다음 예는 프로그램 로그인/로그아웃 API의 사용을 묘사합니다.
public void doGet(HttpServletRequest request, 
HttpServletResponse response) {

   ....
   // to logout the current user. If you are not already authenticate, then no need to call the logout() method.
    
   // to login with a new user
   request.authenticate(response);

   // the new user subject now set on the thread and the LTPA SSO cookie is set in the response
   ....
                  
}
서블릿 3.0 모듈을 개발할 때 isCallerInRole 메소드에서 rolename 요소의 값은 배치 디스크립터에서 security-role-ref 요소를 선언하는 대신에 Java 어노테이션을 사용하여 정의될 수 있습니다.
@javax.annotation.security.DeclareRoles("Mgr")
public void doGet(HttpServletRequest request, 
HttpServletResponse response) {

   ....

   // to get remote user using getUserPrincipal()
   java.security.Principal principal = request.getUserPrincipal();
   String remoteUser = principal.getName();
 
   // to get remote user using getRemoteUser()
   remoteUser = request.getRemoteUser();

   // to check if remote user is granted Mgr role
   boolean isMgr = request.isUserInRole("Mgr");

   // use this information in any way as needed by 
   // the application 
   ....
                  
}

다음 예는 프로그램 보안 모델을 사용하는 웹 애플리케이션 및 서블릿을 묘사합니다.

이 예는 프로그램 보안 모델의 유일한 용도일 필요는 없는 하나의 용도를 설명합니다. 애플리케이션은 해당 애플리케이션에 의미 있는 다른 어떤 방법을 사용하여 getUserPrincipal, isUserInRole 및 getRemoteUser 메소드가 리턴하는 정보를 사용할 수 있습니다. 가능할 때마다 선언적 보안 모델을 사용하십시오.

파일 : HelloServlet.java

public class HelloServlet extends javax.servlet.http.HttpServlet {

	public void doPost(
		javax.servlet.http.HttpServletRequest request,
		javax.servlet.http.HttpServletResponse response)
		throws javax.servlet.ServletException, java.io.IOException {
	}
public void doGet(
		javax.servlet.http.HttpServletRequest request,
		javax.servlet.http.HttpServletResponse response)
		throws javax.servlet.ServletException, java.io.IOException {
			
        String s = "Hello";
  	
        	
        // get remote user using getUserPrincipal()
        java.security.Principal principal = request.getUserPrincipal();
        String remoteUserName = "";
        if( principal != null )
         	remoteUserName = principal.getName();
// get remote user using getRemoteUser()
        String remoteUser = request.getRemoteUser();

        // check if remote user is granted Mgr role
        boolean isMgr = request.isUserInRole("Mgr");

        // display Hello username for managers and bob. 
        if ( isMgr || remoteUserName.equals("bob") )
            s = "Hello " + remoteUserName;

		 String message =  "<html> \n" +
            		"<head><title>Hello Servlet</title></head>\n" +
      			"<body> /n +"
				"<h1> "  +s+ </h1>/n " + 
		byte[] bytes = message.getBytes();
		
		// displays "Hello" for ordinary users 
        // and displays "Hello username" for managers and "bob".
        response.getOutputStream().write(bytes);
	}

}
서블릿을 개발한 후 다음 예에 표시된 대로 HelloServlet 서블릿의 보안 역할 참조를 작성할 수 있습니다.
<security-role-ref>
     <description> </description>
     <role-name>Mgr</role-name>
</security-role-ref>

다음에 수행할 작업

애플리케이션을 개발한 후 어셈블리 도구를 사용하여 역할을 작성하고 security-role-ref 요소에서 실제 역할을 역할 이름에 링크할 수 있습니다. 어셈블리 도구를 사용하여 웹 애플리케이션 보안에 대한 자세한 정보를 참조하십시오.

주제 유형을 표시하는 아이콘 태스크 주제



시간소인 아이콘 마지막 업데이트 날짜: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=tsec_web
파일 이름:tsec_web.html