Class ClientAuthFilter
java.lang.Object
org.glassfish.grizzly.filterchain.BaseFilter
org.glassfish.grizzly.samples.simpleauth.ClientAuthFilter
- All Implemented Interfaces:
org.glassfish.grizzly.filterchain.Filter
public class ClientAuthFilter
extends org.glassfish.grizzly.filterchain.BaseFilter
Client authentication filter, which intercepts client<->server communication,
and checks whether client connection has been authenticated. If not - filter
suspends current message write and initialize authentication. Once authentication
is done - filter resumes all the suspended writes. If connection is authenticated -
filter adds "auth-id: <connection-id>" header to the outgoing message.
- Author:
- Alexey Stashok
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSingle connection authentication info. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.glassfish.grizzly.filterchain.NextActionhandleClose(org.glassfish.grizzly.filterchain.FilterChainContext ctx) The method is called, when a connection gets closed.org.glassfish.grizzly.filterchain.NextActionhandleRead(org.glassfish.grizzly.filterchain.FilterChainContext ctx) The method is called once we have receivedMultiLinePacket.org.glassfish.grizzly.filterchain.NextActionhandleWrite(org.glassfish.grizzly.filterchain.FilterChainContext ctx) The method is called each time, when client sends a message to a server.Methods inherited from class org.glassfish.grizzly.filterchain.BaseFilter
createContext, exceptionOccurred, handleAccept, handleConnect, handleEvent, onAdded, onFilterChainChanged, onRemoved, toString
-
Constructor Details
-
ClientAuthFilter
public ClientAuthFilter()
-
-
Method Details
-
handleRead
public org.glassfish.grizzly.filterchain.NextAction handleRead(org.glassfish.grizzly.filterchain.FilterChainContext ctx) throws IOException The method is called once we have receivedMultiLinePacket. Filter check if incoming message is the server authentication response. If yes - we suppose client authentication is completed, store client id (assigned by the server), and resume all the pending writes. If client was authenticated before - we check the "auth-id: <connection-id>" header to be equal to the client id, stored on client. If it's ok - we pass control to a next filter, if not - throw an Exception.- Specified by:
handleReadin interfaceorg.glassfish.grizzly.filterchain.Filter- Overrides:
handleReadin classorg.glassfish.grizzly.filterchain.BaseFilter- Parameters:
ctx- Request processing context- Returns:
NextAction- Throws:
IOException
-
handleWrite
public org.glassfish.grizzly.filterchain.NextAction handleWrite(org.glassfish.grizzly.filterchain.FilterChainContext ctx) throws IOException The method is called each time, when client sends a message to a server. First of all filter check if this connection has been authenticated. If yes - add "auth-id: <connection-id>" header to a message and pass it to a next filter in a chain. If appears, that client wasn't authenticated yet - filter initialize authentication (only once for the very first message), suspends current write and adds suspended context to a queue to resume it, once authentication will be completed.- Specified by:
handleWritein interfaceorg.glassfish.grizzly.filterchain.Filter- Overrides:
handleWritein classorg.glassfish.grizzly.filterchain.BaseFilter- Parameters:
ctx- Response processing context- Returns:
NextAction- Throws:
IOException
-
handleClose
public org.glassfish.grizzly.filterchain.NextAction handleClose(org.glassfish.grizzly.filterchain.FilterChainContext ctx) throws IOException The method is called, when a connection gets closed. We remove connection entry in authenticated connections map.- Specified by:
handleClosein interfaceorg.glassfish.grizzly.filterchain.Filter- Overrides:
handleClosein classorg.glassfish.grizzly.filterchain.BaseFilter- Parameters:
ctx- Request processing context- Returns:
NextAction- Throws:
IOException
-