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

edu.vt.middleware.ldap.ssl.KeyStoreCredentialReader Maven / Gradle / Ivy

/*
  $Id$

  Copyright (C) 2003-2010 Virginia Tech.
  All rights reserved.

  SEE LICENSE FOR MORE INFORMATION

  Author:  Middleware Services
  Email:   [email protected]
  Version: $Revision$
  Updated: $Date$
*/
package edu.vt.middleware.ldap.ssl;

import java.io.IOException;
import java.io.InputStream;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.util.Arrays;

/**
 * Reads keystore credentials from a classpath, filepath, or stream resource.
 *
 * @author  Middleware Services
 * @version  $Revision$
 */
public class KeyStoreCredentialReader extends AbstractCredentialReader
{


  /**
   * Reads a keystore from an input stream.
   *
   * @param  is  Input stream from which to read keystore.
   * @param  params  Two optional parameters are supported:
   *
   * 
    *
  • KeyStore password
  • *
  • KeyStore type; defaults to JVM default keystore format if * omitted
  • *
* *

If only a single parameter is supplied, it is assumed to be * the password.

* * @return KeyStore read from data in stream. * * @throws IOException On IO errors. * @throws GeneralSecurityException On errors with the credential data. */ public KeyStore read(final InputStream is, final String... params) throws IOException, GeneralSecurityException { char[] password = null; if (params.length > 0 && params[0] != null) { password = params[0].toCharArray(); } String type = KeyStore.getDefaultType(); if (params.length > 1 && params[1] != null) { type = params[1]; } final KeyStore keystore = KeyStore.getInstance(type); if (is != null) { keystore.load(this.getBufferedInputStream(is), password); if (password != null) { Arrays.fill(password, '0'); } } return keystore; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy