Class CredentialsUtils


  • public class CredentialsUtils
    extends java.lang.Object
    An utility class for handling credentials
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  CredentialsUtils.PrivateKeyEncoding
      The encoding used to serialize proxy credentials private key.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void savePrivateKey​(java.io.OutputStream os, java.security.PrivateKey key, CredentialsUtils.PrivateKeyEncoding encoding)
      Serializes a private key to an output stream according to an encoding.
      private static void savePrivateKeyPKCS1​(java.io.OutputStream os, java.security.PrivateKey key)
      Serializes a private key to an output stream following the pkcs1 encoding.
      private static void savePrivateKeyPKCS8​(java.io.OutputStream os, java.security.PrivateKey key)
      Serializes a private key to an output stream following the pkcs8 encoding.
      static void saveProxyCredentials​(java.io.OutputStream os, eu.emi.security.authn.x509.X509Credential uc)
      Saves user credentials as a plain text PEM data.
      static void saveProxyCredentials​(java.io.OutputStream os, eu.emi.security.authn.x509.X509Credential uc, CredentialsUtils.PrivateKeyEncoding encoding)
      Saves user credentials as a plain text PEM data.
      static void saveProxyCredentials​(java.lang.String proxyFileName, eu.emi.security.authn.x509.X509Credential uc)
      Saves proxy credentials to a file.
      static void saveProxyCredentials​(java.lang.String proxyFileName, eu.emi.security.authn.x509.X509Credential uc, CredentialsUtils.PrivateKeyEncoding encoding)
      Saves proxy credentials to a file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CredentialsUtils

        public CredentialsUtils()
    • Method Detail

      • savePrivateKey

        public static void savePrivateKey​(java.io.OutputStream os,
                                          java.security.PrivateKey key,
                                          CredentialsUtils.PrivateKeyEncoding encoding)
                                   throws java.io.IOException
        Serializes a private key to an output stream according to an encoding.
        Parameters:
        os - the target output stream
        key - the key to be serialized
        encoding - the encoding
        Throws:
        java.lang.IllegalArgumentException - for unsupported private key encodings
        java.io.IOException - if write fails for any reason on the output stream
      • savePrivateKeyPKCS8

        private static void savePrivateKeyPKCS8​(java.io.OutputStream os,
                                                java.security.PrivateKey key)
                                         throws java.lang.IllegalArgumentException,
                                                java.io.IOException
        Serializes a private key to an output stream following the pkcs8 encoding. This method just delegates to canl, but provides a much more understandable signature.
        Parameters:
        os -
        key -
        Throws:
        java.lang.IllegalArgumentException
        java.io.IOException
      • savePrivateKeyPKCS1

        private static void savePrivateKeyPKCS1​(java.io.OutputStream os,
                                                java.security.PrivateKey key)
                                         throws java.lang.IllegalArgumentException,
                                                java.io.IOException
        Serializes a private key to an output stream following the pkcs1 encoding. This method just delegates to canl, but provides a much more understandable signature.
        Parameters:
        os -
        key -
        Throws:
        java.lang.IllegalArgumentException
        java.io.IOException
      • saveProxyCredentials

        public static void saveProxyCredentials​(java.io.OutputStream os,
                                                eu.emi.security.authn.x509.X509Credential uc,
                                                CredentialsUtils.PrivateKeyEncoding encoding)
                                         throws java.io.IOException
        Saves user credentials as a plain text PEM data.
        Writes the user certificate chain first, then the user key.
        Parameters:
        os - the output stream
        uc - the user credential that must be serialized
        encoding - the private key encoding
        Throws:
        java.io.IOException - in case of errors writing on the output stream
      • saveProxyCredentials

        public static void saveProxyCredentials​(java.io.OutputStream os,
                                                eu.emi.security.authn.x509.X509Credential uc)
                                         throws java.io.IOException
        Saves user credentials as a plain text PEM data.
        Writes the user certificate chain first, then the user key, using the default encoding specified in DEFAULT_ENCONDING.
        Parameters:
        os - the output stream for the saved proxy
        uc - the user credential
        Throws:
        java.io.IOException - in case of errors writing to the output stream
      • saveProxyCredentials

        public static void saveProxyCredentials​(java.lang.String proxyFileName,
                                                eu.emi.security.authn.x509.X509Credential uc,
                                                CredentialsUtils.PrivateKeyEncoding encoding)
                                         throws java.io.IOException
        Saves proxy credentials to a file. This method ensures that the stored proxy is saved with the appropriate file permissions.
        Parameters:
        proxyFileName - the file where the proxy will be saved
        uc - the credential to be saved
        encoding - the private key encoding
        Throws:
        java.io.IOException - in case of errors writing to the proxy file
      • saveProxyCredentials

        public static void saveProxyCredentials​(java.lang.String proxyFileName,
                                                eu.emi.security.authn.x509.X509Credential uc)
                                         throws java.io.IOException
        Saves proxy credentials to a file. This method ensures that the stored proxy is saved with the appropriate file permissions, using the default encoding specified in DEFAULT_ENCONDING.
        Parameters:
        proxyFileName - the file where the proxy will be saved
        uc - the credential to be saved
        Throws:
        java.io.IOException - in case of errors writing the credential to the proxy file