1 #include "ace/INet/HTTP_BasicAuthentication.h"
2 #include "ace/Codecs.h"
5 #if !defined (__ACE_INLINE__)
6 #include "ace/INet/HTTP_BasicAuthentication.inl"
10 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
16 const char* BasicAuthentication::SCHEME
= "Basic";
18 BasicAuthentication::BasicAuthentication()
22 BasicAuthentication::BasicAuthentication(const ACE_CString
& user
, const ACE_CString
& passwd
)
23 : user_ (user
), passwd_ (passwd
)
27 BasicAuthentication::BasicAuthentication(const Request
& request
)
29 if (request
.has_credentials ())
33 request
.get_credentials (scheme
, info
);
37 std::unique_ptr
<ACE_Byte
[]> safe_buf (ACE_Base64::decode ((const ACE_Byte
*)info
.c_str (),
39 ACE_CString
credentials ((char*)safe_buf
.get (), out_len
);
40 ACE_CString::size_type pos
= credentials
.find (':');
41 if (pos
!= ACE_CString::npos
)
43 this->user_
= credentials
.substr (0, pos
);
44 this->passwd_
= credentials
.substr (pos
+1);
50 BasicAuthentication::~BasicAuthentication()
54 void BasicAuthentication::set_credentials (Request
& request
) const
56 ACE_CString
credentials (this->user_
);
58 credentials
+= this->passwd_
;
60 std::unique_ptr
<ACE_Byte
[]> safe_buf (
61 ACE_Base64::encode ((const ACE_Byte
*)credentials
.c_str (),
62 credentials
.length (),
65 ACE_CString
enc_cred ((char*)safe_buf
.get (), out_len
);
66 request
.set_credentials (SCHEME
, enc_cred
);
71 ACE_END_VERSIONED_NAMESPACE_DECL