summaryrefslogtreecommitdiff
path: root/cpp/src/IceGrid/FileUserAccountMapperI.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/IceGrid/FileUserAccountMapperI.cpp')
-rw-r--r--cpp/src/IceGrid/FileUserAccountMapperI.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/cpp/src/IceGrid/FileUserAccountMapperI.cpp b/cpp/src/IceGrid/FileUserAccountMapperI.cpp
new file mode 100644
index 00000000000..91ab12e6c14
--- /dev/null
+++ b/cpp/src/IceGrid/FileUserAccountMapperI.cpp
@@ -0,0 +1,56 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#include <IceGrid/FileUserAccountMapperI.h>
+
+#include <fstream>
+
+using namespace std;
+using namespace IceGrid;
+
+FileUserAccountMapperI::FileUserAccountMapperI(const string& filename)
+{
+ ifstream file(filename.c_str());
+ if(!file)
+ {
+ throw "cannot open `" + filename + "' for reading: " + strerror(errno);
+ }
+
+ while(true)
+ {
+ string user;
+ file >> user;
+ if(!file)
+ {
+ break;
+ }
+
+ string account;
+ file >> account;
+ if(!file)
+ {
+ break;
+ }
+
+ assert(!user.empty());
+ assert(!account.empty());
+ _accounts.insert(make_pair(user, account));
+ }
+}
+
+string
+FileUserAccountMapperI::getUserAccount(const string& user, const Ice::Current&)
+{
+ map<string, string>::const_iterator p = _accounts.find(user);
+ if(p == _accounts.end())
+ {
+ throw UserAccountNotFoundException();
+ }
+ return p->second;
+}