Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
opcua-asyncio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nikola Balog
opcua-asyncio
Commits
8a6018f9
Commit
8a6018f9
authored
Oct 11, 2024
by
Christoph Ziebuhr
Committed by
oroulet
Oct 16, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow regular users to do write requests
parent
ec227ba7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
15 deletions
+17
-15
asyncua/crypto/permission_rules.py
asyncua/crypto/permission_rules.py
+8
-8
tests/test_permissions.py
tests/test_permissions.py
+9
-7
No files found.
asyncua/crypto/permission_rules.py
View file @
8a6018f9
from
asyncua
import
ua
from
asyncua.server.users
import
UserRole
WRITE_TYPES
=
[
ua
.
ObjectIds
.
WriteRequest_Encoding_DefaultBinary
,
ADMIN_TYPES
=
[
ua
.
ObjectIds
.
RegisterServerRequest_Encoding_DefaultBinary
,
ua
.
ObjectIds
.
RegisterServer2Request_Encoding_DefaultBinary
,
ua
.
ObjectIds
.
AddNodesRequest_Encoding_DefaultBinary
,
...
...
@@ -11,11 +10,12 @@ WRITE_TYPES = [
ua
.
ObjectIds
.
DeleteReferencesRequest_Encoding_DefaultBinary
,
]
READ
_TYPES
=
[
USER
_TYPES
=
[
ua
.
ObjectIds
.
CreateSessionRequest_Encoding_DefaultBinary
,
ua
.
ObjectIds
.
CloseSessionRequest_Encoding_DefaultBinary
,
ua
.
ObjectIds
.
ActivateSessionRequest_Encoding_DefaultBinary
,
ua
.
ObjectIds
.
ReadRequest_Encoding_DefaultBinary
,
ua
.
ObjectIds
.
WriteRequest_Encoding_DefaultBinary
,
ua
.
ObjectIds
.
BrowseRequest_Encoding_DefaultBinary
,
ua
.
ObjectIds
.
GetEndpointsRequest_Encoding_DefaultBinary
,
ua
.
ObjectIds
.
FindServersRequest_Encoding_DefaultBinary
,
...
...
@@ -49,15 +49,15 @@ class PermissionRuleset:
class
SimpleRoleRuleset
(
PermissionRuleset
):
"""
Standard simple role-based ruleset.
Admins alone can
write, admins and users can read
, and anonymous users can't do anything.
Admins alone can
change address space, admins and users can read/write
, and anonymous users can't do anything.
"""
def
__init__
(
self
):
write_ids
=
list
(
map
(
ua
.
NodeId
,
WRITE
_TYPES
))
read_ids
=
list
(
map
(
ua
.
NodeId
,
READ
_TYPES
))
admin_ids
=
list
(
map
(
ua
.
NodeId
,
ADMIN
_TYPES
))
user_ids
=
list
(
map
(
ua
.
NodeId
,
USER
_TYPES
))
self
.
_permission_dict
=
{
UserRole
.
Admin
:
set
().
union
(
write_ids
,
read
_ids
),
UserRole
.
User
:
set
().
union
(
read
_ids
),
UserRole
.
Admin
:
set
().
union
(
admin_ids
,
user
_ids
),
UserRole
.
User
:
set
().
union
(
user
_ids
),
UserRole
.
Anonymous
:
set
()
}
...
...
tests/test_permissions.py
View file @
8a6018f9
...
...
@@ -88,9 +88,9 @@ async def test_permissions_admin(srv_crypto_one_cert):
assert
await
clt
.
get_objects_node
().
get_children
()
objects
=
clt
.
nodes
.
objects
child
=
await
objects
.
get_child
([
'0:MyObject'
,
'0:MyVariable'
])
await
child
.
read_value
()
await
child
.
set_value
(
42.0
)
assert
await
child
.
read_value
()
==
42.0
await
child
.
add_property
(
0
,
"MyProperty1"
,
3
)
async
def
test_permissions_user
(
srv_crypto_one_cert
):
clt
=
Client
(
uri_crypto_cert
)
...
...
@@ -106,9 +106,10 @@ async def test_permissions_user(srv_crypto_one_cert):
assert
await
clt
.
get_objects_node
().
get_children
()
objects
=
clt
.
nodes
.
objects
child
=
await
objects
.
get_child
([
'0:MyObject'
,
'0:MyVariable'
])
await
child
.
read_value
()
await
child
.
set_value
(
44.0
)
assert
await
child
.
read_value
()
==
44.0
with
pytest
.
raises
(
ua
.
uaerrors
.
BadUserAccessDenied
):
await
child
.
set_value
(
42
)
await
child
.
add_property
(
0
,
"MyProperty2"
,
3
)
async
def
test_permissions_anonymous
(
srv_crypto_one_cert
):
...
...
@@ -121,6 +122,7 @@ async def test_permissions_anonymous(srv_crypto_one_cert):
server_certificate
=
srv_crypto_params
[
0
][
1
],
mode
=
ua
.
MessageSecurityMode
.
SignAndEncrypt
)
await
clt
.
connect
()
await
clt
.
get_endpoints
()
await
clt
.
disconnect
()
async
with
clt
:
await
clt
.
get_endpoints
()
with
pytest
.
raises
(
ua
.
uaerrors
.
BadUserAccessDenied
):
await
clt
.
nodes
.
objects
.
get_children
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment