웹 인증에 JAAS(Java Authentication and Authorization Service) 프로그래밍 모델 사용
WebSphere® 애플리케이션 서버는 Java™ EE(Java Platform, Enterprise Edition) 선언 보안 모델을 지원합니다. Java EE 배치 디스크립터를 사용하여 인증 및 액세스 제어 정책을 정의할 수 있습니다. 사용자 정의 로그인 모듈을 추가로 스택하여 WebSphere 애플리케이션 서버 인증 메커니즘을 사용자 정의할 수 있습니다.
시작하기 전에
이 태스크 정보
LTPA(Lightweight Third-Party Authentication) 메커니즘 싱글 사인온(SSO) 옵션을 사용할 수 있는 경우 로그인 후 LTPA SSO 토큰 쿠키를 사용하여 웹 클라이언트 로그인 세션을 추적합니다. 로그아웃하면 이 토큰이 삭제되어 로그인 세션이 종료됩니다. 그러나 서버측 주제는 삭제되지 않습니다. 선언 보안 모델을 사용하는 경우 WebSphere 애플리케이션 서버 웹 컨테이너는 클라이언트 인증 및 로그인 세션 관리를 자동으로 수행합니다. Java EE 보안 제한 없이 로그인 페이지를 설정하고 클라이언트 요청을 로그인 페이지로 먼저 전송하여 애플리케이션 코드로 인증을 수행할 수 있습니다. 로그인 페이지에서 JAAS(Java Authentication and Authorization Service) 프로그래밍 모델을 사용하여 인증을 수행할 수 있습니다. WebSphere 애플리케이션 서버 웹 로그인 모듈을 사용하여 SSO 쿠키를 생성하려면 다음 단계를 수행하십시오.
프로시저
예
인증을 수행하려면 다음 코드 샘플을 사용하십시오.

Suppose you wrote a LoginServlet.java:
Import com.ibm.wsspi.security.auth.callback.WSCallbackHandlerFactory;
Import com.ibm.websphere.security.auth.WSSubject;
public Object login(HttpServletRequest req, HttpServletResponse res)
throws ServletException {
PrintWriter out = null;
try {
out = res.getWriter();
res.setContentType("text/html");
} catch (java.io.IOException e){
// Error handling
}
Subject subject = null;
try {
LoginContext lc = new LoginContext("system.Your_login_configuration",
WSCallbackHandlerFactory.getInstance().getCallbackHandler(
userid, null, password, req, res, null));
lc.login();
subject = lc.getSubject();
WSSubject.setRunAsSubject(subject);
} catch(Exception e) {
// catch all possible exceptions if you want or handle them separately
out.println("Exception in LoginContext login + Exception = " +
e.getMessage());
throw new ServletException(e.getMessage());
}
The following is sample code to revoke the SSO cookies upon a programming logout:
The LogoutServlet.java:
public void logout(HttpServletRequest req, HttpServletResponse res,
Object retCreds) throws ServletException {
PrintWriter out =null;
try {
out = res.getWriter();
res.setContentType("text/html");
} catch (java.io.IOException e){
// Error Handling
}
try {
WSSecurityHelper.revokeSSOCookies(req, res);
} catch(Exception e) {
// catch all possible exceptions if you want or handle them separately
out.println("JAASLogoutServlet: logout Exception = " + e.getMessage());
throw new ServletException(e);
}
}