C
- the type of connection.U
- the user to authenticate.public abstract class SSHAuthenticator<C,U extends com.cloudbees.plugins.credentials.common.StandardUsernameCredentials> extends Object
Modifier and Type | Class and Description |
---|---|
static class |
SSHAuthenticator.Mode
Reflects the different styles of applying authentication.
|
Modifier | Constructor and Description |
---|---|
protected |
SSHAuthenticator(C connection,
U user)
|
protected |
SSHAuthenticator(C connection,
U user,
String username)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
authenticate()
Deprecated.
as of 0.3
Use
authenticate(TaskListener) and provide a listener to receive errors. |
boolean |
authenticate(hudson.model.TaskListener listener)
Authenticate the bound connection using the supplied credentials.
|
boolean |
canAuthenticate()
Returns
true if the bound connection is in a state where authentication can be tried using the
supplied credentials. |
protected abstract boolean |
doAuthenticate()
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.
Use
CredentialsMatchers.filter(List, CredentialsMatcher)
and matcher(Class) |
SSHAuthenticator.Mode |
getAuthenticationMode()
Returns the mode of authentication that this
SSHAuthenticator supports. |
protected C |
getConnection()
Gets the bound connection.
|
hudson.model.TaskListener |
getListener() |
static List<String> |
getPrivateKeys(SSHUserPrivateKey user)
Same as
SSHUserPrivateKey.getPrivateKeys() but backward compatible for old implementations. |
U |
getUser()
Gets the supplied credentials.
|
String |
getUsername()
Returns the username to authenticate as.
|
boolean |
isAuthenticated()
Returns
true if the bound connection has been authenticated. |
static <C,U extends com.cloudbees.plugins.credentials.common.StandardUsernameCredentials> |
isSupported(Class<C> connectionClass,
Class<U> userClass)
Returns
true 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 a
CredentialsMatcher that matches the generic types of credential that are valid for use over
SSH. |
static com.cloudbees.plugins.credentials.CredentialsMatcher |
matcher(Class<?> connectionClass)
Creates a
CredentialsMatcher for the specific type of connection. |
static <C,U extends com.cloudbees.plugins.credentials.common.StandardUsernameCredentials> |
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> |
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.
Use
newInstance(Object, StandardUsernameCredentials) instead. |
void |
setListener(hudson.model.TaskListener listener)
Sets the
TaskListener that receives errors that happen during the authentication. |
@Deprecated protected SSHAuthenticator(@NonNull C connection, @NonNull U user)
SSHAuthenticator(Object, com.cloudbees.plugins.credentials.common.StandardUsernameCredentials, String)
connection
- the connection we will be authenticating.user
- the user we will be authenticating as.protected SSHAuthenticator(@NonNull C connection, @NonNull U user, @CheckForNull String username)
connection
- the connection we will be authenticating.user
- the user we will be authenticating as.username
- the username we will be authenticating as or null
to use the users username.public String getUsername()
@NonNull public hudson.model.TaskListener getListener()
public void setListener(hudson.model.TaskListener listener)
TaskListener
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 another SSHAuthenticator
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.@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
C
- the type of connection.U
- the type of user.connection
- the connection to authenticate on.user
- the user to authenticate with.SSHAuthenticator
that may or may not be able to successfully authenticate.InterruptedException
IOException
@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
C
- the type of connection.U
- the type of user.connection
- the connection to authenticate on.user
- the user to authenticate with.username
- the username or null
to fall back to the username in the user parameter.SSHAuthenticator
that may or may not be able to successfully authenticate.InterruptedException
IOException
@Deprecated public static SSHAuthenticator<Object,com.cloudbees.plugins.credentials.common.StandardUsernameCredentials> newInstance(Object connection, SSHUser user) throws InterruptedException, IOException
newInstance(Object, StandardUsernameCredentials)
instead.InterruptedException
IOException
public static <C,U extends com.cloudbees.plugins.credentials.common.StandardUsernameCredentials> boolean isSupported(@NonNull Class<C> connectionClass, @NonNull Class<U> userClass)
true
if and only if the supplied connection class and user class are supported by at least one
factory.C
- the type of connection.U
- the type of user.connectionClass
- the connection class.userClass
- the user class.true
if and only if the supplied connection class and user class are supported by at least one
factory.public static List<? extends com.cloudbees.plugins.credentials.common.StandardUsernameCredentials> filter(Iterable<? extends com.cloudbees.plugins.credentials.Credentials> credentials, Class<?> connectionClass)
CredentialsMatchers.filter(List, CredentialsMatcher)
and matcher(Class)
Credentials
returning only those which are supported with the specified type of connection.credentials
- the credentials to filter.connectionClass
- the type of connection to filter for.SSHUser
credentials appropriate for use with the supplied type of connection.public static com.cloudbees.plugins.credentials.CredentialsMatcher matcher()
CredentialsMatcher
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 use matcher(Class)
.CredentialsMatcher
that matches the generic types of credential that are valid for use over
SSH.public static com.cloudbees.plugins.credentials.CredentialsMatcher matcher(Class<?> connectionClass)
CredentialsMatcher
for the specific type of connection.connectionClass
- the type of connection.CredentialsMatcher
public boolean canAuthenticate()
true
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.true
if the bound connection is in a state where authentication can be tried using the
supplied credentials.public final boolean isAuthenticated()
true
if the bound connection has been authenticated.true
if the bound connection has been authenticated.@NonNull protected final C getConnection()
@NonNull public U getUser()
protected abstract boolean doAuthenticate()
getListener()
before this method returns with false
. 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)true
if and only if authentication was successful.@NonNull public SSHAuthenticator.Mode getAuthenticationMode()
SSHAuthenticator
supports.SSHAuthenticator
supports.public final boolean authenticate()
authenticate(TaskListener)
and provide a listener to receive errors.public final boolean authenticate(hudson.model.TaskListener listener)
getAuthenticationMode()
of SSHAuthenticator.Mode.BEFORE_CONNECT
the return value is
always true
otherwise the return value is true
if and only if authentication was
successful.public static List<String> getPrivateKeys(SSHUserPrivateKey user)
SSHUserPrivateKey.getPrivateKeys()
but backward compatible for old implementations.Copyright © 2016. All rights reserved.