All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.homeofthewizard.maven.plugins.vault.config.authentication.AuthenticationMethod Maven / Gradle / Ivy

The newest version!
package com.homeofthewizard.maven.plugins.vault.config.authentication;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.jopenlibs.vault.VaultException;
import io.github.jopenlibs.vault.api.Auth;

import java.util.Map;

/**
 * An abstract class that gives a skeleton for classes that implements authentication method to Hashicorp Vault.
 * The generic type argument is the POJO that gives the specific credentials/tokens to each authentication method.
 * @param  Generic type arguments that defines the POJO class of the authentication credentials
 */
public abstract class AuthenticationMethod {

  protected Auth auth;

  protected Class credentialObjectClass;

  /**
   * Initializes a new instance of the {@link AuthenticationMethod} class.
   * @param auth Auth
   */
  public AuthenticationMethod(Auth auth, Class credentialObjectClass) {
    this.auth = auth;
    this.credentialObjectClass = credentialObjectClass;
  }

  public abstract void login() throws VaultException;

  /**
   * Deserialize the Map<\String,Object\> from the server config that contains the authentication's credentials,
   * gives back an object of the generic type given by the implementation of AuthenticationMethod.class
   * @param authMethodMap Map<\String,Object\>
   * @return T is the generic type argument of the class
   */
  public T getAuthCredentials(Map authMethodMap) {
    ObjectMapper mapper = new ObjectMapper();
    return mapper.convertValue(authMethodMap, credentialObjectClass);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy