use of org.eclipse.milo.opcua.sdk.client.api.identity.SignedIdentityToken in project milo by eclipse.
the class SessionFsmFactory method activateSession.
@SuppressWarnings("Duplicates")
private static CompletableFuture<OpcUaSession> activateSession(FsmContext<State, Event> ctx, OpcUaClient client, CreateSessionResponse csr) {
UaStackClient stackClient = client.getStackClient();
try {
EndpointDescription endpoint = client.getConfig().getEndpoint();
ByteString csrNonce = csr.getServerNonce();
SignedIdentityToken signedIdentityToken = client.getConfig().getIdentityProvider().getIdentityToken(endpoint, csrNonce);
UserIdentityToken userIdentityToken = signedIdentityToken.getToken();
SignatureData userTokenSignature = signedIdentityToken.getSignature();
ActivateSessionRequest request = new ActivateSessionRequest(client.newRequestHeader(csr.getAuthenticationToken()), buildClientSignature(client.getConfig(), csrNonce), new SignedSoftwareCertificate[0], new String[0], ExtensionObject.encode(client.getStaticSerializationContext(), userIdentityToken), userTokenSignature);
LOGGER.debug("[{}] Sending ActivateSessionRequest...", ctx.getInstanceId());
return stackClient.sendRequest(request).thenApply(ActivateSessionResponse.class::cast).thenCompose(asr -> {
ByteString asrNonce = asr.getServerNonce();
// TODO check for repeated nonce?
OpcUaSession session = new OpcUaSession(csr.getAuthenticationToken(), csr.getSessionId(), client.getConfig().getSessionName().get(), csr.getRevisedSessionTimeout(), csr.getMaxRequestMessageSize(), csr.getServerCertificate(), csr.getServerSoftwareCertificates());
session.setServerNonce(asrNonce);
return completedFuture(session);
});
} catch (Exception ex) {
return failedFuture(ex);
}
}
Aggregations