Search in sources :

Example 1 with BuildInfo

use of org.eclipse.milo.opcua.stack.core.types.structured.BuildInfo in project milo by eclipse.

the class ReadNodeExample method run.

@Override
public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
    // synchronous connect
    client.connect().get();
    // Get a typed reference to the Server object: ServerNode
    ServerTypeNode serverNode = (ServerTypeNode) client.getAddressSpace().getObjectNode(Identifiers.Server, Identifiers.ServerType);
    // Read properties of the Server object...
    String[] serverArray = serverNode.getServerArray();
    String[] namespaceArray = serverNode.getNamespaceArray();
    logger.info("ServerArray={}", Arrays.toString(serverArray));
    logger.info("NamespaceArray={}", Arrays.toString(namespaceArray));
    // Read the value of attribute the ServerStatus variable component
    ServerStatusDataType serverStatus = serverNode.getServerStatus();
    logger.info("ServerStatus={}", serverStatus);
    // Get a typed reference to the ServerStatus variable
    // component and read value attributes individually
    ServerStatusTypeNode serverStatusNode = serverNode.getServerStatusNode();
    BuildInfo buildInfo = serverStatusNode.getBuildInfo();
    DateTime startTime = serverStatusNode.getStartTime();
    DateTime currentTime = serverStatusNode.getCurrentTime();
    ServerState state = serverStatusNode.getState();
    logger.info("ServerStatus.BuildInfo={}", buildInfo);
    logger.info("ServerStatus.StartTime={}", startTime);
    logger.info("ServerStatus.CurrentTime={}", currentTime);
    logger.info("ServerStatus.State={}", state);
    future.complete(client);
}
Also used : ServerStatusDataType(org.eclipse.milo.opcua.stack.core.types.structured.ServerStatusDataType) ServerTypeNode(org.eclipse.milo.opcua.sdk.client.model.nodes.objects.ServerTypeNode) ServerStatusTypeNode(org.eclipse.milo.opcua.sdk.client.model.nodes.variables.ServerStatusTypeNode) BuildInfo(org.eclipse.milo.opcua.stack.core.types.structured.BuildInfo) ServerState(org.eclipse.milo.opcua.stack.core.types.enumerated.ServerState) DateTime(org.eclipse.milo.opcua.stack.core.types.builtin.DateTime)

Example 2 with BuildInfo

use of org.eclipse.milo.opcua.stack.core.types.structured.BuildInfo in project milo by eclipse.

the class UaNodeTest method serverNode_ServerStatusNode_BuildInfo.

@Test
public void serverNode_ServerStatusNode_BuildInfo() throws UaException {
    AddressSpace addressSpace = client.getAddressSpace();
    ServerTypeNode serverNode = (ServerTypeNode) addressSpace.getNode(Identifiers.Server);
    BuildInfo buildInfo1 = serverNode.getServerStatusNode().getBuildInfo();
    assertNotNull(buildInfo1);
    BuildInfo buildInfo2 = serverNode.getServerStatusNode().readBuildInfo();
    assertNotNull(buildInfo2);
    assertEquals(buildInfo1, buildInfo2);
}
Also used : ServerTypeNode(org.eclipse.milo.opcua.sdk.client.model.nodes.objects.ServerTypeNode) BuildInfo(org.eclipse.milo.opcua.stack.core.types.structured.BuildInfo) Test(org.junit.jupiter.api.Test) AbstractClientServerTest(org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)

Example 3 with BuildInfo

use of org.eclipse.milo.opcua.stack.core.types.structured.BuildInfo in project milo by eclipse.

the class TestServer method create.

public static OpcUaServer create(int port) throws Exception {
    File securityTempDir = new File(System.getProperty("java.io.tmpdir"), "security");
    if (!securityTempDir.exists() && !securityTempDir.mkdirs()) {
        throw new Exception("unable to create security temp dir: " + securityTempDir);
    }
    LoggerFactory.getLogger(TestServer.class).info("security temp dir: {}", securityTempDir.getAbsolutePath());
    KeyStoreLoader loader = new KeyStoreLoader().load(securityTempDir);
    DefaultCertificateManager certificateManager = new DefaultCertificateManager(loader.getServerKeyPair(), loader.getServerCertificateChain());
    File pkiDir = securityTempDir.toPath().resolve("pki").toFile();
    DefaultTrustListManager trustListManager = new DefaultTrustListManager(pkiDir);
    LoggerFactory.getLogger(TestServer.class).info("pki dir: {}", pkiDir.getAbsolutePath());
    DefaultServerCertificateValidator certificateValidator = new DefaultServerCertificateValidator(trustListManager);
    KeyPair httpsKeyPair = SelfSignedCertificateGenerator.generateRsaKeyPair(2048);
    SelfSignedHttpsCertificateBuilder httpsCertificateBuilder = new SelfSignedHttpsCertificateBuilder(httpsKeyPair);
    httpsCertificateBuilder.setCommonName(HostnameUtil.getHostname());
    HostnameUtil.getHostnames("localhost", false).forEach(httpsCertificateBuilder::addDnsName);
    X509Certificate httpsCertificate = httpsCertificateBuilder.build();
    UsernameIdentityValidator identityValidator = new UsernameIdentityValidator(true, authChallenge -> {
        String username = authChallenge.getUsername();
        String password = authChallenge.getPassword();
        boolean user1 = "user1".equals(username) && "password".equals(password);
        boolean user2 = "user2".equals(username) && "password".equals(password);
        boolean admin = "admin".equals(username) && "password".equals(password);
        return user1 || user2 || admin;
    });
    // If you need to use multiple certificates you'll have to be smarter than this.
    X509Certificate certificate = certificateManager.getCertificates().stream().findFirst().orElseThrow(() -> new UaRuntimeException(StatusCodes.Bad_ConfigurationError, "no certificate found"));
    // The configured application URI must match the one in the certificate(s)
    String applicationUri = CertificateUtil.getSanUri(certificate).orElseThrow(() -> new UaRuntimeException(StatusCodes.Bad_ConfigurationError, "certificate is missing the application URI"));
    Set<EndpointConfiguration> endpointConfigurations = createEndpointConfigurations(certificate, port);
    OpcUaServerConfig serverConfig = OpcUaServerConfig.builder().setApplicationUri(applicationUri).setApplicationName(LocalizedText.english("Eclipse Milo OPC UA Example Server")).setEndpoints(endpointConfigurations).setBuildInfo(new BuildInfo("urn:eclipse:milo:example-server", "eclipse", "eclipse milo example server", OpcUaServer.SDK_VERSION, "", DateTime.now())).setCertificateManager(certificateManager).setTrustListManager(trustListManager).setCertificateValidator(certificateValidator).setHttpsKeyPair(httpsKeyPair).setHttpsCertificate(httpsCertificate).setIdentityValidator(identityValidator).setProductUri("urn:eclipse:milo:example-server").build();
    return new OpcUaServer(serverConfig);
}
Also used : KeyPair(java.security.KeyPair) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) OpcUaServerConfig(org.eclipse.milo.opcua.sdk.server.api.config.OpcUaServerConfig) UaRuntimeException(org.eclipse.milo.opcua.stack.core.UaRuntimeException) X509Certificate(java.security.cert.X509Certificate) UaRuntimeException(org.eclipse.milo.opcua.stack.core.UaRuntimeException) DefaultTrustListManager(org.eclipse.milo.opcua.stack.core.security.DefaultTrustListManager) SelfSignedHttpsCertificateBuilder(org.eclipse.milo.opcua.stack.core.util.SelfSignedHttpsCertificateBuilder) UsernameIdentityValidator(org.eclipse.milo.opcua.sdk.server.identity.UsernameIdentityValidator) DefaultCertificateManager(org.eclipse.milo.opcua.stack.core.security.DefaultCertificateManager) BuildInfo(org.eclipse.milo.opcua.stack.core.types.structured.BuildInfo) EndpointConfiguration(org.eclipse.milo.opcua.stack.server.EndpointConfiguration) File(java.io.File) DefaultServerCertificateValidator(org.eclipse.milo.opcua.stack.server.security.DefaultServerCertificateValidator)

Example 4 with BuildInfo

use of org.eclipse.milo.opcua.stack.core.types.structured.BuildInfo in project milo by eclipse.

the class OpcUaNamespace method configureServerObject.

private void configureServerObject() {
    ServerTypeNode serverTypeNode = (ServerTypeNode) getNodeManager().get(Identifiers.Server);
    assert serverTypeNode != null;
    // This Node is optional and we don't support it, so delete it entirely.
    serverTypeNode.getNamespacesNode().delete();
    serverTypeNode.getNamespaceArrayNode().getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(server.getNamespaceTable().toArray()))));
    serverTypeNode.getServerArrayNode().getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(server.getServerTable().toArray()))));
    serverTypeNode.setAuditing(false);
    serverTypeNode.getServerDiagnosticsNode().setEnabledFlag(false);
    serverTypeNode.setServiceLevel(ubyte(255));
    ServerStatusTypeNode serverStatus = serverTypeNode.getServerStatusNode();
    BuildInfo buildInfo = server.getConfig().getBuildInfo();
    serverStatus.setBuildInfo(buildInfo);
    serverStatus.getBuildInfoNode().setBuildDate(buildInfo.getBuildDate());
    serverStatus.getBuildInfoNode().setBuildNumber(buildInfo.getBuildNumber());
    serverStatus.getBuildInfoNode().setManufacturerName(buildInfo.getManufacturerName());
    serverStatus.getBuildInfoNode().setProductName(buildInfo.getProductName());
    serverStatus.getBuildInfoNode().setProductUri(buildInfo.getProductUri());
    serverStatus.getBuildInfoNode().setSoftwareVersion(buildInfo.getSoftwareVersion());
    serverStatus.setCurrentTime(DateTime.now());
    serverStatus.setSecondsTillShutdown(uint(0));
    serverStatus.setShutdownReason(LocalizedText.NULL_VALUE);
    serverStatus.setState(ServerState.Running);
    serverStatus.setStartTime(DateTime.now());
    serverStatus.getCurrentTimeNode().getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(DateTime.now()))));
    serverStatus.getFilterChain().addLast(AttributeFilters.getValue(ctx -> {
        ServerStatusTypeNode serverStatusNode = (ServerStatusTypeNode) ctx.getNode();
        ExtensionObject xo = ExtensionObject.encode(server.getSerializationContext(), new ServerStatusDataType(serverStatusNode.getStartTime(), DateTime.now(), serverStatusNode.getState(), serverStatusNode.getBuildInfo(), serverStatusNode.getSecondsTillShutdown(), serverStatusNode.getShutdownReason()));
        return new DataValue(new Variant(xo));
    }));
    final OpcUaServerConfigLimits limits = server.getConfig().getLimits();
    ServerCapabilitiesTypeNode serverCapabilities = serverTypeNode.getServerCapabilitiesNode();
    serverCapabilities.setServerProfileArray(new String[] { "http://opcfoundation.org/UA-Profile/Server/StandardUA" });
    serverCapabilities.setLocaleIdArray(new String[] { Locale.ENGLISH.getLanguage() });
    serverCapabilities.setMaxArrayLength(limits.getMaxArrayLength());
    serverCapabilities.setMaxStringLength(limits.getMaxStringLength());
    serverCapabilities.setMaxByteStringLength(limits.getMaxByteStringLength());
    serverCapabilities.setMaxBrowseContinuationPoints(limits.getMaxBrowseContinuationPoints());
    serverCapabilities.setMaxHistoryContinuationPoints(limits.getMaxHistoryContinuationPoints());
    serverCapabilities.setMaxQueryContinuationPoints(limits.getMaxQueryContinuationPoints());
    serverCapabilities.setMinSupportedSampleRate(limits.getMinSupportedSampleRate());
    OperationLimitsTypeNode limitsNode = serverCapabilities.getOperationLimitsNode();
    limitsNode.setMaxMonitoredItemsPerCall(limits.getMaxMonitoredItemsPerCall());
    limitsNode.setMaxNodesPerBrowse(limits.getMaxNodesPerBrowse());
    limitsNode.setMaxNodesPerHistoryReadData(limits.getMaxNodesPerHistoryReadData());
    limitsNode.setMaxNodesPerHistoryReadEvents(limits.getMaxNodesPerHistoryReadEvents());
    limitsNode.setMaxNodesPerHistoryUpdateData(limits.getMaxNodesPerHistoryUpdateData());
    limitsNode.setMaxNodesPerHistoryUpdateEvents(limits.getMaxNodesPerHistoryUpdateEvents());
    limitsNode.setMaxNodesPerMethodCall(limits.getMaxNodesPerMethodCall());
    limitsNode.setMaxNodesPerNodeManagement(limits.getMaxNodesPerNodeManagement());
    limitsNode.setMaxNodesPerRead(limits.getMaxNodesPerRead());
    limitsNode.setMaxNodesPerRegisterNodes(limits.getMaxNodesPerRegisterNodes());
    limitsNode.setMaxNodesPerTranslateBrowsePathsToNodeIds(limits.getMaxNodesPerTranslateBrowsePathsToNodeIds());
    limitsNode.setMaxNodesPerWrite(limits.getMaxNodesPerWrite());
    serverTypeNode.getServerRedundancyNode().setRedundancySupport(RedundancySupport.None);
    configureGetMonitoredItems();
    configureResendData();
}
Also used : OperationLimitsTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.OperationLimitsTypeNode) DataItem(org.eclipse.milo.opcua.sdk.server.api.DataItem) LoggerFactory(org.slf4j.LoggerFactory) ServerState(org.eclipse.milo.opcua.stack.core.types.enumerated.ServerState) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) DateTime(org.eclipse.milo.opcua.stack.core.types.builtin.DateTime) GetMonitoredItemsMethod(org.eclipse.milo.opcua.sdk.server.model.methods.GetMonitoredItemsMethod) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Unsigned.uint(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint) Locale(java.util.Locale) AbstractMethodInvocationHandler(org.eclipse.milo.opcua.sdk.server.api.methods.AbstractMethodInvocationHandler) BaseEventTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.BaseEventTypeNode) Out(org.eclipse.milo.opcua.sdk.server.api.methods.Out) EventItem(org.eclipse.milo.opcua.sdk.server.api.EventItem) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) UUID(java.util.UUID) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) SubscriptionModel(org.eclipse.milo.opcua.sdk.server.util.SubscriptionModel) RedundancySupport(org.eclipse.milo.opcua.stack.core.types.enumerated.RedundancySupport) OpcUaServer(org.eclipse.milo.opcua.sdk.server.OpcUaServer) List(java.util.List) NodeLoader(org.eclipse.milo.opcua.sdk.server.namespaces.loader.NodeLoader) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) ResendDataMethod(org.eclipse.milo.opcua.sdk.server.model.methods.ResendDataMethod) ServerTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerTypeNode) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) ServerCapabilitiesTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerCapabilitiesTypeNode) ManagedNamespaceWithLifecycle(org.eclipse.milo.opcua.sdk.server.api.ManagedNamespaceWithLifecycle) Function(java.util.function.Function) Session(org.eclipse.milo.opcua.sdk.server.Session) Lists(com.google.common.collect.Lists) ServerStatusDataType(org.eclipse.milo.opcua.stack.core.types.structured.ServerStatusDataType) AttributeFilters(org.eclipse.milo.opcua.sdk.server.nodes.filters.AttributeFilters) UaMethodNode(org.eclipse.milo.opcua.sdk.server.nodes.UaMethodNode) StatusCodes(org.eclipse.milo.opcua.stack.core.StatusCodes) Logger(org.slf4j.Logger) OpcUaServerConfigLimits(org.eclipse.milo.opcua.sdk.server.api.config.OpcUaServerConfigLimits) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) Unsigned.ushort(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.ushort) MonitoredDataItem(org.eclipse.milo.opcua.sdk.server.items.MonitoredDataItem) UInteger(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger) Subscription(org.eclipse.milo.opcua.sdk.server.subscriptions.Subscription) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText) ConditionRefreshMethod(org.eclipse.milo.opcua.sdk.server.model.methods.ConditionRefreshMethod) BuildInfo(org.eclipse.milo.opcua.stack.core.types.structured.BuildInfo) Unsigned.ubyte(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.ubyte) ServerStatusTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.variables.ServerStatusTypeNode) TimeUnit(java.util.concurrent.TimeUnit) MonitoredItem(org.eclipse.milo.opcua.sdk.server.api.MonitoredItem) NonceUtil(org.eclipse.milo.opcua.stack.core.util.NonceUtil) BaseMonitoredItem(org.eclipse.milo.opcua.sdk.server.items.BaseMonitoredItem) UaException(org.eclipse.milo.opcua.stack.core.UaException) Namespaces(org.eclipse.milo.opcua.stack.core.util.Namespaces) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) ServerStatusDataType(org.eclipse.milo.opcua.stack.core.types.structured.ServerStatusDataType) OperationLimitsTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.OperationLimitsTypeNode) ServerTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerTypeNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) ServerStatusTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.variables.ServerStatusTypeNode) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) BuildInfo(org.eclipse.milo.opcua.stack.core.types.structured.BuildInfo) ServerCapabilitiesTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerCapabilitiesTypeNode) OpcUaServerConfigLimits(org.eclipse.milo.opcua.sdk.server.api.config.OpcUaServerConfigLimits)

Example 5 with BuildInfo

use of org.eclipse.milo.opcua.stack.core.types.structured.BuildInfo in project milo by eclipse.

the class OpcUaServerConfigTest method testCopy.

@Test
public void testCopy() throws IOException {
    DefaultTrustListManager trustListManager = new DefaultTrustListManager(Files.createTempDir());
    ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
    OpcUaServerConfig original = OpcUaServerConfig.builder().setCertificateManager(new DefaultCertificateManager()).setTrustListManager(trustListManager).setCertificateValidator(new DefaultServerCertificateValidator(trustListManager)).setIdentityValidator(AnonymousIdentityValidator.INSTANCE).setBuildInfo(new BuildInfo("a", "b", "c", "d", "e", DateTime.MIN_VALUE)).setLimits(new OpcUaServerConfigLimits() {
    }).setScheduledExecutorService(scheduledExecutorService).build();
    OpcUaServerConfig copy = OpcUaServerConfig.copy(original).build();
    assertEquals(copy.getIdentityValidator(), original.getIdentityValidator());
    assertEquals(copy.getBuildInfo(), original.getBuildInfo());
    assertEquals(copy.getLimits(), original.getLimits());
    assertEquals(copy.getScheduledExecutorService(), original.getScheduledExecutorService());
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) DefaultTrustListManager(org.eclipse.milo.opcua.stack.core.security.DefaultTrustListManager) DefaultCertificateManager(org.eclipse.milo.opcua.stack.core.security.DefaultCertificateManager) BuildInfo(org.eclipse.milo.opcua.stack.core.types.structured.BuildInfo) DefaultServerCertificateValidator(org.eclipse.milo.opcua.stack.server.security.DefaultServerCertificateValidator) Test(org.testng.annotations.Test)

Aggregations

BuildInfo (org.eclipse.milo.opcua.stack.core.types.structured.BuildInfo)6 OpcUaServer (org.eclipse.milo.opcua.sdk.server.OpcUaServer)3 DefaultCertificateManager (org.eclipse.milo.opcua.stack.core.security.DefaultCertificateManager)3 DefaultTrustListManager (org.eclipse.milo.opcua.stack.core.security.DefaultTrustListManager)3 DateTime (org.eclipse.milo.opcua.stack.core.types.builtin.DateTime)3 DefaultServerCertificateValidator (org.eclipse.milo.opcua.stack.server.security.DefaultServerCertificateValidator)3 File (java.io.File)2 KeyPair (java.security.KeyPair)2 X509Certificate (java.security.cert.X509Certificate)2 ServerTypeNode (org.eclipse.milo.opcua.sdk.client.model.nodes.objects.ServerTypeNode)2 OpcUaServerConfig (org.eclipse.milo.opcua.sdk.server.api.config.OpcUaServerConfig)2 UaException (org.eclipse.milo.opcua.stack.core.UaException)2 UaRuntimeException (org.eclipse.milo.opcua.stack.core.UaRuntimeException)2 SelfSignedHttpsCertificateBuilder (org.eclipse.milo.opcua.stack.core.util.SelfSignedHttpsCertificateBuilder)2 EndpointConfiguration (org.eclipse.milo.opcua.stack.server.EndpointConfiguration)2 Lists (com.google.common.collect.Lists)1 List (java.util.List)1 Locale (java.util.Locale)1 UUID (java.util.UUID)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1