-
Notifications
You must be signed in to change notification settings - Fork 560
/
ZeebeCallCredentials.java
61 lines (54 loc) · 2.11 KB
/
ZeebeCallCredentials.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
/*
* Copyright © 2017 camunda services GmbH (info@camunda.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.camunda.zeebe.client.impl;
import io.camunda.zeebe.client.CredentialsProvider;
import io.grpc.Metadata;
import io.grpc.SecurityLevel;
import io.grpc.Status;
import java.io.IOException;
import java.util.concurrent.Executor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class ZeebeCallCredentials extends io.grpc.CallCredentials {
private static final Logger LOG = LoggerFactory.getLogger(ZeebeCallCredentials.class);
private final CredentialsProvider credentialsProvider;
ZeebeCallCredentials(final CredentialsProvider credentialsProvider) {
this.credentialsProvider = credentialsProvider;
}
@Override
public void applyRequestMetadata(
final RequestInfo requestInfo, final Executor appExecutor, final MetadataApplier applier) {
if (requestInfo.getSecurityLevel().ordinal() < SecurityLevel.PRIVACY_AND_INTEGRITY.ordinal()) {
LOG.warn(
"The request's security level does not guarantee that the credentials will be confidential.");
}
appExecutor.execute(
() -> {
try {
final Metadata headers = new Metadata();
credentialsProvider.applyCredentials(headers);
applier.apply(headers);
} catch (final IOException e) {
applier.fail(Status.CANCELLED.withCause(e));
}
});
}
@Override
public void thisUsesUnstableApi() {
// This method's purpose is to make it clearer to implementors that the API is unstable.
// Therefore, it's never called.
}
}