/*
** Module   : WebAuthorizationFactory.java
** Abstract : A factory to create web authorization instances.
**
** Copyright (c) 2022, Golden Code Development Corporation.
**
** -#- -I- --Date-- ---------------------------------------Description----------------------------------------
** 001 CA  20220117 Created initial version.
*/

/*
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
** published by the Free Software Foundation, either version 3 of the
** License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License
** along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


package com.goldencode.harness.test;

import com.goldencode.harness.*;

/**
 * Factory for web authorization types.
 */
public class WebAuthorizationFactory
{
   /**
    * Check if the given authentication type is supported.
    * 
    * @param    authType
    *           The authentication type.
    *           
    * @return   See above.
    */
   public static boolean isSupported(String authType)
   {
      return "oauth1".equalsIgnoreCase(authType) || "basic".equals(authType);
   }

   /**
    * Create a new authorization of the given type.
    * 
    * @param    authType
    * @param    cfg
    *           The session configuration.
    *           
    * @return   See above.
    * 
    * @throws   IllegalArgumentException
    *           If the authorization type is not supported.
    */
   public static WebAuthorization createAuthorization(String authType, WebSessionSettings cfg)
   {
      WebAuthorization auth;
      if ("oauth1".equalsIgnoreCase(authType))
      {
         auth = new OAuth1(cfg);
      }
      else if ("basic".equalsIgnoreCase(authType))
      {
         auth = new BasicAuth(cfg);
      }
      else
      {
         throw new IllegalArgumentException("Authorization type " + authType + " is not supported!");
      }
      
      return auth;
   }
}
