Search in sources :

Example 1 with UserInfo

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);
    }
}
Also used : AuthorizationErrorException(io.cryostat.net.AuthorizationErrorException) TokenReviewStatus(io.fabric8.kubernetes.api.model.authentication.TokenReviewStatus) UserInfo(io.cryostat.net.UserInfo) ExecutionException(java.util.concurrent.ExecutionException) URISyntaxException(java.net.URISyntaxException) MissingEnvironmentVariableException(io.cryostat.net.MissingEnvironmentVariableException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) TokenNotFoundException(io.cryostat.net.TokenNotFoundException) AuthorizationErrorException(io.cryostat.net.AuthorizationErrorException) IOException(java.io.IOException) PermissionDeniedException(io.cryostat.net.PermissionDeniedException) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with UserInfo

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"));
}
Also used : TokenReviewBuilder(io.fabric8.kubernetes.api.model.authentication.TokenReviewBuilder) TokenReview(io.fabric8.kubernetes.api.model.authentication.TokenReview) UserInfo(io.cryostat.net.UserInfo) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

UserInfo (io.cryostat.net.UserInfo)2 AuthorizationErrorException (io.cryostat.net.AuthorizationErrorException)1 MissingEnvironmentVariableException (io.cryostat.net.MissingEnvironmentVariableException)1 PermissionDeniedException (io.cryostat.net.PermissionDeniedException)1 TokenNotFoundException (io.cryostat.net.TokenNotFoundException)1 TokenReview (io.fabric8.kubernetes.api.model.authentication.TokenReview)1 TokenReviewBuilder (io.fabric8.kubernetes.api.model.authentication.TokenReviewBuilder)1 TokenReviewStatus (io.fabric8.kubernetes.api.model.authentication.TokenReviewStatus)1 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 ExecutionException (java.util.concurrent.ExecutionException)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1