summaryrefslogtreecommitdiff
path: root/cpp/src/IceGrid/FileUserAccountMapperI.cpp
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2006-05-23 15:34:01 +0000
committerBenoit Foucher <benoit@zeroc.com>2006-05-23 15:34:01 +0000
commit4112515e65b02ab793f231b5c95401c540c0e317 (patch)
tree1762f086064845cd4ccee74c2e93cac41796d017 /cpp/src/IceGrid/FileUserAccountMapperI.cpp
parentlock() now throws ThreadLockedException for EDEADLK (diff)
downloadice-4112515e65b02ab793f231b5c95401c540c0e317.tar.bz2
ice-4112515e65b02ab793f231b5c95401c540c0e317.tar.xz
ice-4112515e65b02ab793f231b5c95401c540c0e317.zip
Added user account mapper and fixed minor bugs.
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;
+}