use of io.cryostat.net.UserInfo in project cryostat by cryostatio.
the class OpenShiftAuthManager method getUserInfo.
@Override
public Future<UserInfo> getUserInfo(Supplier<String> httpHeaderProvider) {
String token = getTokenFromHttpHeader(httpHeaderProvider.get());
Future<TokenReviewStatus> fStatus = performTokenReview(token);
try {
TokenReviewStatus status = fStatus.get();
if (!Boolean.TRUE.equals(status.getAuthenticated())) {
return CompletableFuture.failedFuture(new AuthorizationErrorException("Authentication Failed"));
}
return CompletableFuture.completedFuture(new UserInfo(status.getUser().getUsername()));
} catch (ExecutionException ee) {
return CompletableFuture.failedFuture(ee.getCause());
} catch (Exception e) {
return CompletableFuture.failedFuture(e);
}
}
use of io.cryostat.net.UserInfo in project cryostat by cryostatio.
the class OpenShiftAuthManagerTest method shouldReturnUserInfo.
@Test
void shouldReturnUserInfo() throws Exception {
TokenReview tokenReview = new TokenReviewBuilder().withNewStatus().withAuthenticated(true).withNewUser().withUsername("fooUser").endUser().endStatus().build();
server.expect().post().withPath(TOKEN_REVIEW_API_PATH).andReturn(HttpURLConnection.HTTP_CREATED, tokenReview).once();
UserInfo userInfo = mgr.getUserInfo(() -> "Bearer abc123").get();
MatcherAssert.assertThat(userInfo.getUsername(), Matchers.equalTo("fooUser"));
}
Aggregations