reSIProcate/DialogUsageManager  9680
ClientAuthManager.hxx
Go to the documentation of this file.
00001 #if !defined(RESIP_CLIENTAUTHMANAGER_HXX)
00002 #define RESIP_CLIENTAUTHMANAGER_HXX
00003 
00004 #include "resip/dum/DialogSetId.hxx"
00005 #include "resip/dum/UserProfile.hxx"
00006 #include "rutil/SharedPtr.hxx"
00007 
00008 #include <map>
00009 #include <functional>
00010 
00011 namespace resip
00012 {
00013 
00014 class Auth;
00015 class SipMessage;
00016 class ClientAuthExtension;
00017 
00018 
00019 class ClientAuthManager
00020 {
00021    public:
00022       ClientAuthManager();
00023       virtual ~ClientAuthManager() {}
00024       
00025       // For any response received by the UAC, handle will be
00026       // called. origRequest is the request that generated the 401/407.
00027       // return true if the challenge can be handled with an updated request. 
00028       // This will increment the CSeq on origRequest
00029       virtual bool handle(UserProfile& userProfile, SipMessage& origRequest, const SipMessage& response);
00030 
00031       //
00032       virtual void addAuthentication(SipMessage& origRequest);
00033       virtual void clearAuthenticationState(const DialogSetId& dsId);
00034       
00035    private:
00036       friend class DialogSet;
00037       virtual void dialogSetDestroyed(const DialogSetId& dsId);      
00038 
00039 //       class CompareAuth  : public std::binary_function<const Auth&, const Auth&, bool>
00040 //       {
00041 //          public:
00042 //             bool operator()(const Auth& lhs, const Auth& rhs) const;
00043 //       };      
00044          
00045 
00046       class RealmState
00047       {
00048          public:     
00049             RealmState();
00050             
00051             void clear();
00052 
00053             bool handleAuth(UserProfile& userProfile, const Auth& auth, bool isProxyCredential);
00054             void authSucceeded();
00055 
00056             void addAuthentication(SipMessage& origRequest);            
00057          private:
00058             typedef enum
00059             {
00060                Invalid,
00061                Cached,
00062                Current,
00063                TryOnce, 
00064                Failed
00065             } State;      
00066 
00067             void transition(State s);
00068             static const Data& getStateString(State s);
00069             bool findCredential(UserProfile& userProfile, const Auth& auth);  
00070             UserProfile::DigestCredential mCredential;
00071             bool mIsProxyCredential;
00072             
00073             State mState;            
00074             unsigned int mNonceCount;
00075             Auth mAuth;            
00076 
00077             // FH add the realm state so it can change
00078             Auth *mAuthPtr;
00079             
00080 //             .dcm. only one credential per realm per challenge supported
00081 //             typedef std::map<Auth, UserProfile::DigestCredential, CompareAuth > CredentialMap;            
00082 //             CredentialMap proxyCredentials;
00083 //             CredentialMap wwwCredentials;  
00084       };      
00085 
00086       class AuthState
00087       {
00088          public:
00089             AuthState();
00090             bool handleChallenge(UserProfile& userProfile, const SipMessage& challenge);
00091             void addAuthentication(SipMessage& origRequest);
00092             void authSucceeded();
00093             
00094          private:
00095             typedef std::map<Data, RealmState> RealmStates;
00096             RealmStates mRealms;
00097             bool mFailed;
00098       };
00099 
00100       typedef std::map<DialogSetId, AuthState> AttemptedAuthMap;
00101       AttemptedAuthMap mAttemptedAuths;      
00102 };
00103  
00104 }
00105 
00106 #endif
00107 
00108 /* ====================================================================
00109  * The Vovida Software License, Version 1.0 
00110  * 
00111  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00112  * 
00113  * Redistribution and use in source and binary forms, with or without
00114  * modification, are permitted provided that the following conditions
00115  * are met:
00116  * 
00117  * 1. Redistributions of source code must retain the above copyright
00118  *    notice, this list of conditions and the following disclaimer.
00119  * 
00120  * 2. Redistributions in binary form must reproduce the above copyright
00121  *    notice, this list of conditions and the following disclaimer in
00122  *    the documentation and/or other materials provided with the
00123  *    distribution.
00124  * 
00125  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00126  *    and "Vovida Open Communication Application Library (VOCAL)" must
00127  *    not be used to endorse or promote products derived from this
00128  *    software without prior written permission. For written
00129  *    permission, please contact vocal@vovida.org.
00130  *
00131  * 4. Products derived from this software may not be called "VOCAL", nor
00132  *    may "VOCAL" appear in their name, without prior written
00133  *    permission of Vovida Networks, Inc.
00134  * 
00135  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00136  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00137  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00138  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00139  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00140  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00141  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00142  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00143  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00144  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00145  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00146  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00147  * DAMAGE.
00148  * 
00149  * ====================================================================
00150  * 
00151  * This software consists of voluntary contributions made by Vovida
00152  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00153  * Inc.  For more information on Vovida Networks, Inc., please see
00154  * <http://www.vovida.org/>.
00155  *
00156  */