Class ClientIdentity

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String ID_FILE_PREFIX  
      static java.lang.String ID_FILE_SUFFIX  
      static java.util.function.Function<java.lang.String,​java.lang.String> ID_GENERATOR  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ClientIdentity()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String getIdentityFileName​(java.lang.String type)  
      static java.lang.String getIdentityFileName​(NamedResource r)  
      static java.lang.String getIdentityType​(java.lang.String name)  
      static java.util.Map<java.lang.String,​java.security.KeyPair> loadDefaultIdentities​(boolean strict, FilePasswordProvider provider, java.nio.file.LinkOption... options)  
      static java.util.Map<java.lang.String,​java.security.KeyPair> loadDefaultIdentities​(java.nio.file.Path dir, boolean strict, FilePasswordProvider provider, java.nio.file.LinkOption... options)  
      static KeyPairProvider loadDefaultKeyPairProvider​(boolean strict, boolean supportedOnly, FilePasswordProvider provider, java.nio.file.LinkOption... options)  
      static KeyPairProvider loadDefaultKeyPairProvider​(java.nio.file.Path dir, boolean strict, boolean supportedOnly, FilePasswordProvider provider, java.nio.file.LinkOption... options)  
      static java.util.Map<java.lang.String,​java.security.KeyPair> loadIdentities​(SessionContext session, java.nio.file.Path dir, boolean strict, java.util.Collection<java.lang.String> types, java.util.function.Function<? super java.lang.String,​java.lang.String> idGenerator, FilePasswordProvider provider, java.nio.file.LinkOption... options)
      Scans a folder and loads all available identity files
      static java.util.Map<java.lang.String,​java.nio.file.Path> scanIdentitiesFolder​(java.nio.file.Path dir, boolean strict, java.util.Collection<java.lang.String> types, java.util.function.Function<? super java.lang.String,​java.lang.String> idGenerator, java.nio.file.LinkOption... options)
      Scans a folder for possible identity files
      • Methods inherited from class java.lang.Object

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

      • ID_GENERATOR

        public static final java.util.function.Function<java.lang.String,​java.lang.String> ID_GENERATOR
    • Constructor Detail

      • ClientIdentity

        private ClientIdentity()
    • Method Detail

      • getIdentityType

        public static java.lang.String getIdentityType​(java.lang.String name)
        Parameters:
        name - The file name - ignored if null/empty
        Returns:
        The identity type - null if cannot determine it - e.g., does not start with the ID_FILE_PREFIX
      • getIdentityFileName

        public static java.lang.String getIdentityFileName​(NamedResource r)
      • loadDefaultKeyPairProvider

        public static KeyPairProvider loadDefaultKeyPairProvider​(boolean strict,
                                                                 boolean supportedOnly,
                                                                 FilePasswordProvider provider,
                                                                 java.nio.file.LinkOption... options)
                                                          throws java.io.IOException,
                                                                 java.security.GeneralSecurityException
        Parameters:
        strict - If true then files that do not have the required access rights are excluded from consideration
        supportedOnly - If true then ignore identities that are not supported internally
        provider - A FilePasswordProvider - may be null if the loaded keys are guaranteed not to be encrypted. The argument to FilePasswordProvider#getPassword is the path of the file whose key is to be loaded
        options - The LinkOptions to apply when checking for existence
        Returns:
        A KeyPair for the identities - null if no identities available (e.g., after filtering unsupported ones or strict permissions)
        Throws:
        java.io.IOException - If failed to access the file system
        java.security.GeneralSecurityException - If failed to load the keys
        See Also:
        PublicKeyEntry.getDefaultKeysFolderPath(), loadDefaultIdentities(Path, boolean, FilePasswordProvider, LinkOption...)
      • loadDefaultKeyPairProvider

        public static KeyPairProvider loadDefaultKeyPairProvider​(java.nio.file.Path dir,
                                                                 boolean strict,
                                                                 boolean supportedOnly,
                                                                 FilePasswordProvider provider,
                                                                 java.nio.file.LinkOption... options)
                                                          throws java.io.IOException,
                                                                 java.security.GeneralSecurityException
        Parameters:
        dir - The folder to scan for the built-in identities
        strict - If true then files that do not have the required access rights are excluded from consideration
        supportedOnly - If true then ignore identities that are not supported internally
        provider - A FilePasswordProvider - may be null if the loaded keys are guaranteed not to be encrypted. The argument to FilePasswordProvider#getPassword is the path of the file whose key is to be loaded
        options - The LinkOptions to apply when checking for existence
        Returns:
        A KeyPair for the identities - null if no identities available (e.g., after filtering unsupported ones or strict permissions)
        Throws:
        java.io.IOException - If failed to access the file system
        java.security.GeneralSecurityException - If failed to load the keys
        See Also:
        loadDefaultIdentities(Path, boolean, FilePasswordProvider, LinkOption...), IdentityUtils.createKeyPairProvider(Map, boolean)
      • loadDefaultIdentities

        public static java.util.Map<java.lang.String,​java.security.KeyPair> loadDefaultIdentities​(boolean strict,
                                                                                                        FilePasswordProvider provider,
                                                                                                        java.nio.file.LinkOption... options)
                                                                                                 throws java.io.IOException,
                                                                                                        java.security.GeneralSecurityException
        Parameters:
        strict - If true then files that do not have the required access rights are excluded from consideration
        provider - A FilePasswordProvider - may be null if the loaded keys are guaranteed not to be encrypted. The argument to FilePasswordProvider#getPassword is the path of the file whose key is to be loaded
        options - The LinkOptions to apply when checking for existence
        Returns:
        A Map of the found files where key=identity type (case insensitive), value=the KeyPair of the identity
        Throws:
        java.io.IOException - If failed to access the file system
        java.security.GeneralSecurityException - If failed to load the keys
        See Also:
        PublicKeyEntry.getDefaultKeysFolderPath(), loadDefaultIdentities(Path, boolean, FilePasswordProvider, LinkOption...)
      • loadDefaultIdentities

        public static java.util.Map<java.lang.String,​java.security.KeyPair> loadDefaultIdentities​(java.nio.file.Path dir,
                                                                                                        boolean strict,
                                                                                                        FilePasswordProvider provider,
                                                                                                        java.nio.file.LinkOption... options)
                                                                                                 throws java.io.IOException,
                                                                                                        java.security.GeneralSecurityException
        Parameters:
        dir - The folder to scan for the built-in identities
        strict - If true then files that do not have the required access rights are excluded from consideration
        provider - A FilePasswordProvider - may be null if the loaded keys are guaranteed not to be encrypted. The argument to FilePasswordProvider#getPassword is the path of the file whose key is to be loaded
        options - The LinkOptions to apply when checking for existence
        Returns:
        A Map of the found files where key=identity type (case insensitive), value=the KeyPair of the identity
        Throws:
        java.io.IOException - If failed to access the file system
        java.security.GeneralSecurityException - If failed to load the keys
        See Also:
        BuiltinIdentities
      • loadIdentities

        public static java.util.Map<java.lang.String,​java.security.KeyPair> loadIdentities​(SessionContext session,
                                                                                                 java.nio.file.Path dir,
                                                                                                 boolean strict,
                                                                                                 java.util.Collection<java.lang.String> types,
                                                                                                 java.util.function.Function<? super java.lang.String,​java.lang.String> idGenerator,
                                                                                                 FilePasswordProvider provider,
                                                                                                 java.nio.file.LinkOption... options)
                                                                                          throws java.io.IOException,
                                                                                                 java.security.GeneralSecurityException
        Scans a folder and loads all available identity files
        Parameters:
        session - The SessionContext for invoking this load command - may be null if not invoked within a session context (e.g., offline tool or session unknown).
        dir - The Path of the folder to scan - ignored if not exists
        strict - If true then files that do not have the required access rights are excluded from consideration
        types - The identity types - ignored if null/empty
        idGenerator - A Function to derive the file name holding the specified type
        provider - A FilePasswordProvider - may be null if the loaded keys are guaranteed not to be encrypted. The argument to FilePasswordProvider#getPassword is the path of the file whose key is to be loaded
        options - The LinkOptions to apply when checking for existence
        Returns:
        A Map of the found files where key=identity type (case insensitive), value=the KeyPair of the identity
        Throws:
        java.io.IOException - If failed to access the file system
        java.security.GeneralSecurityException - If failed to load the keys
      • scanIdentitiesFolder

        public static java.util.Map<java.lang.String,​java.nio.file.Path> scanIdentitiesFolder​(java.nio.file.Path dir,
                                                                                                    boolean strict,
                                                                                                    java.util.Collection<java.lang.String> types,
                                                                                                    java.util.function.Function<? super java.lang.String,​java.lang.String> idGenerator,
                                                                                                    java.nio.file.LinkOption... options)
                                                                                             throws java.io.IOException
        Scans a folder for possible identity files
        Parameters:
        dir - The Path of the folder to scan - ignored if not exists
        strict - If true then files that do not have the required access rights are excluded from consideration
        types - The identity types - ignored if null/empty
        idGenerator - A Function to derive the file name holding the specified type
        options - The LinkOptions to apply when checking for existence
        Returns:
        A Map of the found files where key=identity type (case insensitive), value=the Path of the file holding the key
        Throws:
        java.io.IOException - If failed to access the file system
        See Also:
        KeyUtils.validateStrictKeyFilePermissions(Path, LinkOption...)