📄 svrauth.cpp
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: svrauth.cpp,v 1.1.36.3 2004/07/09 01:47:11 hubbe Exp $ * * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved. * * The contents of this file, and the files included with this file, * are subject to the current version of the RealNetworks Public * Source License (the "RPSL") available at * http://www.helixcommunity.org/content/rpsl unless you have licensed * the file under the current version of the RealNetworks Community * Source License (the "RCSL") available at * http://www.helixcommunity.org/content/rcsl, in which case the RCSL * will apply. You may also obtain the license terms directly from * RealNetworks. You may not use this file except in compliance with * the RPSL or, if you have a valid RCSL with RealNetworks applicable * to this file, the RCSL. Please see the applicable RPSL or RCSL for * the rights, obligations and limitations governing use of the * contents of the file. * * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the * "GPL") in which case the provisions of the GPL are applicable * instead of those above. If you wish to allow use of your version of * this file only under the terms of the GPL, and not to allow others * to use your version of this file under the terms of either the RPSL * or RCSL, indicate your decision by deleting the provisions above * and replace them with the notice and other provisions required by * the GPL. If you do not delete the provisions above, a recipient may * use your version of this file under the terms of any one of the * RPSL, the RCSL or the GPL. * * This file is part of the Helix DNA Technology. RealNetworks is the * developer of the Original Code and owns the copyrights in the * portions it created. * * This file, and the files included with this file, is distributed * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET * ENJOYMENT OR NON-INFRINGEMENT. * * Technology Compatibility Kit Test Suite(s) Location: * http://www.helixcommunity.org/content/tck * * Contributor(s): * * ***** END LICENSE BLOCK ***** */#include "hxtypes.h"#include "hxstrutl.h"#include "hxcom.h"//#include "iostream.h"#include "hxauth.h"#include "hxmon.h"#include "hxplugn.h"#include "ihxpckts.h"#include "hxfiles.h"#include "hxauthn.h"#include "hxdb.h"#include "chxpckts.h"#include "svrauth.h"#include "hxplgsp.h"#include "hxheap.h"#ifdef _DEBUG#undef HX_THIS_FILEstatic char HX_THIS_FILE[] = __FILE__;#endifBEGIN_INTERFACE_LIST(CServerAuthenticator) INTERFACE_LIST_ENTRY ( IID_IHXObjectConfiguration, IHXObjectConfiguration ) INTERFACE_LIST_ENTRY ( IID_IHXServerAuthConversation, IHXServerAuthConversation ) INTERFACE_LIST_ENTRY ( IID_IHXServerAuthResponse, IHXServerAuthResponse ) INTERFACE_LIST_ENTRY ( IID_IHXAuthenticationDBAccess, IHXAuthenticationDBAccess ) INTERFACE_LIST_ENTRY ( IID_IHXAuthenticationDBManager, IHXAuthenticationDBManager ) INTERFACE_LIST_ENTRY ( IID_IHXAuthenticationDBManagerResponse, IHXAuthenticationDBManagerResponse )END_INTERFACE_LISTCServerAuthenticator::CServerAuthenticator() : m_HX_RESULTStatus(HXR_NOT_AUTHORIZED){}CServerAuthenticator::~CServerAuthenticator(){}STDMETHODIMPCServerAuthenticator::SetContext(IUnknown* pIUnknownContext){ m_spIUnknownContext = pIUnknownContext; _TryToLoadPlugins(); return HXR_OK;}STDMETHODIMP CServerAuthenticator::SetConfiguration( IHXValues* pIHXValuesConfiguration){ m_spIHXValuesConfig = pIHXValuesConfiguration; _TryToLoadPlugins(); return HXR_OK;}// IHXServerAuthConversationSTDMETHODIMPCServerAuthenticator::MakeChallenge( IHXServerAuthResponse* pIHXServerAuthResponseRequester, IHXRequest* pIHXRequestResponse){ HX_RESULT hr; if(!pIHXServerAuthResponseRequester) { return HXR_UNEXPECTED; } if ( m_ListOfIUnknownPlugins.begin() == m_ListOfIUnknownPlugins.end() || m_spIHXServerAuthResponseRequester.IsValid() ) { pIHXServerAuthResponseRequester->ChallengeReady ( HXR_UNEXPECTED, NULL ); return HXR_UNEXPECTED; } DECLARE_SMART_POINTER ( IHXServerAuthConversation ) spIHXServerAuthConversationPlugin; m_HX_RESULTStatus = HXR_NOT_AUTHORIZED; m_spIHXServerAuthResponseRequester = pIHXServerAuthResponseRequester; m_spIHXValuesChallengeHeaders = new CHXHeader; m_spIHXRequestResponse = pIHXRequestResponse; m_ListOfIUnknownIteratorCurrent = m_ListOfIUnknownPlugins.begin(); spIHXServerAuthConversationPlugin = ( *m_ListOfIUnknownIteratorCurrent ).wrapped_ptr(); hr = spIHXServerAuthConversationPlugin->MakeChallenge ( this, m_spIHXRequestResponse ); if (FAILED(hr)) { ChallengeReady(hr, m_spIHXRequestResponse); } return HXR_OK;}STDMETHODIMP_(BOOL)CServerAuthenticator::IsAuthenticated(){ _CListOfWrapped_IUnknown_::iterator ListOfIUnknownIteratorCurrent; DECLARE_SMART_POINTER ( IHXServerAuthConversation ) spIHXServerAuthConversationPlugin; BOOL bAuthenticated = FALSE; for ( ListOfIUnknownIteratorCurrent = m_ListOfIUnknownPlugins.begin(); ListOfIUnknownIteratorCurrent != m_ListOfIUnknownPlugins.end(); ++ListOfIUnknownIteratorCurrent ) { spIHXServerAuthConversationPlugin = ( *ListOfIUnknownIteratorCurrent ).wrapped_ptr(); bAuthenticated |= spIHXServerAuthConversationPlugin->IsAuthenticated(); } return bAuthenticated;}STDMETHODIMPCServerAuthenticator::GetUserContext(REF(IUnknown*) pIUnknownUser){ return HXR_FAIL;}// IHXServerAuthResponseSTDMETHODIMPCServerAuthenticator::ChallengeReady( HX_RESULT HX_RESULTStatus, IHXRequest* pIHXRequestChallenge){ DECLARE_SMART_POINTER ( IHXServerAuthConversation ) spIHXServerAuthConversationPlugin; DECLARE_SMART_POINTER(IHXBuffer) spIHXBufferPropValue; DECLARE_SMART_POINTER(IHXValues) spIHXValuesChallengeHeaders; 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(pIHXRequestChallenge) { pIHXRequestChallenge->GetResponseHeaders ( spIHXValuesChallengeHeaders.ptr_reference() ); } if(SUCCEEDED(m_HX_RESULTStatus) && spIHXValuesChallengeHeaders.IsValid()) { // Merge the Headers from this call CHXHeader::mergeHeaders ( m_spIHXValuesChallengeHeaders, spIHXValuesChallengeHeaders ); } ++m_ListOfIUnknownIteratorCurrent; if(m_ListOfIUnknownIteratorCurrent != m_ListOfIUnknownPlugins.end()) { HX_RESULT hr; // Call Next one.. spIHXServerAuthConversationPlugin = ( *m_ListOfIUnknownIteratorCurrent ).wrapped_ptr(); hr = spIHXServerAuthConversationPlugin->MakeChallenge ( this, m_spIHXRequestResponse ); if (FAILED(hr)) { ChallengeReady(hr, m_spIHXRequestResponse); } } else { m_spIHXRequestResponse->SetResponseHeaders ( m_spIHXValuesChallengeHeaders ); m_spIHXServerAuthResponseRequester->ChallengeReady ( m_HX_RESULTStatus, m_spIHXRequestResponse ); // We are done, cleanup.. m_spIHXServerAuthResponseRequester.Release(); m_spIHXRequestResponse.Release(); m_spIHXValuesChallengeHeaders.Release(); } return HXR_OK;}/************************************************************************ * Method: * IHXAuthenticationDBAccess::_NewEnum * Purpose: * * Call this to make a new enumerator of this collection. * */STDMETHODIMPCServerAuthenticator::_NewEnum( REF(IHXAsyncEnumAuthenticationDB*) pAsyncEnumAuthenticationDBNew){ if (m_ListOfIUnknownPlugins.begin() == m_ListOfIUnknownPlugins.end()) { return HXR_UNEXPECTED; } DECLARE_SMART_POINTER ( IHXAuthenticationDBAccess ) spAuthenticationDBAccessPlugin; _CListOfWrapped_IUnknown_::iterator ListOfIUnknownIteratorCurrent; HX_RESULT ResultStatus = HXR_FAIL; ListOfIUnknownIteratorCurrent = m_ListOfIUnknownPlugins.begin(); while ( ListOfIUnknownIteratorCurrent != m_ListOfIUnknownPlugins.end() && FAILED(ResultStatus) ) { spAuthenticationDBAccessPlugin = ( *ListOfIUnknownIteratorCurrent ).wrapped_ptr(); ++ListOfIUnknownIteratorCurrent; if (!spAuthenticationDBAccessPlugin) { ResultStatus = HXR_NOINTERFACE; continue; } ResultStatus = spAuthenticationDBAccessPlugin->_NewEnum(pAsyncEnumAuthenticationDBNew); } return ResultStatus;}/************************************************************************ * Method: * IHXAuthenticationDBAccess::CheckExistence * Purpose: * * Call this to verify the existance of a principal. * */STDMETHODIMPCServerAuthenticator::CheckExistence( IHXAuthenticationDBAccessResponse* pAuthenticationDBAccessResponseNew, IHXBuffer* pBufferPrincipalID){ if(!pAuthenticationDBAccessResponseNew) { return HXR_UNEXPECTED; } pAuthenticationDBAccessResponseNew->ExistenceCheckDone ( HXR_NOTIMPL, pBufferPrincipalID ); return HXR_OK;}/************************************************************************ * Method: * IHXAuthenticationDBAccess::GetCredentials * Purpose: * * Call this to access the credentials for the specified principal. * */STDMETHODIMPCServerAuthenticator::GetCredentials( IHXAuthenticationDBAccessResponse* pAuthenticationDBAccessResponseNew, IHXBuffer* pBufferPrincipalID){ if(!pAuthenticationDBAccessResponseNew) { return HXR_UNEXPECTED; } pAuthenticationDBAccessResponseNew->GetCredentialsDone ( HXR_NOTIMPL, pBufferPrincipalID, NULL ); return HXR_OK;}// IHXAuthenticationDBManagerSTDMETHODIMPCServerAuthenticator::AddPrincipal( IHXAuthenticationDBManagerResponse* pAuthenticationDBManagerResponseNew, IHXBuffer* pBufferPrincipalID){// printf("CServerAuthenticator: Entered - AddPrincipal\n"); if(!pAuthenticationDBManagerResponseNew) {// printf("CServerAuthenticator: Exit - AddPrincipal (bad response interface)\n"); return HXR_UNEXPECTED; } m_spAuthenticationDBManagerResponseRequester = pAuthenticationDBManagerResponseNew; if (m_ListOfIUnknownPlugins.begin() == m_ListOfIUnknownPlugins.end()) { m_spAuthenticationDBManagerResponseRequester->AddPrincipalDone ( HXR_UNEXPECTED, pBufferPrincipalID ); // Must explicitly release this to prevent possible circular // references. m_spAuthenticationDBManagerResponseRequester.Release();// printf("CServerAuthenticator: Exit - AddPrincipal (no auth plugins loaded)\n"); return HXR_UNEXPECTED; } DECLARE_SMART_POINTER ( IHXAuthenticationDBManager ) spAuthenticationDBManagerPlugin; m_HX_RESULTStatus = HXR_FAIL; m_ListOfIUnknownIteratorCurrent = m_ListOfIUnknownPlugins.begin(); spAuthenticationDBManagerPlugin = (
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -