use of org.apache.shiro.authc.BearerToken in project conquery by bakdata.
the class JwtPkceVerifyingRealmTest method falsifyTokenOutdated.
@Test
void falsifyTokenOutdated() {
// Setup the expected user id
UserId expected = new UserId("Test");
Date issueDate = new Date();
Date expDate = DateUtils.addMinutes(issueDate, -2);
String token = JWT.create().withIssuer(HTTP_REALM_URL).withSubject(expected.getName()).withClaim("groups", "conquery").withIssuedAt(issueDate).withExpiresAt(expDate).sign(Algorithm.RSA256(PUBLIC_KEY, PRIVATE_KEY));
BearerToken accessToken = new BearerToken(token);
assertThatCode(() -> REALM.doGetAuthenticationInfo(accessToken)).hasCauseInstanceOf(VerificationException.class);
}
use of org.apache.shiro.authc.BearerToken in project conquery by bakdata.
the class JwtPkceVerifyingRealmTest method verifyTokenInLeeway.
@Test
void verifyTokenInLeeway() {
// Setup the expected user id
User expected = new User("Test", "Test", STORAGE);
Date issueDate = new Date();
Date expDate = DateUtils.addMinutes(issueDate, -1);
String token = JWT.create().withIssuer(HTTP_REALM_URL).withAudience(AUDIENCE).withSubject(expected.getName()).withIssuedAt(issueDate).withExpiresAt(expDate).withClaim("groups", "conquery").withIssuedAt(issueDate).withExpiresAt(expDate).sign(Algorithm.RSA256(PUBLIC_KEY, PRIVATE_KEY));
BearerToken accessToken = new BearerToken(token);
assertThat(REALM.doGetAuthenticationInfo(accessToken).getPrincipals().getPrimaryPrincipal()).isEqualTo(expected);
}
use of org.apache.shiro.authc.BearerToken in project conquery by bakdata.
the class JwtPkceVerifyingRealmTest method verifyTokenAlternativeId.
@Test
void verifyTokenAlternativeId() {
// Setup the expected user id
User expected = new User("Test", "Test", STORAGE);
STORAGE.updateUser(expected);
Date issueDate = new Date();
Date expDate = DateUtils.addMinutes(issueDate, 1);
final String primId = UUID.randomUUID().toString();
String token = JWT.create().withIssuer(HTTP_REALM_URL).withAudience(AUDIENCE).withSubject(primId).withClaim("groups", "conquery").withIssuedAt(issueDate).withExpiresAt(expDate).withClaim(ALTERNATIVE_ID_CLAIM, expected.getName()).sign(Algorithm.RSA256(PUBLIC_KEY, PRIVATE_KEY));
BearerToken accessToken = new BearerToken(token);
assertThat(REALM.doGetAuthenticationInfo(accessToken).getPrincipals().getPrimaryPrincipal()).isEqualTo(expected);
}
use of org.apache.shiro.authc.BearerToken in project conquery by bakdata.
the class JwtPkceVerifyingRealmTest method falsifyTokenWrongIssuer.
@Test
void falsifyTokenWrongIssuer() {
// Setup the expected user id
UserId expected = new UserId("Test");
Date issueDate = new Date();
Date expDate = DateUtils.addMinutes(issueDate, 1);
String token = JWT.create().withIssuer("wrong_iss").withAudience(AUDIENCE).withSubject(expected.getName()).withIssuedAt(issueDate).withExpiresAt(expDate).withClaim("groups", "conquery").withIssuedAt(issueDate).withExpiresAt(expDate).sign(Algorithm.RSA256(PUBLIC_KEY, PRIVATE_KEY));
BearerToken accessToken = new BearerToken(token);
assertThatCode(() -> REALM.doGetAuthenticationInfo(accessToken)).hasCauseInstanceOf(VerificationException.class);
}
use of org.apache.shiro.authc.BearerToken in project conquery by bakdata.
the class JwtPkceVerifyingRealmTest method falsifyTokenWrongAudience.
@Test
void falsifyTokenWrongAudience() {
// Setup the expected user id
UserId expected = new UserId("Test");
Date issueDate = new Date();
Date expDate = DateUtils.addMinutes(issueDate, 1);
String token = JWT.create().withIssuer(HTTP_REALM_URL).withAudience("wrong_aud").withSubject(expected.getName()).withClaim("groups", "conquery").withIssuedAt(issueDate).withExpiresAt(expDate).sign(Algorithm.RSA256(PUBLIC_KEY, PRIVATE_KEY));
BearerToken accessToken = new BearerToken(token);
assertThatCode(() -> REALM.doGetAuthenticationInfo(accessToken)).hasCauseInstanceOf(VerificationException.class);
}
Aggregations