How to use the node-opcua-status-code.StatusCodes.BadUserAccessDenied function in node-opcua-status-code

To help you get started, we’ve selected a few node-opcua-status-code examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_variable.js View on Github external
// adjust arguments if optional indexRange Parameter is not given
    if (!_.isFunction(callback) && _.isFunction(indexRange)) {
        callback = indexRange;
        indexRange = new NumericRange();
    }
    assert(_.isFunction(callback));
    assert(dataValue instanceof DataValue);

    indexRange = NumericRange.coerce(indexRange);

    // test write permission
    if (!self.isWritable(context)) {
        return callback(null, StatusCodes.BadNotWritable);
    }
    if (!self.isUserWritable(context)) {
        return callback(null, StatusCodes.BadUserAccessDenied);
    }

    // adjust special case
    const variant = adjustVariant(self, dataValue.value);

    const statusCode = self.isValueInRange(variant);
    if (statusCode.isNot(StatusCodes.Good)) {
        return callback(null, statusCode);
    }

    if (!self._timestamped_set_func) {
        console.log(" warning " + self.nodeId.toString() + " has no _timestamped_set_func");
        return callback(null, StatusCodes.BadNotWritable);
    }

    assert(self._timestamped_set_func);
github node-opcua / node-opcua / packages / node-opcua-server-configuration / source / push_certificate_manager_helpers.ts View on Github external
async function _applyChanges(
  this: UAMethod,
  inputArguments: Variant[],
  context: SessionContext
): Promise {

    // This Method requires an encrypted channel and that the Client provide credentials with
    // administrative rights on the Server.
    if (!hasEncryptedChannel(context)) {
        return { statusCode: StatusCodes.BadSecurityModeInsufficient };
    }
    if (!hasExpectedUserAccess(context)) {
        return { statusCode: StatusCodes.BadUserAccessDenied };
    }

    const pushCertificateManager = getPushCertificateManager(this);
    if (!pushCertificateManager) {
        return { statusCode: StatusCodes.BadNotImplemented };
    }
    const statusCode = await pushCertificateManager.applyChanges();
    return { statusCode };
}
github node-opcua / node-opcua / packages / node-opcua-server / source / server_engine.ts View on Github external
assert(_.isFunction(callback));

  assert(context.hasOwnProperty("session"), " expecting a session id in the context object");

  const session = context.session as ServerSession;
  if (!session) {
    return callback(null, { statusCode: StatusCodes.BadInternalError });
  }

  const subscriptionId = inputArguments[0].value;
  const subscription = session.getSubscription(subscriptionId);
  if (!subscription) {
    // subscription may belongs to a different session  that ours
    if (engine.findSubscription(subscriptionId)) {
      // if yes, then access to  Subscription data should be denied
      return callback(null, { statusCode: StatusCodes.BadUserAccessDenied });
    }

    return callback(null, { statusCode: StatusCodes.BadSubscriptionIdInvalid });
  }
  const result = subscription.getMonitoredItems();
  assert(result.statusCode);
  assert(_.isArray(result.serverHandles));
  assert(_.isArray(result.clientHandles));
  assert(result.serverHandles.length === result.clientHandles.length);
  const callMethodResult = new CallMethodResult({
    statusCode: result.statusCode,

    outputArguments: [
      { dataType: DataType.UInt32, arrayType: VariantArrayType.Array, value: result.serverHandles },
      { dataType: DataType.UInt32, arrayType: VariantArrayType.Array, value: result.clientHandles }
    ]
github node-opcua / node-opcua / packages / node-opcua-server / src / server_engine.js View on Github external
assert(_.isFunction(callback));

    assert(context.hasOwnProperty("session"), " expecting a session id in the context object");

    const session = context.session;
    if (!session) {
        return callback(null, {statusCode: StatusCodes.BadInternalError});
    }

    const subscriptionId = inputArguments[0].value;
    const subscription = session.getSubscription(subscriptionId);
    if (!subscription) {
        // subscription may belongs to a different session  that ours
        if (engine.findSubscription(subscriptionId)) {
            // if yes, then access to  Subscription data should be denied
            return callback(null, {statusCode: StatusCodes.BadUserAccessDenied});
        }

        return callback(null, {statusCode: StatusCodes.BadSubscriptionIdInvalid});
    }
    const result = subscription.getMonitoredItems();
    assert(result.statusCode);
    assert(_.isArray(result.serverHandles));
    assert(_.isArray(result.clientHandles));
    assert(result.serverHandles.length === result.clientHandles.length);
    const callMethodResult = new CallMethodResult({
        statusCode: result.statusCode,
        outputArguments: [
            {dataType: DataType.UInt32, arrayType: VariantArrayType.Array, value: result.serverHandles},
            {dataType: DataType.UInt32, arrayType: VariantArrayType.Array, value: result.clientHandles}
        ]
    });
github node-opcua / node-opcua / packages / node-opcua-server / src / opcua_server.js View on Github external
server.isUserAuthorized(channel, session, request.userIdentityToken, function (err, authorized) {

        if (err) {
            return rejectConnection(StatusCodes.BadInternalError);
        }

        if (!authorized) {
            return rejectConnection(StatusCodes.BadUserAccessDenied);
        } else {
            // extract : OPC UA part 4 - 5.6.3
            // Once used, a serverNonce cannot be used again. For that reason, the Server returns a new
            // serverNonce each time the ActivateSession Service is called.
            session.nonce = server.makeServerNonce();

            session.status = "active";

            response = new ActivateSessionResponse({serverNonce: session.nonce});
            channel.send_response("MSG", response, message);

            const userIdentityTokenPasswordRemoved = function (userIdentityToken) {
                const a = userIdentityToken;
                // to do remove password
                return a;
            };
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_variable.ts View on Github external
callback = args[1];
        } else {
            throw new Error("Invalid Number of args");
        }

        assert(_.isFunction(callback));
        assert(dataValue instanceof DataValue);
        // index range could be string
        indexRange = NumericRange.coerce(indexRange);

        // test write permission
        if (!this.isWritable(context)) {
            return callback!(null, StatusCodes.BadNotWritable);
        }
        if (!this.isUserWritable(context)) {
            return callback!(null, StatusCodes.BadUserAccessDenied);
        }

        // adjust special case
        const variant = adjustVariant.call(this, dataValue.value);

        const statusCode = this.checkVariantCompatibility(variant);
        if (statusCode.isNot(StatusCodes.Good)) {
            return callback!(null, statusCode);
        }

        const write_func = this._timestamped_set_func || ((
            dataValue1: DataValue,
            indexRange1: NumericRange,
            callback1: (err: Error | null, statusCode: StatusCode, dataValue?: DataValue | null | undefined) => void
        ) => {
            // xx assert(!indexRange,"indexRange Not Implemented");
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_variable.ts View on Github external
public readValue(context?: SessionContext | null, indexRange?: NumericRange, dataEncoding?: string) {

        if (!context) {
            context = SessionContext.defaultContext;
        }

        if (!this.isReadable(context)) {
            return new DataValue({ statusCode: StatusCodes.BadNotReadable });
        }
        if (!this.isUserReadable(context)) {
            return new DataValue({ statusCode: StatusCodes.BadUserAccessDenied });
        }
        if (!isValidDataEncoding(dataEncoding)) {
            return new DataValue({ statusCode: StatusCodes.BadDataEncodingInvalid });
        }

        if (this._timestamped_get_func) {
            assert(this._timestamped_get_func.length === 0);
            this._dataValue = this._timestamped_get_func();
        }

        let dataValue = this._dataValue;

        if (isGoodish(dataValue.statusCode)) {
            // note : extractRange will clone the dataValue
            dataValue = extractRange(dataValue, indexRange);
        }
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_variable.js View on Github external
func = function (callback) {
            const dataValue = new DataValue({statusCode: StatusCodes.BadUserAccessDenied});
            callback(null, dataValue);
        }
    } else {
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_variable.js View on Github external
UAVariable.prototype.readValue = function (context, indexRange, dataEncoding) {

    if (!context) {
        context = SessionContext.defaultContext;
    }
    const self = this;

    if (!self.isReadable(context)) {
        return new DataValue({statusCode: StatusCodes.BadNotReadable});
    }
    if (!self.isUserReadable(context)) {
        return new DataValue({statusCode: StatusCodes.BadUserAccessDenied});
    }
    if (!is_valid_dataEncoding(dataEncoding)) {
        return new DataValue({statusCode: StatusCodes.BadDataEncodingInvalid});
    }

    if (self._timestamped_get_func) {
        assert(self._timestamped_get_func.length === 0);
        self._dataValue = self._timestamped_get_func();
    }

    let dataValue = self._dataValue;

    if (isGoodish(dataValue.statusCode)) {

        dataValue = extractRange(dataValue, indexRange);
    }