Package jadex

Class ForwardFilter

  • All Implemented Interfaces:
    javax.servlet.Filter
    Direct Known Subclasses:
    WebProxyFilter

    public class ForwardFilter
    extends java.lang.Object
    implements javax.servlet.Filter
    The forward filter is a kind of web proxy that offers rest methods to adjust its mappings. A mapping expresses a source path and a target address on another web server server. Incoming requests are checked if the begin with one of the paths in the mapping and if yes are forwarded to the corresponding remote server. Answers are directly passed back as result of the web request with one exception. In case the mime type is "text/html" the proxy will inspect the result and replace absolute urls with its own server address. This allows links to work from the remote server. Supported methods are: /(displayInfo) : Display info /displayUsers : Show the current users /displayMappings : Show the current mappings in html /addMapping?name=a&target=b : Add a new mapping /removeMapping?name=a : Remove an existing mapping /refreshMapping?name=a : Update time stamp of mapping /getLeasetime : Get the lease time /setLeasetime?leasetime=a : Set the lease time /login?user=a&pass=b : Login /logout : Logout /addUser?user=a&pass=b : Add a new user /removeUser?user=a&pass=b : Remove an existing user Parameters in filter init: leasetime: [mins], default 5 mins leasetime for refreshs https: true/false default=false must use https? authentication: true/false default=true must service calls be authenticated? adminpass: default="admin" admin password httpsport: default=8443 https port filepath: default=tomcat home directory for storing files
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String addmapping
      Supported commands.
      static java.lang.String adduser  
      static java.lang.String authenticated  
      protected boolean authentication
      Flag if authentication is required.
      static java.util.Set<java.lang.String> commands  
      static java.lang.String displayinfo  
      static java.lang.String displaymappings  
      static java.lang.String displayusers  
      protected java.lang.String filepath
      The file path.
      static java.lang.String getleasetime  
      protected boolean https
      Flag if https should be enforced.
      protected java.lang.String httpsport
      The https port of the server.
      protected static java.util.Map<java.lang.String,​ForwardFilter.ForwardInfo> infos
      The mapping infos.
      protected long leasetime
      The lease time in millis.
      static java.lang.String login  
      static java.lang.String logout  
      protected LRU<java.lang.String,​java.lang.String> nonces
      The emitted nonces.
      static java.lang.String refreshmapping  
      static java.lang.String remmapping  
      static java.lang.String remuser  
      static java.lang.String setleasetime  
      protected java.util.Map<java.lang.String,​java.lang.String> users
      The known users and passwords.
    • Constructor Summary

      Constructors 
      Constructor Description
      ForwardFilter()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addUser​(java.lang.String user, java.lang.String pass)  
      protected boolean checkAuthentication​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.util.List<java.lang.String> mimetypes, java.lang.String username)  
      protected boolean checkDigestAuthentication​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.util.Collection<java.lang.String> mimetypes)  
      protected boolean checkSecure​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)  
      protected void checkUrlParameterAuthentication​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.util.Collection<java.lang.String> mimetypes)  
      java.lang.String createNonce()  
      java.lang.String cutUrl​(java.lang.String url)  
      void destroy()
      Destroy the filter.
      static byte[] digest​(byte[] input)
      Build the digest given the timestamp and password.
      static byte[] digest​(java.lang.String input)
      Build the digest given the timestamp and password.
      void doFilter​(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)  
      protected ForwardFilter.ForwardInfo[] getForwardInfos()  
      long getLeasetime()
      Get the lease time.
      protected java.util.Map.Entry<java.lang.String,​java.lang.String>[] getUsers()  
      static java.lang.String hex​(byte[] data)
      Convert to hex value.
      void init​(javax.servlet.FilterConfig conf)
      Init the filter.
      protected java.lang.String isAuthenticated​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)  
      protected boolean isBrowserClient​(java.util.Collection<java.lang.String> mimetypes)  
      static void main​(java.lang.String[] args)
      Main for testing.
      protected java.util.Map<java.lang.String,​java.lang.String> parseHeader​(java.lang.String header)
      Convert header to key value pairs.
      protected java.util.List<java.lang.String> parseMimetypes​(javax.servlet.http.HttpServletRequest request)  
      protected java.lang.String readRequestBody​(javax.servlet.http.HttpServletRequest request)
      Returns the request body as string.
      protected void readUsersFromFile()  
      protected void removeDueMappings()
      Remove all mappings with too old timestamps.
      protected void removeUser​(java.lang.String user)  
      protected void saveUserstoFile()  
      protected void sendAuthorizationRequest​(java.lang.String realm, javax.servlet.http.HttpServletResponse response)  
      protected void sendDisplayInfo​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)  
      protected void sendDisplayMappings​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)  
      protected void sendDisplayUsers​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)  
      protected void sendForward​(ForwardFilter.ForwardInfo fi, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)  
      protected void sendLoginPage​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String next)  
      void setLeaseTime​(long leasetime)
      Set the lease time.
      void setLeaseTime​(java.lang.String val)
      Set the lease time.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • addmapping

        public static final java.lang.String addmapping
        Supported commands.
        See Also:
        Constant Field Values
      • commands

        public static final java.util.Set<java.lang.String> commands
      • authentication

        protected boolean authentication
        Flag if authentication is required.
      • https

        protected boolean https
        Flag if https should be enforced.
      • httpsport

        protected java.lang.String httpsport
        The https port of the server.
      • leasetime

        protected long leasetime
        The lease time in millis.
      • filepath

        protected java.lang.String filepath
        The file path.
      • nonces

        protected LRU<java.lang.String,​java.lang.String> nonces
        The emitted nonces.
      • users

        protected java.util.Map<java.lang.String,​java.lang.String> users
        The known users and passwords.
    • Constructor Detail

      • ForwardFilter

        public ForwardFilter()
    • Method Detail

      • init

        public void init​(javax.servlet.FilterConfig conf)
                  throws javax.servlet.ServletException
        Init the filter.
        Specified by:
        init in interface javax.servlet.Filter
        Throws:
        javax.servlet.ServletException
      • destroy

        public void destroy()
        Destroy the filter.
        Specified by:
        destroy in interface javax.servlet.Filter
      • doFilter

        public void doFilter​(javax.servlet.ServletRequest request,
                             javax.servlet.ServletResponse response,
                             javax.servlet.FilterChain chain)
                      throws java.io.IOException,
                             javax.servlet.ServletException
        Specified by:
        doFilter in interface javax.servlet.Filter
        Throws:
        java.io.IOException
        javax.servlet.ServletException
      • cutUrl

        public java.lang.String cutUrl​(java.lang.String url)
      • parseMimetypes

        protected java.util.List<java.lang.String> parseMimetypes​(javax.servlet.http.HttpServletRequest request)
      • checkSecure

        protected boolean checkSecure​(javax.servlet.http.HttpServletRequest request,
                                      javax.servlet.http.HttpServletResponse response)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • checkAuthentication

        protected boolean checkAuthentication​(javax.servlet.http.HttpServletRequest request,
                                              javax.servlet.http.HttpServletResponse response,
                                              java.util.List<java.lang.String> mimetypes,
                                              java.lang.String username)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • checkDigestAuthentication

        protected boolean checkDigestAuthentication​(javax.servlet.http.HttpServletRequest request,
                                                    javax.servlet.http.HttpServletResponse response,
                                                    java.util.Collection<java.lang.String> mimetypes)
                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • checkUrlParameterAuthentication

        protected void checkUrlParameterAuthentication​(javax.servlet.http.HttpServletRequest request,
                                                       javax.servlet.http.HttpServletResponse response,
                                                       java.util.Collection<java.lang.String> mimetypes)
                                                throws java.io.IOException
        Throws:
        java.io.IOException
      • isAuthenticated

        protected java.lang.String isAuthenticated​(javax.servlet.http.HttpServletRequest request,
                                                   javax.servlet.http.HttpServletResponse response)
      • removeDueMappings

        protected void removeDueMappings()
        Remove all mappings with too old timestamps.
      • setLeaseTime

        public void setLeaseTime​(long leasetime)
        Set the lease time.
        Parameters:
        leasetime - The lease time.
      • setLeaseTime

        public void setLeaseTime​(java.lang.String val)
        Set the lease time.
        Parameters:
        leasetime - The lease time.
      • getLeasetime

        public long getLeasetime()
        Get the lease time.
        Returns:
        The lease time.
      • getUsers

        protected java.util.Map.Entry<java.lang.String,​java.lang.String>[] getUsers()
      • sendForward

        protected void sendForward​(ForwardFilter.ForwardInfo fi,
                                   javax.servlet.http.HttpServletRequest request,
                                   javax.servlet.http.HttpServletResponse response)
      • sendDisplayMappings

        protected void sendDisplayMappings​(javax.servlet.http.HttpServletRequest request,
                                           javax.servlet.http.HttpServletResponse response)
      • sendLoginPage

        protected void sendLoginPage​(javax.servlet.http.HttpServletRequest request,
                                     javax.servlet.http.HttpServletResponse response,
                                     java.lang.String next)
      • sendDisplayUsers

        protected void sendDisplayUsers​(javax.servlet.http.HttpServletRequest request,
                                        javax.servlet.http.HttpServletResponse response)
      • sendDisplayInfo

        protected void sendDisplayInfo​(javax.servlet.http.HttpServletRequest request,
                                       javax.servlet.http.HttpServletResponse response)
      • sendAuthorizationRequest

        protected void sendAuthorizationRequest​(java.lang.String realm,
                                                javax.servlet.http.HttpServletResponse response)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • isBrowserClient

        protected boolean isBrowserClient​(java.util.Collection<java.lang.String> mimetypes)
      • parseHeader

        protected java.util.Map<java.lang.String,​java.lang.String> parseHeader​(java.lang.String header)
        Convert header to key value pairs.
      • createNonce

        public java.lang.String createNonce()
      • hex

        public static java.lang.String hex​(byte[] data)
        Convert to hex value.
      • digest

        public static byte[] digest​(java.lang.String input)
        Build the digest given the timestamp and password.
      • digest

        public static byte[] digest​(byte[] input)
        Build the digest given the timestamp and password.
      • readRequestBody

        protected java.lang.String readRequestBody​(javax.servlet.http.HttpServletRequest request)
                                            throws java.io.IOException
        Returns the request body as string.
        Throws:
        java.io.IOException
      • addUser

        protected void addUser​(java.lang.String user,
                               java.lang.String pass)
      • removeUser

        protected void removeUser​(java.lang.String user)
      • saveUserstoFile

        protected void saveUserstoFile()
      • readUsersFromFile

        protected void readUsersFromFile()
      • main

        public static void main​(java.lang.String[] args)
        Main for testing.