OW_RemoteProviderUtils.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2004 Vintela, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Vintela, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
00029 *******************************************************************************/
00030 
00035 #include "OW_config.h"
00036 #include "OW_RemoteProviderUtils.hpp"
00037 #include "OW_URL.hpp"
00038 #include "OW_OperationContext.hpp"
00039 #include "OW_ProviderEnvironmentIFC.hpp"
00040 #include "OW_ClientCIMOMHandleConnectionPool.hpp"
00041 #include "OW_Format.hpp"
00042 #include "OW_CIMException.hpp"
00043 #include "OW_HTTPClient.hpp"
00044 #include "OW_Assertion.hpp"
00045 #include "OW_Logger.hpp"
00046 #include "OW_ProviderEnvironmentIFC.hpp"
00047 #include "OW_ClientCIMOMHandle.hpp"
00048 
00049 namespace OW_NAMESPACE
00050 {
00051 
00052 namespace RemoteProviderUtils
00053 {
00054 
00055 namespace
00056 {
00057    const String COMPONENT_NAME("ow.provider.remote.ifc");
00058 }
00059 
00061 ClientCIMOMHandleRef getRemoteClientCIMOMHandle(String& remoteUrl,
00062    bool useConnectionCredentials, const ProviderEnvironmentIFCRef &env,
00063    const ClientCIMOMHandleConnectionPoolRef& pool, bool alwaysSendCredentials)
00064 {
00065    ClientCIMOMHandleRef hdl;
00066    try
00067    {
00068       if (useConnectionCredentials)
00069       {
00070          URL url(remoteUrl);
00071          try
00072          {
00073             url.principal = env->getOperationContext().getStringData(OperationContext::USER_NAME);
00074             url.credential = env->getOperationContext().getStringData("remote_provider.user_credentials");
00075          }
00076          catch (ContextDataNotFoundException& e)
00077          {
00078          }
00079          remoteUrl = url.toString();
00080       }
00081       hdl = pool->getConnection(remoteUrl);
00082    }
00083    catch (const Exception& e)
00084    {
00085       String msg = Format("RemoteProviderUtils::getRemoteClientCIMOMHandle() failed to get a connection: %1", e);
00086       OW_LOG_ERROR(env->getLogger(COMPONENT_NAME), msg);
00087       OW_THROWCIMMSG_SUBEX(CIMException::FAILED, msg.c_str(), e);
00088    }
00089 
00090    if (alwaysSendCredentials)
00091    {
00092       CIMProtocolIFCRef tmp = hdl->getWBEMProtocolHandler();
00093       if (tmp)
00094       {
00095          IntrusiveReference<HTTPClient> httpClient = tmp.cast_to<HTTPClient>();
00096          if (httpClient)
00097          {
00098             httpClient->assumeBasicAuth();
00099          }
00100       }
00101    }
00102    OW_ASSERT(hdl);
00103    return hdl;
00104 }
00105 
00106 
00107 } // end namespace RemoteProviderUtils
00108 
00109 } // end namespace OW_NAMESPACE
00110 
00111 
00112 
00113                
00114 
00115 

Generated on Thu Feb 9 08:48:10 2006 for openwbem by  doxygen 1.4.6