How come the BaseObjectState is used to implement Role objects instead of the RoleState? #2215
Unanswered
DmitryFarberov
asked this question in
Q&A
Replies: 2 comments
-
|
Hello @DmitryFarberov , Thanks |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
It's been a while, so let me see if I remember this correctly. It wasn't all that easy or obvious, so here it goes.
First of all, I added a Role Node Manager (all my Node Managers derive from CustomNodeManager2) and provided this override:
public override void CreateAddressSpace(IDictionary<NodeId, IList<IReference>> externalReferences)
{
var accessControl = ConfigurationContext.OpcUaServerConfiguration.AccessControl;
uint numericNodeId = 100000;
foreach (var accessControlRole in accessControl.Roles)
{
if (accessControlRole.IsWellKnowwn)
continue;
accessControlRole.NodeId = new NodeId(numericNodeId++, NamespaceIndex);
RoleState role = new RoleState(null)
{
NodeId = accessControlRole.NodeId,
ReferenceTypeId = ReferenceTypeIds.HasComponent,
TypeDefinitionId = ObjectTypeIds.RoleType,
SymbolicName = "ConfiguredRole_" + accessControlRole.Name,
BrowseName = accessControlRole.Name,
DisplayName = accessControlRole.Name,
WriteMask = AttributeWriteMask.None,
UserWriteMask = AttributeWriteMask.None,
EventNotifier = EventNotifiers.None
};
PropertyState property = role.AddProperty<IdentityMappingRuleTypeCollection>("Identities", DataTypeIds.IdentityMappingRuleType, ValueRanks.OneDimension);
property.NodeId = new NodeId(numericNodeId++, NamespaceIndex);
property.ArrayDimensions = new ReadOnlyList<uint>(new List<uint>() {0});
property.MinimumSamplingInterval = 0;
property = role.AddProperty<bool>("ApplicationsExclude", DataTypeIds.Boolean, ValueRanks.Scalar);
property.NodeId = new NodeId(numericNodeId++, NamespaceIndex);
property.Value = false;
property.MinimumSamplingInterval = 0;
property = role.AddProperty<StringCollection>("Applications", DataTypeIds.String, ValueRanks.OneDimension);
property.NodeId = new NodeId(numericNodeId++, NamespaceIndex);
property.ArrayDimensions = new ReadOnlyList<uint>(new List<uint>() {0});
property.MinimumSamplingInterval = 0;
property = role.AddProperty<bool>("EndpointsExclude", DataTypeIds.Boolean, ValueRanks.Scalar);
property.NodeId = new NodeId(numericNodeId++, NamespaceIndex);
property.Value = false;
property.MinimumSamplingInterval = 0;
property = role.AddProperty<EndpointTypeCollection>("Endpoints", DataTypeIds.EndpointType, ValueRanks.OneDimension);
property.NodeId = new NodeId(numericNodeId++, NamespaceIndex);
property.ArrayDimensions = new ReadOnlyList<uint>(new List<uint>() {0});
property.MinimumSamplingInterval = 0;
AddPredefinedNode(SystemContext, role);
}
}
Also, in my main Server class derived from StandardServer I provided this override:
protected override void OnNodeManagerStarted(IServerInternal server)
{
// allow base class processing to happen first.
base.OnNodeManagerStarted(server);
UapRoleNodeManager roleNodeManager = server.NodeManager?.NodeManagers.FirstOrDefault(m => m is UapRoleNodeManager) as UapRoleNodeManager;
RoleSetState roleSet = server.ServerObject.ServerCapabilities.RoleSet;
var accessControl = ConfigurationContext.OpcUaServerConfiguration.AccessControl;
foreach (var accessControlRole in accessControl.Roles)
{
if (accessControlRole.IsWellKnowwn)
continue;
roleSet.AddReference(ReferenceTypeIds.HasComponent, false, accessControlRole.NodeId);
}
IList<IReference> references = new List<IReference>();
roleSet.GetReferences(server.DefaultSystemContext, references);
foreach (var reference in references)
{
NodeId nodeId = new NodeId(reference.TargetId.Identifier, reference.TargetId.NamespaceIndex);
INodeManager nodeManager;
NodeHandle handle = server.NodeManager.GetManagerHandle(nodeId, out nodeManager) as NodeHandle;
string typeName = handle.Node.GetType().Name;
BaseObjectState roleObject = handle.Node as BaseObjectState;
IList<IReference> roleReferences = new List<IReference>();
roleObject.GetReferences(server.DefaultSystemContext, roleReferences);
}
}
HTH. Good luck.
From: anderZubi <notifications@github.com>
Sent: Tuesday, February 2, 2021 6:06 AM
To: OPCFoundation/UA-.NETStandard <UA-.NETStandard@noreply.github.com>
Cc: Dmitry Farberov <dmitry@sisconet.com> <Dmitry@sisconet.com>; Mention <mention@noreply.github.com>
Subject: Re: [OPCFoundation/UA-.NETStandard] How come the BaseObjectState is used to implement Role objects instead of the RoleState? (#1005)
Hello @DmitryFarberov<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FDmitryFarberov&data=04%7C01%7C%7C5a8a6e3882cb475bfe8308d8c783b641%7C3facb489b8934c828d7b0d43735c80dd%7C0%7C0%7C637478715800440085%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=5QDxO51Xs8QhYBvquZLebiNlcJUMvYyGTHDimQVeHKg%3D&reserved=0> ,
Could you implement custom roles? How did you do it? I'm struggling to figure it out.
Thanks
-
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FOPCFoundation%2FUA-.NETStandard%2Fissues%2F1005%23issuecomment-771657699&data=04%7C01%7C%7C5a8a6e3882cb475bfe8308d8c783b641%7C3facb489b8934c828d7b0d43735c80dd%7C0%7C0%7C637478715800440085%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=lmcr2IC9YEnluLl9M87crsELnQoub4gus%2FR%2FdB3loyM%3D&reserved=0>, or unsubscribe<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAPPKB4HQH4BVPLUUZK5CWDDS5ABFVANCNFSM4NVG2EGQ&data=04%7C01%7C%7C5a8a6e3882cb475bfe8308d8c783b641%7C3facb489b8934c828d7b0d43735c80dd%7C0%7C0%7C637478715800450042%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=qy9S8EHMJGAfpq9emjjE9WTwD%2F8Ng8fLn%2BHakWNB5Do%3D&reserved=0>.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I would've thought the RoleState class would've been used here, but it doesn't appear to be the case.
First of all, I would like a conformation that my findings are correct, and they are, I would like to know why it was implemented this way. And if I'm implementing custom Roles, should I use the BaseObjectState or RoleState?
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions