Class XSRFToken

java.lang.Object
services.moleculer.service.MoleculerComponent
services.moleculer.service.Service
services.moleculer.web.middleware.HttpMiddleware
services.moleculer.web.middleware.XSRFToken
All Implemented Interfaces:
services.moleculer.service.MoleculerLifecycle, HttpConstants

public class XSRFToken extends HttpMiddleware implements HttpConstants
This middleware adds "X-XSRF-TOKEN" header to responses. Sample:
restRoute.use(new XSRFToken());
  • Field Details

    • logger

      protected static final org.slf4j.Logger logger
    • headerName

      protected String headerName
      Name of the HTTP-header.
    • cookieName

      protected String cookieName
      Name of the HTTP-cookie.
    • secret

      protected String secret
      Secret.
    • path

      protected String path
      Cookie path.
    • maxAge

      protected long maxAge
      Cookie / token timeout in SECONDS.
    • enableCookie

      protected boolean enableCookie
      Enable XSRF-TOKEN cookie.
    • tokenHandlers

      protected ThreadLocal<XSRFToken.TokenHandler> tokenHandlers
  • Constructor Details

    • XSRFToken

      public XSRFToken()
    • XSRFToken

      public XSRFToken(long maxAge)
  • Method Details

    • getThreadHandler

    • install

      public RequestProcessor install(RequestProcessor next, io.datatree.Tree config)
      Specified by:
      install in class HttpMiddleware
    • getCookieName

      public String getCookieName()
      Returns:
      the cookieName
    • setCookieName

      public void setCookieName(String cookieName)
      Parameters:
      cookieName - the cookieName to set
    • getPath

      public String getPath()
      Returns:
      the path
    • setPath

      public void setPath(String path)
      Parameters:
      path - the path to set
    • getMaxAge

      public long getMaxAge()
      Returns:
      the maxAge
    • setMaxAge

      public void setMaxAge(long maxAge)
      Parameters:
      maxAge - the maxAge to set
    • getHeaderName

      public String getHeaderName()
      Returns:
      the headerName
    • setHeaderName

      public void setHeaderName(String headerName)
      Parameters:
      headerName - the headerName to set
    • getSecret

      public String getSecret()
      Returns:
      the secret
    • setSecret

      public void setSecret(String secret)
      Parameters:
      secret - the secret to set
    • isEnableCookie

      public boolean isEnableCookie()
      Returns:
      the enableCookie
    • setEnableCookie

      public void setEnableCookie(boolean enableCookie)
      Parameters:
      enableCookie - the enableCookie to set