Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cadc-util/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ sourceCompatibility = 1.8

group = 'org.opencadc'

version = '1.12.17'
version = '1.13.0'

description = 'OpenCADC core utility library'
def git_url = 'https://github.com/opencadc/core'
Expand Down
51 changes: 29 additions & 22 deletions cadc-util/src/main/java/ca/nrc/cadc/auth/AuthorizationToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
package ca.nrc.cadc.auth;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;

/**
Expand All @@ -83,26 +84,26 @@ public class AuthorizationToken {
private String credentials;

// Domain-level scope.
private List<String> domains;
private List<String> domains = new ArrayList<>();

// Application-level scope.
private URI scope;
// scopes present in the token
private List<String> scopes = new ArrayList<>();

// audiences present in the token
private List<String> audience = new ArrayList<>();

/**
* Contructor.
* Standard contructor.
*
* @param type The type of the token. (eg, Bearer)
* @param credentials The token credentials.
* @param domains one or more internet domains/server names where the token can be sent
*/
public AuthorizationToken(String type, String credentials, List<String> domains) {
this(type, credentials, domains, null);
}

/**
* Contructor.
* @param type The type of the token. (eg, Bearer)
* @param credentials The token credentials.
*/
public AuthorizationToken(String type, String credentials, List<String> domains, URI scope) {

private AuthorizationToken(String type, String credentials, List<String> domains, List<String> scopes) {
if (type == null) {
throw new IllegalArgumentException("type required");
}
Expand All @@ -114,8 +115,22 @@ public AuthorizationToken(String type, String credentials, List<String> domains,
}
this.type = type;
this.credentials = credentials;
this.domains = domains;
this.scope = scope;
this.domains.addAll(domains);
if (scopes != null) {
this.scopes.addAll(scopes);
}
}

public List<String> getAudience() {
return audience;
}

/**
* List of scopes for this token.
* @return
*/
public List<String> getScopes() {
return scopes;
}

/**
Expand All @@ -142,20 +157,12 @@ public List<String> getDomains() {
return domains;
}

/**
* Scope getter.
* @return The scope.
*/
public URI getScope() {
return scope;
}

/**
* String output.
*/
@Override
public String toString() {
return "AuthorizationToken[type=[" + type + "],domains=" + domains + ", scope=[" + scope + "]]";
return "AuthorizationToken[type=[" + type + "],domains=" + domains + "]";
}

}
3 changes: 2 additions & 1 deletion cadc-util/src/main/java/ca/nrc/cadc/auth/TokenValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ public static Subject validateTokens(Subject subject) throws NotAuthenticatedExc
subject.getPrincipals().addAll(validatedToken.getIdentityPrincipals());

AuthorizationToken authToken = new AuthorizationToken(
challengeType, credentials, validatedToken.getDomains(), validatedToken.getScope());
challengeType, credentials, validatedToken.getDomains());
authToken.getScopes().add(validatedToken.getScope().toASCIIString());

log.debug("Adding token credential to subject, removing token principal");
subject.getPublicCredentials().add(authToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ public void testValidateTokens() {
AuthorizationToken authToken = subject.getPublicCredentials(AuthorizationToken.class).iterator().next();
Assert.assertEquals("bearer token type", AuthenticationUtil.CHALLENGE_TYPE_BEARER, authToken.getType());
Assert.assertEquals("bearer token value", value, authToken.getCredentials());
Assert.assertEquals("bearer token scope", "the:scope", authToken.getScope().toString());
Assert.assertFalse(authToken.getScopes().isEmpty());
String authTokenScope = authToken.getScopes().get(0);
Assert.assertEquals("bearer token scope", "the:scope", authTokenScope);
Assert.assertEquals("token principal", 0, subject.getPrincipals(AuthorizationTokenPrincipal.class).size());

// ivoa tokens
Expand Down
Loading