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

  1 karl  1.7 //%2003////////////////////////////////////////////////////////////////////////
  2 mike  1.2 //
  3 karl  1.7 // Copyright (c) 2000, 2001, 2002  BMC Software, Hewlett-Packard Development
  4           // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
  5           // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
  6           // IBM Corp.; EMC Corporation, The Open Group.
  7 mike  1.2 //
  8 kumpf 1.6 // Permission is hereby granted, free of charge, to any person obtaining a copy
  9           // of this software and associated documentation files (the "Software"), to
 10           // deal in the Software without restriction, including without limitation the
 11           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 12           // sell copies of the Software, and to permit persons to whom the Software is
 13           // furnished to do so, subject to the following conditions:
 14           // 
 15           // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 16           // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 17           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 18           // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 19           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 20           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 21           // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 22           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 23 mike  1.2 //
 24           //==============================================================================
 25           //
 26           // Author: Nag Boranna, Hewlett-Packard Company(nagaraja_boranna@hp.com)
 27           //
 28           // Modified By:
 29           //
 30           //%/////////////////////////////////////////////////////////////////////////////
 31           
 32           
 33           #include <Pegasus/Common/FileSystem.h>
 34 kumpf 1.3 #include <Pegasus/Common/Tracer.h>
 35 kumpf 1.5 
 36           #include "LocalAuthFile.h"
 37 mike  1.2 #include "SecureLocalAuthenticator.h"
 38           
 39 kumpf 1.5 PEGASUS_USING_STD;
 40           
 41 mike  1.2 PEGASUS_NAMESPACE_BEGIN
 42           
 43           
 44 kumpf 1.5 /**
 45               Constant representing the pegasus authentication challenge header.
 46           */
 47           static const String PEGASUS_CHALLENGE_HEADER = "WWW-Authenticate: ";
 48           
 49           
 50 mike  1.2 /* constructor. */
 51           SecureLocalAuthenticator::SecureLocalAuthenticator() 
 52           { 
 53 kumpf 1.5     PEG_METHOD_ENTER(TRC_AUTHENTICATION,
 54                   "SecureLocalAuthenticator::SecureLocalAuthenticator()");
 55 kumpf 1.3 
 56 kumpf 1.5     PEG_METHOD_EXIT();
 57 mike  1.2 
 58           }
 59           
 60           /* destructor. */
 61           SecureLocalAuthenticator::~SecureLocalAuthenticator() 
 62           { 
 63 kumpf 1.5     PEG_METHOD_ENTER(TRC_AUTHENTICATION,
 64                   "SecureLocalAuthenticator::~SecureLocalAuthenticator()");
 65 kumpf 1.3 
 66 kumpf 1.5     PEG_METHOD_EXIT();
 67 mike  1.2 
 68           }
 69           
 70           //
 71           // Does local authentication
 72           //
 73           Boolean SecureLocalAuthenticator::authenticate
 74           (
 75 kumpf 1.3    const String& filePath, 
 76              const String& secretReceived, 
 77              const String& secretKept
 78 mike  1.2 )
 79           {
 80 kumpf 1.5     PEG_METHOD_ENTER(TRC_AUTHENTICATION,
 81                   "SecureLocalAuthenticator::authenticate()");
 82 kumpf 1.3 
 83 kumpf 1.5     Boolean authenticated = false;
 84 kumpf 1.3 
 85 mike  1.2 
 86               if ((!String::equal(secretReceived, String::EMPTY)) &&
 87                   (!String::equal(secretKept, String::EMPTY)))
 88               {
 89                   if (String::equal(secretKept, secretReceived))
 90                   {
 91                       authenticated = true;
 92                   }
 93               }
 94           
 95               //
 96               // remove the auth file created for this user request
 97               //
 98 kumpf 1.4     if (filePath.size())
 99 mike  1.2     {
100 kumpf 1.4         if (FileSystem::exists(filePath))
101 mike  1.2         {
102 kumpf 1.4             FileSystem::removeFile(filePath);
103 mike  1.2         }
104               }
105           
106 kumpf 1.5     PEG_METHOD_EXIT();
107 kumpf 1.3 
108 mike  1.2     return (authenticated);
109           }
110           
111           //
112           // Create authentication response header
113           //
114           String SecureLocalAuthenticator::getAuthResponseHeader(
115 kumpf 1.3     const String& authType, 
116               const String& userName, 
117 mike  1.2     String& challenge)
118           {
119 kumpf 1.5     PEG_METHOD_ENTER(TRC_AUTHENTICATION,
120                   "SecureLocalAuthenticator::getAuthResponseHeader()");
121 kumpf 1.3 
122 kumpf 1.5     String responseHeader = PEGASUS_CHALLENGE_HEADER;
123 kumpf 1.3     responseHeader.append(authType);
124               responseHeader.append(" \"");
125 kumpf 1.5 
126 mike  1.2     //
127               // create a file using user name and write a random number in it.
128               //
129               LocalAuthFile localAuthFile(userName);
130               String filePath  = localAuthFile.create();
131           
132               //
133               // get the challenge string
134               //
135               String temp = localAuthFile.getChallengeString();
136               challenge = temp;
137           
138               // 
139               // build response header with file path and challenge string.
140               //
141               responseHeader.append(filePath);
142               responseHeader.append("\"");
143 kumpf 1.3 
144 kumpf 1.5     PEG_METHOD_EXIT();
145 mike  1.2 
146               return (responseHeader);
147           }
148           
149           
150           PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2