(file) Return to AuthenticationManager.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Security / Authentication

Diff for /pegasus/src/Pegasus/Security/Authentication/AuthenticationManager.cpp between version 1.26 and 1.33

version 1.26, 2007/02/28 20:46:08 version 1.33, 2008/05/12 09:14:56
Line 35 
Line 35 
 #include <Pegasus/Common/XmlWriter.h> #include <Pegasus/Common/XmlWriter.h>
 #include <Pegasus/Common/Tracer.h> #include <Pegasus/Common/Tracer.h>
 #include <Pegasus/Common/PegasusVersion.h> #include <Pegasus/Common/PegasusVersion.h>
   #include <Pegasus/Common/HTTPMessage.h>
  
 #include <Pegasus/Config/ConfigManager.h> #include <Pegasus/Config/ConfigManager.h>
  
Line 99 
Line 100 
             getCurrentValue("enableRemotePrivilegedUserAccess"))             getCurrentValue("enableRemotePrivilegedUserAccess"))
         && System::isPrivilegedUser(userName))         && System::isPrivilegedUser(userName))
     {     {
         Tracer::trace(TRC_AUTHENTICATION, Tracer::LEVEL2,          PEG_TRACE((TRC_AUTHENTICATION, Tracer::LEVEL2,
             "Authentication failed for user '%s' because "             "Authentication failed for user '%s' because "
             "enableRemotePrivilegedUserAccess is not set to 'true'.",             "enableRemotePrivilegedUserAccess is not set to 'true'.",
             (const char*) userName.getCString());              (const char*) userName.getCString()));
         Logger::put_l(         Logger::put_l(
             Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,             Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION,
             "Security.Authentication.BasicAuthenticationHandler."             "Security.Authentication.BasicAuthenticationHandler."
Line 118 
Line 119 
 // //
 // Perform http authentication // Perform http authentication
 // //
 Boolean AuthenticationManager::performHttpAuthentication  Boolean AuthenticationManager::performHttpAuthentication(
 (  
     const String& authHeader,     const String& authHeader,
     AuthenticationInfo* authInfo      AuthenticationInfo* authInfo)
 )  
 { {
     PEG_METHOD_ENTER(      PEG_METHOD_ENTER(TRC_AUTHENTICATION,
         TRC_AUTHENTICATION, "AuthenticationManager::performHttpAuthentication()");          "AuthenticationManager::performHttpAuthentication()");
   
     String authType = String::EMPTY;  
   
     String cookie = String::EMPTY;  
  
     Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::TRACE,      String authType;
                 "AuthenticationManager:: performHttpAuthentication - Authority Header: $0", authHeader);      String cookie;
  
     //     //
     // Parse the HTTP authentication header for authentication information     // Parse the HTTP authentication header for authentication information
     //     //
     if ( !_parseHttpAuthHeader(authHeader, authType, cookie) )      if ( !HTTPMessage::parseHttpAuthHeader(authHeader, authType, cookie) )
     {     {
           PEG_TRACE((
               TRC_DISCARDED_DATA,
               Tracer::LEVEL2,
               "HTTPAuthentication failed. "
                   "Malformed HTTP authentication header: %s",
               (const char*)authHeader.getCString()));
         PEG_METHOD_EXIT();         PEG_METHOD_EXIT();
         return false;         return false;
     }     }
Line 165 
Line 166 
  
     if ( authenticated )     if ( authenticated )
     {     {
         authInfo->setAuthStatus(AuthenticationInfoRep::AUTHENTICATED);  
   
         authInfo->setAuthType(authType);         authInfo->setAuthType(authType);
     }     }
  
     PEG_METHOD_EXIT();     PEG_METHOD_EXIT();
  
     return ( authenticated );      return authenticated;
 } }
  
 // //
 // Perform pegasus sepcific local authentication // Perform pegasus sepcific local authentication
 // //
 Boolean AuthenticationManager::performPegasusAuthentication  Boolean AuthenticationManager::performPegasusAuthentication(
 (  
     const String& authHeader,     const String& authHeader,
     AuthenticationInfo* authInfo      AuthenticationInfo* authInfo)
 )  
 { {
     PEG_METHOD_ENTER(      PEG_METHOD_ENTER(TRC_AUTHENTICATION,
         TRC_AUTHENTICATION, "AuthenticationManager::performPegasusAuthentication()");          "AuthenticationManager::performPegasusAuthentication()");
  
     Boolean authenticated = false;     Boolean authenticated = false;
  
     String authType = String::EMPTY;      String authType;
     String userName = String::EMPTY;      String userName;
     String cookie = String::EMPTY;      String cookie;
   
     Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::TRACE,  
                 "AuthenticationManager:: performPegasusAuthentication - Authority Header: $0",  
                 authHeader);  
  
     //     //
     // Parse the pegasus authentication header authentication information     // Parse the pegasus authentication header authentication information
     //     //
     if ( !_parseLocalAuthHeader(authHeader, authType, userName, cookie) )      if ( !HTTPMessage::parseLocalAuthHeader(authHeader,
                 authType, userName, cookie) )
     {     {
           PEG_TRACE((
               TRC_DISCARDED_DATA,
               Tracer::LEVEL2,
               "PegasusAuthentication failed. "
                   "Malformed Pegasus authentication header: %s",
               (const char*)authHeader.getCString()));
         PEG_METHOD_EXIT();         PEG_METHOD_EXIT();
         return false;         return false;
     }     }
  
     if ( String::equalNoCase(authType, "Local") )      // The HTTPAuthenticatorDelegator ensures only local authentication
     {      // requests get here.
         if (authInfo->isAuthenticated() &&      PEGASUS_ASSERT(authType == "Local");
             String::equal(userName, authInfo->getAuthenticatedUser()))  
         {  
             PEG_METHOD_EXIT();  
             return true;  
         }  
     }  
     else  
     {  
         PEG_METHOD_EXIT();  
         return false;  
     }  
   
     //  
     // Check if the authentication information is present  
     //  
     if ( String::equal(cookie, String::EMPTY) )  
     {  
         PEG_METHOD_EXIT();  
         return false;  
     }  
  
     authenticated =     authenticated =
         _localAuthHandler->authenticate(cookie, authInfo);         _localAuthHandler->authenticate(cookie, authInfo);
  
     if ( authenticated )     if ( authenticated )
     {     {
         authInfo->setAuthStatus(AuthenticationInfoRep::AUTHENTICATED);  
         authInfo->setAuthType(authType);         authInfo->setAuthType(authType);
     }     }
  
     PEG_METHOD_EXIT();     PEG_METHOD_EXIT();
  
     return ( authenticated );      return authenticated;
 } }
  
 // //
Line 255 
Line 234 
 // //
 // Get pegasus/local authentication response header // Get pegasus/local authentication response header
 // //
 String AuthenticationManager::getPegasusAuthResponseHeader  String AuthenticationManager::getPegasusAuthResponseHeader(
 (  
     const String& authHeader,     const String& authHeader,
     AuthenticationInfo* authInfo      AuthenticationInfo* authInfo)
 )  
 { {
     PEG_METHOD_ENTER(      PEG_METHOD_ENTER(TRC_AUTHENTICATION,
         TRC_AUTHENTICATION, "AuthenticationManager::getPegasusAuthResponseHeader()");          "AuthenticationManager::getPegasusAuthResponseHeader()");
  
     String respHeader = String::EMPTY;      String respHeader;
  
     String authType = String::EMPTY;      String authType;
     String userName = String::EMPTY;      String userName;
     String cookie = String::EMPTY;      String cookie;
  
     //     //
     // Parse the pegasus authentication header authentication information     // Parse the pegasus authentication header authentication information
     //     //
     if ( !_parseLocalAuthHeader(authHeader, authType, userName, cookie) )      if ( !HTTPMessage::parseLocalAuthHeader(authHeader,
                 authType, userName, cookie) )
     {     {
         PEG_METHOD_EXIT();         PEG_METHOD_EXIT();
         return (respHeader);          return respHeader;
     }     }
  
     //     //
Line 285 
Line 263 
     if ( String::equal(userName, String::EMPTY) )     if ( String::equal(userName, String::EMPTY) )
     {     {
         PEG_METHOD_EXIT();         PEG_METHOD_EXIT();
         return (respHeader);          return respHeader;
     }     }
  
     respHeader =     respHeader =
Line 293 
Line 271 
  
     PEG_METHOD_EXIT();     PEG_METHOD_EXIT();
  
     return (respHeader);      return respHeader;
  
 } }
  
Line 301 
Line 279 
 // Get HTTP authentication response header // Get HTTP authentication response header
 // //
 #ifdef PEGASUS_KERBEROS_AUTHENTICATION #ifdef PEGASUS_KERBEROS_AUTHENTICATION
 String AuthenticationManager::getHttpAuthResponseHeader( AuthenticationInfo* authInfo )  String AuthenticationManager::getHttpAuthResponseHeader(
       AuthenticationInfo* authInfo)
 #else #else
 String AuthenticationManager::getHttpAuthResponseHeader() String AuthenticationManager::getHttpAuthResponseHeader()
 #endif #endif
 { {
     PEG_METHOD_ENTER(      PEG_METHOD_ENTER(TRC_AUTHENTICATION,
         TRC_AUTHENTICATION, "AuthenticationManager::getHttpAuthResponseHeader()");          "AuthenticationManager::getHttpAuthResponseHeader()");
  
 #ifdef PEGASUS_KERBEROS_AUTHENTICATION #ifdef PEGASUS_KERBEROS_AUTHENTICATION
     String respHeader = _httpAuthHandler->getAuthResponseHeader(     String respHeader = _httpAuthHandler->getAuthResponseHeader(
Line 318 
Line 297 
  
     PEG_METHOD_EXIT();     PEG_METHOD_EXIT();
  
     return (respHeader);      return respHeader;
 } }
  
 // //
 // parse the local authentication header  
 //  
 Boolean AuthenticationManager::_parseLocalAuthHeader(  
     const String& authHeader, String& authType, String& userName, String& cookie)  
 {  
     PEG_METHOD_ENTER(  
         TRC_AUTHENTICATION, "AuthenticationManager::_parseLocalAuthHeader()");  
   
     //  
     // Extract the authentication type:  
     //  
     Uint32 space = authHeader.find(' ');  
   
     if ( space == PEG_NOT_FOUND )  
     {  
         PEG_METHOD_EXIT();  
         return false;  
     }  
   
     authType = authHeader.subString(0, space);  
   
     Uint32 startQuote = authHeader.find(space, '"');  
   
     if ( startQuote == PEG_NOT_FOUND )  
     {  
         PEG_METHOD_EXIT();  
         return false;  
     }  
   
     Uint32 endQuote = authHeader.find(startQuote + 1, '"');  
   
     if ( endQuote == PEG_NOT_FOUND )  
     {  
         PEG_METHOD_EXIT();  
         return false;  
     }  
   
     String temp = authHeader.subString(  
         startQuote + 1, (endQuote - startQuote - 1));  
   
     //  
     // Extract the user name and cookie:  
     //  
     Uint32 colon = temp.find(0, ':');  
   
     if ( colon == PEG_NOT_FOUND )  
     {  
         userName = temp;  
     }  
     else  
     {  
         userName = temp.subString(0, colon);  
         cookie = temp;  
     }  
   
     PEG_METHOD_EXIT();  
   
     return true;  
 }  
   
 //  
 // parse the HTTP authentication header  
 //  
 Boolean AuthenticationManager::_parseHttpAuthHeader(  
     const String& authHeader, String& authType, String& cookie)  
 {  
     PEG_METHOD_ENTER(  
         TRC_AUTHENTICATION, "AuthenticationManager::_parseHttpAuthHeader()");  
   
     //  
     // Extract the authentication type:  
     //  
     Uint32 space = authHeader.find(' ');  
   
     if ( space == PEG_NOT_FOUND )  
     {  
         PEG_METHOD_EXIT();  
         return false;  
     }  
   
     authType = authHeader.subString(0, space);  
   
     //  
     // Extract the cookie:  
     //  
     cookie = authHeader.subString(space + 1);  
   
     PEG_METHOD_EXIT();  
   
     return true;  
 }  
 //  
 // Get local authentication handler // Get local authentication handler
 // //
 Authenticator* AuthenticationManager::_getLocalAuthHandler() Authenticator* AuthenticationManager::_getLocalAuthHandler()
Line 425 
Line 312 
     //     //
     // create and return a local authentication handler.     // create and return a local authentication handler.
     //     //
     return (new LocalAuthenticationHandler());      return new LocalAuthenticationHandler();
 } }
  
  
Line 456 
Line 343 
     else if ( String::equalNoCase(_httpAuthType, "Kerberos") )     else if ( String::equalNoCase(_httpAuthType, "Kerberos") )
     {     {
         handler.reset((Authenticator* ) new KerberosAuthenticationHandler( ));         handler.reset((Authenticator* ) new KerberosAuthenticationHandler( ));
         AutoPtr<KerberosAuthenticationHandler> kerberosHandler((KerberosAuthenticationHandler *)handler.get());          AutoPtr<KerberosAuthenticationHandler> kerberosHandler(
               (KerberosAuthenticationHandler *)handler.get());
         int itFailed = kerberosHandler->initialize();         int itFailed = kerberosHandler->initialize();
         kerberosHandler.release();         kerberosHandler.release();
         if (itFailed)         if (itFailed)
Line 465 
Line 353 
             {             {
                 handler.reset(0);                 handler.reset(0);
             }             }
             // L10N TODO DONE  
             //Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,  
                 //"CIMOM server authentication handler for Kerberos failed to initialize properly. The CIMOM server is not started.");  
             Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,             Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::SEVERE,
                 "Security.Authentication.AuthenticationManager.AUTHENTICATION_HANDLER_KERBEROS_FAILED_TO_INITIALIZE",                  "Security.Authentication.AuthenticationManager."
                 "CIMOM server authentication handler for Kerberos failed to initialize properly. The CIMOM server is not started.");                      "AUTHENTICATION_HANDLER_KERBEROS_FAILED_TO_INITIALIZE",
             // end the server because Kerberos could not initialized.                  "CIMOM server authentication handler for Kerberos failed to "
             MessageLoaderParms parms(                   "Security.Authentication.AuthenticationManager.AUTHENTICATION_HANDLER_KERBEROS_FAILED_TO_INITIALIZE",                      "initialize properly.");
                 "CIMOM server authentication handler for Kerberos failed to initialize properly. The CIMOM server is not started.");              MessageLoaderParms parms(
                   "Security.Authentication.AuthenticationManager."
                       "AUTHENTICATION_HANDLER_KERBEROS_FAILED_TO_INITIALIZE",
                   "CIMOM server authentication handler for Kerberos failed to "
                       "initialize properly.");
             throw Exception(parms);             throw Exception(parms);
         }         }
     }     }
Line 495 
Line 384 
     }     }
  
     PEG_METHOD_EXIT();     PEG_METHOD_EXIT();
     return ( handler.release() );      return handler.release();
 } }
  
   
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END
   


Legend:
Removed from v.1.26  
changed lines
  Added in v.1.33

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2