• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 The gRPC Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package io.grpc;
18 
19 import com.google.common.base.Preconditions;
20 
21 /**
22  * {@code ChannelCredentials} which use per-RPC {@link CallCredentials}. If the {@code
23  * ChannelCredentials} has multiple {@code CallCredentials} (e.g., a composite credential inside a
24  * composite credential), then all of the {@code CallCredentials} should be used; one {@code
25  * CallCredentials} does not override another.
26  */
27 public final class CompositeChannelCredentials extends ChannelCredentials {
create( ChannelCredentials channelCreds, CallCredentials callCreds)28   public static ChannelCredentials create(
29       ChannelCredentials channelCreds, CallCredentials callCreds) {
30     return new CompositeChannelCredentials(channelCreds, callCreds);
31   }
32 
33   private final ChannelCredentials channelCredentials;
34   private final CallCredentials callCredentials;
35 
CompositeChannelCredentials(ChannelCredentials channelCreds, CallCredentials callCreds)36   private CompositeChannelCredentials(ChannelCredentials channelCreds, CallCredentials callCreds) {
37     this.channelCredentials = Preconditions.checkNotNull(channelCreds, "channelCreds");
38     this.callCredentials = Preconditions.checkNotNull(callCreds, "callCreds");
39   }
40 
getChannelCredentials()41   public ChannelCredentials getChannelCredentials() {
42     return channelCredentials;
43   }
44 
getCallCredentials()45   public CallCredentials getCallCredentials() {
46     return callCredentials;
47   }
48 
49   @Override
withoutBearerTokens()50   public ChannelCredentials withoutBearerTokens() {
51     return channelCredentials.withoutBearerTokens();
52   }
53 }
54