use of com.prosysopc.ua.stack.builtintypes.LocalizedText in project FAAAST-Service by FraunhoferIOSB.
the class TestUtils method checkDisplayName.
/**
* Checks the Display Name of the given Node.
*
* @param client The OPC UA Client
* @param nodeId The desired Node.
* @param desiredName The desired Display Name.
* @throws ServiceException If the operation fails
* @throws AddressSpaceException If the operation fails
*/
public static void checkDisplayName(UaClient client, NodeId nodeId, String desiredName) throws ServiceException, AddressSpaceException {
UaNode node = client.getAddressSpace().getNode(nodeId);
Assert.assertNotNull("Node is null: " + desiredName, node);
LocalizedText lt = node.getDisplayName();
Assert.assertEquals(desiredName, lt.getText());
}
use of com.prosysopc.ua.stack.builtintypes.LocalizedText in project FAAAST-Service by FraunhoferIOSB.
the class Server method startup.
/**
* Starts the server
*
* @throws UaServerException If an error occurs
* @throws IOException If an error occurs
* @throws SecureIdentityException If an error occurs
*/
public void startup() throws UaServerException, IOException, SecureIdentityException {
try {
String hostName;
hostName = InetAddress.getLocalHost().getHostName();
ApplicationIdentity.setActualHostName(hostName);
// *** Create the server
uaServer = new UaServer();
// currently without IPv6
uaServer.setEnableIPv6(false);
// Use PKI files to keep track of the trusted and rejected client
// certificates...
final PkiDirectoryCertificateStore applicationCertificateStore = new PkiDirectoryCertificateStore("PKI/CA");
final PkiDirectoryCertificateStore applicationIssuerCertificateStore = new PkiDirectoryCertificateStore("PKI/CA/issuers");
final DefaultCertificateValidator applicationCertificateValidator = new DefaultCertificateValidator(applicationCertificateStore, applicationIssuerCertificateStore);
uaServer.setCertificateValidator(applicationCertificateValidator);
// ...and react to validation results with a custom handler
applicationCertificateValidator.setValidationListener(validationListener);
// Handle user certificates
final PkiDirectoryCertificateStore userCertificateStore = new PkiDirectoryCertificateStore("USERS_PKI/CA");
final PkiDirectoryCertificateStore userIssuerCertificateStore = new PkiDirectoryCertificateStore("USERS_PKI/CA/issuers");
final DefaultCertificateValidator userCertificateValidator = new DefaultCertificateValidator(userCertificateStore, userIssuerCertificateStore);
userValidator = new AasUserValidator(userCertificateValidator);
// ...and react to validation results with a custom handler
userCertificateValidator.setValidationListener(userCertificateValidationListener);
// *** Application Description is sent to the clients
ApplicationDescription appDescription = new ApplicationDescription();
// 'localhost' (all lower case) in the ApplicationName and
// ApplicationURI is converted to the actual host name of the computer
// (including the possible domain part) in which the application is run.
// (as available from ApplicationIdentity.getActualHostName())
// 'hostname' is converted to the host name without the domain part.
// (as available from
// ApplicationIdentity.getActualHostNameWithoutDomain())
appDescription.setApplicationName(new LocalizedText(APPLICATION_NAME + "@hostname"));
appDescription.setApplicationUri(APPLICATION_URI);
appDescription.setProductUri("urn:de:fraunhofer:iosb:opcua:aas:server");
appDescription.setApplicationType(ApplicationType.Server);
// *** Server Endpoints
// TCP Port number for the UA TCP protocol
uaServer.setPort(Protocol.OpcTcp, tcpPort);
// TCP Port for the HTTPS protocol - currently disabled
// server.setPort(Protocol.OpcHttps, httpsPort);
// optional server name part of the URI (default for all protocols)
// server.setServerName("OPCUA/" + applicationName);
// Optionally restrict the InetAddresses to which the server is bound.
// You may also specify the addresses for each Protocol.
// The default is binding to IPv6 wildcard '[::]' when isEnableIPv6 is true
// or to IPv4 wildcard '0.0.0.0' otherwise.
// Alternatively, the Server can be bound to all available InetAddresses.
// isEnableIPv6 defines whether IPv6 address should be included in the bound addresses.
// Note that it requires Java 7 or later to work in practice in Windows
// server.setBindAddresses(EndpointUtil.getInetAddresses(server.isEnableIPv6()));
// *** Certificates
LOGGER.info("Loading certificates..");
File privatePath = new File(applicationCertificateStore.getBaseDir(), "private");
// Define a certificate for a Certificate Authority (CA) which is used
// to issue the keys. Especially
// the HTTPS certificate should be signed by a CA certificate, in order
// to make the .NET applications trust it.
//
// If you have a real CA, you should use that instead of this sample CA
// and create the keys with it.
// Here we use the IssuerCertificate only to sign the HTTPS certificate
// (below) and not the Application Instance Certificate.
KeyPair issuerCertificate = ApplicationIdentity.loadOrCreateIssuerCertificate("FraunhoferIosbSampleCA@" + ApplicationIdentity.getActualHostNameWithoutDomain() + "_https_" + CERT_KEY_SIZE, privatePath, PRIV_KEY_PASS, 3650, false, CERT_KEY_SIZE);
int[] keySizes = new int[] { CERT_KEY_SIZE };
// If you wish to use big certificates (4096 bits), you will need to
// define two certificates for your application, since to interoperate
// with old applications, you will also need to use a small certificate
// (up to 2048 bits).
// Also, 4096 bits can only be used with Basic256Sha256 security
// profile, which is currently not enabled by default, so we will also
// leave the the keySizes array as null. In that case, the default key
// size defined by CertificateUtils.getKeySize() is used.
// keySizes = new int[] { 2048, 4096 };
// *** Application Identity
// Define the Server application identity, including the Application
// Instance Certificate (but don't sign it with the issuerCertificate as
// explained above).
final ApplicationIdentity identity = ApplicationIdentity.loadOrCreateCertificate(appDescription, "Fraunhofer IOSB", /* Private Key Password */
PRIV_KEY_PASS, /* Key File Path */
privatePath, /* Issuer Certificate & Private Key */
null, /* Key Sizes for instance certificates to create */
keySizes, /* Enable renewing the certificate */
true);
// Create the HTTPS certificate bound to the hostname.
// The HTTPS certificate must be created, if you enable HTTPS.
hostName = ApplicationIdentity.getActualHostName();
identity.setHttpsCertificate(ApplicationIdentity.loadOrCreateHttpsCertificate(appDescription, hostName, PRIV_KEY_PASS, issuerCertificate, privatePath, true, CERT_KEY_SIZE));
uaServer.setApplicationIdentity(identity);
// *** Security settings
/*
* Define the security modes to support for the Binary protocol.
* Note that different versions of the specification might add/deprecate some modes, in this
* example all the modes are added, but you should add some way in your application to configure
* these. The set is empty by default, you must add at least one SecurityMode for the server to
* start.
*/
Set<SecurityPolicy> supportedSecurityPolicies = new HashSet<>();
/*
* This policy does not support any security. Should only be used in isolated networks.
*/
supportedSecurityPolicies.add(SecurityPolicy.NONE);
// Modes defined in previous versions of the specification
supportedSecurityPolicies.addAll(SecurityPolicy.ALL_SECURE_101);
supportedSecurityPolicies.addAll(SecurityPolicy.ALL_SECURE_102);
supportedSecurityPolicies.addAll(SecurityPolicy.ALL_SECURE_103);
/*
* Per the 1.04 specification, only these should be used. However in practice this list only
* contains very new security policies, which most of the client applications as of today that
* are used might not be unable to (yet) use.
*/
supportedSecurityPolicies.addAll(SecurityPolicy.ALL_SECURE_104);
Set<MessageSecurityMode> supportedMessageSecurityModes = new HashSet<>();
/*
* This mode does not support any security. Should only be used in isolated networks. This is
* also the only mode, which does not require certificate exchange between the client and server
* application (when used in conjunction of only ANONYMOUS UserTokenPolicy).
*/
supportedMessageSecurityModes.add(MessageSecurityMode.None);
/*
* This mode support signing, so it is possible to detect if messages are tampered. Note that
* they are not encrypted.
*/
supportedMessageSecurityModes.add(MessageSecurityMode.Sign);
/*
* This mode signs and encrypts the messages. Only this mode is recommended outside of isolated
* networks.
*/
supportedMessageSecurityModes.add(MessageSecurityMode.SignAndEncrypt);
/*
* This creates all possible combinations (NONE pairs only with None) of the configured
* MessageSecurityModes and SecurityPolicies) for opc.tcp communication.
*/
uaServer.getSecurityModes().addAll(SecurityMode.combinations(supportedMessageSecurityModes, supportedSecurityPolicies));
/*
* NOTE! The MessageSecurityMode.None for HTTPS means Application level authentication is not
* used. If used in combination with the UserTokenPolicy ANONYMOUS anyone can access the server
* (but the traffic is encrypted). HTTPS mode is always encrypted, therefore the given
* MessageSecurityMode only affects if the UA certificates are exchanged when forming the
* Session.
*/
uaServer.getHttpsSecurityModes().addAll(SecurityMode.combinations(EnumSet.of(MessageSecurityMode.None, MessageSecurityMode.Sign), supportedSecurityPolicies));
// The TLS security policies to use for HTTPS
Set<HttpsSecurityPolicy> supportedHttpsSecurityPolicies = new HashSet<>();
// (HTTPS was defined starting from OPC UA Specification 1.02)
supportedHttpsSecurityPolicies.addAll(HttpsSecurityPolicy.ALL_102);
supportedHttpsSecurityPolicies.addAll(HttpsSecurityPolicy.ALL_103);
// Only these are recommended by the 1.04 Specification
supportedHttpsSecurityPolicies.addAll(HttpsSecurityPolicy.ALL_104);
uaServer.getHttpsSettings().setHttpsSecurityPolicies(supportedHttpsSecurityPolicies);
// Number of threads to reserve for the HTTPS server, default is 10
// server.setHttpsWorkerThreadCount(10);
// Define the certificate validator for the HTTPS certificates;
// we use the same validator that we use for Application Instance Certificates
uaServer.getHttpsSettings().setCertificateValidator(applicationCertificateValidator);
// Define the supported user authentication methods
uaServer.addUserTokenPolicy(UserTokenPolicies.ANONYMOUS);
uaServer.addUserTokenPolicy(UserTokenPolicies.SECURE_USERNAME_PASSWORD);
uaServer.addUserTokenPolicy(UserTokenPolicies.SECURE_CERTIFICATE);
// Define a validator for checking the user accounts
uaServer.setUserValidator(userValidator);
// currently skip discovery
// // Register to the local discovery server (if present)
// try {
// server.setDiscoveryServerUrl(DISCOVERY_SERVER_URL);
// }
// catch (URISyntaxException e) {
// logger.error("DiscoveryURL is not valid", e);
// }
// *** 'init' creates the service handlers and the default endpoints
// *** according to the settings defined above
uaServer.init();
initBuildInfo();
// "Safety limits" for ill-behaving clients
uaServer.getSessionManager().setMaxSessionCount(500);
// one hour
uaServer.getSessionManager().setMaxSessionTimeout(3600000);
uaServer.getSubscriptionManager().setMaxSubscriptionCount(50);
/*
* Safety limits for XXXContinuationPoints. Note! These are the current defaults. Technically a
* value of 0 (unlimited) is allowed by the OPC UA Specification, but our implementation does
* allocate server-side memory, thus do not use value of 0 (or you can run out of memory).
* Future SDK releases may improve this.
*/
ServerCapabilitiesTypeNode serverCapabilities = uaServer.getAddressSpace().getNodeManagerRoot().getServerData().getServerCapabilitiesNode();
serverCapabilities.setMaxBrowseContinuationPoints(UnsignedShort.MAX_VALUE);
serverCapabilities.setMaxQueryContinuationPoints(UnsignedShort.MAX_VALUE);
serverCapabilities.setMaxHistoryContinuationPoints(UnsignedShort.MAX_VALUE);
// You can do your own additions to server initializations here
createAddressSpace();
uaServer.start();
running = true;
} catch (Exception ex) {
LOGGER.error("startup Exception", ex);
throw ex;
}
}
use of com.prosysopc.ua.stack.builtintypes.LocalizedText in project FAAAST-Service by FraunhoferIOSB.
the class Server method shutdown.
/**
* Stops the OPC UA server
*
* @param secondsTillShutdown The number of seconds until the server stops
*/
public void shutdown(int secondsTillShutdown) {
running = false;
uaServer.shutdown(secondsTillShutdown, new LocalizedText("Server stopped", Locale.ENGLISH));
}
use of com.prosysopc.ua.stack.builtintypes.LocalizedText in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addAasSubmodelElementCollection.
/**
* Adds a SubmodelElementCollection to the given node.
*
* @param node The desired UA node
* @param aasColl The corresponding SubmodelElementCollection to add
* @param submodel The corresponding Submodel as parent object of the data element
* @param parentRef The AAS reference to the parent object
* @param ordered Specifies whether the entity should be added ordered
* (true) or unordered (false)
* @throws StatusException If the operation fails
* @throws ServiceException If the operation fails
* @throws AddressSpaceException If the operation fails
* @throws ServiceResultException If the operation fails
*/
private void addAasSubmodelElementCollection(UaNode node, SubmodelElementCollection aasColl, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException, ServiceException, AddressSpaceException, ServiceResultException {
try {
if ((node != null) && (aasColl != null)) {
String name = aasColl.getIdShort();
QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASSubmodelElementCollectionType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
NodeId nid = getDefaultNodeId();
AASSubmodelElementCollectionType collNode;
if (aasColl.getOrdered()) {
collNode = createAasOrderedSubmodelElementCollection(name, nid);
} else {
collNode = createInstance(AASSubmodelElementCollectionType.class, nid, browseName, LocalizedText.english(name));
}
addSubmodelElementBaseData(collNode, aasColl);
// AllowDuplicates
if (collNode.getAllowDuplicatesNode() == null) {
NodeId myPropertyId = new NodeId(getNamespaceIndex(), collNode.getNodeId().getValue().toString() + "." + AASSubmodelElementCollectionType.ALLOW_DUPLICATES);
PlainProperty<Boolean> myProperty = new PlainProperty<>(this, myPropertyId, UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASSubmodelElementCollectionType.getNamespaceUri(), AASSubmodelElementCollectionType.ALLOW_DUPLICATES).toQualifiedName(getNamespaceTable()), LocalizedText.english(AASSubmodelElementCollectionType.ALLOW_DUPLICATES));
myProperty.setDataTypeId(Identifiers.Boolean);
myProperty.setDescription(new LocalizedText("", ""));
if (VALUES_READ_ONLY) {
myProperty.setAccessLevel(AccessLevelType.CurrentRead);
}
collNode.addProperty(myProperty);
}
collNode.setAllowDuplicates(aasColl.getAllowDuplicates());
Reference collRef = AasUtils.toReference(parentRef, aasColl);
// SubmodelElements
addSubmodelElements(collNode, aasColl.getValues(), submodel, collRef, aasColl.getOrdered());
if (ordered) {
node.addReference(collNode, Identifiers.HasOrderedComponent, false);
} else {
node.addComponent(collNode);
}
referableMap.put(collRef, new ObjectData(aasColl, collNode, submodel));
}
} catch (Exception ex) {
LOG.error("createAasSubmodelElementCollection Exception", ex);
throw ex;
}
}
use of com.prosysopc.ua.stack.builtintypes.LocalizedText in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addAasFile.
/**
* Adds an AAS file to the given node.
*
* @param node The desired UA node
* @param aasFile The AAS file object
* @param submodel The corresponding Submodel as parent object of the data element
* @param parentRef The AAS reference to the parent node
* @param ordered Specifies whether the file should be added ordered (true) or unordered (false)
* @param nodeName The desired Name of the node. If this value is not set,
* the IdShort of the file is used.
* @throws StatusException If the operation fails
*/
private void addAasFile(UaNode node, File aasFile, Submodel submodel, Reference parentRef, boolean ordered, String nodeName) throws StatusException {
try {
if ((node != null) && (aasFile != null)) {
String name = aasFile.getIdShort();
if ((nodeName != null) && (!nodeName.isEmpty())) {
name = nodeName;
}
QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASFileType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
NodeId nid = getDefaultNodeId();
AASFileType fileNode = createInstance(AASFileType.class, nid, browseName, LocalizedText.english(name));
addSubmodelElementBaseData(fileNode, aasFile);
// MimeType
if (!aasFile.getMimeType().isEmpty()) {
fileNode.setMimeType(aasFile.getMimeType());
}
// Value
if (aasFile.getValue() != null) {
if (fileNode.getValueNode() == null) {
addFileValueNode(fileNode);
}
fileNode.setValue(aasFile.getValue());
if (!aasFile.getValue().isEmpty()) {
java.io.File f = new java.io.File(aasFile.getValue());
if (!f.exists()) {
LOG.warn("addAasFile: File '{}' does not exist!", f.getAbsolutePath());
} else {
// File Object: include only when the file exists
QualifiedName fileBrowseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASFileType.getNamespaceUri(), AASFileType.FILE).toQualifiedName(getNamespaceTable());
NodeId fileId = new NodeId(getNamespaceIndex(), fileNode.getNodeId().getValue().toString() + "." + AASFileType.FILE);
FileTypeNode fileType = createInstance(FileTypeNode.class, fileId, fileBrowseName, LocalizedText.english(AASFileType.FILE));
fileType.setFile(new java.io.File(aasFile.getValue()));
fileType.setWritable(false);
fileType.setUserWritable(false);
if (fileType.getNodeVersion() != null) {
fileType.getNodeVersion().setDescription(new LocalizedText("", ""));
}
fileNode.addReference(fileType, Identifiers.HasAddIn, false);
}
}
}
if (ordered) {
node.addReference(fileNode, Identifiers.HasOrderedComponent, false);
} else {
node.addComponent(fileNode);
}
if (parentRef != null) {
Reference fileRef = AasUtils.toReference(parentRef, aasFile);
referableMap.put(fileRef, new ObjectData(aasFile, fileNode, submodel));
}
}
} catch (Exception ex) {
LOG.error("addAasFile Exception", ex);
throw ex;
}
}
Aggregations