use of org.eclipse.jetty.server.session.SessionHandler in project dropwizard by dropwizard.
the class ServletEnvironmentTest method setsSessionHandlers.
@Test
public void setsSessionHandlers() throws Exception {
final SessionHandler sessionHandler = mock(SessionHandler.class);
environment.setSessionHandler(sessionHandler);
verify(handler).setSessionHandler(sessionHandler);
verify(handler).setSessionsEnabled(true);
}
use of org.eclipse.jetty.server.session.SessionHandler in project jetty.project by eclipse.
the class AliasedConstraintTest method startServer.
@BeforeClass
public static void startServer() throws Exception {
server = new Server();
connector = new LocalConnector(server);
server.setConnectors(new Connector[] { connector });
ContextHandler context = new ContextHandler();
SessionHandler session = new SessionHandler();
TestLoginService loginService = new TestLoginService(TEST_REALM);
loginService.putUser("user0", new Password("password"), new String[] {});
loginService.putUser("user", new Password("password"), new String[] { "user" });
loginService.putUser("user2", new Password("password"), new String[] { "user" });
loginService.putUser("admin", new Password("password"), new String[] { "user", "administrator" });
loginService.putUser("user3", new Password("password"), new String[] { "foo" });
context.setContextPath("/ctx");
context.setResourceBase(MavenTestingUtils.getTestResourceDir("docroot").getAbsolutePath());
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { context, new DefaultHandler() });
server.setHandler(handlers);
context.setHandler(session);
// context.addAliasCheck(new AllowSymLinkAliasChecker());
server.addBean(loginService);
security = new ConstraintSecurityHandler();
session.setHandler(security);
ResourceHandler handler = new ResourceHandler();
security.setHandler(handler);
List<ConstraintMapping> constraints = new ArrayList<>();
Constraint constraint0 = new Constraint();
constraint0.setAuthenticate(true);
constraint0.setName("forbid");
ConstraintMapping mapping0 = new ConstraintMapping();
mapping0.setPathSpec("/forbid/*");
mapping0.setConstraint(constraint0);
constraints.add(mapping0);
Set<String> knownRoles = new HashSet<>();
knownRoles.add("user");
knownRoles.add("administrator");
security.setConstraintMappings(constraints, knownRoles);
server.start();
}
use of org.eclipse.jetty.server.session.SessionHandler in project jetty.project by eclipse.
the class Response method reset.
public void reset(boolean preserveCookies) {
resetForForward();
_status = 200;
_reason = null;
_contentLength = -1;
List<HttpField> cookies = preserveCookies ? _fields.stream().filter(f -> f.getHeader() == HttpHeader.SET_COOKIE).collect(Collectors.toList()) : null;
_fields.clear();
String connection = _channel.getRequest().getHeader(HttpHeader.CONNECTION.asString());
if (connection != null) {
for (String value : StringUtil.csvSplit(null, connection, 0, connection.length())) {
HttpHeaderValue cb = HttpHeaderValue.CACHE.get(value);
if (cb != null) {
switch(cb) {
case CLOSE:
_fields.put(HttpHeader.CONNECTION, HttpHeaderValue.CLOSE.toString());
break;
case KEEP_ALIVE:
if (HttpVersion.HTTP_1_0.is(_channel.getRequest().getProtocol()))
_fields.put(HttpHeader.CONNECTION, HttpHeaderValue.KEEP_ALIVE.toString());
break;
case TE:
_fields.put(HttpHeader.CONNECTION, HttpHeaderValue.TE.toString());
break;
default:
}
}
}
}
if (preserveCookies)
cookies.forEach(f -> _fields.add(f));
else {
Request request = getHttpChannel().getRequest();
HttpSession session = request.getSession(false);
if (session != null && session.isNew()) {
SessionHandler sh = request.getSessionHandler();
if (sh != null) {
HttpCookie c = sh.getSessionCookie(session, request.getContextPath(), request.isSecure());
if (c != null)
addCookie(c);
}
}
}
}
use of org.eclipse.jetty.server.session.SessionHandler in project jetty.project by eclipse.
the class DataConstraintsTest method startServer.
@Before
public void startServer() {
_server = new Server();
HttpConnectionFactory http = new HttpConnectionFactory();
http.getHttpConfiguration().setSecurePort(9999);
http.getHttpConfiguration().setSecureScheme("BWTP");
_connector = new LocalConnector(_server, http);
_connector.setIdleTimeout(300000);
HttpConnectionFactory https = new HttpConnectionFactory();
https.getHttpConfiguration().addCustomizer(new HttpConfiguration.Customizer() {
@Override
public void customize(Connector connector, HttpConfiguration channelConfig, Request request) {
request.setScheme(HttpScheme.HTTPS.asString());
request.setSecure(true);
}
});
_connectorS = new LocalConnector(_server, https);
_server.setConnectors(new Connector[] { _connector, _connectorS });
ContextHandler _context = new ContextHandler();
_session = new SessionHandler();
_context.setContextPath("/ctx");
_server.setHandler(_context);
_context.setHandler(_session);
_security = new ConstraintSecurityHandler();
_session.setHandler(_security);
_security.setHandler(new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
baseRequest.setHandled(true);
response.sendError(404);
}
});
}
use of org.eclipse.jetty.server.session.SessionHandler in project jetty.project by eclipse.
the class SpecExampleConstraintTest method startServer.
@BeforeClass
public static void startServer() {
_server = new Server();
_connector = new LocalConnector(_server);
_server.setConnectors(new Connector[] { _connector });
ContextHandler _context = new ContextHandler();
_session = new SessionHandler();
TestLoginService _loginService = new TestLoginService(TEST_REALM);
_loginService.putUser("fred", new Password("password"), IdentityService.NO_ROLES);
_loginService.putUser("harry", new Password("password"), new String[] { "HOMEOWNER" });
_loginService.putUser("chris", new Password("password"), new String[] { "CONTRACTOR" });
_loginService.putUser("steven", new Password("password"), new String[] { "SALESCLERK" });
_context.setContextPath("/ctx");
_server.setHandler(_context);
_context.setHandler(_session);
_server.addBean(_loginService);
}
Aggregations