/
OpcUaServerConfig.java
188 lines (162 loc) · 6.22 KB
/
OpcUaServerConfig.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
* Copyright (c) 2022 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.milo.opcua.sdk.server;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;
import java.util.function.Consumer;
import org.eclipse.milo.opcua.sdk.server.identity.AnonymousIdentityValidator;
import org.eclipse.milo.opcua.sdk.server.identity.CompositeValidator;
import org.eclipse.milo.opcua.sdk.server.identity.IdentityValidator;
import org.eclipse.milo.opcua.sdk.server.identity.UsernameIdentityValidator;
import org.eclipse.milo.opcua.sdk.server.identity.X509IdentityValidator;
import org.eclipse.milo.opcua.stack.core.channel.EncodingLimits;
import org.eclipse.milo.opcua.stack.core.security.CertificateManager;
import org.eclipse.milo.opcua.stack.core.security.SecurityPolicy;
import org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText;
import org.eclipse.milo.opcua.stack.core.types.enumerated.UserTokenType;
import org.eclipse.milo.opcua.stack.core.types.structured.ApplicationDescription;
import org.eclipse.milo.opcua.stack.core.types.structured.BuildInfo;
import org.eclipse.milo.opcua.stack.core.types.structured.UserTokenPolicy;
public interface OpcUaServerConfig {
/**
* A {@link UserTokenPolicy} for anonymous access.
*/
UserTokenPolicy USER_TOKEN_POLICY_ANONYMOUS = new UserTokenPolicy(
"anonymous",
UserTokenType.Anonymous,
null,
null,
null
);
/**
* A {@link UserTokenPolicy} for username-based access.
*/
UserTokenPolicy USER_TOKEN_POLICY_USERNAME = new UserTokenPolicy(
"username",
UserTokenType.UserName,
null,
null,
SecurityPolicy.Basic256.getUri()
);
UserTokenPolicy USER_TOKEN_POLICY_X509 = new UserTokenPolicy(
"certificate",
UserTokenType.Certificate,
null,
null,
SecurityPolicy.Basic256.getUri()
);
/**
* @return the {@link EndpointConfig}s for this server.
*/
Set<EndpointConfig> getEndpoints();
/**
* Get the application name for the server.
* <p/>
* This will be used in the {@link ApplicationDescription} returned to clients.
*
* @return the application name for the server.
*/
LocalizedText getApplicationName();
/**
* Get the application uri for the server.
* <p/>
* This will be used in the {@link ApplicationDescription} returned to clients.
* <p/>
* <b>The application uri must match the application uri used on the server's application instance certificate.</b>
*
* @return the application uri for the server.
*/
String getApplicationUri();
/**
* Get the product uri for the server.
* <p/>
* This will be used in the {@link ApplicationDescription} returned to clients.
*
* @return the product uri for the server.
*/
String getProductUri();
/**
* @return the server {@link BuildInfo}.
*/
BuildInfo getBuildInfo();
/**
* Get the {@link IdentityValidator} for the server.
*
* @return the {@link IdentityValidator} for the server.
* @see AnonymousIdentityValidator
* @see UsernameIdentityValidator
* @see X509IdentityValidator
* @see CompositeValidator
*/
IdentityValidator getIdentityValidator();
/**
* @return the configured {@link EncodingLimits}.
*/
EncodingLimits getEncodingLimits();
/**
* @return the {@link OpcUaServerConfigLimits}.
*/
OpcUaServerConfigLimits getLimits();
/**
* @return the {@link CertificateManager} for this server.
*/
CertificateManager getCertificateManager();
/**
* @return the {@link ExecutorService} for this server.
*/
ExecutorService getExecutor();
/**
* @return the {@link ScheduledExecutorService} used by the {@link OpcUaServer} being configured.
*/
ScheduledExecutorService getScheduledExecutorService();
/**
* @return a {@link OpcUaServerConfigBuilder}.
*/
static OpcUaServerConfigBuilder builder() {
return new OpcUaServerConfigBuilder();
}
/**
* Copy the values from an existing {@link OpcUaServerConfig} into a new {@link OpcUaServerConfigBuilder}. This
* builder can be used to make any desired modifications before invoking {@link OpcUaServerConfigBuilder#build()}
* to produce a new config.
*
* @param config the {@link OpcUaServerConfig} to copy from.
* @return a {@link OpcUaServerConfigBuilder} pre-populated with values from {@code config}.
*/
static OpcUaServerConfigBuilder copy(OpcUaServerConfig config) {
var builder = new OpcUaServerConfigBuilder();
builder.setEndpoints(config.getEndpoints());
builder.setApplicationName(config.getApplicationName());
builder.setApplicationUri(config.getApplicationUri());
builder.setProductUri(config.getProductUri());
builder.setBuildInfo(config.getBuildInfo());
builder.setEncodingLimits(config.getEncodingLimits());
builder.setLimits(config.getLimits());
builder.setIdentityValidator(config.getIdentityValidator());
builder.setCertificateManager(config.getCertificateManager());
builder.setExecutor(config.getExecutor());
builder.setScheduledExecutor(config.getScheduledExecutorService());
return builder;
}
/**
* Copy the values from an existing {@link OpcUaServerConfig} into a new {@link OpcUaServerConfigBuilder} and then
* submit the builder to the provided consumer for modification.
*
* @param config the {@link OpcUaServerConfig} to copy from.
* @param consumer a {@link Consumer} that may modify the builder.
* @return a {@link OpcUaServerConfig} built from the builder provided to {@code consumer}.
*/
static OpcUaServerConfig copy(OpcUaServerConfig config, Consumer<OpcUaServerConfigBuilder> consumer) {
OpcUaServerConfigBuilder builder = copy(config);
consumer.accept(builder);
return builder.build();
}
}