use of org.eclipse.jetty.security.SecurityHandler in project airlift by airlift.
the class HttpServer method createServletContext.
private static ServletContextHandler createServletContext(Servlet theServlet, Set<HttpResourceBinding> resources, Map<String, String> parameters, Set<Filter> filters, TraceTokenManager tokenManager, LoginService loginService, String... connectorNames) {
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
context.addFilter(new FilterHolder(new TimingFilter()), "/*", null);
if (tokenManager != null) {
context.addFilter(new FilterHolder(new TraceTokenFilter(tokenManager)), "/*", null);
}
// -- security handler
if (loginService != null) {
SecurityHandler securityHandler = createSecurityHandler(loginService);
context.setSecurityHandler(securityHandler);
}
// -- user provided filters
for (Filter filter : filters) {
context.addFilter(new FilterHolder(filter), "/*", null);
}
// -- static resources
for (HttpResourceBinding resource : resources) {
ClassPathResourceFilter servlet = new ClassPathResourceFilter(resource.getBaseUri(), resource.getClassPathResourceBase(), resource.getWelcomeFiles());
context.addFilter(new FilterHolder(servlet), servlet.getBaseUri() + "/*", null);
}
// -- gzip handler
context.setGzipHandler(new GzipHandler());
// -- the servlet
ServletHolder servletHolder = new ServletHolder(theServlet);
servletHolder.setInitParameters(ImmutableMap.copyOf(parameters));
context.addServlet(servletHolder, "/*");
// Starting with Jetty 9 there is no way to specify connectors directly, but
// there is this wonky @ConnectorName virtual hosts automatically added
String[] virtualHosts = new String[connectorNames.length];
for (int i = 0; i < connectorNames.length; i++) {
virtualHosts[i] = "@" + connectorNames[i];
}
context.setVirtualHosts(virtualHosts);
return context;
}
use of org.eclipse.jetty.security.SecurityHandler in project jena by apache.
the class TestRemoteEndpointResultsWithAuth method setup.
/**
* Setup for the tests by allocating a Fuseki instance to work with
*
* @throws SQLException
* @throws IOException
*/
@BeforeClass
public static void setup() throws SQLException, IOException {
SecurityHandler sh = FusekiTestAuth.makeSimpleSecurityHandler("/*", USER, PASSWORD);
FusekiTestAuth.setupServer(true, sh);
client = HttpClient.newBuilder().authenticator(AuthLib.authenticator(USER, PASSWORD)).build();
connection = new RemoteEndpointConnection(FusekiTestAuth.serviceQuery(), FusekiTestAuth.serviceUpdate(), null, null, null, null, client, JenaConnection.DEFAULT_HOLDABILITY, JdbcCompatibility.DEFAULT, null, null);
connection.setJdbcCompatibilityLevel(JdbcCompatibility.HIGH);
}
use of org.eclipse.jetty.security.SecurityHandler in project jena by apache.
the class EnvTest method startServer.
private static FusekiServer startServer(String dsName, DatasetGraph dsg, StringHolderServlet holder, boolean verbose, String user, String password) {
if (user != null && password == null)
throw new IllegalArgumentException("User, not null, but password null");
if (user != null) {
}
String data = "/data";
FusekiServer.Builder builder = FusekiServer.create().port(0).verbose(verbose).enablePing(true).auth(AuthScheme.BASIC).addServlet(data, holder).add(dsName, dsg);
if (user != null) {
UserStore userStore = JettyLib.makeUserStore(user, password);
SecurityHandler sh = JettyLib.makeSecurityHandler("TripleStore", userStore, AuthScheme.BASIC);
builder.securityHandler(sh).serverAuthPolicy(Auth.policyAllowSpecific(user));
}
FusekiServer server = builder.build();
server.start();
return server;
}
use of org.eclipse.jetty.security.SecurityHandler in project jena by apache.
the class ExFusekiMain_1_Servlet_AddFilter method main.
public static void main(String... a) {
try {
FusekiLogging.setLogging();
UserStore userStore = JettyLib.makeUserStore("u", "p");
SecurityHandler sh = JettyLib.makeSecurityHandler("TripleStore", userStore, AuthScheme.BASIC);
FusekiServer server = FusekiServer.create().add("/ds", DatasetGraphFactory.createTxnMem()).serverAuthPolicy(Auth.ANY_USER).securityHandler(sh).build();
addExtraFilter(server);
server.start();
// And use it.
String URL = "http://localhost:3330/ds";
try (RDFConnection conn = RDFConnection.connectPW(URL, "u", "p")) {
boolean b = conn.queryAsk("ASK{}");
System.out.println("ASK=" + b);
}
// server.join();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
System.exit(0);
}
}
Aggregations