14 #define epicsExportSharedSymbols 33 const pvd::PVStructure::const_shared_pointer initdata;
35 SimpleSession(
const pvd::PVStructure::const_shared_pointer& data) :initdata(data) {}
36 virtual ~SimpleSession() {}
46 AnonPlugin(
bool server) :server(server) {}
47 virtual ~AnonPlugin() {}
49 virtual std::tr1::shared_ptr<pva::AuthenticationSession> createSession(
50 const std::tr1::shared_ptr<pva::PeerInfo>& peer,
51 std::tr1::shared_ptr<pva::AuthenticationPluginControl>
const & control,
52 epics::pvData::PVStructure::shared_pointer
const & data)
OVERRIDE FINAL 54 std::tr1::shared_ptr<SimpleSession> sess(
new SimpleSession(pvd::PVStructure::const_shared_pointer()));
56 peer->identified =
false;
57 peer->account =
"anonymous";
72 ,user(userAndHostStructure->build())
74 std::vector<char> buffer(256u);
76 throw std::runtime_error(
"Unable to determine user account name");
78 buffer[buffer.size()-1] =
'\0';
83 if (gethostname(&buffer[0], buffer.size()) != 0)
84 throw std::runtime_error(
"Unable to determine host name");
86 buffer[buffer.size()-1] =
'\0';
89 virtual ~CAPlugin() {}
91 virtual std::tr1::shared_ptr<pva::AuthenticationSession> createSession(
92 const std::tr1::shared_ptr<pva::PeerInfo>& peer,
93 std::tr1::shared_ptr<pva::AuthenticationPluginControl>
const & control,
94 epics::pvData::PVStructure::shared_pointer
const & data)
OVERRIDE FINAL 96 std::tr1::shared_ptr<SimpleSession> sess(
new SimpleSession(user));
98 pvd::PVString::shared_pointer user;
103 peer->account = user->
get();
104 peer->identified = !peer->account.empty();
115 virtual ~GroupsPlugin() {}
117 void authorize(
const std::tr1::shared_ptr<pva::PeerInfo>& peer)
119 if(!peer->identified)
131 size_t PeerInfo::num_instances;
134 :transportVersion(0u)
165 void authGblInit(
void *)
167 authGbl =
new authGbl_t;
170 AnonPlugin::shared_pointer plugin(
new AnonPlugin(
true));
171 authGbl->servers.add(-1024,
"anonymous", plugin);
174 AnonPlugin::shared_pointer plugin(
new AnonPlugin(
false));
175 authGbl->clients.add(-1024,
"anonymous", plugin);
179 CAPlugin::shared_pointer plugin(
new CAPlugin(
true));
180 authGbl->servers.add(0,
"ca", plugin);
183 CAPlugin::shared_pointer plugin(
new CAPlugin(
false));
184 authGbl->clients.add(0,
"ca", plugin);
187 GroupsPlugin::shared_pointer plugin(
new GroupsPlugin);
188 authGbl->authorizers.add(0, plugin);
201 return authGbl->clients;
208 return authGbl->servers;
215 plugmap.reserve(map.size());
216 for(map_t::const_iterator it(map.begin()), end(map.end()); it!=end; ++it) {
217 plugmap.push_back(it->second);
222 const AuthenticationPlugin::shared_pointer& plugin)
225 if(map.find(prio)!=map.end())
226 THROW_EXCEPTION2(std::logic_error,
"Authentication plugin already registered with this priority");
227 map[prio] = std::make_pair(name, plugin);
233 for(map_t::iterator it(map.begin()), end(map.end()); it!=end; ++it) {
234 if(it->second.second==plugin) {
246 for(map_t::const_iterator it(map.begin()), end(map.end()); it!=end; ++it) {
247 if(it->second.first==name)
248 return it->second.second;
250 return AuthenticationPlugin::shared_pointer();
262 return authGbl->authorizers;
270 throw std::runtime_error(
"AuthorizationRegistry busy");
271 if(map.find(prio)!=map.end())
272 THROW_EXCEPTION2(std::logic_error,
"Authorization plugin already registered with this priority");
280 throw std::runtime_error(
"AuthorizationRegistry busy");
281 for(map_t::iterator it(map.begin()), end(map.end()); it!=end; ++it) {
282 if(it->second==plugin) {
296 for(map_t::iterator it(map.begin()), end(map.end()); it!=end; ++it)
298 (it->second)->authorize(peer);
308 Transport::shared_pointer
const & transport,
316 pvd::PVStructure::shared_pointer data;
326 transport->authNZMessage(data);
#define assert(exp)
Declare that a condition should be true.
virtual ~AuthenticationSession()
std::tr1::shared_ptr< detail::SharedPut > put
#define THROW_EXCEPTION2(TYPE, MSG)
virtual void handleResponse(osiSockAddr *responseFrom, Transport::shared_pointer const &transport, epics::pvData::int8 version, epics::pvData::int8 command, std::size_t payloadSize, epics::pvData::ByteBuffer *payloadBuffer)
Actor through which authentication exchanges are initiated.
void run(const std::tr1::shared_ptr< PeerInfo > &peer)
shared_ptr< T > static_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
TODO only here because of the Lockable.
std::tr1::shared_ptr< const Structure > StructureConstPtr
epicsShareFunc void osdGetRoles(const std::string &account, PeerInfo::roles_t &roles)
Query OS specific DB for role/group names assocated with a user account.
virtual ~AuthenticationPlugin()
void add(int prio, const AuthorizationPlugin::shared_pointer &plugin)
static epics::pvData::PVField::shared_pointer deserializeFull(epics::pvData::ByteBuffer *payloadBuffer, epics::pvData::DeserializableControl *control)
storage_t::arg_type get() const
AuthenticationRegistry servers
bool remove(const AuthenticationPlugin::shared_pointer &plugin)
Remove an existing entry. Remove true if the entry was actually removed.
bool remove(const AuthorizationPlugin::shared_pointer &plugin)
PVString is special case, since it implements SerializableArray.
#define EPICS_THREAD_ONCE_INIT
static AuthenticationRegistry & servers()
The server side of the conversation.
static size_t num_instances
epicsGuard< epicsMutex > Guard
LIBCOM_API void epicsStdCall epicsThreadOnce(epicsThreadOnceId *id, EPICSTHREADFUNC, void *arg)
void snapshot(list_t &plugmap) const
Save a copy of the current registry in order of increasing priority.
AuthenticationPlugin::shared_pointer lookup(const std::string &name) const
This class implements a Bytebuffer that is like the java.nio.ByteBuffer.
void add(int prio, const std::string &name, const AuthenticationPlugin::shared_pointer &plugin)
Add a new plugin to this registry.
Data interface for a structure,.
void registerRefCounter(const char *name, const size_t *counter)
std::tr1::shared_ptr< PVStructure > PVStructurePtr
virtual void handleResponse(osiSockAddr *responseFrom, Transport::shared_pointer const &transport, epics::pvData::int8 version, epics::pvData::int8 command, size_t payloadSize, epics::pvData::ByteBuffer *payloadBuffer)
virtual ~AuthenticationPluginControl()
LIBCOM_API osiGetUserNameReturn epicsStdCall osiGetUserName(char *pBuf, unsigned bufSizeIn)
AuthenticationRegistry clients
AuthorizationRegistry authorizers
static AuthorizationRegistry & plugins()
static AuthenticationRegistry & clients()
The client side of the conversation.
virtual epics::pvData::PVStructure::const_shared_pointer initializationData()
std::vector< map_t::mapped_type > list_t
C++ and C descriptions for a thread.
static FieldBuilderPtr begin()
FORCE_INLINE const PVDataCreatePtr & getPVDataCreate()
virtual ~AuthorizationPlugin()
~AuthenticationRegistry()