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

io.github.oliviercailloux.plaquette.AuthenticatorHelper Maven / Gradle / Ivy

There is a newer version: 0.0.21
Show newest version
package io.github.oliviercailloux.plaquette;

import io.github.oliviercailloux.jaris.credentials.Credentials;
import io.github.oliviercailloux.jaris.credentials.CredentialsReader;
import java.net.Authenticator;
import java.net.PasswordAuthentication;

public class AuthenticatorHelper {

  public static void setDefaultAuthenticator() {
    final Authenticator myAuth =
        getConstantAuthenticator(CredentialsReader.classicalReader().getCredentials());
    Authenticator.setDefault(myAuth);
  }

  private static Authenticator getConstantAuthenticator(Credentials credentials) {
    final PasswordAuthentication passwordAuthentication = new PasswordAuthentication(
        credentials.API_USERNAME(), credentials.API_PASSWORD().toCharArray());
    final Authenticator myAuth = new Authenticator() {
      @Override
      protected PasswordAuthentication getPasswordAuthentication() {
        return passwordAuthentication;
      }
    };
    return myAuth;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy