Search in sources :

Example 21 with IamCredentialsClient

use of com.google.cloud.iam.credentials.v1.IamCredentialsClient in project spring-vault by spring-projects.

the class GcpIamCredentialsAuthentication method signJwt.

protected String signJwt() {
    String serviceAccount = getServiceAccountId();
    Map<String, Object> jwtPayload = getJwtPayload(this.options, serviceAccount);
    try {
        IamCredentialsSettings credentialsSettings = IamCredentialsSettings.newBuilder().setCredentialsProvider(() -> this.credentials).setTransportChannelProvider(this.transportChannelProvider).build();
        try (IamCredentialsClient iamCredentialsClient = IamCredentialsClient.create(credentialsSettings)) {
            String payload = JSON_FACTORY.toString(jwtPayload);
            ServiceAccountName serviceAccountName = ServiceAccountName.of("-", serviceAccount);
            SignJwtResponse response = iamCredentialsClient.signJwt(serviceAccountName, Collections.emptyList(), payload);
            return response.getSignedJwt();
        }
    } catch (IOException e) {
        throw new VaultLoginException("Cannot sign JWT", e);
    }
}
Also used : SignJwtResponse(com.google.cloud.iam.credentials.v1.SignJwtResponse) IamCredentialsClient(com.google.cloud.iam.credentials.v1.IamCredentialsClient) ServiceAccountName(com.google.cloud.iam.credentials.v1.ServiceAccountName) IOException(java.io.IOException) IamCredentialsSettings(com.google.cloud.iam.credentials.v1.IamCredentialsSettings)

Aggregations

IamCredentialsClient (com.google.cloud.iam.credentials.v1.IamCredentialsClient)21 ArrayList (java.util.ArrayList)11 ServiceAccountName (com.google.cloud.iam.credentials.v1.ServiceAccountName)5 SignJwtResponse (com.google.cloud.iam.credentials.v1.SignJwtResponse)5 GenerateIdTokenResponse (com.google.cloud.iam.credentials.v1.GenerateIdTokenResponse)4 SignBlobResponse (com.google.cloud.iam.credentials.v1.SignBlobResponse)4 ByteString (com.google.protobuf.ByteString)4 GenerateAccessTokenResponse (com.google.cloud.iam.credentials.v1.GenerateAccessTokenResponse)3 IamCredentialsSettings (com.google.cloud.iam.credentials.v1.IamCredentialsSettings)3 HttpTransport (com.google.api.client.http.HttpTransport)2 GenerateIdTokenRequest (com.google.cloud.iam.credentials.v1.GenerateIdTokenRequest)2 SignBlobRequest (com.google.cloud.iam.credentials.v1.SignBlobRequest)2 SignJwtRequest (com.google.cloud.iam.credentials.v1.SignJwtRequest)2 Duration (com.google.protobuf.Duration)2 IOException (java.io.IOException)2 RetryerBuilder (com.github.rholder.retry.RetryerBuilder)1 GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)1 GoogleNetHttpTransport (com.google.api.client.googleapis.javanet.GoogleNetHttpTransport)1 ApacheHttpTransport (com.google.api.client.http.apache.ApacheHttpTransport)1 JsonFactory (com.google.api.client.json.JsonFactory)1