(file) Return to PAMSessionBasicAuthenticator.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Security / Authentication

  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 karl  1.1.2.3 #include "pam_rcToAuthStatus.h"
 36 karl  1.1.2.2 
 37               PEGASUS_USING_STD;
 38               
 39               PEGASUS_NAMESPACE_BEGIN
 40               
 41               PAMSessionBasicAuthenticator::PAMSessionBasicAuthenticator()
 42               {
 43                   PEG_METHOD_ENTER(TRC_AUTHENTICATION,
 44                       "PAMSessionBasicAuthenticator::PAMSessionBasicAuthenticator()");
 45               
 46                   // Build Authentication parameter realm required for Basic Challenge
 47                   // e.g. realm="HostName"
 48               
 49                   _realm.assign("realm=");
 50                   _realm.append(Char16('"'));
 51                   _realm.append(System::getHostName());
 52                   _realm.append(Char16('"'));
 53               
 54                   PEG_METHOD_EXIT();
 55               }
 56               
 57 karl  1.1.2.2 PAMSessionBasicAuthenticator::~PAMSessionBasicAuthenticator()
 58               {
 59                   PEG_METHOD_ENTER(TRC_AUTHENTICATION,
 60                       "PAMSessionBasicAuthenticator::~PAMSessionBasicAuthenticator()");
 61               
 62                   PEG_METHOD_EXIT();
 63               }
 64               
 65 karl  1.1.2.3 AuthenticationStatus PAMSessionBasicAuthenticator::authenticate(
 66 karl  1.1.2.2     const String& userName,
 67                   const String& password,
 68                   AuthenticationInfo* authInfo)
 69               {
 70               
 71                   PEG_METHOD_ENTER(TRC_AUTHENTICATION,
 72                       "PAMSessionBasicAuthenticator::authenticate()");
 73               
 74 karl  1.1.2.3     int pamRC = _PAMAuthenticate(
 75 karl  1.1.2.2         userName.getCString(),
 76                       password.getCString(),
 77 karl  1.1.2.3         authInfo);
 78                   
 79                   AuthenticationStatus authStatus = _getAuthStatusFromPAM_RC(pamRC);
 80               
 81                   // in case of an expired password, store user authenticated password
 82                   if (authStatus.isPasswordExpired())
 83 karl  1.1.2.2     {
 84 karl  1.1.2.3         authInfo->setAuthenticatedPassword(password);
 85                       authInfo->setAuthenticatedUser(userName);
 86                       authInfo->setExpiredPassword(true);
 87 karl  1.1.2.2     }
 88                   
 89                   PEG_METHOD_EXIT();
 90 karl  1.1.2.3     return authStatus;
 91 karl  1.1.2.2 }
 92               
 93 karl  1.1.2.3 AuthenticationStatus PAMSessionBasicAuthenticator::validateUser(
 94 karl  1.1.2.2     const String& userName,
 95                   AuthenticationInfo* authInfo)
 96               {
 97                   PEG_METHOD_ENTER(TRC_AUTHENTICATION,
 98                       "PAMSessionBasicAuthenticator::validateUser()");
 99               
100 karl  1.1.2.3     int pamRC = _PAMValidateUser(userName.getCString(), authInfo);
101                   AuthenticationStatus authStatus = _getAuthStatusFromPAM_RC(pamRC);
102                   
103 karl  1.1.2.2     PEG_METHOD_EXIT();
104 karl  1.1.2.3     return authStatus;
105 karl  1.1.2.2 }
106               
107               
108               String PAMSessionBasicAuthenticator::getAuthResponseHeader()
109               {
110                   PEG_METHOD_ENTER(TRC_AUTHENTICATION,
111                       "PAMSessionBasicAuthenticator::getAuthResponseHeader()");
112               
113                   // Build response header: WWW-Authenticate: Basic realm="HostName"
114               
115                   String responseHeader = "WWW-Authenticate: Basic ";
116                   responseHeader.append(_realm);
117               
118                   PEG_METHOD_EXIT();
119                   return responseHeader;
120               }
121               
122 karl  1.1.2.3 AuthenticationStatus PAMSessionBasicAuthenticator::updateExpiredPassword(
123                       const String& userName,
124                       const String& oldPass,
125 karl  1.1.2.4         const String& newPass,
126                       const String& ipAddress)
127 karl  1.1.2.3 {
128                   PEG_METHOD_ENTER(TRC_AUTHENTICATION,
129                       "PAMSessionBasicAuthenticator::updateExpiredPassword()");
130               
131                   int pamRC = _PAMUpdateExpiredPassword(
132                       userName.getCString(),
133                       oldPass.getCString(),
134 karl  1.1.2.4         newPass.getCString(),
135                       ipAddress.getCString());
136 karl  1.1.2.3 
137                   AuthenticationStatus authStatus = _getAuthStatusFromPAM_RC(pamRC);
138                   
139                   PEG_METHOD_EXIT();
140                   return authStatus;
141               }
142               
143               
144 karl  1.1.2.2 PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2