📄 cliauth.cpp
字号:
return (rlriocLeft.m_plocCurrent != rlriocRight.m_plocCurrent);}BEGIN_INTERFACE_LIST(CHXClientAuthenticator) INTERFACE_LIST_ENTRY ( IID_IHXObjectConfiguration, IHXObjectConfiguration ) INTERFACE_LIST_ENTRY ( IID_IHXClientAuthConversation, IHXClientAuthConversation ) INTERFACE_LIST_ENTRY ( IID_IHXClientAuthResponse, IHXClientAuthResponse ) INTERFACE_LIST_ENTRY(IID_IHXCredRequest, IHXCredRequest) INTERFACE_LIST_ENTRY ( IID_IHXCredRequestResponse, IHXCredRequestResponse ) INTERFACE_LIST_ENTRY ( IID_IHXAuthenticationManagerResponse, IHXAuthenticationManagerResponse )END_INTERFACE_LISTCHXClientAuthenticator::CHXClientAuthenticator() : m_HX_RESULTStatus(HXR_NOT_AUTHORIZED) , m_pRegistry(NULL) , m_pRealm(NULL) , m_pCredentialsCache(NULL){}CHXClientAuthenticator::~CHXClientAuthenticator(){ HX_RELEASE(m_pRegistry); HX_RELEASE(m_pRealm); HX_RELEASE(m_pCredentialsCache);}// IHXObjectConfigurationSTDMETHODIMPCHXClientAuthenticator::SetContext(IUnknown* pIUnknownContext){ m_spIUnknownContext = pIUnknownContext; HX_RELEASE(m_pRegistry); m_spIUnknownContext->QueryInterface ( IID_IHXRegistry, (void**)&m_pRegistry ); if (HXR_OK != m_spIUnknownContext->QueryInterface(IID_IHXCredentialsCache, (void**)&m_pCredentialsCache)) { m_pCredentialsCache = NULL; } _TryToLoadPlugins(); _CListOfWrapped_IUnknown_::iterator ListOfIUnknownIteratorCurrent; DECLARE_SMART_POINTER ( IHXObjectConfiguration ) sIHXObjectConfigurationPlugin; for ( ListOfIUnknownIteratorCurrent = m_ListOfIUnknownPlugins.begin(); ListOfIUnknownIteratorCurrent != m_ListOfIUnknownPlugins.end(); ++ListOfIUnknownIteratorCurrent ) { sIHXObjectConfigurationPlugin = ( *ListOfIUnknownIteratorCurrent ).wrapped_ptr(); // Initialize this instance sIHXObjectConfigurationPlugin->SetContext(pIUnknownContext); } return HXR_OK;}STDMETHODIMP CHXClientAuthenticator::SetConfiguration( IHXValues* pIHXValuesConfiguration){ m_spIHXValuesConfig = pIHXValuesConfiguration; _TryToLoadPlugins(); return HXR_OK;}// IHXClientAuthConversationSTDMETHODIMP CHXClientAuthenticator::MakeResponse( IHXClientAuthResponse* pIHXClientAuthResponseRequester, IHXRequest* pIHXRequestChallenge){ if(!pIHXClientAuthResponseRequester) { return HXR_UNEXPECTED; } if ( m_ListOfIUnknownPlugins.begin() == m_ListOfIUnknownPlugins.end() || m_spIHXClientAuthResponseRequester.IsValid() ) { pIHXClientAuthResponseRequester->ResponseReady ( HXR_UNEXPECTED, NULL ); return HXR_UNEXPECTED; } DECLARE_SMART_POINTER ( IHXClientAuthConversation ) spIHXClientAuthConversationPlugin; m_HX_RESULTStatus = HXR_FAIL; m_spIHXClientAuthResponseRequester = pIHXClientAuthResponseRequester; m_spIHXValuesResponseHeaders = new CHXHeader; m_spIHXRequestChallenge = pIHXRequestChallenge; m_ListOfIUnknownIteratorCurrent = m_ListOfIUnknownPlugins.begin(); spIHXClientAuthConversationPlugin = ( *m_ListOfIUnknownIteratorCurrent ).wrapped_ptr(); spIHXClientAuthConversationPlugin->MakeResponse ( this, m_spIHXRequestChallenge ); return HXR_OK;}BOOL CHXClientAuthenticator::IsDone(){ _CListOfWrapped_IUnknown_::iterator ListOfIUnknownIteratorCurrent; DECLARE_SMART_POINTER ( IHXClientAuthConversation ) spIHXClientAuthConversationPlugin; BOOL bDone = FALSE; for ( ListOfIUnknownIteratorCurrent = m_ListOfIUnknownPlugins.begin(); ListOfIUnknownIteratorCurrent != m_ListOfIUnknownPlugins.end(); ++ListOfIUnknownIteratorCurrent ) { spIHXClientAuthConversationPlugin = ( *ListOfIUnknownIteratorCurrent ).wrapped_ptr(); bDone |= spIHXClientAuthConversationPlugin->IsDone(); } return bDone;}STDMETHODIMPCHXClientAuthenticator::Authenticated(BOOL bAuthenticated){ if (!bAuthenticated && m_pCredentialsCache) { m_pCredentialsCache->Empty(m_pRealm); } return HXR_OK;}// IHXClientAuthResponseSTDMETHODIMP CHXClientAuthenticator::ResponseReady( HX_RESULT HX_RESULTStatus, IHXRequest* pIHXRequestResponse){ DECLARE_SMART_POINTER ( IHXClientAuthConversation ) spIHXClientAuthConversationPlugin; DECLARE_SMART_POINTER(IHXBuffer) spIHXBufferPropValue; DECLARE_SMART_POINTER(IHXValues) spIHXValuesResponseHeaders; HX_RESULT HX_RESULTRet = HXR_FAIL; const char* pcharPropName = NULL; if(FAILED(m_HX_RESULTStatus) && HX_RESULTStatus != HXR_FAIL) { m_HX_RESULTStatus = HX_RESULTStatus; } if ( SUCCEEDED(m_HX_RESULTStatus) && pIHXRequestResponse && SUCCEEDED ( pIHXRequestResponse->GetResponseHeaders ( spIHXValuesResponseHeaders.ptr_reference() ) ) && spIHXValuesResponseHeaders.IsValid() ) { // Merge the Headers from this call CHXHeader::mergeHeaders ( m_spIHXValuesResponseHeaders, spIHXValuesResponseHeaders ); } ++m_ListOfIUnknownIteratorCurrent; if(m_ListOfIUnknownIteratorCurrent != m_ListOfIUnknownPlugins.end()) { // Call Next one.. spIHXClientAuthConversationPlugin = ( *m_ListOfIUnknownIteratorCurrent ).wrapped_ptr(); spIHXClientAuthConversationPlugin->MakeResponse ( this, m_spIHXRequestChallenge ); } else { m_spIHXRequestChallenge->SetResponseHeaders ( m_spIHXValuesResponseHeaders ); m_spIHXClientAuthResponseRequester->ResponseReady ( m_HX_RESULTStatus, m_spIHXRequestChallenge ); // We are done, cleanup.. m_spIHXClientAuthResponseRequester.Release(); m_spIHXValuesResponseHeaders.Release(); m_spIHXRequestChallenge.Release(); } return HXR_OK;}// IHXCredRequestSTDMETHODIMP CHXClientAuthenticator::GetCredentials( IHXCredRequestResponse* pIHXCredRequestResponseRequester, IHXValues* pIHXValuesCredentialRequest){ IHXBuffer* pRealm = NULL; if(pIHXValuesCredentialRequest) { m_spIHXValuesCredentialRequest = pIHXValuesCredentialRequest; } else { m_spIHXValuesCredentialRequest = new CHXHeader; } HX_RELEASE(m_pRealm); if (HXR_OK != pIHXValuesCredentialRequest->GetPropertyCString("Realm", m_pRealm)) { m_pRealm = NULL; } // Handle credentials Cache if (m_pCredentialsCache && !m_pCredentialsCache->IsEmpty(m_pRealm)) { m_pCredentialsCache->FillCredentials ( pIHXValuesCredentialRequest ); return pIHXCredRequestResponseRequester->CredentialsReady ( HXR_OK, pIHXValuesCredentialRequest ); } m_spIHXCredRequestResponseRequester = pIHXCredRequestResponseRequester; // Contact the UI IHXCredRequest* pCredRequestContext = NULL; // XXXkshoop allow existing UI for now IHXAuthenticationManager* pAuthMgr = NULL; IHXAuthenticationManager2* pAuthMgr2 = NULL; if ( m_spIUnknownContext.IsValid() && SUCCEEDED ( m_spIUnknownContext->QueryInterface ( IID_IHXCredRequest, (void**)&pCredRequestContext ) ) && pCredRequestContext ) { pCredRequestContext->GetCredentials ( this, pIHXValuesCredentialRequest ); } else if ( m_spIUnknownContext.IsValid() && SUCCEEDED ( m_spIUnknownContext->QueryInterface ( IID_IHXAuthenticationManager2, (void**)&pAuthMgr2 ) ) && pAuthMgr2 ) { pAuthMgr2->HandleAuthenticationRequest2(this, m_spIHXValuesCredentialRequest); } else if ( m_spIUnknownContext.IsValid() && SUCCEEDED ( m_spIUnknownContext->QueryInterface ( IID_IHXAuthenticationManager, (void**)&pAuthMgr ) ) && pAuthMgr ) { pAuthMgr->HandleAuthenticationRequest(this); } else { // The current context does not support a username/password dialog. CredentialsReady(HXR_NOTIMPL, NULL); } HX_RELEASE(pAuthMgr); HX_RELEASE(pCredRequestContext); return HXR_OK;}// IHXCredRequestResponseSTDMETHODIMP CHXClientAuthenticator::CredentialsReady( HX_RESULT HX_RESULTStatus, IHXValues* pIHXValuesCredentials){ // Handle credentials Cache if (m_pCredentialsCache) { if ( SUCCEEDED(HX_RESULTStatus) && m_pCredentialsCache->IsEmpty(m_pRealm) ) { m_pCredentialsCache->SetCredentials ( pIHXValuesCredentials ); } else if (FAILED(HX_RESULTStatus)) { m_pCredentialsCache->Empty(m_pRealm); } } // Forward credentials to requestor m_spIHXCredRequestResponseRequester->CredentialsReady ( HX_RESULTStatus, pIHXValuesCredentials ); return HXR_OK;}// IHXAuthenticationManagerResponseSTDMETHODIMP CHXClientAuthenticator::AuthenticationRequestDone( HX_RESULT result, const char* user, const char* password){ DECLARE_SMART_POINTER(IHXBuffer) spIHXBufferPropValue; if(SUCCEEDED(result)) { if(user && *user) { if ( SUCCEEDED ( CHXBuffer::FromCharArray(user, &spIHXBufferPropValue) ) ) { m_spIHXValuesCredentialRequest->SetPropertyCString ( "Username", spIHXBufferPropValue ); } } spIHXBufferPropValue.Release(); if(password && *password) { if ( SUCCEEDED ( CHXBuffer::FromCharArray ( password, &spIHXBufferPropValue ) ) ) { m_spIHXValuesCredentialRequest->SetPropertyCString ( "Password", spIHXBufferPropValue ); } } } return CredentialsReady(result, m_spIHXValuesCredentialRequest);}HX_RESULT CHXClientAuthenticator::_TryToLoadPlugins(){ HX_RESULT HX_RESULTRet = HXR_FAIL; if ( m_spIUnknownContext.IsValid() && m_ListOfIUnknownPlugins.begin() == m_ListOfIUnknownPlugins.end() ) { DECLARE_SMART_POINTER ( IHXClientAuthConversation ) spIHXClientAuthConversationPlugin; DECLARE_SMART_POINTER ( IHXPluginEnumerator ) spIHXPluginEnumeratorPlugins; DECLARE_SMART_POINTER ( IHXObjectConfiguration ) spIHXObjectConfigurationPlugin; DECLARE_SMART_POINTER_UNKNOWN spIUnknownPlugin; UINT32 ulIndex; UINT32 ulNumPlugins; spIHXPluginEnumeratorPlugins = m_spIUnknownContext; if(spIHXPluginEnumeratorPlugins.IsValid()) { ulNumPlugins = spIHXPluginEnumeratorPlugins->GetNumOfPlugins(); // Load all auth plugins for(ulIndex = 0; ulIndex < ulNumPlugins; ++ulIndex) { spIUnknownPlugin.Release(); spIHXPluginEnumeratorPlugins->GetPlugin ( ulIndex, spIUnknownPlugin.ptr_reference() ); spIHXClientAuthConversationPlugin = spIUnknownPlugin; if(spIHXClientAuthConversationPlugin.IsValid()) { spIHXObjectConfigurationPlugin = spIUnknownPlugin; spIHXObjectConfigurationPlugin->SetContext(m_spIUnknownContext); // Insert at end!! Order matters!! m_ListOfIUnknownPlugins.insert ( m_ListOfIUnknownPlugins.end(), spIUnknownPlugin ); } } HX_RESULTRet = HXR_OK; } } return HX_RESULTRet;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -