forked from j62/ctbrec
Fix SonarLint issues
This commit is contained in:
parent
a4b805c038
commit
ce103853a3
|
@ -61,7 +61,7 @@ import ctbrec.sites.streamate.Streamate;
|
|||
|
||||
public class HttpServer {
|
||||
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(HttpServer.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger(HttpServer.class);
|
||||
private Recorder recorder;
|
||||
private OnlineMonitor onlineMonitor;
|
||||
private Config config;
|
||||
|
@ -142,11 +142,11 @@ public class HttpServer {
|
|||
private void startHttpServer() throws Exception {
|
||||
server = new Server();
|
||||
|
||||
HttpConfiguration config = new HttpConfiguration();
|
||||
config.setSendServerVersion(false);
|
||||
config.setSecurePort(this.config.getSettings().httpSecurePort);
|
||||
config.setSecureScheme("https");
|
||||
HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory(config);
|
||||
HttpConfiguration httpConfig = new HttpConfiguration();
|
||||
httpConfig.setSendServerVersion(false);
|
||||
httpConfig.setSecurePort(this.config.getSettings().httpSecurePort);
|
||||
httpConfig.setSecureScheme("https");
|
||||
HttpConnectionFactory httpConnectionFactory = new HttpConnectionFactory(httpConfig);
|
||||
|
||||
SslContextFactory sslContextFactory = new SslContextFactory.Server();
|
||||
URL keyStoreUrl = getClass().getResource("/keystore.pkcs12");
|
||||
|
@ -157,13 +157,14 @@ public class HttpServer {
|
|||
sslContextFactory.setTrustStorePath(keyStoreSrc);
|
||||
sslContextFactory.setTrustStorePassword(keyStorePassword);
|
||||
|
||||
try (ServerConnector http = new ServerConnector(server, httpConnectionFactory);
|
||||
ServerConnector https = new ServerConnector(server, sslContextFactory, httpConnectionFactory)) {
|
||||
|
||||
// connector for http
|
||||
ServerConnector http = new ServerConnector(server, httpConnectionFactory);
|
||||
http.setPort(this.config.getSettings().httpPort);
|
||||
http.setIdleTimeout(this.config.getSettings().httpTimeout);
|
||||
|
||||
// connector for https (TLS)
|
||||
ServerConnector https = new ServerConnector(server, sslContextFactory, httpConnectionFactory);
|
||||
https.setPort(this.config.getSettings().httpSecurePort);
|
||||
https.setIdleTimeout(this.config.getSettings().httpTimeout);
|
||||
|
||||
|
@ -195,14 +196,18 @@ public class HttpServer {
|
|||
basicAuthContext.setSecurityHandler(basicAuth(username, password, "CTB Recorder"));
|
||||
basicAuthContext.addServlet(new ServletHolder(new HttpServlet() {
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException {
|
||||
if (Objects.equal(username, req.getRemoteUser())) {
|
||||
resp.setStatus(HttpServletResponse.SC_OK);
|
||||
resp.setContentType("application/json");
|
||||
byte[] hmac = Optional.ofNullable(HttpServer.this.config.getSettings().key).orElse(new byte[0]);
|
||||
try {
|
||||
JSONObject response = new JSONObject();
|
||||
response.put("hmac", new String(hmac, "utf-8"));
|
||||
resp.getOutputStream().println(response.toString());
|
||||
} catch (Exception e) {
|
||||
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}), "/hmac");
|
||||
|
@ -229,6 +234,7 @@ public class HttpServer {
|
|||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final SecurityHandler basicAuth(String username, String password, String realm) {
|
||||
UserStore userStore = new UserStore();
|
||||
|
@ -256,10 +262,10 @@ public class HttpServer {
|
|||
}
|
||||
|
||||
private void registerAlertSystem() {
|
||||
for (EventHandlerConfiguration config : Config.getInstance().getSettings().eventHandlers) {
|
||||
EventHandler handler = new EventHandler(config);
|
||||
for (EventHandlerConfiguration ehconfig : Config.getInstance().getSettings().eventHandlers) {
|
||||
EventHandler handler = new EventHandler(ehconfig);
|
||||
EventBusHolder.register(handler);
|
||||
LOG.debug("Registered event handler for {} {}", config.getEvent(), config.getName());
|
||||
LOG.debug("Registered event handler for {} {}", ehconfig.getEvent(), ehconfig.getName());
|
||||
}
|
||||
LOG.debug("Alert System registered");
|
||||
}
|
||||
|
@ -268,8 +274,9 @@ public class HttpServer {
|
|||
LOG.debug("OS:\t{} {}", System.getProperty("os.name"), System.getProperty("os.version"));
|
||||
LOG.debug("Java:\t{} {} {}", System.getProperty("java.vendor"), System.getProperty("java.vm.name"), System.getProperty("java.version"));
|
||||
try {
|
||||
LOG.debug("ctbrec server {}", getVersion().toString());
|
||||
LOG.debug("ctbrec server {}", getVersion());
|
||||
} catch (IOException e) {
|
||||
// nothing to do here
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue