Class ServerAuthFilter
java.lang.Object
org.glassfish.grizzly.filterchain.BaseFilter
org.glassfish.grizzly.samples.simpleauth.ServerAuthFilter
- All Implemented Interfaces:
org.glassfish.grizzly.filterchain.Filter
public class ServerAuthFilter
extends org.glassfish.grizzly.filterchain.BaseFilter
Server authentication filter, which intercepts client<->server communication.
Filter checks, if coming message is authentication request, sent by client.
If yes - the filter generated client id and sends the authentication reponse
to a client. If incoming message is not authentication request - filter
checks whether client connection has been authenticated. If yes - filter
removes client authentication header ("auth-id: <connection-id>") from
a message and pass control to a next filter in a chain, otherwise -
throws an Exception.
- Author:
- Alexey Stashok
-
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 receivedMultiLinePacketfrom a client.org.glassfish.grizzly.filterchain.NextActionhandleWrite(org.glassfish.grizzly.filterchain.FilterChainContext ctx) The method is called each time, when server sends a message to a client.Methods inherited from class org.glassfish.grizzly.filterchain.BaseFilter
createContext, exceptionOccurred, handleAccept, handleConnect, handleEvent, onAdded, onFilterChainChanged, onRemoved, toString
-
Constructor Details
-
ServerAuthFilter
public ServerAuthFilter()
-
-
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 receivedMultiLinePacketfrom a client. Filter check if incoming message is the client authentication request. If yes - we generate new client id and send it back in the authentication response. If the message is not authentication request - we check message authentication header to correspond to a connection id in the authenticated clients map. If it's ok - the filter removes authentication header from the message and pass the message to a next filter in a filter chain, otherwise, if authentication failed - the filter throws 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 server sends a message to a client. First of all filter check if this packet is not authentication-response. If yes - filter just passes control to a next filter in a chain, if not - filter gets the client id from its local authenticated clients map and adds "auth-id: <connection-id>" header to the outgoing message and finally passes control to a next filter in a chain.- 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
-