/*
 * @(#)ResponderServlet.java
 *
 * Copyright (C) 2006 Infocity Inc. All Rights Reserved.
 */
package info.dragonlady.sso.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import info.dragonlady.sso.Responder;
import info.dragonlady.sso.SSOException;
import info.dragonlady.sso.message.SSOMessageResource;

/**
 * SAML応答処理サーブレット。
 * 
 * @author Hiroshi.Ebata(INFOCITY)
 * @version $Revision: 1.0 $ $Date: 2006/10/19 17:40:11 $
 */
public class ResponderServlet extends SSOBaseServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -9140276146875567412L;

	/**
	 * コンストラクタ。
	 */
	public ResponderServlet() {
		super();
	}

	/**
	 * SAML応答処理。
	 * 
	 * @param request HTTP要求オブジェクト
	 * @param response HTTP応答オブジェクト
	 * @throws ServletException
	 * @throws IOException
	 * @see info.dragonlady.sso.servlet.SSOBaseServlet#process(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	protected void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			// SAML要求に含まれるアーティファクトに対応するアサーションを取得し、SAML応答に含めて応答する
			Responder responder = new Responder(request, response);
			responder.processRequest();
		} catch(SSOException e) {
			processException(SSOMessageResource.getMessage("5101"), e, response, HttpServletResponse.SC_FORBIDDEN);
		} catch(Exception e) {
			processException(SSOMessageResource.getMessage("5102"), e, response, HttpServletResponse.SC_NOT_FOUND);
		}
	}

}
