Package com.pusher.client.util
Class HttpUserAuthenticator
- java.lang.Object
-
- com.pusher.client.util.HttpUserAuthenticator
-
- All Implemented Interfaces:
UserAuthenticator
public class HttpUserAuthenticator extends java.lang.Object implements UserAuthenticator
Used to authenticate the user when signing in on a Pusher Channels connection.Makes an HTTP request to a defined HTTP endpoint. Expects a user authentication token to be returned.
For more information see the Authenticating Users documentation.
-
-
Field Summary
Fields Modifier and Type Field Description protected ConnectionFactorymConnectionFactory
-
Constructor Summary
Constructors Constructor Description HttpUserAuthenticator(java.lang.String endPoint)Creates a new user authenticator.HttpUserAuthenticator(java.lang.String endPoint, ConnectionFactory connectionFactory)Creates a new user authenticator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringauthenticate(java.lang.String socketId)Called when a user is to be authenticated.protected java.lang.RuntimeExceptionauthFailureException(java.io.IOException e)protected java.lang.RuntimeExceptionauthFailureException(java.lang.String msg)java.lang.BooleanisSSL()Identifies if the HTTP request will be sent over HTTPS.protected java.lang.StringperformAuthRequest()Performs an HTTP request to the endpoint provided on construction.voidsetHeaders(java.util.Map<java.lang.String,java.lang.String> headers)Set additional headers to be sent as part of the request.
-
-
-
Field Detail
-
mConnectionFactory
protected ConnectionFactory mConnectionFactory
-
-
Constructor Detail
-
HttpUserAuthenticator
public HttpUserAuthenticator(java.lang.String endPoint)
Creates a new user authenticator.- Parameters:
endPoint- The endpoint to be called when authenticating.
-
HttpUserAuthenticator
public HttpUserAuthenticator(java.lang.String endPoint, ConnectionFactory connectionFactory)
Creates a new user authenticator.- Parameters:
endPoint- The endpoint to be called when authenticating.connectionFactory- a custom connection factory to be used for building the connection
-
-
Method Detail
-
authenticate
public java.lang.String authenticate(java.lang.String socketId) throws AuthenticationFailureException
Description copied from interface:UserAuthenticatorCalled when a user is to be authenticated.- Specified by:
authenticatein interfaceUserAuthenticator- Parameters:
socketId- A unique socket connection ID to be used with the authentication. This uniquely identifies the connection that on which the user is being authenticated.- Returns:
- A user authentication token.
- Throws:
AuthenticationFailureException- if the authentication fails.
-
authFailureException
protected java.lang.RuntimeException authFailureException(java.lang.String msg)
-
authFailureException
protected java.lang.RuntimeException authFailureException(java.io.IOException e)
-
setHeaders
public void setHeaders(java.util.Map<java.lang.String,java.lang.String> headers)
Set additional headers to be sent as part of the request.- Parameters:
headers- A map of headers
-
isSSL
public java.lang.Boolean isSSL()
Identifies if the HTTP request will be sent over HTTPS.- Returns:
- true if the endpoint protocol is 'https'
-
performAuthRequest
protected java.lang.String performAuthRequest()
Performs an HTTP request to the endpoint provided on construction.The request shall include the headers and parameters provided by the connectionFactory.
Child classes must provide the connection parameters to the connectionFactory before calling this method.
- Returns:
- HTTP request response body
-
-