下面列出了javax.servlet.ServletContext#getVirtualServerName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Start this component and implement the requirements of
* {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
*
* @exception LifecycleException
* if this component detects a fatal error that prevents this
* component from being used
*/
@Override
protected synchronized void startInternal() throws LifecycleException {
ServletContext servletContext = context.getServletContext();
jaspicAppContextID = servletContext.getVirtualServerName() + " " +
servletContext.getContextPath();
// Look up the SingleSignOn implementation in our request processing
// path, if there is one
Container parent = context.getParent();
while ((sso == null) && (parent != null)) {
Valve valves[] = parent.getPipeline().getValves();
for (int i = 0; i < valves.length; i++) {
if (valves[i] instanceof SingleSignOn) {
sso = (SingleSignOn) valves[i];
break;
}
}
if (sso == null) {
parent = parent.getParent();
}
}
if (log.isDebugEnabled()) {
if (sso != null) {
log.debug("Found SingleSignOn Valve at " + sso);
} else {
log.debug("No SingleSignOn Valve is present");
}
}
sessionIdGenerator = new StandardSessionIdGenerator();
sessionIdGenerator.setSecureRandomAlgorithm(getSecureRandomAlgorithm());
sessionIdGenerator.setSecureRandomClass(getSecureRandomClass());
sessionIdGenerator.setSecureRandomProvider(getSecureRandomProvider());
super.startInternal();
}
/**
* Initialize Eleos
*
* @param classes the classes.
* @param servletContext the Servlet context.
* @throws ServletException when a Servlet error occurs.
*/
@Override
public void onStartup(Set<Class<?>> classes, ServletContext servletContext) throws ServletException {
// Gets the authentication module class that was configured externally
Class<?> authModuleClass = (Class<?>) servletContext.getAttribute(AUTH_MODULE_CLASS);
if (authModuleClass == null) {
authModuleClass = DoNothingServerAuthModule.class;
}
String appContextId = servletContext.getVirtualServerName() + " " + servletContext.getContextPath();
// This sets the authentication factory to the default factory. This factory stores and retrieves
// the authentication artifacts.
Security.setProperty(DEFAULT_FACTORY_SECURITY_PROPERTY, DefaultConfigFactory.class.getName());
// Defines the modules that we have available. Here it's only a single fixed module.
ConfigParser configParser = new DefaultConfigParser(authModuleClass);
// Indicates the module we want to use
Map<String, Object> options = new HashMap<>();
options.put("authModuleId", authModuleClass.getSimpleName());
// This authentication service installs an authentication config provider in the default factory, which
// is the one we setup above. This authentication config provider uses the passed-in configParser to
// retrieve configuration for authentication modules from.
DefaultAuthenticationService authenticationService = new DefaultAuthenticationService(appContextId, options, configParser, null);
servletContext.setAttribute(AUTH_SERVICE, authenticationService);
servletContext.addFilter(AuthenticationFilter.class.getSimpleName(), AuthenticationFilter.class);
// TMP - should use Dynamic
((WebApplication) servletContext).addFilterMapping(AuthenticationFilter.class.getSimpleName(), "/*");
}
public static WebApiBinder newBinder(ApiBinder apiBinder) throws IOException {
Environment environment = apiBinder.getEnvironment();
Object context = environment.getContext();
if (!(context instanceof ServletContext)) {
return null;
}
ServletContext servletContext = (ServletContext) context;
//
// .MimeType
MimeTypeSupplier mimeTypeContext = new MimeTypeSupplier(servletContext);
mimeTypeContext.loadResource("/META-INF/mime.types.xml");
mimeTypeContext.loadResource("mime.types.xml");
apiBinder.bindType(MimeType.class, mimeTypeContext);
//
//.ServletVersion
ServletVersion curVersion = ServletVersion.V2_3;
try {
environment.getClassLoader().loadClass("javax.servlet.ServletRequestListener");
curVersion = ServletVersion.V2_4;
servletContext.getContextPath();
curVersion = ServletVersion.V2_5;
servletContext.getEffectiveMajorVersion();
curVersion = ServletVersion.V3_0;
servletContext.getVirtualServerName();
curVersion = ServletVersion.V3_1;
} catch (Throwable e) { /* 忽略 */ }
//
// .Binder
apiBinder.bindType(ServletContext.class).toInstance(servletContext);
apiBinder.bindType(ServletVersion.class).toInstance(curVersion);
//
return new InvokerWebApiBinder(curVersion, mimeTypeContext, apiBinder);
}
public static String getAppContextID(ServletContext context) {
return context.getVirtualServerName() + " " + context.getContextPath();
}