2014-05-30 10:31:51 -07:00
package com.foundation.web ;
import java.io.File ;
import javax.net.ssl.SSLContext ;
import com.foundation.web.WebApplication.ISslMapping ;
import com.foundation.web.WebOptions.SslMapping ;
import com.foundation.web.interfaces.ICachedResource ;
2014-07-11 10:41:39 -07:00
import com.foundation.web.interfaces.IConnectionContext ;
2014-05-30 10:31:51 -07:00
import com.foundation.web.interfaces.IContent ;
import com.foundation.web.interfaces.IMimeTypeProvider ;
import com.foundation.web.interfaces.IPassThroughDomain ;
import com.foundation.web.interfaces.IRequest ;
import com.foundation.web.interfaces.IResponse ;
import com.foundation.web.interfaces.ISession ;
import com.foundation.web.interfaces.IWebApplication ;
import com.foundation.web.interfaces.IWebApplicationContainer ;
/ * *
* Allows a domain to be mapped to another service in another process . Currently only useable with SSL .
* A socket will be created to the given address : port when an SSL socket is received with the given domain in the TLS handshake . All data will be sent directly to the receiving process via this extra socket , and the extra socket will be listened to for data that needs to be encrypted and forwarded to the client .
* /
public class PassThroughDomain implements IPassThroughDomain {
/** The name used to map the web application to its self when reloading a webapp bundle. */
private String name = null ;
/** The container for this application. This will be set once the application is added to the server and should no longer be modified. */
private IWebApplicationContainer webApplicationContainer = null ;
/** The domains that this web server accepts. */
private String [ ] domains = null ;
/** The services to listen for connections on. Should only ever include "SSL" currently. */
private String [ ] services = null ;
/** The address that all content will be passed through to. */
private String address = null ;
/** The port that all content will be passed through to. */
private int port = 0 ;
/** The mappings between domains and SSLContext's. */
private ISslMapping [ ] sslMappings = null ;
/ * *
* PassThroughDomain constructor .
* @param name The name of the web application ( unique ) , used by the web server to link resources back to the web application when it is restarted . This should never change between runnings of the web app .
* @param services Currently only " SSL " is accepted .
* @param domains The domains for which this web application is used .
* @param address The address of the remote process receiving the content sent by the client . Can be " localhost " .
* @param port The port of the remote process .
* @param sslMappings The ssl mappings to be used .
* /
public PassThroughDomain ( String name , String [ ] services , String [ ] domains , String address , int port , WebOptions . SslMapping [ ] sslMappings ) {
this . name = name ;
this . domains = domains ;
this . address = address ;
this . port = port ;
this . services = services ;
this . sslMappings = ( ISslMapping [ ] ) sslMappings . clone ( ) ;
} //PassThroughDomain()//
/ * ( non - Javadoc )
* @see com . foundation . web . interfaces . IPassThroughDomain # getAddress ( )
* /
public String getAddress ( ) {
return address ;
} //getAddress()//
/ * ( non - Javadoc )
* @see com . foundation . web . interfaces . IPassThroughDomain # getPort ( )
* /
public int getPort ( ) {
return port ;
} //getPort()//
/ * ( non - Javadoc )
* @see com . foundation . web . interfaces . IWebApplication # getName ( )
* /
public String getName ( ) {
return name ;
} //getName()//
/ * ( non - Javadoc )
* @see com . foundation . web . interfaces . IWebApplication # getCompressResponses ( )
* /
public boolean getCompressResponses ( ) {
return false ;
} //getCompressResponses()//
/ * ( non - Javadoc )
* @see com . foundation . web . interfaces . IWebApplication # getDefaultPackageName ( )
* /
public String getDefaultPackageName ( ) {
return null ;
} //getDefaultPackageName()//
/ * ( non - Javadoc )
* @see com . foundation . web . interfaces . IWebApplication # setCacheCuttoffSize ( long )
* /
public void setCacheCuttoffSize ( long cacheCutoffSize ) {
} //setCacheCuttoffSize()//
/ * ( non - Javadoc )
* @see com . foundation . web . interfaces . IWebApplication # clearCaches ( )
* /
public void clearCaches ( ) {
} //clearCaches()//
/ * ( non - Javadoc )
* @see com . foundation . web . interfaces . IWebApplication # release ( )
* /
public void release ( ) {
} //release()//
/ * ( non - Javadoc )
* @see com . foundation . web . interfaces . IWebApplication # serializeSessions ( )
* /
public File serializeSessions ( ) {
return null ;
} //serializeSessions()//
/ * ( non - Javadoc )
* @see com . foundation . web . interfaces . IWebApplication # deserializeSessions ( java . io . File )
* /
public boolean deserializeSessions ( File sessionFile ) {
return true ;
} //deserializeSessions()//
/ * ( non - Javadoc )
* @see com . foundation . web . interfaces . IWebApplication # getWebApplicationContainer ( )
* /
public IWebApplicationContainer getWebApplicationContainer ( ) {
return webApplicationContainer ;
} //getWebApplicationContainer()//
/ * ( non - Javadoc )
* @see com . foundation . web . interfaces . IWebApplication # completeInitialization ( com . foundation . web . interfaces . IWebApplicationContainer )
* /
public void completeInitialization ( IWebApplicationContainer webApplicationContainer ) {
if ( webApplicationContainer = = null ) {
throw new IllegalArgumentException ( " Must provide a web server reference. " ) ;
} //if//
else if ( this . webApplicationContainer ! = null ) {
throw new IllegalArgumentException ( " Cannot complete the initialization of a web application twice. " ) ;
} //else if//
this . webApplicationContainer = webApplicationContainer ;
} //completeInitialization()//
/ * ( non - Javadoc )
* @see com . foundation . web . server . IWebApplication # getCachedResource ( java . lang . String )
* /
public ICachedResource getCachedResource ( String canonicalPath ) {
return null ;
} //getCachedResource()//
/ * ( non - Javadoc )
* @see com . foundation . web . server . IWebApplication # getMaxCachedResourceSize ( )
* /
public long getMaxCachedResourceSize ( ) {
return 0 ;
} //getMaxCachedResourceSize()//
/ * ( non - Javadoc )
* @see com . foundation . web . server . IWebApplication # getMimeTypeProvider ( )
* /
public IMimeTypeProvider getMimeTypeProvider ( ) {
return null ;
} //getMimeTypeProvider()//
/ * ( non - Javadoc )
* @see com . foundation . web . server . IWebApplication # isCachingResources ( )
* /
public boolean isCachingResources ( ) {
return false ;
} //isCachingResources()//
/ * ( non - Javadoc )
* @see com . foundation . web . server . IWebApplication # setCachedResource ( java . lang . String , java . io . File , byte [ ] )
* /
public void setCachedResource ( String canonicalPath , File file , byte [ ] contents ) {
} //setCachedResource()//
/ * ( non - Javadoc )
* @see com . foundation . web . interfaces . IWebApplication # createSecureSession ( com . foundation . web . interfaces . ISession )
* /
public void createSecureSession ( ISession session ) {
} //createSecureSession()//
/ * ( non - Javadoc )
* @see com . foundation . web . interfaces . IWebApplication # createSession ( )
* /
public ISession createSession ( ) {
return null ;
} //createSession()//
/ * ( non - Javadoc )
* @see com . foundation . web . interfaces . IWebApplication # recreateSession ( java . lang . String )
* /
public ISession recreateSession ( String sessionId ) {
return null ;
} //recreateSession()//
/ * ( non - Javadoc )
* @see com . foundation . web . interfaces . IWebApplication # getSessionData ( com . foundation . web . interfaces . ISession )
* /
public byte [ ] getSessionData ( ISession session ) {
return null ;
} //getSessionData()//
/ * ( non - Javadoc )
* @see com . foundation . web . interfaces . IWebApplication # getMaxMessageSize ( com . foundation . web . interfaces . IRequest , java . lang . Object , java . lang . Object )
* /
public int getMaxMessageSize ( IRequest request , Object sessionData , Object secureSessionData ) {
return 0 ;
} //getMaxMessageSize()//
/ * ( non - Javadoc )
* @see com . foundation . web . server . IWebServerApplication # getBaseDirectory ( )
* /
public File getBaseDirectory ( ) {
return null ;
} //getBaseDirectory()//
/ * ( non - Javadoc )
* @see com . foundation . web . interfaces . IWebApplication # getExternalBaseDirectory ( )
* /
public File getExternalBaseDirectory ( ) {
return null ;
} //getExternalBaseDirectory()//
/ * ( non - Javadoc )
* @see com . foundation . web . interfaces . IWebApplication # getCacheBaseDirectory ( )
* /
public File getCacheBaseDirectory ( ) {
return null ;
} //getCacheBaseDirectory()//
/ * ( non - Javadoc )
* @see com . foundation . web . interfaces . IWebApplication # initiateOpenIdAuth ( java . lang . String )
* /
public String initiateOpenIdAuth ( String userId ) {
return null ;
} //initiateOpenIdAuth()//
/ * ( non - Javadoc )
* @see com . foundation . web . server . IWebServerApplication # getDomains ( )
* /
public String [ ] getDomains ( ) {
return domains ;
} //getDomains()//
/ * ( non - Javadoc )
* @see com . foundation . web . server . IWebApplication # getServices ( )
* /
public String [ ] getServices ( ) {
return services ;
} //getServices()//
/ * ( non - Javadoc )
* @see com . foundation . web . server . IWebApplication # getSslContext ( java . lang . String )
* /
public SSLContext getSslContext ( String domain ) {
SSLContext result = null ;
//Search for the first matching domain. Note that the domain passed may contain sub-domain markings while the ssl mapping may be just the top level domain.//
for ( int index = 0 , size = sslMappings = = null ? 0 : sslMappings . length ; result = = null & & index < size ; index + + ) {
String [ ] domains = sslMappings [ index ] . getDomains ( ) ;
for ( int domainIndex = 0 ; domainIndex < domains . length ; domainIndex + + ) {
//TODO: Support wild cards here!
if ( domain . equals ( domains [ domainIndex ] ) ) {
result = sslMappings [ index ] . getSslContext ( ) ;
} //if//
} //for//
} //for//
return result ;
} //getSslContext()//
/ * ( non - Javadoc )
* @see com . foundation . web . server . IWebServerApplication # getErrorContent ( int )
* /
public IContent getErrorContent ( int errorCode ) {
return null ;
} //getErrorContent()//
/ * ( non - Javadoc )
* @see com . foundation . web . server . IWebServerApplication # getErrorHeader ( int )
* /
public String getErrorHeader ( int errorCode ) {
return null ;
} //getErrorHeader()//
/ * ( non - Javadoc )
* @see com . foundation . web . server . IWebServerApplication # getSession ( java . lang . String )
* /
public ISession getSession ( String sessionId ) {
return null ;
} //getSession()//
/ * ( non - Javadoc )
2014-07-11 10:41:39 -07:00
* @see com . foundation . web . interfaces . IWebApplication # processRequest ( com . foundation . web . interfaces . IRequest , com . foundation . web . interfaces . IResponse , com . foundation . web . interfaces . ISession , boolean , boolean , com . foundation . web . interfaces . IConnectionContext )
2014-05-30 10:31:51 -07:00
* /
2014-07-11 10:41:39 -07:00
public void processRequest ( IRequest request , IResponse response , ISession session , boolean isSecure , boolean clientHadBadSession , IConnectionContext connectionContext ) {
2014-05-30 10:31:51 -07:00
response . setForwardUri ( " https:// " + request . getHost ( ) + request . getUri ( ) + ( request . getParameterString ( ) ! = null ? request . getParameterString ( ) : " " ) ) ;
} //processRequest()//
/ * ( non - Javadoc )
* @see com . foundation . web . interfaces . IWebApplication # retainWholeRequestBuffer ( com . foundation . web . interfaces . IRequest )
* /
public boolean retainWholeRequestBuffer ( IRequest request ) {
return false ;
} //retainWholeRequestBuffer()//
} //PassThroughDomain//