forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTTPBasicCredentials.h
More file actions
111 lines (79 loc) · 2.69 KB
/
HTTPBasicCredentials.h
File metadata and controls
111 lines (79 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//
// HTTPBasicCredentials.h
//
// Library: Net
// Package: HTTP
// Module: HTTPBasicCredentials
//
// Definition of the HTTPBasicCredentials class.
//
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef Net_HTTPBasicCredentials_INCLUDED
#define Net_HTTPBasicCredentials_INCLUDED
#include "Poco/Net/Net.h"
namespace Poco {
namespace Net {
class HTTPRequest;
class Net_API HTTPBasicCredentials
/// This is a utility class for working with
/// HTTP Basic Authentication in HTTPRequest
/// objects.
{
public:
HTTPBasicCredentials();
/// Creates an empty HTTPBasicCredentials object.
HTTPBasicCredentials(const std::string& username, const std::string& password);
/// Creates a HTTPBasicCredentials object with the given username and password.
explicit HTTPBasicCredentials(const HTTPRequest& request);
/// Creates a HTTPBasicCredentials object with the authentication information
/// from the given request.
///
/// Throws a NotAuthenticatedException if the request does
/// not contain basic authentication information.
explicit HTTPBasicCredentials(const std::string& authInfo);
/// Creates a HTTPBasicCredentials object with the authentication information
/// in the given string. The authentication information can be extracted
/// from a HTTPRequest object by calling HTTPRequest::getCredentials().
~HTTPBasicCredentials();
/// Destroys the HTTPBasicCredentials.
void setUsername(const std::string& username);
/// Sets the username.
const std::string& getUsername() const;
/// Returns the username.
void setPassword(const std::string& password);
/// Sets the password.
const std::string& getPassword() const;
/// Returns the password.
void authenticate(HTTPRequest& request) const;
/// Adds authentication information to the given HTTPRequest.
void proxyAuthenticate(HTTPRequest& request) const;
/// Adds proxy authentication information to the given HTTPRequest.
static const std::string SCHEME;
protected:
void parseAuthInfo(const std::string& authInfo);
/// Extracts username and password from Basic authentication info
/// by base64-decoding authInfo and splitting the resulting
/// string at the ':' delimiter.
private:
HTTPBasicCredentials(const HTTPBasicCredentials&);
HTTPBasicCredentials& operator = (const HTTPBasicCredentials&);
std::string _username;
std::string _password;
};
//
// inlines
//
inline const std::string& HTTPBasicCredentials::getUsername() const
{
return _username;
}
inline const std::string& HTTPBasicCredentials::getPassword() const
{
return _password;
}
} } // namespace Poco::Net
#endif // Net_HTTPBasicCredentials_INCLUDED