Skip to content

Commit bccef32

Browse files
authored
Enable the usage of bearer tokens (#14)
1 parent bebaa6a commit bccef32

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.aserto</groupId>
88
<artifactId>aserto-java</artifactId>
9-
<version>0.20.7</version>
9+
<version>0.20.8</version>
1010

1111
<name>${project.groupId}:${project.artifactId}</name>
1212
<description>Java SDK to interact with aserto services</description>

src/main/java/com/aserto/ChannelBuilder.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ public ChannelBuilder withAPIKeyAuth(String apiKey) {
4848
return this;
4949
}
5050

51+
public ChannelBuilder withTokenAuth(String token) {
52+
cfg.setToken(token);
53+
54+
return this;
55+
}
56+
5157
public ChannelBuilder withInsecure(Boolean insecure) {
5258
cfg.setInsecure(insecure);
5359

@@ -69,8 +75,14 @@ public ManagedChannel build() throws SSLException {
6975
metadata.put(asertoTenantId, cfg.getTenantId());
7076
}
7177

78+
if (cfg.getApiKey() != null && cfg.getToken() != null) {
79+
throw new IllegalArgumentException("ApiKey and Token cannot be both specified");
80+
}
81+
7282
if (cfg.getApiKey() != null) {
7383
metadata.put(authorization, "basic " + cfg.getApiKey());
84+
} else if (cfg.getToken() != null) {
85+
metadata.put(authorization, "bearer " + cfg.getToken());
7486
}
7587

7688
NettyChannelBuilder channelBuilder = NettyChannelBuilder

src/main/java/com/aserto/model/Config.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ public class Config {
55
private int port;
66
private String apiKey;
77
private String tenantId;
8+
private String token;
89
private Boolean insecure = false;
9-
private String caCertPath = "";
10+
private String caCertPath;
1011

1112
public Config() {
1213
}
1314

14-
public Config(String host, int port, String apiKey, String tenantID, Boolean insecure, String caCertPath) {
15+
public Config(String host, int port, String apiKey, String tenantID, String token, Boolean insecure, String caCertPath) {
1516
this.host = host;
1617
this.port = port;
1718
this.apiKey = apiKey;
1819
this.tenantId = tenantID;
20+
this.token = token;
1921
this.insecure = insecure;
2022
this.caCertPath = caCertPath;
2123
}
@@ -52,6 +54,14 @@ public void setTenantId(String tenantId) {
5254
this.tenantId = tenantId;
5355
}
5456

57+
public String getToken() {
58+
return token;
59+
}
60+
61+
public void setToken(String token) {
62+
this.token = token;
63+
}
64+
5565
public Boolean getInsecure() {
5666
return insecure;
5767
}

0 commit comments

Comments
 (0)