Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove AuthenticationLoggingInterceptor #1014

Merged
merged 4 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public GoogleCredentialsFactory(@NonNull GoogleCredentialsConfiguration configur
@Requires(property = GoogleCredentialsConfiguration.PREFIX + ".enabled", value = StringUtils.TRUE, defaultValue = StringUtils.TRUE)
@Primary
@Singleton
@LogAuthenticationFailures
protected GoogleCredentials defaultGoogleCredentials() throws IOException {
final List<String> scopes = configuration.getScopes().stream()
.map(URI::toString).collect(Collectors.toList());
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package io.micronaut.gcp.credentials

import com.google.auth.RequestMetadataCallback

import com.google.auth.oauth2.GoogleCredentials
import com.google.auth.oauth2.ImpersonatedCredentials
import com.google.auth.oauth2.ServiceAccountCredentials
import com.google.auth.oauth2.UserCredentials
import com.google.common.util.concurrent.MoreExecutors
import io.micronaut.context.ApplicationContext
import io.micronaut.context.annotation.Requires
import io.micronaut.context.exceptions.BeanInstantiationException
Expand All @@ -16,7 +15,6 @@ import io.micronaut.http.HttpResponse
import io.micronaut.http.MediaType
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Post
import io.micronaut.runtime.server.EmbeddedServer
import org.spockframework.runtime.IStandardStreamsListener
import org.spockframework.runtime.StandardStreamsCapturer
import spock.lang.AutoCleanup
Expand Down Expand Up @@ -191,7 +189,7 @@ class GoogleCredentialsFactorySpec extends Specification {

then:
gc != null
ImpersonatedCredentials ic = gc.$target
ImpersonatedCredentials ic = (ImpersonatedCredentials) gc
UserCredentials uc = (UserCredentials) ic.getSourceCredentials()
ic.getAccount() == "sa-test1@micronaut-gcp-testing.iam.gserviceaccount.com"
with(uc) {
Expand Down Expand Up @@ -249,58 +247,18 @@ class GoogleCredentialsFactorySpec extends Specification {
matchesJsonServiceAccountCredentials(pk, gc)
}

void "invalid credentials cause a warning to be logged when metadata is requested"(){
given:
PrivateKey pk = generatePrivateKey()
String encodedServiceAccountCredentials = encodeServiceCredentials(pk)
EmbeddedServer gcp = ApplicationContext.run(EmbeddedServer, [
"spec.name" : "GoogleCredentialsFactorySpec",
"micronaut.server.port" : 8080
])
def ctx = ApplicationContext.run([
(GoogleCredentialsConfiguration.PREFIX + ".encoded-key"): encodedServiceAccountCredentials
])
GoogleCredentials gc = ctx.getBean(GoogleCredentials)

when:
gc.getRequestMetadata(null, MoreExecutors.directExecutor(), new RequestMetadataCallback() {
@Override
void onSuccess(Map<String, List<String>> metadata) {

}

@Override
void onFailure(Throwable exception) {

}
})

then:
conditions.eventually {
captured.messages.any {
it.contains("WARN")
it.contains("A failure occurred while attempting to build credential metadata for a GCP API request. The GCP libraries treat this as " +
"a retryable error, but misconfigured credentials can keep it from ever succeeding.")
}
}

cleanup:
ctx.stop()
gcp.stop()
}

private void matchesJsonUserCredentials(GoogleCredentials gc) {
assert gc != null && gc.$target != null && gc.$target instanceof UserCredentials
UserCredentials uc = (UserCredentials) gc.$target
assert gc != null && gc instanceof UserCredentials
UserCredentials uc = (UserCredentials) gc
assert uc.getClientId() == "client-id-1.apps.googleusercontent.com"
assert uc.getClientSecret() == "client-secret-1"
assert uc.getQuotaProjectId() == "micronaut-gcp-test"
assert uc.getRefreshToken() == "refresh-token-1"
}

private void matchesJsonServiceAccountCredentials(PrivateKey pk, GoogleCredentials gc) {
assert gc != null && gc.$target != null && gc.$target instanceof ServiceAccountCredentials
ServiceAccountCredentials sc = (ServiceAccountCredentials) gc.$target
assert gc != null && gc instanceof ServiceAccountCredentials
ServiceAccountCredentials sc = (ServiceAccountCredentials) gc
assert sc.getAccount() == "sa-test1@micronaut-gcp-testing.iam.gserviceaccount.com"
assert sc.getClientId() == "client-id-1"
assert sc.getProjectId() == "micronaut-gcp-testing"
Expand Down

This file was deleted.

Loading