io.undertow.servlet.api.ServletSessionConfig Java Examples

The following examples show how to use io.undertow.servlet.api.ServletSessionConfig. 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: DeploymentManagerImpl.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
public void handleDeploymentSessionConfig(DeploymentInfo deploymentInfo, ServletContextImpl servletContext) {
    SessionCookieConfigImpl sessionCookieConfig = servletContext.getSessionCookieConfig();
    ServletSessionConfig sc = deploymentInfo.getServletSessionConfig();
    if (sc != null) {
        sessionCookieConfig.setName(sc.getName());
        sessionCookieConfig.setComment(sc.getComment());
        sessionCookieConfig.setDomain(sc.getDomain());
        sessionCookieConfig.setHttpOnly(sc.isHttpOnly());
        sessionCookieConfig.setMaxAge(sc.getMaxAge());
        if(sc.getPath() != null) {
            sessionCookieConfig.setPath(sc.getPath());
        } else {
            sessionCookieConfig.setPath(deploymentInfo.getContextPath());
        }
        sessionCookieConfig.setSecure(sc.isSecure());
        if (sc.getSessionTrackingModes() != null) {
            servletContext.setDefaultSessionTrackingModes(new HashSet<>(sc.getSessionTrackingModes()));
        }
    }
}
 
Example #2
Source File: DeploymentManagerImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void handleDeploymentSessionConfig(DeploymentInfo deploymentInfo, ServletContextImpl servletContext) {
    SessionCookieConfigImpl sessionCookieConfig = servletContext.getSessionCookieConfig();
    ServletSessionConfig sc = deploymentInfo.getServletSessionConfig();
    if (sc != null) {
        sessionCookieConfig.setName(sc.getName());
        sessionCookieConfig.setComment(sc.getComment());
        sessionCookieConfig.setDomain(sc.getDomain());
        sessionCookieConfig.setHttpOnly(sc.isHttpOnly());
        sessionCookieConfig.setMaxAge(sc.getMaxAge());
        if(sc.getPath() != null) {
            sessionCookieConfig.setPath(sc.getPath());
        } else {
            sessionCookieConfig.setPath(deploymentInfo.getContextPath());
        }
        sessionCookieConfig.setSecure(sc.isSecure());
        if (sc.getSessionTrackingModes() != null) {
            servletContext.setDefaultSessionTrackingModes(new HashSet<>(sc.getSessionTrackingModes()));
        }
    }
}
 
Example #3
Source File: ServletURLRewritingSessionTestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() {
    DeploymentUtils.setupServlet(new ServletExtension() {
        @Override
        public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) {
            deploymentInfo.setServletSessionConfig(new ServletSessionConfig().setSessionTrackingModes(Collections.singleton(SessionTrackingMode.URL)));
        }
    }, Servlets.servlet(URLRewritingServlet.class).addMapping("/foo"));
}
 
Example #4
Source File: CrossContextServletSessionTestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
private static void createDeployment(final String name, final ServletContainer container,  final PathHandler path) throws ServletException {

        ServletInfo s = new ServletInfo("servlet", SessionServlet.class)
                .addMapping("/servlet");
        ServletInfo forward = new ServletInfo("forward", ForwardServlet.class)
                .addMapping("/forward");
        ServletInfo include = new ServletInfo("include", IncludeServlet.class)
                .addMapping("/include");

        ServletInfo includeAdd = new ServletInfo("includeadd", IncludeAddServlet.class)
                .addMapping("/includeadd");
        ServletInfo forwardAdd = new ServletInfo("forwardadd", ForwardAddServlet.class)
                .addMapping("/forwardadd");

        ServletInfo accessTimeServlet = new ServletInfo("accesstimeservlet", LastAccessTimeSessionServlet.class)
                .addMapping("/accesstimeservlet");

        DeploymentInfo builder = new DeploymentInfo()
                .setClassLoader(SimpleServletTestCase.class.getClassLoader())
                .setContextPath("/" + name)
                .setClassIntrospecter(TestClassIntrospector.INSTANCE)
                .setDeploymentName( name + ".war")
                .setServletSessionConfig(new ServletSessionConfig().setPath("/"))
                .addServlets(s, forward, include, forwardAdd, includeAdd, accessTimeServlet);

        DeploymentManager manager = container.addDeployment(builder);
        manager.deploy();
        path.addPrefixPath(builder.getContextPath(), manager.start());
    }
 
Example #5
Source File: ServletFormAuthURLRewriteTestCase.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {

    final PathHandler path = new PathHandler();

    final ServletContainer container = ServletContainer.Factory.newInstance();

    ServletInfo s = new ServletInfo("servlet", SendUsernameServlet.class)
            .setServletSecurityInfo(new ServletSecurityInfo()
                    .addRoleAllowed("role1"))
            .addMapping("/secured/*");

    ServletInfo echo = new ServletInfo("echo", EchoServlet.class)
            .setServletSecurityInfo(new ServletSecurityInfo()
                    .addRoleAllowed("role1"))
            .addMapping("/secured/echo");

    ServletInfo echoParam = new ServletInfo("echoParam", RequestParamEchoServlet.class)
            .setServletSecurityInfo(new ServletSecurityInfo()
                    .addRoleAllowed("role1"))
            .addMapping("/secured/echoParam");

    ServletInfo s1 = new ServletInfo("loginPage", FormLoginServlet.class)
            .setServletSecurityInfo(new ServletSecurityInfo()
                    .addRoleAllowed("group1"))
            .addMapping("/FormLoginServlet");


    ServletIdentityManager identityManager = new ServletIdentityManager();
    identityManager.addUser("user1", "password1", "role1");

    DeploymentInfo builder = new DeploymentInfo()
            .setServletSessionConfig(new ServletSessionConfig().setSessionTrackingModes(Collections.singleton(SessionTrackingMode.URL)))
            .setClassLoader(SimpleServletTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .setAuthenticationMode(AuthenticationMode.CONSTRAINT_DRIVEN)
            .setIdentityManager(identityManager)
            .setLoginConfig(new LoginConfig("FORM", "Test Realm", "/FormLoginServlet", "/error.html"))
            .addServlets(s, s1, echo,echoParam);

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    path.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(path);
}
 
Example #6
Source File: ServletSessionPersistenceTestCase.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
@Test
public void testSimpleSessionUsage() throws IOException, ServletException {
    final PathHandler pathHandler = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(SimpleServletTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .setSessionPersistenceManager(new InMemorySessionPersistence())
            .setServletSessionConfig(new ServletSessionConfig().setPath("/servletContext/aa"))
            .addServlets(new ServletInfo("servlet", SessionServlet.class)
                    .addMapping("/aa/b"));
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    try {
        pathHandler.addPrefixPath(builder.getContextPath(), manager.start());
    } catch (ServletException e) {
        throw new RuntimeException(e);
    }
    DefaultServer.setRootHandler(pathHandler);
    TestHttpClient client = new TestHttpClient();
    try {
        HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/aa/b");
        HttpResponse result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        String response = HttpClientUtils.readResponse(result);
        Assert.assertEquals("1", response);

        String cookieValue = result.getHeaders("Set-Cookie")[0].getValue();
        Assert.assertTrue(cookieValue, cookieValue.contains("JSESSIONID"));
        Assert.assertTrue(cookieValue, cookieValue.contains("/servletContext/aa"));

        result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        response = HttpClientUtils.readResponse(result);
        Assert.assertEquals("2", response);

        manager.stop();
        manager.undeploy();
        manager.deploy();
        pathHandler.addPrefixPath(builder.getContextPath(), manager.start());

        result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        response = HttpClientUtils.readResponse(result);
        Assert.assertEquals("3", response);


    } finally {
        client.getConnectionManager().shutdown();
    }
}