1 karl 1.1.2.2 //%LICENSE////////////////////////////////////////////////////////////////
2 //
3 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 karl 1.1.2.2 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 //////////////////////////////////////////////////////////////////////////
29 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #include <Pegasus/Common/Tracer.h>
33 #include "PAMSessionBasicAuthenticator.h"
34 #include "PAMSession.h"
35
36 PEGASUS_USING_STD;
37
38 PEGASUS_NAMESPACE_BEGIN
39
40 PAMSessionBasicAuthenticator::PAMSessionBasicAuthenticator()
41 {
42 PEG_METHOD_ENTER(TRC_AUTHENTICATION,
43 karl 1.1.2.2 "PAMSessionBasicAuthenticator::PAMSessionBasicAuthenticator()");
44
45 // Build Authentication parameter realm required for Basic Challenge
46 // e.g. realm="HostName"
47
48 _realm.assign("realm=");
49 _realm.append(Char16('"'));
50 _realm.append(System::getHostName());
51 _realm.append(Char16('"'));
52
53 PEG_METHOD_EXIT();
54 }
55
56 PAMSessionBasicAuthenticator::~PAMSessionBasicAuthenticator()
57 {
58 PEG_METHOD_ENTER(TRC_AUTHENTICATION,
59 "PAMSessionBasicAuthenticator::~PAMSessionBasicAuthenticator()");
60
61 PEG_METHOD_EXIT();
62 }
63
64 karl 1.1.2.2 Boolean PAMSessionBasicAuthenticator::authenticate(
65 const String& userName,
66 const String& password,
67 AuthenticationInfo* authInfo)
68 {
69
70 PEG_METHOD_ENTER(TRC_AUTHENTICATION,
71 "PAMSessionBasicAuthenticator::authenticate()");
72
73 if (PAM_SUCCESS != _PAMAuthenticate(
74 userName.getCString(),
75 password.getCString(),
76 authInfo))
77 {
78 PEG_METHOD_EXIT();
79 return false;
80 }
81
82 PEG_METHOD_EXIT();
83 return true;
84 }
85 karl 1.1.2.2
86 Boolean PAMSessionBasicAuthenticator::validateUser(
87 const String& userName,
88 AuthenticationInfo* authInfo)
89 {
90 PEG_METHOD_ENTER(TRC_AUTHENTICATION,
91 "PAMSessionBasicAuthenticator::validateUser()");
92
93 if (PAM_SUCCESS != _PAMValidateUser(
94 userName.getCString(),
95 authInfo))
96 {
97 PEG_METHOD_EXIT();
98 return false;
99 }
100
101 PEG_METHOD_EXIT();
102 return true;
103 }
104
105
106 karl 1.1.2.2 String PAMSessionBasicAuthenticator::getAuthResponseHeader()
107 {
108 PEG_METHOD_ENTER(TRC_AUTHENTICATION,
109 "PAMSessionBasicAuthenticator::getAuthResponseHeader()");
110
111 // Build response header: WWW-Authenticate: Basic realm="HostName"
112
113 String responseHeader = "WWW-Authenticate: Basic ";
114 responseHeader.append(_realm);
115
116 PEG_METHOD_EXIT();
117 return responseHeader;
118 }
119
120 PEGASUS_NAMESPACE_END
|