Java Code Examples for javax.servlet.ServletContext#getVirtualServerName()

The following examples show how to use javax.servlet.ServletContext#getVirtualServerName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuthenticatorBase.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * 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();
}
 
Example 2
Source File: AuthenticationInitializer.java    From piranha with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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(), "/*");
}
 
Example 3
Source File: InvokerWebApiBinderCreator.java    From hasor with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 4
Source File: CustomServletContextListener.java    From eplmp with Eclipse Public License 1.0 4 votes vote down vote up
public static String getAppContextID(ServletContext context) {
    return context.getVirtualServerName() + " " + context.getContextPath();
}