sciortid commented on issue #1844:
URL: https://github.com/apache/plc4x/issues/1844#issuecomment-2435514816
I would be glad to help in case you need some dumb tester 😅
Here is my server that accepts both user and certificate authentication, as
said I tested it with UA expert with both methods
```
from opcua import Server, ua
import time
import random
# Imposta il server
server = Server()
# Imposta l'endpoint del server
server.set_endpoint("opc.tcp://127.0.0.1:4840")
# Aggiungi un namespace personalizzato
uri = "urn:freeopcua:python:server"
idx = server.register_namespace(uri)
# Imposta le politiche di sicurezza
server.set_security_policy([
#ua.SecurityPolicyType.NoSecurity, # Connessioni non sicure (solo per
testing)
# ua.SecurityPolicyType.Basic256Sha256_Sign, # Connessioni sicure seza
cifratura
ua.SecurityPolicyType.Basic256Sha256_SignAndEncrypt # Connessioni
sicure con cifratura
])
# Imposta i tipi di sicurezza
server.set_security_IDs(["Basic256Sha256", "Username"])
### AUTENTICAZIONE CON USERNAME E PASSWORD ###
def user_manager(isession, username, password):
users = {
"user1": "password1",
"user2": "password2"
}
if username in users and users[username] == password:
print(f"Login riuscito per l'utente: {username}")
return True
else:
print(f"Tentativo di login fallito per l'utente: {username}")
return False
# Configura il server per utilizzare l'autenticazione username/password
server.user_manager.set_user_manager(user_manager)
### AUTENTICAZIONE CON CERTIFICATI ###
server.load_certificate("certificates/server_certificate.der")
server.load_private_key("certificates/server_private_key.pem")
# Crea un oggetto principale per i tag
tags_container = server.nodes.objects.add_object("ns=2;i=1", "Tags")
# Dizionario per memorizzare i riferimenti ai nodi delle variabili
node_references = {}
# Aggiungi variabili all'oggetto Tags
variables = {
"Var1": (44, ua.VariantType.Int32),
"Var2": (19, ua.VariantType.Int32)
}
# Aggiungi le variabili al container Tags e memorizza i riferimenti
for name, (value, var_type) in variables.items():
variable = tags_container.add_variable("ns=2;s={}".format(name), name,
value, varianttype=var_type)
variable.set_writable() # Imposta la variabile come scrivibile
node_references[name] = variable # Memorizza il riferimento
# Avvia il server
server.start()
try:
while True:
# Aggiorna i valori casualmente per alcune variabili
node_references["Var1"].set_value(random.randint(0, 100))
time.sleep(1) # Aspetta 1 secondo
finally:
# Ferma il server al termine
server.stop()
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]