![]() ![]() |
![]() |
File: [Pegasus] / pegasus / src / Pegasus / Security / Authentication / BasicAuthenticationHandler.cpp
(download)
Revision: 1.23, Tue Sep 26 16:26:25 2006 UTC (17 years, 9 months ago) by marek Branch: MAIN CVS Tags: TASK-TASK-BUG4011_WinLocalConnect-branch-New-root, TASK-TASK-BUG4011_WinLocalConnect-branch-New-merged_out_to_branch, TASK-TASK-BUG4011_WinLocalConnect-branch-New-merged_out_from_trunk, TASK-TASK-BUG4011_WinLocalConnect-branch-New-merged_in_to_trunk, TASK-TASK-BUG4011_WinLocalConnect-branch-New-merged_in_from_branch, TASK-TASK-BUG4011_WinLocalConnect-branch-New-branch, TASK-PEP268_SSLClientCertificatePropagation-root, TASK-PEP268_SSLClientCertificatePropagation-merged_out_to_branch, TASK-PEP268_SSLClientCertificatePropagation-merged_out_from_trunk, TASK-PEP268_SSLClientCertificatePropagation-merged_in_to_trunk, TASK-PEP268_SSLClientCertificatePropagation-merged_in_from_branch, TASK-PEP268_SSLClientCertificatePropagation-branch, TASK-PEP267_SLPReregistrationSupport-root, TASK-PEP267_SLPReregistrationSupport-merging_out_to_branch, TASK-PEP267_SLPReregistrationSupport-merging_out_from_trunk, TASK-PEP267_SLPReregistrationSupport-merged_out_to_branch, TASK-PEP267_SLPReregistrationSupport-merged_out_from_trunk, TASK-PEP267_SLPReregistrationSupport-merged_in_to_trunk, TASK-PEP267_SLPReregistrationSupport-merged_in_from_branch, TASK-PEP267_SLPReregistrationSupport-branch, TASK-Bugs5690_3913_RemoteCMPI-root, TASK-Bugs5690_3913_RemoteCMPI-merged_out_to_branch, TASK-Bugs5690_3913_RemoteCMPI-merged_out_from_trunk, TASK-Bugs5690_3913_RemoteCMPI-merged_in_to_trunk, TASK-Bugs5690_3913_RemoteCMPI-merged_in_from_branch, TASK-Bugs5690_3913_RemoteCMPI-branch, TASK-Bug2021_RemoteCMPIonWindows-root, TASK-Bug2021_RemoteCMPIonWindows-merged_out_to_branch, TASK-Bug2021_RemoteCMPIonWindows-merged_out_from_trunk, TASK-Bug2021_RemoteCMPIonWindows-merged_in_to_trunk, TASK-Bug2021_RemoteCMPIonWindows-merged_in_from_branch, TASK-Bug2021_RemoteCMPIonWindows-branch, TASK-Bug2021_RCMPIonWindows-root, TASK-Bug2021_RCMPIonWindows-merged_out_to_branch, TASK-Bug2021_RCMPIonWindows-merged_out_from_trunk, TASK-Bug2021_RCMPIonWindows-merged_in_to_trunk, TASK-Bug2021_RCMPIonWindows-merged_in_from_branch, TASK-Bug2021_RCMPIonWindows-branch, TASK-BUG4011_WinLocalConnect-branch-New Changes since 1.22: +0 -29 lines BUG#:5599 TITLE: Avoid double search through user database on each request DESCRIPTION: |
//%2006//////////////////////////////////////////////////////////////////////// // // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.; // IBM Corp.; EMC Corporation, The Open Group. // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.; // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; // EMC Corporation; VERITAS Software Corporation; The Open Group. // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.; // EMC Corporation; Symantec Corporation; The Open Group. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // //============================================================================== // //%///////////////////////////////////////////////////////////////////////////// #include <Pegasus/Common/Logger.h> #include <Pegasus/Common/Tracer.h> #include <Pegasus/Common/Base64.h> #include <Pegasus/Config/ConfigManager.h> #include "SecureBasicAuthenticator.h" #include "PAMBasicAuthenticator.h" #include "BasicAuthenticationHandler.h" PEGASUS_USING_STD; PEGASUS_NAMESPACE_BEGIN BasicAuthenticationHandler::BasicAuthenticationHandler() { PEG_METHOD_ENTER(TRC_AUTHENTICATION, "BasicAuthenticationHandler::BasicAuthenticationHandler()"); #ifdef PEGASUS_PAM_AUTHENTICATION _basicAuthenticator = (BasicAuthenticator*) new PAMBasicAuthenticator(); #else _basicAuthenticator = (BasicAuthenticator*) new SecureBasicAuthenticator(); #endif PEG_METHOD_EXIT(); } BasicAuthenticationHandler::~BasicAuthenticationHandler() { PEG_METHOD_ENTER(TRC_AUTHENTICATION, "BasicAuthenticationHandler::~BasicAuthenticationHandler()"); delete _basicAuthenticator; PEG_METHOD_EXIT(); } Boolean BasicAuthenticationHandler::authenticate( const String& authHeader, AuthenticationInfo* authInfo) { PEG_METHOD_ENTER( TRC_AUTHENTICATION, "BasicAuthenticationHandler::authenticate()"); Boolean authenticated = false; // // copy userPass string to char array for decoding // Buffer userPassArray; Uint32 length = authHeader.size(); userPassArray.reserveCapacity( length ); userPassArray.clear(); for( Uint32 i = 0; i < length; i++ ) { userPassArray.append( static_cast<char>(authHeader[i]) ); } // // base64 decode the userPass array // Buffer decodedArray; decodedArray = Base64::decode( userPassArray ); String decodedStr = String( (const char*)decodedArray.getData(), decodedArray.size() ); Uint32 pos = decodedStr.find(':'); if (pos == PEG_NOT_FOUND) { PEG_METHOD_EXIT(); return (authenticated); } String userName = decodedStr.subString(0, pos); String password = decodedStr.subString(pos + 1); #ifdef PEGASUS_OS_OS400 // OS400 APIs require user profile to be uppercase for(int i=0; i < userName.size(); i++) { userName[i] = toupper(userName[i]); } #endif #ifdef PEGASUS_WMIMAPPER authenticated = true; authInfo->setAuthenticatedUser(userName); authInfo->setAuthenticatedPassword(password); #else authenticated = _basicAuthenticator->authenticate(userName, password); if (authenticated) { authInfo->setAuthenticatedUser(userName); } else { // // Log a message for basic authentication failure // Logger::put_l (Logger::STANDARD_LOG, System::CIMSERVER, Logger::INFORMATION, BASIC_AUTHENTICATION_FAILED_KEY, BASIC_AUTHENTICATION_FAILED, userName ); } #endif PEG_METHOD_EXIT(); return (authenticated); } Boolean BasicAuthenticationHandler::validateUser(const String& userName) { return _basicAuthenticator->validateUser(userName); } String BasicAuthenticationHandler::getAuthResponseHeader( const String& authType, const String& userName, AuthenticationInfo* authInfo) { PEG_METHOD_ENTER(TRC_AUTHENTICATION, "BasicAuthenticationHandler::getAuthResponseHeader()"); String respHeader = _basicAuthenticator->getAuthResponseHeader(); PEG_METHOD_EXIT(); return (respHeader); } PEGASUS_NAMESPACE_END
No CVS admin address has been configured |
Powered by ViewCVS 0.9.2 |