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 Classes
    Modifier and Type
    Class
    Description
    static class 
    Single connection authentication info.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.glassfish.grizzly.filterchain.NextAction
    handleClose(org.glassfish.grizzly.filterchain.FilterChainContext ctx)
    The method is called, when a connection gets closed.
    org.glassfish.grizzly.filterchain.NextAction
    handleRead(org.glassfish.grizzly.filterchain.FilterChainContext ctx)
    The method is called once we have received MultiLinePacket.
    org.glassfish.grizzly.filterchain.NextAction
    handleWrite(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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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 received MultiLinePacket. 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:
      handleRead in interface org.glassfish.grizzly.filterchain.Filter
      Overrides:
      handleRead in class org.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:
      handleWrite in interface org.glassfish.grizzly.filterchain.Filter
      Overrides:
      handleWrite in class org.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:
      handleClose in interface org.glassfish.grizzly.filterchain.Filter
      Overrides:
      handleClose in class org.glassfish.grizzly.filterchain.BaseFilter
      Parameters:
      ctx - Request processing context
      Returns:
      NextAction
      Throws:
      IOException