open62541pp 0.16.0
C++ wrapper of open62541
Loading...
Searching...
No Matches
accesscontrol.hpp
Go to the documentation of this file.
1#pragma once
2
4#include "open62541pp/common.hpp" // AccessLevel, WriteMask
5#include "open62541pp/detail/open62541/common.h" // UA_AccessControl
10#include "open62541pp/types_composed.hpp" // UserTokenPolicy, PerformUpdateType
11
12namespace opcua {
13
14/**
15 * Access control base class.
16 *
17 * Used to authenticate sessions and grant access rights accordingly.
18 * Custom access control can be implemented by deriving from this class and overwriting the access
19 * control callbacks.
20 *
21 * If exceptions are thrown within the access control callbacks, they are caught in the C callbacks
22 * and will return the most restrictive access rights, e.g. `AccessLevel::None` in
23 * `getUserAccessLevel` or `false` in `allowAddNode`. The exception will be logged (warning level).
24 *
25 * The `sessionId` can originally be both `NULL` in open62541.
26 * This is the case when, for example, a MonitoredItem (the underlying Subscription) is detached
27 * from its Session but continues to run.
28 * This wrapper passes `session` by reference, so it can't be `NULL`.
29 * Instead, a `session` with an empty `sessionId` will be passed.
30 *
31 * @see UA_AccessControl
32 * @see https://www.open62541.org/doc/1.3/plugin_accesscontrol.html
33 */
34class AccessControlBase : public PluginAdapter<UA_AccessControl> {
35public:
36 /**
37 * Get available user token policies.
38 * If the `securityPolicyUri` is empty, the highest available security policy will be used to
39 * transfer user tokens.
40 * @note The returned span must be valid throughout the lifetime of the instance.
41 */
43
44 /**
45 * Authenticate a session.
46 * The new session is rejected if a status code other than `UA_STATUSCODE_GOOD` is returned.
47 */
49 Session& session,
50 const EndpointDescription& endpointDescription,
51 const ByteString& secureChannelRemoteCertificate,
52 const ExtensionObject& userIdentityToken
53 ) = 0;
54
55 /// Deauthenticate a session and cleanup session context.
56 virtual void closeSession(Session& session) = 0;
57
58 /// Access control for all nodes.
59 virtual Bitmask<WriteMask> getUserRightsMask(Session& session, const NodeId& nodeId) = 0;
60
61 /// Additional access control for variable nodes.
62 virtual Bitmask<AccessLevel> getUserAccessLevel(Session& session, const NodeId& nodeId) = 0;
63
64 /// Additional access control for method nodes.
65 virtual bool getUserExecutable(Session& session, const NodeId& methodId) = 0;
66
67 /// Additional access control for calling a method node in the context of a specific object.
69 Session& session, const NodeId& methodId, const NodeId& objectId
70 ) = 0;
71
72 /// Allow adding a node.
73 virtual bool allowAddNode(Session& session, const AddNodesItem& item) = 0;
74
75 /// Allow adding a reference.
76 virtual bool allowAddReference(Session& session, const AddReferencesItem& item) = 0;
77
78 /// Allow deleting a node.
79 virtual bool allowDeleteNode(Session& session, const DeleteNodesItem& item) = 0;
80
81 /// Allow deleting a reference.
82 virtual bool allowDeleteReference(Session& session, const DeleteReferencesItem& item) = 0;
83
84 /// Allow browsing a node.
85 virtual bool allowBrowseNode(Session& session, const NodeId& nodeId) = 0;
86
87 /// Allow transfer of a subscription to another session.
88 virtual bool allowTransferSubscription(Session& oldSession, Session& newSession) = 0;
89
90 /// Allow insert, replace, update of historical data.
91 virtual bool allowHistoryUpdate(
92 Session& session,
93 const NodeId& nodeId,
94 PerformUpdateType performInsertReplace,
95 const DataValue& value
96 ) = 0;
97
98 /// Allow delete of historical data.
99 virtual bool allowHistoryDelete(
100 Session& session,
101 const NodeId& nodeId,
102 DateTime startTimestamp,
103 DateTime endTimestamp,
104 bool isDeleteModified
105 ) = 0;
106
107 UA_AccessControl create(bool ownsAdapter) override;
108};
109
110namespace detail {
111void clear(UA_AccessControl& ac) noexcept;
112} // namespace detail
113
114} // namespace opcua
Access control base class.
virtual Span< UserTokenPolicy > getUserTokenPolicies()=0
Get available user token policies.
virtual bool allowDeleteReference(Session &session, const DeleteReferencesItem &item)=0
Allow deleting a reference.
virtual bool allowHistoryDelete(Session &session, const NodeId &nodeId, DateTime startTimestamp, DateTime endTimestamp, bool isDeleteModified)=0
Allow delete of historical data.
virtual bool getUserExecutableOnObject(Session &session, const NodeId &methodId, const NodeId &objectId)=0
Additional access control for calling a method node in the context of a specific object.
virtual bool allowAddNode(Session &session, const AddNodesItem &item)=0
Allow adding a node.
virtual bool getUserExecutable(Session &session, const NodeId &methodId)=0
Additional access control for method nodes.
virtual bool allowBrowseNode(Session &session, const NodeId &nodeId)=0
Allow browsing a node.
virtual bool allowDeleteNode(Session &session, const DeleteNodesItem &item)=0
Allow deleting a node.
UA_AccessControl create(bool ownsAdapter) override
virtual Bitmask< WriteMask > getUserRightsMask(Session &session, const NodeId &nodeId)=0
Access control for all nodes.
virtual Bitmask< AccessLevel > getUserAccessLevel(Session &session, const NodeId &nodeId)=0
Additional access control for variable nodes.
virtual StatusCode activateSession(Session &session, const EndpointDescription &endpointDescription, const ByteString &secureChannelRemoteCertificate, const ExtensionObject &userIdentityToken)=0
Authenticate a session.
virtual bool allowTransferSubscription(Session &oldSession, Session &newSession)=0
Allow transfer of a subscription to another session.
virtual bool allowHistoryUpdate(Session &session, const NodeId &nodeId, PerformUpdateType performInsertReplace, const DataValue &value)=0
Allow insert, replace, update of historical data.
virtual void closeSession(Session &session)=0
Deauthenticate a session and cleanup session context.
virtual bool allowAddReference(Session &session, const AddReferencesItem &item)=0
Allow adding a reference.
UA_AddNodesItem wrapper class.
UA_AddReferencesItem wrapper class.
Bitmask using (scoped) enums.
Definition bitmask.hpp:125
UA_ByteString wrapper class.
Definition types.hpp:490
UA_DataValue wrapper class.
Definition types.hpp:1478
UA_DateTime wrapper class.
Definition types.hpp:354
UA_DeleteNodesItem wrapper class.
UA_DeleteReferencesItem wrapper class.
UA_EndpointDescription wrapper class.
UA_ExtensionObject wrapper class.
Definition types.hpp:1664
UA_NodeId wrapper class.
Definition types.hpp:590
Base class to implement plugin adapters.
High-level session class to manage client sessions.
Definition session.hpp:20
View to a contiguous sequence of objects, similar to std::span in C++20.
Definition span.hpp:26
UA_StatusCode wrapper class.
Definition types.hpp:44
PerformUpdateType
Perform update type for structured data history updates.
constexpr void clear(T &native, const UA_DataType &type) noexcept