Skip to content

Commit

Permalink
[DM-37318] Switch to AuthorizationTokenPrincipal
Browse files Browse the repository at this point in the history
Pat says this is the future proof way of doing this, and they will
be getting rid of the BearerTokenPrincipal probably sometime in the
future.
  • Loading branch information
cbanek committed Dec 13, 2022
1 parent 68edfdb commit 44a5f2b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/main/java/org/opencadc/tap/impl/AuthenticatorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

import ca.nrc.cadc.auth.Authenticator;
import ca.nrc.cadc.auth.AuthMethod;
import ca.nrc.cadc.auth.AuthorizationTokenPrincipal;
import ca.nrc.cadc.auth.HttpPrincipal;
import ca.nrc.cadc.auth.NumericPrincipal;
import ca.nrc.cadc.auth.BearerTokenPrincipal;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
Expand Down Expand Up @@ -76,16 +76,16 @@ public Subject validate(Subject subject) throws AccessControlException {
}

List<Principal> addedPrincipals = new ArrayList<Principal>();
BearerTokenPrincipal tokenPrincipal = null;
AuthorizationTokenPrincipal tokenPrincipal = null;

for (Principal principal : subject.getPrincipals()) {
if (principal instanceof BearerTokenPrincipal) {
tokenPrincipal = (BearerTokenPrincipal) principal;
if (principal instanceof AuthorizationTokenPrincipal) {
tokenPrincipal = (AuthorizationTokenPrincipal) principal;
TokenInfo tokenInfo = null;

for (int i = 1; i < 5 && tokenInfo == null; i++) {
try {
tokenInfo = getTokenInfo(tokenPrincipal.getName());
tokenInfo = getTokenInfo(tokenPrincipal.getHeaderValue());
} catch (IOException|InterruptedException e) {
log.warn("Exception thrown while getting info from Gafaelfawr");
log.warn(e);
Expand Down Expand Up @@ -134,7 +134,7 @@ private TokenInfo getTokenInfo(String token) throws IOException, InterruptedExce
if (!tokenCache.containsKey(token)) {
HttpRequest request = HttpRequest.newBuilder(URI.create(gafaelfawr_url))
.header("Accept", "application/json")
.header("Authorization", "bearer " + token)
.header("Authorization", token)
.build();

HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
Expand Down

0 comments on commit 44a5f2b

Please sign in to comment.