Top Description Inners Fields Constructors Methods
org.apache.sshd.server.config.keys

public Class AuthorizedKeysAuthenticator

extends ModifiableFileWatcher
implements PublickeyAuthenticator
Class Inheritance
All Implemented Interfaces
org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator
Known Direct Subclasses
org.apache.sshd.server.config.keys.DefaultAuthorizedKeysAuthenticator
Imports
java.io.IOException, java.nio.file.Files, .LinkOption, .OpenOption, .Path, java.security.GeneralSecurityException, .PublicKey, java.util.Collection, .Collections, .List, .Objects, java.util.concurrent.atomic.AtomicReference, org.apache.sshd.common.config.keys.AuthorizedKeyEntry, .PublicKeyEntry, .PublicKeyEntryResolver, org.apache.sshd.common.util.GenericUtils, org.apache.sshd.common.util.io.IoUtils, .ModifiableFileWatcher, org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator, .RejectAllPublickeyAuthenticator, org.apache.sshd.server.session.ServerSession

Uses the authorized keys file to implement PublickeyAuthenticator while automatically re-loading the keys if the file has changed when a new authentication request is received

Note

by default, the only validation of the username is that it is not null/empty - see isValidUsername(String, ServerSession)

Author
Apache MINA SSHD Project

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final AtomicReference<PublickeyAuthenticator>
public static final String
STD_AUTHORIZED_KEYS_FILENAME

Standard OpenSSH authorized keys file name

Inherited from org.apache.sshd.common.util.io.ModifiableFileWatcher:
optionsSTRICTLY_PROHIBITED_FILE_PERMISSION

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public boolean
authenticate(String
the username
username
,
PublicKey
the key
key
,
ServerSession
the server session
session
)

Implements org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator.authenticate.

Check the validity of a public key.

protected PublickeyAuthenticator
public static Path

Returns:

The default Path location of the OpenSSH authorized keys file
getDefaultAuthorizedKeysFile
()

protected PublicKeyEntryResolver
protected boolean
public static List<AuthorizedKeyEntry>

Returns:

A List of all the AuthorizedKeyEntry-ies found there - or empty if file does not exist
readDefaultAuthorizedKeys
(OpenOption...
The OpenOptions to use when reading the file
options
)

Reads read the contents of the default OpenSSH authorized_keys file

protected Collection<AuthorizedKeyEntry>
reloadAuthorizedKeys(Path path, String username, ServerSession session)

protected PublickeyAuthenticator
Inherited from org.apache.sshd.common.util.io.ModifiableFileWatcher:
checkReloadRequiredexistsgetPathlastModifiedresetReloadAttributessizetoPathResourcetoPathResourcetoStringupdateReloadAttributesvalidateStrictConfigFilePermissions

Field Detail

delegateHolderback to summary
private final AtomicReference<PublickeyAuthenticator> delegateHolder
STD_AUTHORIZED_KEYS_FILENAMEback to summary
public static final String STD_AUTHORIZED_KEYS_FILENAME

Standard OpenSSH authorized keys file name

Constructor Detail

AuthorizedKeysAuthenticatorback to summary
public AuthorizedKeysAuthenticator(Path file)
AuthorizedKeysAuthenticatorback to summary
public AuthorizedKeysAuthenticator(Path file, LinkOption... options)

Method Detail

authenticateback to summary
public boolean authenticate(String username, PublicKey key, ServerSession session)

Implements org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator.authenticate.

Doc from org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator.authenticate.

Check the validity of a public key.

Parameters
username:String

the username

key:PublicKey

the key

session:ServerSession

the server session

Returns:boolean

a boolean indicating if authentication succeeded or not

Annotations
@Override
createDelegateAuthenticatorback to summary
protected PublickeyAuthenticator createDelegateAuthenticator(String username, ServerSession session, Path path, Collection<AuthorizedKeyEntry> entries, PublicKeyEntryResolver fallbackResolver) throws IOException, GeneralSecurityException
getDefaultAuthorizedKeysFileback to summary
public static Path getDefaultAuthorizedKeysFile()
Returns:Path

The default Path location of the OpenSSH authorized keys file

Annotations
@SuppressWarnings:synthetic-access
getFallbackPublicKeyEntryResolverback to summary
protected PublicKeyEntryResolver getFallbackPublicKeyEntryResolver()
isValidUsernameback to summary
protected boolean isValidUsername(String username, ServerSession session)
readDefaultAuthorizedKeysback to summary
public static List<AuthorizedKeyEntry> readDefaultAuthorizedKeys(OpenOption... options) throws IOException

Reads read the contents of the default OpenSSH authorized_keys file

Parameters
options:OpenOption[]

The OpenOptions to use when reading the file

Returns:List<AuthorizedKeyEntry>

A List of all the AuthorizedKeyEntry-ies found there - or empty if file does not exist

Exceptions
IOException:
If failed to read keys from file
reloadAuthorizedKeysback to summary
protected Collection<AuthorizedKeyEntry> reloadAuthorizedKeys(Path path, String username, ServerSession session) throws IOException, GeneralSecurityException
resolvePublickeyAuthenticatorback to summary
protected PublickeyAuthenticator resolvePublickeyAuthenticator(String username, ServerSession session) throws IOException, GeneralSecurityException
org.apache.sshd.server.config.keys back to summary

private final Class AuthorizedKeysAuthenticator.LazyDefaultAuthorizedKeysFileHolder

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.sshd.server.config.keys.AuthorizedKeysAuthenticator.LazyDefaultAuthorizedKeysFileHolder

Field Summary

Modifier and TypeField and Description
private static final Path

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

KEYS_FILEback to summary
private static final Path KEYS_FILE

Constructor Detail

LazyDefaultAuthorizedKeysFileHolderback to summary
private LazyDefaultAuthorizedKeysFileHolder()