Package com.pusher.client.util
Class HttpChannelAuthorizer
- java.lang.Object
-
- com.pusher.client.util.HttpChannelAuthorizer
-
- All Implemented Interfaces:
ChannelAuthorizer
- Direct Known Subclasses:
HttpAuthorizer
public class HttpChannelAuthorizer extends java.lang.Object implements ChannelAuthorizer
Used to authorize aprivateorpresencechannel subscription.Makes an HTTP request to a defined HTTP endpoint. Expects a channel authorization token to be returned.
For more information see the Authorizing Users documentation.
-
-
Field Summary
Fields Modifier and Type Field Description protected ConnectionFactorymConnectionFactory
-
Constructor Summary
Constructors Constructor Description HttpChannelAuthorizer(java.lang.String endPoint)Creates a new channel authorizer.HttpChannelAuthorizer(java.lang.String endPoint, ConnectionFactory connectionFactory)Creates a new channel authorizer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.RuntimeExceptionauthFailureException(java.io.IOException e)protected java.lang.RuntimeExceptionauthFailureException(java.lang.String msg)java.lang.Stringauthorize(java.lang.String channelName, java.lang.String socketId)Called when a channel subscription is to be authorized.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
-
HttpChannelAuthorizer
public HttpChannelAuthorizer(java.lang.String endPoint)
Creates a new channel authorizer.- Parameters:
endPoint- The endpoint to be called when authorizing.
-
HttpChannelAuthorizer
public HttpChannelAuthorizer(java.lang.String endPoint, ConnectionFactory connectionFactory)
Creates a new channel authorizer.- Parameters:
endPoint- The endpoint to be called when authorizing.connectionFactory- a custom connection factory to be used for building the connection
-
-
Method Detail
-
authorize
public java.lang.String authorize(java.lang.String channelName, java.lang.String socketId) throws AuthorizationFailureException
Description copied from interface:ChannelAuthorizerCalled when a channel subscription is to be authorized.- Specified by:
authorizein interfaceChannelAuthorizer- Parameters:
channelName- The name of the channel to be authorized.socketId- A unique socket connection ID to be used with the authorization. This uniquely identifies the connection that the subscription is being authorized for.- Returns:
- A channel authorization token.
- Throws:
AuthorizationFailureException- if the authorization 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
-
-