/*  Copyright (c) 2000, 2002 by Oracle Corporation. All Rights Reserved. */

package oracle.portal.provider.v1.http;

import oracle.portal.provider.v1.ExternalPrincipal;
import oracle.portal.provider.v1.ProviderLog;
import oracle.portal.provider.v1.ProviderException;
import oracle.portal.provider.v1.AuthenticationException;
import oracle.portal.provider.v1.ProviderUser;
import oracle.portal.provider.v1.ProviderSession;

/**
 * <p>BasicURLProvider is meant for extracting external application and making 
 * it accessible to the renderer. Portlet will be rendered based on the 
 * Login URL and additional field information specified in external 
 * application.</p>
 */
public class BasicURLProvider extends URLProvider
{
  /**
   * Overridden method which does the job of extracting external applicaiton
   * information through PDK-Java and store it for future reference. This enables
   * the portlets to authenticate the user individually.
   * 
   * ExternalApplication can be extracted from provider session as follows -
   * <pre>      
   * ExternalPrincipal externalApp = (ExternalPrincipal) 
   *       pSession.getAttribute(UrlServicesUtils.EXTERNAL_APP);</pre>
   *
   * @param user  Current provider user. Used for getting provider session and
   * the portal user name.
   * @param externalApp Object holding external application details.
   * @throws ProviderException
   * @return Array of cookie objects back. This is returned to portal
   */
  public Object[] initSession(ProviderUser user, ExternalPrincipal externalApp)
                                throws ProviderException
  {
      UrlServicesUtils.logMessage(this, "BasicURLProvider : Entering initSession.",
          getDebugLevel());

      // Call super's initSession in order to initialize Basic and Proxy 
      // Authentication related information.

      Object[] cookies = super.initSession(user, externalApp);
      ProviderSession pSession = user.getSession();
      // Store external app in provider session so that other modules
      // can extract it later.
      if (pSession != null)
      {
          pSession.setAttribute(UrlServicesUtils.EXTERNAL_APP, externalApp);
      }
      return cookies;
  }

}

