Getting BadUserAccessDenied error in Write()

Unified Architecture topics related to OPC UA Specification, compliant behavior and any technical issues of OPC UA, like Security, Information Model, Companion Specs DI, PLCopen, ADI, ...

Moderator: Support Team

Post Reply
jschulte@wyatt.com
Jr. Member
Jr. Member
Posts: 3
Joined: 29 Oct 2018, 23:42

Getting BadUserAccessDenied error in Write()

Post by jschulte@wyatt.com »

Hello!

I've edited this to add this part upfront. My original question is still below. I think my larger issue is really just I don't understand how a device that hosts a server is supposed to write to nodes on that server, and otherwise control it. I thought the most natural thing is to use the functions that the server provides in the examples directly, but now I'm not so sure. Let's say you had an instrument that would report some kind of measurement to the server (which I imagine is most often how these servers are used). How does it do its reporting? Does the instrument itself own a client? That is the only way I've gotten it to work - to write to server nodes through a client - but that seems wrong.

I'm adding a writeToNode() function to the Lesson3aNodeManager class from the Getting Started Lesson 3 example server. I just want to be able to write to a node directly, so the writeToNode() function will really just be a wrapper for the Write() function. With my current setup (code below) The Write() function is getting into the m_system.Write() attempt, but this is returning false, which results in a StatusCodes.BadUserAccessDenied error. You can see I've got printouts above where I try to see whether this context has access to Write to this node. This printout prints "True". Is there some other type access the context needs in order to be able to write to this node? Thanks!

Code: Select all

protected override void Write(
            RequestContext context,
            TransactionHandle transaction,
            IList<NodeAttributeOperationHandle> operationHandles,
            IList<WriteValue> settings)
        {
            for (int ii = 0; ii < operationHandles.Count; ii++)
            {
                StatusCode error = StatusCodes.Good;

                UserAccessMask mask = UserAccessMask.Write;
                Console.Write(this.HasAccess(Server.DefaultRequestContext, operationHandles[ii].NodeHandle, mask));
                Console.Write("\n");

                // the data passed to CreateVariable is returned as the UserData in the handle.
                SystemAddress address = operationHandles[ii].NodeHandle.UserData as SystemAddress;

                if (address != null)
                {
                    if (!String.IsNullOrEmpty(settings[ii].IndexRange))
                    {
                        error = StatusCodes.BadIndexRangeInvalid;
                    }
                    else if (!m_system.Write(address.Address, address.Offset, settings[ii].Value.Value))
                    {
                        error = StatusCodes.BadUserAccessDenied;
                    }
                }
                else
                {
                    error = StatusCodes.BadNodeIdUnknown;
                }

                // return the data to the caller.
                ((WriteCompleteEventHandler)transaction.Callback)(
                    operationHandles[ii],
                    transaction.CallbackData,
                    error,
                    false);
            }
        }
        /// [Write]

Post Reply