use of com.yahoo.athenz.auth.token.AccessToken in project athenz by yahoo.
the class TestAuthZpe method createInvalidAccessToken.
private String createInvalidAccessToken(String svcDomain, List<String> roles) {
AccessToken token = new AccessToken();
token.setVersion(1);
token.setAudience(svcDomain);
token.setScope(roles);
long now = System.currentTimeMillis();
token.setIssuer("athenz");
token.setIssueTime(now);
token.setExpiryTime(now + 120);
return token.getSignedToken(ztsPrivateKeyK0, "1", SignatureAlgorithm.RS256);
}
use of com.yahoo.athenz.auth.token.AccessToken in project athenz by yahoo.
the class TestAuthZpe method createAccessToken.
private String createAccessToken(String svcDomain, List<String> roles, String keyId, long expiry) {
AccessToken token = new AccessToken();
token.setVersion(1);
token.setAudience(svcDomain);
token.setScope(roles);
long now = System.currentTimeMillis();
token.setIssuer("athenz");
token.setIssueTime(now);
token.setExpiryTime(now + expiry);
try {
Path path = Paths.get("src/test/resources/mtls_token_spec.cert");
String certStr = new String(Files.readAllBytes(path));
X509Certificate cert = Crypto.loadX509Certificate(certStr);
token.setConfirmX509CertHash(cert);
} catch (IOException ignored) {
fail();
}
PrivateKey key = null;
if ("1".equals(keyId)) {
key = ztsPrivateKeyK1;
} else if ("0".equals(keyId)) {
key = ztsPrivateKeyK0;
} else if ("17".equals(keyId)) {
key = ztsPrivateKeyK17;
} else if ("99".equals(keyId)) {
key = ztsPrivateKeyK99;
}
assertNotNull(key);
return token.getSignedToken(key, keyId, SignatureAlgorithm.RS256);
}
use of com.yahoo.athenz.auth.token.AccessToken in project athenz by yahoo.
the class TestAuthZpe method testAllowAccessExpiredAccessToken.
@Test
public void testAllowAccessExpiredAccessToken() {
String action = "all";
String resource = "angler:stuff";
StringBuilder roleName = new StringBuilder();
long now = System.currentTimeMillis() / 1000;
AccessToken accessToken = new AccessToken();
accessToken.setIssueTime(now - 3600);
accessToken.setExpiryTime(now - 3000);
accessToken.setAudience("angler");
accessToken.setScope(Collections.singletonList("matchall"));
AccessCheckStatus status = AuthZpeClient.allowAccess(accessToken, resource, action, roleName);
Assert.assertEquals(status, AccessCheckStatus.DENY_ROLETOKEN_EXPIRED);
}
Aggregations