Skip to content

Commit 9270f86

Browse files
Add support for bearer tokens (#1)
* Add support for bearer tokens * Change authBearerKey to String
1 parent 71dc1cb commit 9270f86

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/main/java/org/fanout/pubcontrol/PubControl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public void applyConfig(List<Map<String, Object>> config) {
6262
Map<String, Object> claims = new HashMap<String, Object>();
6363
claims.put("iss", (String)iss);
6464
client.setAuthJwt(claims, (byte[])key);
65+
} else if (key != null) {
66+
client.setAuthBearer(key);
6567
}
6668
this.clients.add(client);
6769
}

src/main/java/org/fanout/pubcontrol/PubControlClient.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ public class PubControlClient implements Runnable {
3737
private Thread pubWorker;
3838
private Deque<Object[]> reqQueue = new LinkedList<Object[]>();
3939
private String authBasicUser;
40-
private String authBasicPass;;
40+
private String authBasicPass;
4141
private Map<String, Object> authJwtClaim;
4242
private byte[] authJwtKey;
43+
private String authBearerKey;
4344

4445
/**
4546
* Initialize this class with a URL representing the publishing endpoint.
@@ -68,6 +69,15 @@ public void setAuthJwt(Map<String, Object> claims, byte[] key) {
6869
this.lock.unlock();
6970
}
7071

72+
/**
73+
* Pass a key to use bearer authentication with the configured endpoint.
74+
*/
75+
public void setAuthBearer(String key) {
76+
this.lock.lock();
77+
this.authBearerKey = key;
78+
this.lock.unlock();
79+
}
80+
7181
/**
7282
* Publish the item synchronously to the specified channels.
7383
*/
@@ -176,6 +186,8 @@ else if (this.authJwtClaim != null) {
176186
String token = Jwts.builder().setClaims(claims).
177187
signWith(SignatureAlgorithm.HS256, decodedKey).compact();
178188
return "Bearer " + token;
189+
} else if (this.authBearerKey != null) {
190+
return "Bearer " + this.authBearerKey;
179191
}
180192

181193
return null;

0 commit comments

Comments
 (0)