00001 #include "OW_config.h"
00002 #include "OW_AuthorizerManager.hpp"
00003 #include "OW_OperationContext.hpp"
00004 #include "OW_CIMObjectPath.hpp"
00005 #include "OW_CIMOMHandleIFC.hpp"
00006 #include "OW_Logger.hpp"
00007 #include "OW_RequestHandlerIFC.hpp"
00008 #include "OW_ServiceEnvironmentIFC.hpp"
00009 #include "OW_CIMInstance.hpp"
00010 #include "OW_Array.hpp"
00011 #include "OW_ServiceIFCNames.hpp"
00012
00013 namespace OW_NAMESPACE
00014 {
00015
00016 namespace
00017 {
00018
00019 const String AUTH_ACTIVE_KEY("_aUtHoRiZeR@aCtIvE@kEy_");
00020 const String DISABLED_KEY("__aUtH@mGr@DiSaBlEd__");
00021 const String COMPONENT_NAME("ow.authorizer.AuthorizerManager");
00022
00023 class AuthorizerEnvironment : public ServiceEnvironmentIFC
00024 {
00025 public:
00026
00027 AuthorizerEnvironment(const ServiceEnvironmentIFCRef& env,
00028 OperationContext& context)
00029 : ServiceEnvironmentIFC()
00030 , m_env(env)
00031 , m_context(context)
00032 {}
00033
00034 virtual String getConfigItem(const String &name,
00035 const String& defRetVal) const
00036 {
00037 return m_env->getConfigItem(name, defRetVal);
00038 }
00039 virtual StringArray getMultiConfigItem(const String &itemName,
00040 const StringArray& defRetVal, const char* tokenizeSeparator) const
00041 {
00042 return m_env->getMultiConfigItem(itemName, defRetVal, tokenizeSeparator);
00043 }
00044 virtual void setConfigItem(const String &item, const String &value,
00045 ServiceEnvironmentIFC::EOverwritePreviousFlag overwritePrevious)
00046 {
00047 m_env->setConfigItem(item, value, overwritePrevious);
00048 }
00049 virtual RequestHandlerIFCRef getRequestHandler(const String &id) const
00050 {
00051 return m_env->getRequestHandler(id);
00052 }
00053
00054 virtual void addSelectable(const SelectableIFCRef &obj,
00055 const SelectableCallbackIFCRef &cb)
00056 {
00057 m_env->addSelectable(obj, cb);
00058 }
00059 virtual void removeSelectable(const SelectableIFCRef &obj)
00060 {
00061 m_env->removeSelectable(obj);
00062 }
00063
00064 virtual CIMOMHandleIFCRef getCIMOMHandle(OperationContext &context,
00065 EBypassProvidersFlag bypassProviders,
00066 ELockingFlag locking) const
00067 {
00068
00069 return m_env->getCIMOMHandle(m_context, bypassProviders,
00070 ServiceEnvironmentIFC::E_NO_LOCKING);
00071 }
00072
00073 virtual LoggerRef getLogger() const
00074 {
00075 return m_env->getLogger(COMPONENT_NAME);
00076 }
00077
00078 virtual LoggerRef getLogger(const String& componentName) const
00079 {
00080 return m_env->getLogger(componentName);
00081 }
00082
00083 virtual bool authenticate(String &userName, const String &info,
00084 String &details, OperationContext &context) const
00085 {
00086 return m_env->authenticate(userName, info, details, context);
00087 }
00088
00089 virtual OperationContext& getOperationContext()
00090 {
00091 return m_context;
00092 }
00093 private:
00094 ServiceEnvironmentIFCRef m_env;
00095 OperationContext& m_context;
00096 };
00097
00098 inline ServiceEnvironmentIFCRef createAuthEnvRef(OperationContext& context,
00099 const ServiceEnvironmentIFCRef& env)
00100 {
00101 return ServiceEnvironmentIFCRef(new AuthorizerEnvironment(env, context));
00102 }
00103
00105 struct AuthorizerMarker
00106 {
00107 OperationContext& m_context;
00108 AuthorizerMarker(OperationContext& context)
00109 : m_context(context)
00110 {
00111 m_context.setStringData(AUTH_ACTIVE_KEY, "1");
00112 }
00113 ~AuthorizerMarker()
00114 {
00115 m_context.removeData(AUTH_ACTIVE_KEY);
00116 }
00117
00118 static bool active(OperationContext& context)
00119 {
00120 return context.getStringDataWithDefault(AUTH_ACTIVE_KEY) == "1";
00121 }
00122 };
00123
00124 }
00125
00126
00128 void
00129 AuthorizerManager::turnOff(
00130 OperationContext& context)
00131 {
00132 context.setStringData(DISABLED_KEY, "1");
00133
00134 }
00136 void
00137 AuthorizerManager::turnOn(
00138 OperationContext& context)
00139 {
00140 try
00141 {
00142 context.removeData(DISABLED_KEY);
00143 }
00144 catch(...)
00145 {
00146
00147 }
00148 }
00150 bool
00151 AuthorizerManager::isOn(
00152 OperationContext& context)
00153 {
00154 return context.getStringDataWithDefault(DISABLED_KEY) != "1";
00155 }
00157 AuthorizerManager::AuthorizerManager()
00158 : m_authorizer()
00159 , m_initialized(false)
00160 {
00161 }
00162
00164 AuthorizerManager::AuthorizerManager(const Authorizer2IFCRef& authorizerRef)
00165 : m_authorizer(authorizerRef)
00166 {
00167 }
00169 AuthorizerManager::~AuthorizerManager()
00170 {
00171 }
00172
00174 String
00175 AuthorizerManager::getName() const
00176 {
00177 return ServiceIFCNames::AuthorizerManager;
00178 }
00179
00181 void
00182 AuthorizerManager::init(const ServiceEnvironmentIFCRef& env)
00183 {
00184 if (!m_initialized)
00185 {
00186 if (m_authorizer)
00187 {
00188 OperationContext oc;
00189 ServiceEnvironmentIFCRef envref = createAuthEnvRef(oc, env);
00190 m_authorizer->init(envref);
00191
00192 }
00193 m_initialized = true;
00194 }
00195 }
00196
00198 bool
00199 AuthorizerManager::allowReadInstance(
00200 const ServiceEnvironmentIFCRef& env,
00201 const String& ns,
00202 const String& className,
00203 const StringArray* clientPropertyList,
00204 StringArray& authorizedPropertyList,
00205 OperationContext& context)
00206 {
00207
00208
00209
00210 if (AuthorizerMarker::active(context)
00211 || !m_authorizer
00212 || !m_initialized
00213 || !isOn(context))
00214 {
00215 return true;
00216 }
00217
00218 AuthorizerMarker am(context);
00219 return m_authorizer->doAllowReadInstance(
00220 createAuthEnvRef(context, env), ns, className,
00221 clientPropertyList, authorizedPropertyList, context);
00222 }
00223 #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00224
00225 bool
00226 AuthorizerManager::allowWriteInstance(
00227 const ServiceEnvironmentIFCRef& env,
00228 const String& ns,
00229 const CIMObjectPath& op,
00230 Authorizer2IFC::EDynamicFlag dynamic,
00231 Authorizer2IFC::EWriteFlag flag,
00232 OperationContext& context)
00233 {
00234
00235
00236
00237 if (AuthorizerMarker::active(context)
00238 || !m_authorizer
00239 || !m_initialized
00240 || !isOn(context))
00241 {
00242 return true;
00243 }
00244
00245 AuthorizerMarker am(context);
00246 return m_authorizer->doAllowWriteInstance(
00247 createAuthEnvRef(context, env), ns, op, dynamic, flag,
00248 context);
00249 }
00250 #endif
00251
00252 bool
00253 AuthorizerManager::allowReadSchema(
00254 const ServiceEnvironmentIFCRef& env,
00255 const String& ns,
00256 OperationContext& context)
00257 {
00258
00259
00260
00261 if (AuthorizerMarker::active(context)
00262 || !m_authorizer
00263 || !m_initialized
00264 || !isOn(context))
00265 {
00266 return true;
00267 }
00268
00269 AuthorizerMarker am(context);
00270 return m_authorizer->doAllowReadSchema(
00271 createAuthEnvRef(context, env), ns, context);
00272 }
00273 #if !defined(OW_DISABLE_SCHEMA_MANIPULATION) || !defined(OW_DISABLE_QUALIFIER_DECLARATION)
00274
00275 bool
00276 AuthorizerManager::allowWriteSchema(
00277 const ServiceEnvironmentIFCRef& env,
00278 const String& ns,
00279 Authorizer2IFC::EWriteFlag flag,
00280 OperationContext& context)
00281 {
00282
00283
00284
00285 if (AuthorizerMarker::active(context)
00286 || !m_authorizer
00287 || !m_initialized
00288 || !isOn(context))
00289 {
00290 return true;
00291 }
00292
00293 AuthorizerMarker am(context);
00294 return m_authorizer->doAllowWriteSchema(
00295 createAuthEnvRef(context, env), ns, flag, context);
00296 }
00297 #endif
00298
00299 bool
00300 AuthorizerManager::allowAccessToNameSpace(
00301 const ServiceEnvironmentIFCRef& env,
00302 const String& ns,
00303 Authorizer2IFC::EAccessType accessType,
00304 OperationContext& context)
00305 {
00306
00307
00308
00309 if (AuthorizerMarker::active(context)
00310 || !m_authorizer
00311 || !m_initialized
00312 || !isOn(context))
00313 {
00314 return true;
00315 }
00316
00317 AuthorizerMarker am(context);
00318 return m_authorizer->doAllowAccessToNameSpace(
00319 createAuthEnvRef(context, env), ns, accessType, context);
00320 }
00321 #if !defined(OW_DISABLE_INSTANCE_MANIPULATION) && !defined(OW_DISABLE_NAMESPACE_MANIPULATION)
00322
00323 bool
00324 AuthorizerManager::allowCreateNameSpace(
00325 const ServiceEnvironmentIFCRef& env,
00326 const String& ns,
00327 OperationContext& context)
00328 {
00329
00330
00331
00332 if (AuthorizerMarker::active(context)
00333 || !m_authorizer
00334 || !m_initialized
00335 || !isOn(context))
00336 {
00337 return true;
00338 }
00339
00340 AuthorizerMarker am(context);
00341 return m_authorizer->doAllowCreateNameSpace(
00342 createAuthEnvRef(context, env), ns, context);
00343 }
00345 bool
00346 AuthorizerManager::allowDeleteNameSpace(
00347 const ServiceEnvironmentIFCRef& env,
00348 const String& ns,
00349 OperationContext& context)
00350 {
00351
00352
00353
00354 if (AuthorizerMarker::active(context)
00355 || !m_authorizer
00356 || !m_initialized
00357 || !isOn(context))
00358 {
00359 return true;
00360 }
00361
00362 AuthorizerMarker am(context);
00363 return m_authorizer->doAllowDeleteNameSpace(
00364 createAuthEnvRef(context, env), ns, context);
00365 }
00366 #endif
00367
00368 bool
00369 AuthorizerManager::allowEnumNameSpace(
00370 const ServiceEnvironmentIFCRef& env,
00371 OperationContext& context)
00372 {
00373
00374
00375
00376 if (AuthorizerMarker::active(context)
00377 || !m_authorizer
00378 || !m_initialized
00379 || !isOn(context))
00380 {
00381 return true;
00382 }
00383
00384 AuthorizerMarker am(context);
00385 return m_authorizer->doAllowEnumNameSpace(
00386 createAuthEnvRef(context, env), context);
00387 }
00388
00390 bool
00391 AuthorizerManager::allowMethodInvocation(
00392 const ServiceEnvironmentIFCRef& env,
00393 const String& ns,
00394 const CIMObjectPath& path,
00395 const String& methodName,
00396 OperationContext& context)
00397 {
00398
00399
00400
00401 if (AuthorizerMarker::active(context)
00402 || !m_authorizer
00403 || !m_initialized
00404 || !isOn(context))
00405 {
00406 return true;
00407 }
00408
00409 AuthorizerMarker am(context);
00410 return m_authorizer->doAllowMethodInvocation(
00411 createAuthEnvRef(context, env), ns, path, methodName,
00412 context);
00413 }
00414
00416 void
00417 AuthorizerManager::shutdown()
00418 {
00419 m_authorizer.setNull();
00420 }
00421
00422 }