tomcat.addUser(USER_NAME,PASSWORD);
tomcat.addRole(USER_NAME,ROLE_NAME);
// brings logging.properties
tomcat.setBaseDir(docBase);
final SessionManager sessionManager = createSessionManager();
Context context;
try {
context = tomcat.addWebapp(CONTEXT_PATH, docBase + fileSeparator + "webapp");
} catch (ServletException e) {
throw new IllegalStateException(e);
}
context.setManager( sessionManager );
context.setBackgroundProcessorDelay( 1 );
context.setCookies(cookies);
if ( loginType != null ) {
context.addConstraint( createSecurityConstraint( "/*", ROLE_NAME ) );
context.addSecurityRole( ROLE_NAME );
final LoginConfig loginConfig = loginType == LoginType.FORM
? new LoginConfig( "FORM", null, "/login", "/error" )
: new LoginConfig( "BASIC", null, null, null );
context.setLoginConfig( loginConfig );
}
/* we must set the maxInactiveInterval after the context,
* as setContainer(context) uses the session timeout set on the context
*/
sessionManager.getMemcachedSessionService().setMemcachedNodes( memcachedNodes );
sessionManager.getMemcachedSessionService().setFailoverNodes( failoverNodes );
sessionManager.getMemcachedSessionService().setEnabled(enabled);
sessionManager.getMemcachedSessionService().setSticky(sticky);
if(lockingMode != null) {
sessionManager.getMemcachedSessionService().setLockingMode(lockingMode.name());
}
sessionManager.getMemcachedSessionService().setMemcachedProtocol(memcachedProtocol);
sessionManager.getMemcachedSessionService().setUsername(username);
sessionManager.setMaxInactiveInterval( sessionTimeout ); // 1 second
sessionManager.getMemcachedSessionService().setSessionBackupAsync( false );
sessionManager.getMemcachedSessionService().setSessionBackupTimeout( 100 );
sessionManager.setProcessExpiresFrequency( 1 ); // 1 second (factor for context.setBackgroundProcessorDelay)
sessionManager.getMemcachedSessionService().setTranscoderFactoryClass( transcoderFactoryClassName != null ? transcoderFactoryClassName : DEFAULT_TRANSCODER_FACTORY );
sessionManager.getMemcachedSessionService().setRequestUriIgnorePattern(".*\\.(png|gif|jpg|css|js|ico)$");
sessionManager.getMemcachedSessionService().setStorageKeyPrefix(storageKeyPrefix);
return tomcat;
}