当前位置: 首页>>代码示例>>Java>>正文


Java StatusCodes类代码示例

本文整理汇总了Java中com.digitalpetri.opcua.stack.core.StatusCodes的典型用法代码示例。如果您正苦于以下问题:Java StatusCodes类的具体用法?Java StatusCodes怎么用?Java StatusCodes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StatusCodes类属于com.digitalpetri.opcua.stack.core包,在下文中一共展示了StatusCodes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validateSubjectAltNameField

import com.digitalpetri.opcua.stack.core.StatusCodes; //导入依赖的package包/类
public static boolean validateSubjectAltNameField(X509Certificate certificate, int field,
                                                  Predicate<Object> fieldValidator) throws UaException {

    try {
        Collection<List<?>> subjectAltNames = certificate.getSubjectAlternativeNames();
        if (subjectAltNames == null) subjectAltNames = Collections.emptyList();

        for (List<?> idAndValue : subjectAltNames) {
            if (idAndValue != null && idAndValue.size() == 2) {
                if (idAndValue.get(0).equals(field)) {
                    if (fieldValidator.test(idAndValue.get(1))) {
                        return true;
                    }
                }
            }
        }

        return false;
    } catch (CertificateParsingException e) {
        throw new UaException(StatusCodes.Bad_CertificateInvalid, e);
    }
}
 
开发者ID:digitalpetri,项目名称:opc-ua-stack,代码行数:23,代码来源:CertificateValidationUtil.java

示例2: getServerSignature

import com.digitalpetri.opcua.stack.core.StatusCodes; //导入依赖的package包/类
private SignatureData getServerSignature(ByteString clientNonce,
                                         ByteString clientCertificate,
                                         SecurityPolicy securityPolicy,
                                         KeyPair keyPair) throws UaException {

    if (clientNonce.isNull() || clientCertificate.isNull() || keyPair == null) {
        return new SignatureData(null, null);
    }

    try {
        SecurityAlgorithm algorithm = securityPolicy.getAsymmetricSignatureAlgorithm();

        byte[] data = Bytes.concat(clientCertificate.bytes(), clientNonce.bytes());

        byte[] signature = SignatureUtil.sign(
                algorithm,
                keyPair.getPrivate(),
                ByteBuffer.wrap(data)
        );

        return new SignatureData(algorithm.getUri(), ByteString.of(signature));
    } catch (UaRuntimeException e) {
        throw new UaException(StatusCodes.Bad_SecurityChecksFailed);
    }
}
 
开发者ID:digitalpetri,项目名称:ua-server-sdk,代码行数:26,代码来源:SessionManager.java

示例3: getAndInitializeCipher

import com.digitalpetri.opcua.stack.core.StatusCodes; //导入依赖的package包/类
@Override
public Cipher getAndInitializeCipher(SecureChannel channel) throws UaException {
    try {
        String transformation = channel.getSecurityPolicy().getSymmetricEncryptionAlgorithm().getTransformation();
        ChannelSecurity.SecretKeys secretKeys = channel.getEncryptionKeys(securitySecrets);

        SecretKeySpec keySpec = new SecretKeySpec(secretKeys.getEncryptionKey(), "AES");
        IvParameterSpec ivSpec = new IvParameterSpec(secretKeys.getInitializationVector());

        Cipher cipher = Cipher.getInstance(transformation);
        cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec);

        assert (cipher.getBlockSize() == channel.getSymmetricCipherTextBlockSize());

        return cipher;
    } catch (GeneralSecurityException e) {
        throw new UaException(StatusCodes.Bad_SecurityChecksFailed, e);
    }
}
 
开发者ID:digitalpetri,项目名称:opc-ua-stack,代码行数:20,代码来源:ChunkEncoder.java

示例4: sign

import com.digitalpetri.opcua.stack.core.StatusCodes; //导入依赖的package包/类
/**
 * Sign the contents of the provided buffers using the provided {@link SecurityAlgorithm}.
 * Note that only the bytes between position and limit of each buffer are considered.
 *
 * @param securityAlgorithm the {@link SecurityAlgorithm}.
 * @param privateKey        the {@link PrivateKey} to sign with.
 * @param buffers           the data to sign.
 * @return the signature bytes.
 * @throws UaException
 */
public static byte[] sign(SecurityAlgorithm securityAlgorithm,
                          PrivateKey privateKey,
                          ByteBuffer... buffers) throws UaException {

    String transformation = securityAlgorithm.getTransformation();

    try {
        Signature signature = Signature.getInstance(transformation);
        signature.initSign(privateKey);

        for (ByteBuffer buffer : buffers) {
            signature.update(buffer);
        }

        return signature.sign();
    } catch (GeneralSecurityException e) {
        throw new UaException(StatusCodes.Bad_InternalError, e);
    }
}
 
开发者ID:digitalpetri,项目名称:opc-ua-stack,代码行数:30,代码来源:SignatureUtil.java

示例5: setPublishingMode

import com.digitalpetri.opcua.stack.core.StatusCodes; //导入依赖的package包/类
public void setPublishingMode(ServiceRequest<SetPublishingModeRequest, SetPublishingModeResponse> service) {
    SetPublishingModeRequest request = service.getRequest();
    UInteger[] subscriptionIds = request.getSubscriptionIds();
    StatusCode[] results = new StatusCode[subscriptionIds.length];

    for (int i = 0; i < subscriptionIds.length; i++) {
        Subscription subscription = subscriptions.get(subscriptionIds[i]);
        if (subscription == null) {
            results[i] = new StatusCode(StatusCodes.Bad_SubscriptionIdInvalid);
        } else {
            subscription.setPublishingMode(request);
            results[i] = StatusCode.GOOD;
        }
    }

    ResponseHeader header = service.createResponseHeader();
    SetPublishingModeResponse response = new SetPublishingModeResponse(
            header, results, new DiagnosticInfo[0]);

    service.setResponse(response);
}
 
开发者ID:digitalpetri,项目名称:ua-server-sdk,代码行数:22,代码来源:SubscriptionManager.java

示例6: returnStatusChangeNotification

import com.digitalpetri.opcua.stack.core.StatusCodes; //导入依赖的package包/类
void returnStatusChangeNotification(ServiceRequest<PublishRequest, PublishResponse> service) {
    StatusChangeNotification statusChange = new StatusChangeNotification(
            new StatusCode(StatusCodes.Bad_Timeout), null);

    UInteger sequenceNumber = uint(nextSequenceNumber());

    NotificationMessage notificationMessage = new NotificationMessage(
            sequenceNumber,
            new DateTime(),
            new ExtensionObject[]{ExtensionObject.encode(statusChange)}
    );

    ResponseHeader header = service.createResponseHeader();

    PublishResponse response = new PublishResponse(
            header, subscriptionId,
            new UInteger[0], false, notificationMessage,
            new StatusCode[0], new DiagnosticInfo[0]);

    service.setResponse(response);

    logger.debug("[id={}] returned StatusChangeNotification sequenceNumber={}.", subscriptionId, sequenceNumber);
}
 
开发者ID:digitalpetri,项目名称:ua-server-sdk,代码行数:24,代码来源:Subscription.java

示例7: onRegisterNodes

import com.digitalpetri.opcua.stack.core.StatusCodes; //导入依赖的package包/类
@Override
public void onRegisterNodes(ServiceRequest<RegisterNodesRequest, RegisterNodesResponse> service) throws UaException {
    OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();

    RegisterNodesRequest request = service.getRequest();

    NodeId[] nodeIds = request.getNodesToRegister();

    if (nodeIds.length == 0) {
        throw new UaException(StatusCodes.Bad_NothingToDo);
    }

    if (nodeIds.length > server.getConfig().getLimits().getMaxNodesPerRegisterNodes().intValue()) {
        throw new UaException(StatusCodes.Bad_TooManyOperations);
    }

    service.setResponse(new RegisterNodesResponse(
            service.createResponseHeader(StatusCode.GOOD),
            nodeIds
    ));
}
 
开发者ID:digitalpetri,项目名称:ua-server-sdk,代码行数:22,代码来源:ViewServices.java

示例8: onUnregisterNodes

import com.digitalpetri.opcua.stack.core.StatusCodes; //导入依赖的package包/类
@Override
public void onUnregisterNodes(ServiceRequest<UnregisterNodesRequest, UnregisterNodesResponse> service) throws UaException {
    OpcUaServer server = service.attr(ServiceAttributes.SERVER_KEY).get();

    UnregisterNodesRequest request = service.getRequest();

    NodeId[] nodeIds = request.getNodesToUnregister();

    if (nodeIds.length == 0) {
        throw new UaException(StatusCodes.Bad_NothingToDo);
    }

    if (nodeIds.length > server.getConfig().getLimits().getMaxNodesPerRegisterNodes().intValue()) {
        throw new UaException(StatusCodes.Bad_TooManyOperations);
    }

    service.setResponse(new UnregisterNodesResponse(service.createResponseHeader(StatusCode.GOOD)));
}
 
开发者ID:digitalpetri,项目名称:ua-server-sdk,代码行数:19,代码来源:ViewServices.java

示例9: encodeArray

import com.digitalpetri.opcua.stack.core.StatusCodes; //导入依赖的package包/类
@Override
public <T> void encodeArray(String field, T[] values, BiConsumer<String, T> consumer) throws UaSerializationException {
    if (values == null) {
        buffer.writeInt(-1);
    } else {
        if (values.length > maxArrayLength) {
            throw new UaSerializationException(StatusCodes.Bad_EncodingLimitsExceeded,
                    "max array length exceeded");
        }

        encodeInt32(null, values.length);
        for (T t : values) {
            consumer.accept(null, t);
        }
    }
}
 
开发者ID:digitalpetri,项目名称:opc-ua-stack,代码行数:17,代码来源:BinaryEncoder.java

示例10: writeDataTypeAttribute

import com.digitalpetri.opcua.stack.core.StatusCodes; //导入依赖的package包/类
private static void writeDataTypeAttribute(NamespaceManager ns, DataTypeNode node, AttributeId attributeId, DataValue value) throws UaException {
    UInteger writeMask = node.getWriteMask().orElse(uint(0));
    EnumSet<WriteMask> writeMasks = WriteMask.fromMask(writeMask);

    switch (attributeId) {
        case IsAbstract:
            if (writeMasks.contains(WriteMask.IsAbstract)) {
                node.setIsAbstract(extract(value));
            } else {
                throw new UaException(StatusCodes.Bad_NotWritable);
            }
            break;

        default:
            writeNodeAttribute(ns, node, attributeId, value);
    }
}
 
开发者ID:digitalpetri,项目名称:ua-server-sdk,代码行数:18,代码来源:AttributeWriter.java

示例11: writeObjectAttribute

import com.digitalpetri.opcua.stack.core.StatusCodes; //导入依赖的package包/类
private static void writeObjectAttribute(NamespaceManager ns, ObjectNode node, AttributeId attributeId, DataValue value) throws UaException {
    UInteger writeMask = node.getWriteMask().orElse(uint(0));
    EnumSet<WriteMask> writeMasks = WriteMask.fromMask(writeMask);

    switch (attributeId) {
        case EventNotifier:
            if (writeMasks.contains(WriteMask.EventNotifier)) {
                node.setWriteMask(Optional.ofNullable(extract(value)));
            } else {
                throw new UaException(StatusCodes.Bad_NotWritable);
            }
            break;

        default:
            writeNodeAttribute(ns, node, attributeId, value);
    }
}
 
开发者ID:digitalpetri,项目名称:ua-server-sdk,代码行数:18,代码来源:AttributeWriter.java

示例12: hmac

import com.digitalpetri.opcua.stack.core.StatusCodes; //导入依赖的package包/类
/**
 * Compute the HMAC of the provided buffers.
 *
 * @param securityAlgorithm the {@link SecurityAlgorithm} that provides the transformation for
 *                          {@link Mac#getInstance(String)}}.
 * @param secretKey         the secret key.
 * @param buffers           the buffers to use.
 * @return the computed HMAC.
 * @throws UaException
 */
public static byte[] hmac(SecurityAlgorithm securityAlgorithm,
                          byte[] secretKey,
                          ByteBuffer... buffers) throws UaException {

    String transformation = securityAlgorithm.getTransformation();

    try {
        Mac mac = Mac.getInstance(transformation);
        mac.init(new SecretKeySpec(secretKey, transformation));

        for (ByteBuffer buffer : buffers) {
            mac.update(buffer);
        }

        return mac.doFinal();
    } catch (GeneralSecurityException e) {
        throw new UaException(StatusCodes.Bad_SecurityChecksFailed, e);
    }
}
 
开发者ID:digitalpetri,项目名称:opc-ua-stack,代码行数:30,代码来源:SignatureUtil.java

示例13: getCipher

import com.digitalpetri.opcua.stack.core.StatusCodes; //导入依赖的package包/类
@Override
public Cipher getCipher(SecureChannel channel) throws UaException {
    try {
        String transformation = channel.getSecurityPolicy().getSymmetricEncryptionAlgorithm().getTransformation();
        ChannelSecurity.SecretKeys decryptionKeys = channel.getDecryptionKeys(securitySecrets);

        SecretKeySpec keySpec = new SecretKeySpec(decryptionKeys.getEncryptionKey(), "AES");
        IvParameterSpec ivSpec = new IvParameterSpec(decryptionKeys.getInitializationVector());

        Cipher cipher = Cipher.getInstance(transformation);
        cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);

        return cipher;
    } catch (GeneralSecurityException e) {
        throw new UaException(StatusCodes.Bad_SecurityChecksFailed, e);
    }
}
 
开发者ID:digitalpetri,项目名称:opc-ua-stack,代码行数:18,代码来源:ChunkDecoder.java

示例14: decodeGuid

import com.digitalpetri.opcua.stack.core.StatusCodes; //导入依赖的package包/类
@Override
public UUID decodeGuid(String field) throws UaSerializationException {
    requireNextStartElement(field);

    UUID uuid;

    if (nextStartElement("String")) {
        try {
            String text = streamReader.getElementText();
            uuid = UUID.fromString(text);

            // getElementText() advances to end of element

            requireNextEndElement(field);
        } catch (XMLStreamException e) {
            throw new UaSerializationException(StatusCodes.Bad_DecodingError, e);
        }
    } else {
        uuid = new UUID(0, 0);

        requireCurrentElement(field);
    }

    return uuid;
}
 
开发者ID:digitalpetri,项目名称:opc-ua-stack,代码行数:26,代码来源:XmlDecoder.java

示例15: handlerAdded

import com.digitalpetri.opcua.stack.core.StatusCodes; //导入依赖的package包/类
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
    SecurityTokenRequestType requestType = secureChannel.getChannelId() == 0 ?
            SecurityTokenRequestType.Issue : SecurityTokenRequestType.Renew;

    secureChannelTimeout = client.getConfig().getWheelTimer().newTimeout(
            timeout -> {
                if (!timeout.isCancelled()) {
                    handshakeFuture.completeExceptionally(
                            new UaException(
                                    StatusCodes.Bad_Timeout,
                                    "timed out waiting for secure channel"));
                    ctx.close();
                }
            },
            5, TimeUnit.SECONDS
    );

    logger.debug("OpenSecureChannel timeout scheduled for +5s");

    sendOpenSecureChannelRequest(ctx, requestType);
}
 
开发者ID:digitalpetri,项目名称:opc-ua-stack,代码行数:23,代码来源:UaTcpClientMessageHandler.java


注:本文中的com.digitalpetri.opcua.stack.core.StatusCodes类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。