/[resiprocate]/main/sip/resiprocate/dum/ServerAuthManager.cxx
ViewVC logotype

Diff of /main/sip/resiprocate/dum/ServerAuthManager.cxx

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4335 by jason, Tue Apr 12 21:40:15 2005 UTC revision 4378 by jason, Sat Apr 16 21:17:09 2005 UTC
# Line 20  Line 20 
20  {  {
21  }  }
22    
23  bool  SipMessage*
24  ServerAuthManager::handleUserAuthInfo(std::auto_ptr<Message>& msg)  ServerAuthManager::handleUserAuthInfo(UserAuthInfo* userAuth)
25  {  {
26     InfoLog( << "Checking for auth result" );     assert(userAuth);
   
    std::auto_ptr<UserAuthInfo> userAuth(dynamic_cast<UserAuthInfo*>(msg.get()));  
     
    if (!userAuth.get())  
    {  
       return false;  
    }  
27    
28     MessageMap::iterator it = mMessages.find(userAuth->getTransactionId());     MessageMap::iterator it = mMessages.find(userAuth->getTransactionId());
29     assert(it != mMessages.end());     assert(it != mMessages.end());
30     SipMessage* requestWithAuth = it->second;     SipMessage* requestWithAuth = it->second;
31     mMessages.erase(it);     mMessages.erase(it);
32    
33       InfoLog( << "Checking for auth result in realm=" << userAuth->getRealm()
34                << " A1=" << userAuth->getA1());
35            
36     if (userAuth->getA1().empty())     if (userAuth->getA1().empty())
37     {     {
38        InfoLog (<< "Account does not exist " << userAuth->getUser() << " in " << userAuth->getRealm());        InfoLog (<< "Account does not exist " << userAuth->getUser() << " in " << userAuth->getRealm());
39        SipMessage response;        SipMessage response;
40        Helper::makeResponse(*requestWithAuth, 404, "Account does not exist.");        Helper::makeResponse(response, *requestWithAuth, 404, "Account does not exist.");
41        mDum.send(response);        mDum.send(response);
42        delete requestWithAuth;        delete requestWithAuth;
43        return true;        return 0;
44     }     }
45     else     else
46     {     {
# Line 54  Line 51 
51                                               userAuth->getRealm(),                                               userAuth->getRealm(),
52                                               userAuth->getA1(),                                               userAuth->getA1(),
53                                               3000);                                               3000);
         
54        if (resPair.first == Helper::Authenticated)        if (resPair.first == Helper::Authenticated)
55        {        {
56           InfoLog (<< "Retrieved stored message with challenge and passed on to dum");           InfoLog (<< "Authorized request for " << userAuth->getRealm());
57           msg = std::auto_ptr<Message>(requestWithAuth);           return requestWithAuth;
          return false;  
58        }        }
59        else        else
60        {        {
61           InfoLog (<< "Invalid password provided " << userAuth->getUser() << " in " << userAuth->getRealm());           InfoLog (<< "Invalid password provided " << userAuth->getUser() << " in " << userAuth->getRealm());
62    
63           SipMessage response;           SipMessage response;
64           Helper::makeResponse(*requestWithAuth, 403, "Invalid password provided");           Helper::makeResponse(response, *requestWithAuth, 403, "Invalid password provided");
65           mDum.send(response);           mDum.send(response);
66           delete requestWithAuth;           delete requestWithAuth;
67           return true;           return 0;
68        }        }
69     }     }
70  }  }
71                
72  // return true if request has been consumed  // return true if request has been consumed
73  bool  ServerAuthManager::Result
74  ServerAuthManager::handle(std::auto_ptr<Message>& msg)  ServerAuthManager::handle(const SipMessage& sipMsg)
75  {  {
76     //InfoLog( << "trying to do auth" );     //InfoLog( << "trying to do auth" );
77       if (sipMsg.isRequest())
    SipMessage* sipMsg = dynamic_cast<SipMessage*>(msg.get());  
    assert(sipMsg);  
     
    if (sipMsg->isResponse())  
78     {     {
79        return false;        if (!sipMsg.exists(h_ProxyAuthorizations))
    }  
   
    if (!sipMsg->exists(h_ProxyAuthorizations))  
80     {     {
81        //assume TransactionUser has matched/repaired a realm        //assume TransactionUser has matched/repaired a realm
82        SipMessage* challenge =           SipMessage* challenge = Helper::makeProxyChallenge(sipMsg,
83           Helper::makeProxyChallenge(*sipMsg,                                                              sipMsg.header(h_RequestLine).uri().host(),
                                     sipMsg->header(h_RequestLine).uri().host(),  
84                                      true,                                      true,
85                                      false);                                      false);
86             InfoLog (<< "Sending challenge to " << sipMsg.brief());
87        mDum.send(*challenge);        mDum.send(*challenge);
88        delete challenge;        delete challenge;
89        return true;           return Challenged;
90     }     }
91    
92     try     try
93     {     {
94        for(Auths::iterator it = sipMsg->header(h_ProxyAuthorizations).begin();           for(Auths::const_iterator it = sipMsg.header(h_ProxyAuthorizations).begin();
95            it  != sipMsg->header(h_ProxyAuthorizations).end(); it++)               it  != sipMsg.header(h_ProxyAuthorizations).end(); it++)
96        {        {
97           if (mDum.isMyDomain(it->param(p_realm)))           if (mDum.isMyDomain(it->param(p_realm)))
98           {           {
99                   InfoLog (<< "Requesting credential for "
100                            << it->param(p_username) << " @ " << it->param(p_realm));
101                  
102              requestCredential(it->param(p_username),              requestCredential(it->param(p_username),
103                                it->param(p_realm),                                it->param(p_realm),
104                                sipMsg->getTransactionId());                                   sipMsg.getTransactionId());
105              mMessages[sipMsg->getTransactionId()] = sipMsg;                 mMessages[sipMsg.getTransactionId()] = static_cast<SipMessage*>(sipMsg.clone());
106              msg.release();                 return RequestedCredentials;
             return true;  
107           }           }
108        }        }
109        return false;  
110             InfoLog (<< "Didn't find matching realm ");
111             SipMessage response;
112             Helper::makeResponse(response, sipMsg, 404, "Account does not exist");
113             mDum.send(response);
114             return Rejected;
115     }     }
116     catch(BaseException& e)     catch(BaseException& e)
117     {     {
118        InfoLog (<< "Invalid auth header provided " << e);        InfoLog (<< "Invalid auth header provided " << e);
119        SipMessage response;        SipMessage response;
120        Helper::makeResponse(*sipMsg, 400, "Invalid auth header");           Helper::makeResponse(response, sipMsg, 400, "Invalid auth header");
121        mDum.send(response);        mDum.send(response);
122        return true;           return Rejected;
123          }
124     }     }
125       return Skipped;
126  }  }
127    
128    

Legend:
Removed from v.4335  
changed lines
  Added in v.4378

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27