Class SSHAuthenticator<C,U extends com.cloudbees.plugins.credentials.common.StandardUsernameCredentials>
- Type Parameters:
C
- the type of connection.U
- the user to authenticate.
- Direct Known Subclasses:
TrileadSSHPasswordAuthenticator
,TrileadSSHPublicKeyAuthenticator
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Reflects the different styles of applying authentication. -
Constructor Summary
ModifierConstructorDescriptionprotected
SSHAuthenticator
(C connection, U user) Deprecated.protected
SSHAuthenticator
(C connection, U user, String username) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
Deprecated.as of 0.3 Useauthenticate(TaskListener)
and provide a listener to receive errors.final boolean
authenticate
(TaskListener listener) Authenticate the bound connection using the supplied credentials.final void
boolean
Returnstrue
if the bound connection is in a state where authentication can be tried using the supplied credentials.protected abstract boolean
SPI for authenticating the bound connection using the supplied credentials.static List<? extends com.cloudbees.plugins.credentials.common.StandardUsernameCredentials>
filter
(Iterable<? extends com.cloudbees.plugins.credentials.Credentials> credentials, Class<?> connectionClass) Deprecated.UseCredentialsMatchers.filter(List, CredentialsMatcher)
andmatcher(Class)
Returns the mode of authentication that thisSSHAuthenticator
supports.protected final C
Gets the bound connection.Same asSSHUserPrivateKey.getPrivateKeys()
but backward compatible for old implementations.getUser()
Gets the supplied credentials.Returns the username to authenticate as.final boolean
Returnstrue
if the bound connection has been authenticated.static <C,
U extends com.cloudbees.plugins.credentials.common.StandardUsernameCredentials>
booleanisSupported
(Class<C> connectionClass, Class<U> userClass) Returnstrue
if and only if the supplied connection class and user class are supported by at least one factory.static com.cloudbees.plugins.credentials.CredentialsMatcher
matcher()
Returns aCredentialsMatcher
that matches the generic types of credential that are valid for use over SSH.static com.cloudbees.plugins.credentials.CredentialsMatcher
Creates aCredentialsMatcher
for the specific type of connection.static <C,
U extends com.cloudbees.plugins.credentials.common.StandardUsernameCredentials>
SSHAuthenticator<C,U> newInstance
(C connection, U user) Creates an authenticator that may be able to authenticate the supplied connection with the supplied user.static <C,
U extends com.cloudbees.plugins.credentials.common.StandardUsernameCredentials>
SSHAuthenticator<C,U> newInstance
(C connection, U user, String username) Creates an authenticator that may be able to authenticate the supplied connection with the supplied user.static SSHAuthenticator<Object,
com.cloudbees.plugins.credentials.common.StandardUsernameCredentials> newInstance
(Object connection, SSHUser user) Deprecated.UsenewInstance(Object, StandardUsernameCredentials)
instead.void
setListener
(TaskListener listener) Sets theTaskListener
that receives errors that happen during the authentication.
-
Constructor Details
-
SSHAuthenticator
Deprecated.Constructor.- Parameters:
connection
- the connection we will be authenticating.user
- the user we will be authenticating as.
-
SSHAuthenticator
Constructor.- Parameters:
connection
- the connection we will be authenticating.user
- the user we will be authenticating as.username
- the username we will be authenticating as ornull
to use the users username.- Since:
- 1.4
-
-
Method Details
-
getUsername
Returns the username to authenticate as.- Returns:
- the username to authenticate as.
- Since:
- 1.4
-
getListener
-
setListener
Sets theTaskListener
that receives errors that happen during the authentication.If you are doing this as a part of a build, pass in your
BuildListener
. Pass in null to suppress the error reporting. Doing so is useful if the caller intends to try anotherSSHAuthenticator
when this one fails.For assisting troubleshooting with callers that do not provide a valid listener, by default the errors will be sent to stderr of the server.
-
newInstance
@NonNull public static <C,U extends com.cloudbees.plugins.credentials.common.StandardUsernameCredentials> SSHAuthenticator<C,U> newInstance(@NonNull C connection, @NonNull U user) throws InterruptedException, IOException Creates an authenticator that may be able to authenticate the supplied connection with the supplied user.- Type Parameters:
C
- the type of connection.U
- the type of user.- Parameters:
connection
- the connection to authenticate on.user
- the user to authenticate with.- Returns:
- a
SSHAuthenticator
that may or may not be able to successfully authenticate. - Throws:
InterruptedException
IOException
-
newInstance
@NonNull public static <C,U extends com.cloudbees.plugins.credentials.common.StandardUsernameCredentials> SSHAuthenticator<C,U> newInstance(@NonNull C connection, @NonNull U user, @CheckForNull String username) throws InterruptedException, IOException Creates an authenticator that may be able to authenticate the supplied connection with the supplied user.- Type Parameters:
C
- the type of connection.U
- the type of user.- Parameters:
connection
- the connection to authenticate on.user
- the user to authenticate with.username
- the username ornull
to fall back to the username in the user parameter.- Returns:
- a
SSHAuthenticator
that may or may not be able to successfully authenticate. - Throws:
InterruptedException
IOException
- Since:
- 1.4
-
newInstance
@Deprecated public static SSHAuthenticator<Object,com.cloudbees.plugins.credentials.common.StandardUsernameCredentials> newInstance(Object connection, SSHUser user) throws InterruptedException, IOException Deprecated.UsenewInstance(Object, StandardUsernameCredentials)
instead.- Throws:
InterruptedException
IOException
-
isSupported
public static <C,U extends com.cloudbees.plugins.credentials.common.StandardUsernameCredentials> boolean isSupported(@NonNull Class<C> connectionClass, @NonNull Class<U> userClass) Returnstrue
if and only if the supplied connection class and user class are supported by at least one factory.- Type Parameters:
C
- the type of connection.U
- the type of user.- Parameters:
connectionClass
- the connection class.userClass
- the user class.- Returns:
true
if and only if the supplied connection class and user class are supported by at least one factory.
-
filter
public static List<? extends com.cloudbees.plugins.credentials.common.StandardUsernameCredentials> filter(Iterable<? extends com.cloudbees.plugins.credentials.Credentials> credentials, Class<?> connectionClass) Deprecated.UseCredentialsMatchers.filter(List, CredentialsMatcher)
andmatcher(Class)
FiltersCredentials
returning only those which are supported with the specified type of connection.- Parameters:
credentials
- the credentials to filter.connectionClass
- the type of connection to filter for.- Returns:
- a list of
SSHUser
credentials appropriate for use with the supplied type of connection.
-
matcher
public static com.cloudbees.plugins.credentials.CredentialsMatcher matcher()Returns aCredentialsMatcher
that matches the generic types of credential that are valid for use over SSH. When you know the connection type you will be using, it is better to usematcher(Class)
.- Returns:
- a
CredentialsMatcher
that matches the generic types of credential that are valid for use over SSH.
-
matcher
public static com.cloudbees.plugins.credentials.CredentialsMatcher matcher(Class<?> connectionClass) Creates aCredentialsMatcher
for the specific type of connection.- Parameters:
connectionClass
- the type of connection.- Returns:
- a
CredentialsMatcher
- Since:
- 0.5
-
canAuthenticate
public boolean canAuthenticate()Returnstrue
if the bound connection is in a state where authentication can be tried using the supplied credentials.Subclasses can override this if they can tell whether it is possible to make an authentication attempt, default implementation is one-shot always.
- Returns:
true
if the bound connection is in a state where authentication can be tried using the supplied credentials.
-
isAuthenticated
public final boolean isAuthenticated()Returnstrue
if the bound connection has been authenticated.- Returns:
true
if the bound connection has been authenticated.
-
getConnection
Gets the bound connection.- Returns:
- the bound connection.
-
getUser
Gets the supplied credentials.- Returns:
- the supplied credentials.
-
doAuthenticate
protected abstract boolean doAuthenticate()SPI for authenticating the bound connection using the supplied credentials.As a guideline, authentication errors should be reported to
getListener()
before this method returns withfalse
. This helps an user better understand what is tried and failing. Logging can be used in addition to this to capture further details. (in contrast, please avoid reporting a success to the listener to improve S/N ratio)- Returns:
true
if and only if authentication was successful.
-
getAuthenticationMode
Returns the mode of authentication that thisSSHAuthenticator
supports.- Returns:
- the mode of authentication that this
SSHAuthenticator
supports. - Since:
- 0.2
-
authenticate
public final boolean authenticate()Deprecated.as of 0.3 Useauthenticate(TaskListener)
and provide a listener to receive errors. -
authenticateOrFail
- Throws:
IOException
- Failure reason- Since:
- TODO
-
authenticate
Authenticate the bound connection using the supplied credentials.- Returns:
- For an
getAuthenticationMode()
ofSSHAuthenticator.Mode.BEFORE_CONNECT
the return value is alwaystrue
otherwise the return value istrue
if and only if authentication was successful.
-
getPrivateKeys
Same asSSHUserPrivateKey.getPrivateKeys()
but backward compatible for old implementations.- Since:
- 1.3
-
SSHAuthenticator(Object, com.cloudbees.plugins.credentials.common.StandardUsernameCredentials, String)