/*
 * $Id: AddLdapAccessorAclAction.java,v 1.4 2005/02/14 14:01:53 bigmac Exp $
 * 
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 * 
 * $Log: AddLdapAccessorAclAction.java,v $
 * Revision 1.4  2005/02/14 14:01:53  bigmac
 * Applikationsweites CSS konfigurierbar gemacht + Refactorings
 *
 * Revision 1.3  2004/11/10 15:02:45  koppy
 * Projektweite Überarbeitung von Error-Logs, Stacktraces,..
 *
 * Revision 1.2  2004/11/02 21:42:30  marbobo
 * + Einige Funktionen für Gast-Benutzer gesperrt
 * + WebShare.LOGIN_PAGE mit WebShare.getLoginPage() ersetzt
 *
 * Revision 1.1  2004/10/22 13:54:02  vchris
 * First Strike
 *
 *
 */

package vkc.view.action;

import java.util.Collection;

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

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import vkc.db.entities.VKCUser;
import vkc.exception.DBException;
import vkc.ldap.db.serializer.VKCLdapServerSerializer;
import vkc.misc.VKCLogManager;
import vkc.view.WebShare;
import vkc.view.form.AddLdapAccessorAclForm;

/**
 * In dieser Klasse wird eine Auswahlbox zur Verfügung gestellt, die hinzufügbare
 * Accessoren beim Editieren einer ACL anzeigt.
 *
 * @author vchris
 */
public final class AddLdapAccessorAclAction extends Action {

    private ActionForward INFO_FORWARD = 
		new ActionForward( "/templates/${template.name}/common/InfoPage.jsp" );

	/**
	 * comment
	 */
	public ActionForward execute( ActionMapping mapping, 
	        					  ActionForm f,
	        					  HttpServletRequest request,
	        					  HttpServletResponse response ) {
		AddLdapAccessorAclForm form = (AddLdapAccessorAclForm)f;
		VKCUser user = (VKCUser) request.getSession().getAttribute(WebShare.USER_KEY);

		if ( user.isGuestUser() ) {
			request.setAttribute( WebShare.INFO_KEY, "vkc.info.access_denied" );
			
			return INFO_FORWARD;
		}

		// Liste der verfügbaren LDAP-Server laden
		try {
			Collection activeLdaps = VKCLdapServerSerializer.getAllActiveLdapServers().values();
			form.setLdapServers( activeLdaps );
		} catch ( DBException e ) {
			VKCLogManager.errorLog( this, "", "Error retrieving all active LDAP Servers from DB",e );
		}
		
		return mapping.getInputForward();
	}
}