Package jadex
Class ForwardFilter
- java.lang.Object
- 
- jadex.ForwardFilter
 
- 
- All Implemented Interfaces:
- javax.servlet.Filter
 - Direct Known Subclasses:
- WebProxyFilter
 
 public class ForwardFilter extends java.lang.Object implements javax.servlet.FilterThe 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
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classForwardFilter.ForwardInfo
 - 
Field SummaryFields Modifier and Type Field Description static java.lang.StringaddmappingSupported commands.static java.lang.Stringadduserstatic java.lang.Stringauthenticatedprotected booleanauthenticationFlag if authentication is required.static java.util.Set<java.lang.String>commandsstatic java.lang.Stringdisplayinfostatic java.lang.Stringdisplaymappingsstatic java.lang.Stringdisplayusersprotected java.lang.StringfilepathThe file path.static java.lang.Stringgetleasetimeprotected booleanhttpsFlag if https should be enforced.protected java.lang.StringhttpsportThe https port of the server.protected static java.util.Map<java.lang.String,ForwardFilter.ForwardInfo>infosThe mapping infos.protected longleasetimeThe lease time in millis.static java.lang.Stringloginstatic java.lang.Stringlogoutprotected LRU<java.lang.String,java.lang.String>noncesThe emitted nonces.static java.lang.Stringrefreshmappingstatic java.lang.Stringremmappingstatic java.lang.Stringremuserstatic java.lang.Stringsetleasetimeprotected java.util.Map<java.lang.String,java.lang.String>usersThe known users and passwords.
 - 
Constructor SummaryConstructors Constructor Description ForwardFilter()
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddUser(java.lang.String user, java.lang.String pass)protected booleancheckAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.util.List<java.lang.String> mimetypes, java.lang.String username)protected booleancheckDigestAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.util.Collection<java.lang.String> mimetypes)protected booleancheckSecure(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)protected voidcheckUrlParameterAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.util.Collection<java.lang.String> mimetypes)java.lang.StringcreateNonce()java.lang.StringcutUrl(java.lang.String url)voiddestroy()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.voiddoFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)protected ForwardFilter.ForwardInfo[]getForwardInfos()longgetLeasetime()Get the lease time.protected java.util.Map.Entry<java.lang.String,java.lang.String>[]getUsers()static java.lang.Stringhex(byte[] data)Convert to hex value.voidinit(javax.servlet.FilterConfig conf)Init the filter.protected java.lang.StringisAuthenticated(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)protected booleanisBrowserClient(java.util.Collection<java.lang.String> mimetypes)static voidmain(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.StringreadRequestBody(javax.servlet.http.HttpServletRequest request)Returns the request body as string.protected voidreadUsersFromFile()protected voidremoveDueMappings()Remove all mappings with too old timestamps.protected voidremoveUser(java.lang.String user)protected voidsaveUserstoFile()protected voidsendAuthorizationRequest(java.lang.String realm, javax.servlet.http.HttpServletResponse response)protected voidsendDisplayInfo(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)protected voidsendDisplayMappings(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)protected voidsendDisplayUsers(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)protected voidsendForward(ForwardFilter.ForwardInfo fi, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)protected voidsendLoginPage(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String next)voidsetLeaseTime(long leasetime)Set the lease time.voidsetLeaseTime(java.lang.String val)Set the lease time.
 
- 
- 
- 
Field Detail- 
infosprotected static java.util.Map<java.lang.String,ForwardFilter.ForwardInfo> infos The mapping infos.
 - 
addmappingpublic static final java.lang.String addmapping Supported commands.- See Also:
- Constant Field Values
 
 - 
remmappingpublic static final java.lang.String remmapping - See Also:
- Constant Field Values
 
 - 
refreshmappingpublic static final java.lang.String refreshmapping - See Also:
- Constant Field Values
 
 - 
getleasetimepublic static final java.lang.String getleasetime - See Also:
- Constant Field Values
 
 - 
setleasetimepublic static final java.lang.String setleasetime - See Also:
- Constant Field Values
 
 - 
loginpublic static final java.lang.String login - See Also:
- Constant Field Values
 
 - 
logoutpublic static final java.lang.String logout - See Also:
- Constant Field Values
 
 - 
adduserpublic static final java.lang.String adduser - See Also:
- Constant Field Values
 
 - 
remuserpublic static final java.lang.String remuser - See Also:
- Constant Field Values
 
 - 
displayinfopublic static final java.lang.String displayinfo - See Also:
- Constant Field Values
 
 - 
displayuserspublic static final java.lang.String displayusers - See Also:
- Constant Field Values
 
 - 
displaymappingspublic static final java.lang.String displaymappings - See Also:
- Constant Field Values
 
 - 
authenticatedpublic static final java.lang.String authenticated - See Also:
- Constant Field Values
 
 - 
commandspublic static final java.util.Set<java.lang.String> commands 
 - 
authenticationprotected boolean authentication Flag if authentication is required.
 - 
httpsprotected boolean https Flag if https should be enforced.
 - 
httpsportprotected java.lang.String httpsport The https port of the server.
 - 
leasetimeprotected long leasetime The lease time in millis.
 - 
filepathprotected java.lang.String filepath The file path.
 - 
noncesprotected LRU<java.lang.String,java.lang.String> nonces The emitted nonces.
 - 
usersprotected java.util.Map<java.lang.String,java.lang.String> users The known users and passwords.
 
- 
 - 
Method Detail- 
initpublic void init(javax.servlet.FilterConfig conf) throws javax.servlet.ServletExceptionInit the filter.- Specified by:
- initin interface- javax.servlet.Filter
- Throws:
- javax.servlet.ServletException
 
 - 
destroypublic void destroy() Destroy the filter.- Specified by:
- destroyin interface- javax.servlet.Filter
 
 - 
doFilterpublic void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws java.io.IOException, javax.servlet.ServletException- Specified by:
- doFilterin interface- javax.servlet.Filter
- Throws:
- java.io.IOException
- javax.servlet.ServletException
 
 - 
cutUrlpublic java.lang.String cutUrl(java.lang.String url) 
 - 
parseMimetypesprotected java.util.List<java.lang.String> parseMimetypes(javax.servlet.http.HttpServletRequest request) 
 - 
checkSecureprotected boolean checkSecure(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
checkAuthenticationprotected 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
 
 - 
checkDigestAuthenticationprotected 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
 
 - 
checkUrlParameterAuthenticationprotected 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
 
 - 
isAuthenticatedprotected java.lang.String isAuthenticated(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
 - 
removeDueMappingsprotected void removeDueMappings() Remove all mappings with too old timestamps.
 - 
setLeaseTimepublic void setLeaseTime(long leasetime) Set the lease time.- Parameters:
- leasetime- The lease time.
 
 - 
setLeaseTimepublic void setLeaseTime(java.lang.String val) Set the lease time.- Parameters:
- leasetime- The lease time.
 
 - 
getLeasetimepublic long getLeasetime() Get the lease time.- Returns:
- The lease time.
 
 - 
getForwardInfosprotected ForwardFilter.ForwardInfo[] getForwardInfos() 
 - 
getUsersprotected java.util.Map.Entry<java.lang.String,java.lang.String>[] getUsers() 
 - 
sendForwardprotected void sendForward(ForwardFilter.ForwardInfo fi, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) 
 - 
sendDisplayMappingsprotected void sendDisplayMappings(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
 - 
sendLoginPageprotected void sendLoginPage(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String next)
 - 
sendDisplayUsersprotected void sendDisplayUsers(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
 - 
sendDisplayInfoprotected void sendDisplayInfo(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
 - 
sendAuthorizationRequestprotected void sendAuthorizationRequest(java.lang.String realm, javax.servlet.http.HttpServletResponse response) throws java.io.IOException- Throws:
- java.io.IOException
 
 - 
isBrowserClientprotected boolean isBrowserClient(java.util.Collection<java.lang.String> mimetypes) 
 - 
parseHeaderprotected java.util.Map<java.lang.String,java.lang.String> parseHeader(java.lang.String header) Convert header to key value pairs.
 - 
createNoncepublic java.lang.String createNonce() 
 - 
hexpublic static java.lang.String hex(byte[] data) Convert to hex value.
 - 
digestpublic static byte[] digest(java.lang.String input) Build the digest given the timestamp and password.
 - 
digestpublic static byte[] digest(byte[] input) Build the digest given the timestamp and password.
 - 
readRequestBodyprotected java.lang.String readRequestBody(javax.servlet.http.HttpServletRequest request) throws java.io.IOExceptionReturns the request body as string.- Throws:
- java.io.IOException
 
 - 
addUserprotected void addUser(java.lang.String user, java.lang.String pass)
 - 
removeUserprotected void removeUser(java.lang.String user) 
 - 
saveUserstoFileprotected void saveUserstoFile() 
 - 
readUsersFromFileprotected void readUsersFromFile() 
 - 
mainpublic static void main(java.lang.String[] args) Main for testing.
 
- 
 
-