Search in sources :

Example 6 with AccessToken

use of io.vertx.ext.auth.oauth2.AccessToken in project docker-client by spotify.

the class ContainerRegistryAuthSupplier method authForBuild.

@Override
public RegistryConfigs authForBuild() throws DockerException {
    final AccessToken accessToken;
    try {
        accessToken = getAccessToken();
    } catch (IOException e) {
        // do not fail as the GCR access token may not be necessary for building the image currently
        // being built
        log.warn("unable to get access token for Google Container Registry, " + "configuration for building image will not contain RegistryAuth for GCR", e);
        return RegistryConfigs.empty();
    }
    final Map<String, RegistryAuth> configs = new HashMap<>(GCR_REGISTRIES.size());
    for (String serverName : GCR_REGISTRIES) {
        configs.put(serverName, authForAccessToken(accessToken));
    }
    return RegistryConfigs.create(configs);
}
Also used : HashMap(java.util.HashMap) AccessToken(com.google.auth.oauth2.AccessToken) IOException(java.io.IOException) RegistryAuth(com.spotify.docker.client.messages.RegistryAuth)

Example 7 with AccessToken

use of io.vertx.ext.auth.oauth2.AccessToken in project docker-client by spotify.

the class ContainerRegistryAuthSupplierTest method testAuthForBuild_TokenWithoutExpirationDoesNotCauseRefresh.

@Test
public void testAuthForBuild_TokenWithoutExpirationDoesNotCauseRefresh() throws Exception {
    final AccessToken accessToken = new AccessToken(tokenValue, null);
    final GoogleCredentials credentials = new GoogleCredentials(accessToken);
    final ContainerRegistryAuthSupplier supplier = new ContainerRegistryAuthSupplier(credentials, clock, TimeUnit.SECONDS.toMillis(minimumExpirationSecs), refresher);
    final RegistryConfigs configs = supplier.authForBuild();
    assertThat(configs.configs().values(), is(not(empty())));
    assertThat(configs.configs().values(), everyItem(matchesAccessToken(accessToken)));
    verify(refresher, never()).refresh(credentials);
}
Also used : RegistryConfigs(com.spotify.docker.client.messages.RegistryConfigs) AccessToken(com.google.auth.oauth2.AccessToken) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials) Test(org.junit.Test)

Example 8 with AccessToken

use of io.vertx.ext.auth.oauth2.AccessToken in project docker-client by spotify.

the class ContainerRegistryAuthSupplierTest method testAuthForSwarm_TokenWithoutExpirationDoesNotCauseRefresh.

@Test
public void testAuthForSwarm_TokenWithoutExpirationDoesNotCauseRefresh() throws Exception {
    final AccessToken accessToken = new AccessToken(tokenValue, null);
    final GoogleCredentials credentials = new GoogleCredentials(accessToken);
    final ContainerRegistryAuthSupplier supplier = new ContainerRegistryAuthSupplier(credentials, clock, TimeUnit.SECONDS.toMillis(minimumExpirationSecs), refresher);
    assertThat(supplier.authForSwarm(), matchesAccessToken(accessToken));
    verify(refresher, never()).refresh(credentials);
}
Also used : AccessToken(com.google.auth.oauth2.AccessToken) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials) Test(org.junit.Test)

Example 9 with AccessToken

use of io.vertx.ext.auth.oauth2.AccessToken in project api-framework by vinscom.

the class LoadUserFromSessionRouteBuillder method handle.

public void handle(RoutingContext pRoutingContext) {
    Session session = pRoutingContext.session();
    if (session != null && getOAuth2Auth() != null) {
        JsonObject principal = session.get(FrameworkConstants.Session.PRINCIPAL);
        if (principal != null) {
            OAuth2AuthProviderImpl provider = (OAuth2AuthProviderImpl) getOAuth2Auth().getDelegate();
            try {
                OAuth2TokenImpl token = new OAuth2TokenImpl(provider, principal);
                pRoutingContext.setUser(new AccessToken(token));
            } catch (RuntimeException e) {
                getLog().error(e);
                pRoutingContext.fail(401);
                return;
            }
        }
    }
    pRoutingContext.next();
}
Also used : AccessToken(io.vertx.reactivex.ext.auth.oauth2.AccessToken) JsonObject(io.vertx.core.json.JsonObject) OAuth2AuthProviderImpl(io.vertx.ext.auth.oauth2.impl.OAuth2AuthProviderImpl) OAuth2TokenImpl(io.vertx.ext.auth.oauth2.impl.OAuth2TokenImpl) Session(io.vertx.reactivex.ext.web.Session)

Example 10 with AccessToken

use of io.vertx.ext.auth.oauth2.AccessToken in project vertx-auth by vert-x3.

the class OAuth2IntrospectTest method introspectAccessToken.

@Test
public void introspectAccessToken() {
    config = oauthIntrospect;
    fixture = fixtureIntrospect;
    oauth2.introspectToken(token, res -> {
        if (res.failed()) {
            fail(res.cause().getMessage());
        } else {
            AccessToken token = res.result();
            assertNotNull(token);
            JsonObject principal = token.principal();
            // clean time specific value
            principal.remove("expires_at");
            principal.remove("access_token");
            final JsonObject assertion = fixtureIntrospect.copy();
            assertEquals(assertion.getMap(), principal.getMap());
            token.isAuthorized("scopeB", res0 -> {
                if (res0.failed()) {
                    fail(res0.cause().getMessage());
                } else {
                    if (res0.result()) {
                        testComplete();
                    } else {
                        fail("Should be allowed");
                    }
                }
            });
        }
    });
    await();
}
Also used : AccessToken(io.vertx.ext.auth.oauth2.AccessToken) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)25 AccessToken (com.google.auth.oauth2.AccessToken)22 JsonObject (io.vertx.core.json.JsonObject)13 AccessToken (io.vertx.ext.auth.oauth2.AccessToken)13 Date (java.util.Date)10 IOException (java.io.IOException)9 OAuth2TokenImpl (io.vertx.ext.auth.oauth2.impl.OAuth2TokenImpl)8 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)7 OAuth2Credentials (com.google.auth.oauth2.OAuth2Credentials)5 OAuth2Response (io.vertx.ext.auth.oauth2.OAuth2Response)5 Client (javax.ws.rs.client.Client)5 AccessToken (org.glassfish.jersey.client.oauth1.AccessToken)5 ConsumerCredentials (org.glassfish.jersey.client.oauth1.ConsumerCredentials)5 Metadata (io.grpc.Metadata)4 Feature (javax.ws.rs.core.Feature)4 JerseyTest (org.glassfish.jersey.test.JerseyTest)4 ServiceAccountCredentials (com.google.auth.oauth2.ServiceAccountCredentials)3 Buffer (io.vertx.core.buffer.Buffer)3 URI (java.net.URI)3 WebTarget (javax.ws.rs.client.WebTarget)3