/** * Enable authentication for this endpoint * * @param context The context to enable authentication for. * @param credentials The optional credentials to enforce. This is a (key,value) pair */ private static void withAuth(HttpContext context, Optional<Pair<String,String>> credentials) { credentials.ifPresent(c -> context.setAuthenticator(new BasicAuthenticator("corenlp") { @Override public boolean checkCredentials(String user, String pwd) { return user.equals(c.first) && pwd.equals(c.second); } })); }
/** * Build the HttpContext for the given endpoint. * @param endpoint the JAX-WS Provider Endpoint object * @param serviceName the given service name * @return the fully populated HttpContext */ protected HttpContext buildHttpContext(Endpoint endpoint, String serviceName) { Assert.state(this.server != null, "No HttpServer available"); String fullPath = calculateEndpointPath(endpoint, serviceName); HttpContext httpContext = this.server.createContext(fullPath); if (this.filters != null) { httpContext.getFilters().addAll(this.filters); } if (this.authenticator != null) { httpContext.setAuthenticator(this.authenticator); } return httpContext; }
@Override public void afterPropertiesSet() throws IOException { InetSocketAddress address = (this.hostname != null ? new InetSocketAddress(this.hostname, this.port) : new InetSocketAddress(this.port)); this.server = HttpServer.create(address, this.backlog); if (this.executor != null) { this.server.setExecutor(this.executor); } if (this.contexts != null) { this.contexts.forEach((key, context) -> { HttpContext httpContext = this.server.createContext(key, context); if (this.filters != null) { httpContext.getFilters().addAll(this.filters); } if (this.authenticator != null) { httpContext.setAuthenticator(this.authenticator); } }); } if (logger.isInfoEnabled()) { logger.info("Starting HttpServer at address " + address); } this.server.start(); }
/** * Build the HttpContext for the given endpoint. * @param endpoint the JAX-WS Provider Endpoint object * @param serviceName the given service name * @return the fully populated HttpContext */ protected HttpContext buildHttpContext(Endpoint endpoint, String serviceName) { Assert.state(this.server != null, "No HttpServer available"); String fullPath = calculateEndpointPath(endpoint, serviceName); HttpContext httpContext = this.server.createContext(fullPath); if (this.filters != null) { httpContext.getFilters().addAll(this.filters); } if (this.authenticator != null) { httpContext.setAuthenticator(this.authenticator); } return httpContext; }
@Override public void afterPropertiesSet() throws IOException { InetSocketAddress address = (this.hostname != null ? new InetSocketAddress(this.hostname, this.port) : new InetSocketAddress(this.port)); this.server = HttpServer.create(address, this.backlog); if (this.executor != null) { this.server.setExecutor(this.executor); } if (this.contexts != null) { this.contexts.forEach((key, context) -> { HttpContext httpContext = this.server.createContext(key, context); if (this.filters != null) { httpContext.getFilters().addAll(this.filters); } if (this.authenticator != null) { httpContext.setAuthenticator(this.authenticator); } }); } if (logger.isInfoEnabled()) { logger.info("Starting HttpServer at address " + address); } this.server.start(); }
/** * Initialize this JolokiaServer with the given HttpServer. The calle is responsible for managing (starting/stopping) * the HttpServer. * * @param pServer server to use * @param pConfig configuration * @param pLazy whether the initialization should be done lazy or not */ protected final void init(HttpServer pServer, JolokiaServerConfig pConfig, boolean pLazy) { config = pConfig; lazy = pLazy; // Create proper context along with handler final String contextPath = pConfig.getContextPath(); jolokiaHttpHandler = new JolokiaHttpHandler(pConfig.getJolokiaConfig()); HttpContext context = pServer.createContext(contextPath, jolokiaHttpHandler); // Add authentication if configured final Authenticator authenticator = pConfig.getAuthenticator(); if (authenticator != null) { context.setAuthenticator(authenticator); } url = detectAgentUrl(pServer, pConfig, contextPath); }
/** * Enable authentication for this endpoint * * @param context The context to enable authentication for. * @param credentials The optional credentials to enforce. This is a (key,value) pair */ private static void withAuth(HttpContext context, Optional<Pair<String,String>> credentials) { credentials.ifPresent(c -> context.setAuthenticator(new BasicAuthenticator("corenlp") { @Override public boolean checkCredentials(String user, String pwd) { return user.equals(c.first) && pwd.equals(c.second); } })); }
protected void initHttpContext(HttpContext context) { context.getFilters().addAll(httpServerFilters); if (httpServerAuthenticator != null) context.setAuthenticator(httpServerAuthenticator); }
private void setupAuthentication() { // Add authentication if configured final Authenticator authenticator = config.getAuthenticator(); if (authenticator != null) { httpContext.setAuthenticator(authenticator); } }
/** * {@inheritDoc} */ @Override public HttpRestServer onBasicAuthRequest( BasicAuthObserver aBasicAuthObserver ) { HttpContext theHttpContext = _httpContext; HttpBasicAuthenticator theHttpBasicAuthenticator = null; if ( aBasicAuthObserver != null ) { theHttpBasicAuthenticator = new HttpBasicAuthenticator( aBasicAuthObserver ); if ( theHttpContext != null ) { theHttpContext.setAuthenticator( theHttpBasicAuthenticator ); } } _httpBasicAuthenticator = theHttpBasicAuthenticator; return this; }
/** * Build the HttpContext for the given endpoint. * @param endpoint the JAX-WS Provider Endpoint object * @param serviceName the given service name * @return the fully populated HttpContext */ protected HttpContext buildHttpContext(Endpoint endpoint, String serviceName) { Assert.state(this.server != null, "No HttpServer available"); String fullPath = calculateEndpointPath(endpoint, serviceName); HttpContext httpContext = this.server.createContext(fullPath); if (this.filters != null) { httpContext.getFilters().addAll(this.filters); } if (this.authenticator != null) { httpContext.setAuthenticator(this.authenticator); } return httpContext; }
/** * Build the HttpContext for the given endpoint. * @param endpoint the JAX-WS Provider Endpoint object * @param serviceName the given service name * @return the fully populated HttpContext */ protected HttpContext buildHttpContext(Endpoint endpoint, String serviceName) { Assert.state(this.server != null, "No HttpServer available"); String fullPath = calculateEndpointPath(endpoint, serviceName); HttpContext httpContext = this.server.createContext(fullPath); if (this.filters != null) { httpContext.getFilters().addAll(this.filters); } if (this.authenticator != null) { httpContext.setAuthenticator(this.authenticator); } return httpContext; }
@Override public void afterPropertiesSet() throws IOException { InetSocketAddress address = (this.hostname != null ? new InetSocketAddress(this.hostname, this.port) : new InetSocketAddress(this.port)); this.server = HttpServer.create(address, this.backlog); if (this.executor != null) { this.server.setExecutor(this.executor); } if (this.contexts != null) { this.contexts.forEach((key, context) -> { HttpContext httpContext = this.server.createContext(key, context); if (this.filters != null) { httpContext.getFilters().addAll(this.filters); } if (this.authenticator != null) { httpContext.setAuthenticator(this.authenticator); } }); } if (logger.isInfoEnabled()) { logger.info("Starting HttpServer at address " + address); } this.server.start(); }
/** * Construct and start an instance of QpidRestAPI. This class used a Delegator class to delegate to underlying * Server instances that actually implement the business logic of the REST API. * * @param addr the the address the QpidRestAPI is bound to (null = default). * @param port the port the QpidRestAPI is bound to. * @param broker the address of the Qpid broker to connect to (null = default). * @param backlog the socket backlog. * @param webroot the directory of the QpidRestAPI Web Site. */ public QpidRestAPI(final String addr, final int port, String broker, final int backlog, final String webroot) throws IOException { final InetSocketAddress inetaddr = (addr == null) ? new InetSocketAddress(port) : new InetSocketAddress(addr, port); final HttpServer server = HttpServer.create(inetaddr, backlog); broker = (broker == null) ? inetaddr.getAddress().getHostAddress() + ":5672" : broker; Delegator fileserver = new Delegator(new FileServer(webroot + "/web", true)); Delegator qpidserver = new Delegator(new QpidServer(broker)); Authenticator authenticator = new Authenticator(this.getClass().getCanonicalName(), webroot + "/authentication"); server.setExecutor(Executors.newCachedThreadPool()); server.createContext("/", fileserver); server.createContext("/ui", fileserver).setAuthenticator(authenticator); server.createContext("/qpid/connection", qpidserver).setAuthenticator(authenticator); server.start(); }
HttpBasicAuthenticator theHttpBasicAuthenticator = _httpBasicAuthenticator; if ( theHttpBasicAuthenticator != null ) { theHttpContext.setAuthenticator( theHttpBasicAuthenticator );