11.4. Login Form With Extract Filter & Cookie Filter

For applications that return the login page when the user tries to access a page without a valid session. This template shows how to use the ExtractFilter to find the login page on the response and use the CookieFilter to ensure the cookies from the application are replayed on each request. The sample application in this template is OpenAM. If you change the TARGETIP:PORT to be the IP address of OpenAM, the TARGETDN:PORT to be the fully qualified name and port of OpenAM and modify USERNAME and PASSWORD in the LoginRequest you automatically log USERNAME into OpenAM.

[Note] Note

Without the CookieFilter in the OutgoingChain the cookie set in the login page response would not get set in the browser since that request is intercepted before it gets to the browser. The simplest way to deal with this situation is to let OpenIG manage all the cookies by enabling the CookieFilter. The side effect of OpenIG managing cookies is none of the cookies are sent to the browser, but are managed locally by OpenIG.

{
  "heap": {
    "objects": [
    {
        "name": "HandlerServlet",
        "comment": "Entry point that transforms Servlet request to handler request.",
        "type": "HandlerServlet",
        "config": {
            "handler": "FindLoginPageChain",
            "baseURI":"http://TARGETIP:PORT"
        }
    },
    {
        "name": "FindLoginPageChain",
        "type": "Chain",
        "config": {
            "filters": ["IsLoginPage","FindLoginPage"],
            "handler": "OutgoingChain" 
        }   
    },
    {
        "name": "FindLoginPage",
        "type": "EntityExtractFilter",
        "config": {
            "messageType": "response",
            "target": "${exchange.isLoginPage}",
            "bindings": [
                 {
                     "key": "found",
                     "pattern": "OpenAM\s\(Login\)",
                     "template": "true"
                 }
             ]
          }
    },
    {
        "name": "IsLoginPage",
        "type": "SwitchFilter",
        "config": {
            "onResponse": [
                 {
                    "condition": "${exchange.isLoginPage.found == 'true'}",
                     "handler": "LoginChain"
                 }
             ]
          }
    },
    {
        "name": "LoginChain",
        "type": "Chain",
        "config": {
            "filters": ["LoginRequest"],
            "handler": "OutgoingChain"
        }
    },
    {   
        "name": "LoginRequest",
        "type": "StaticRequestFilter",
        "config": {
            "method": "POST",
            "uri": "http://TARGETIP:PORT/openam/UI/Login"
            "form": {
                "IDToken0":[""]
                "IDToken1":["USERNAME"]
                "IDToken2":["PASSWORD"]
                "IDButton":["Log+In"]
                "encoded":["false"]
            },   
            "headers": {
                "host":["TARGETFQDN:PORT"]
            }   
            
        }   
    },
   {
        "name": "OutgoingChain",
        "type": "Chain",
        "config": {
            "filters": ["CookieFilter","CaptureFilter"],
            "handler": "ClientHandler" 
        }   
    },
            {
                "name": "CookieFilter",
                "type": "CookieFilter",
                "config": {
                }
         },

    {   
        "name": "CaptureFilter",
        "type": "CaptureFilter",
        "config": {
            "captureEntity": true,
            "file": "/tmp/gateway.log",
        }       
    },
    {
    "name": "LogSink",
    "comment": "Default sink for logging information.",
    "type": "ConsoleLogSink",
    "config": {
        "level": "DEBUG",
    }
}
    {
        "name": "ClientHandler",
        "comment": "Responsible for sending all requests to remote servers.",
        "type": "ClientHandler",
        "config": {
            }
        }
    ]
  },
  "servletObject": "HandlerServlet",
}