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 Summary
Nested Classes Modifier and Type Class Description static classForwardFilter.ForwardInfo
-
Field Summary
Fields 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 Summary
Constructors Constructor Description ForwardFilter()
-
Method Summary
All 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
-
infos
protected static java.util.Map<java.lang.String,ForwardFilter.ForwardInfo> infos
The mapping infos.
-
addmapping
public static final java.lang.String addmapping
Supported commands.- See Also:
- Constant Field Values
-
remmapping
public static final java.lang.String remmapping
- See Also:
- Constant Field Values
-
refreshmapping
public static final java.lang.String refreshmapping
- See Also:
- Constant Field Values
-
getleasetime
public static final java.lang.String getleasetime
- See Also:
- Constant Field Values
-
setleasetime
public static final java.lang.String setleasetime
- See Also:
- Constant Field Values
-
login
public static final java.lang.String login
- See Also:
- Constant Field Values
-
logout
public static final java.lang.String logout
- See Also:
- Constant Field Values
-
adduser
public static final java.lang.String adduser
- See Also:
- Constant Field Values
-
remuser
public static final java.lang.String remuser
- See Also:
- Constant Field Values
-
displayinfo
public static final java.lang.String displayinfo
- See Also:
- Constant Field Values
-
displayusers
public static final java.lang.String displayusers
- See Also:
- Constant Field Values
-
displaymappings
public static final java.lang.String displaymappings
- See Also:
- Constant Field Values
-
authenticated
public static final java.lang.String authenticated
- 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.
-
-
Method Detail
-
init
public void init(javax.servlet.FilterConfig conf) throws javax.servlet.ServletExceptionInit the filter.- Specified by:
initin interfacejavax.servlet.Filter- Throws:
javax.servlet.ServletException
-
destroy
public void destroy()
Destroy the filter.- Specified by:
destroyin interfacejavax.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:
doFilterin interfacejavax.servlet.Filter- Throws:
java.io.IOExceptionjavax.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.
-
getForwardInfos
protected ForwardFilter.ForwardInfo[] getForwardInfos()
-
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.IOExceptionReturns 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.
-
-