/** * Method to start the Jetty server * * @param jobDataMap */ private void startServer(JobDataMap jobDataMap) { if (LOG.isDebugEnabled()) { LOG.debug("Initialising HTTP server"); } int port = Integer.parseInt(jobDataMap.getString("port")); String bindAddress = jobDataMap.getString("bindAddress"); String authConfigFile = jobDataMap.getString("authConfigFile"); String keystore = jobDataMap.getString("keystore"); Server server = new Server(); if (keystore == null || keystore.equals("")) { LOG.info("Starting with HTTP (non-encrypted) protocol"); SelectChannelConnector connector = new SelectChannelConnector(); connector.setHost(bindAddress); connector.setPort(port); server.addConnector(connector); } else { LOG.info("Starting with HTTPS (encrypted) protocol"); SslSocketConnector sslConnector = new SslSocketConnector(); sslConnector.setHost(bindAddress); sslConnector.setPort(port); sslConnector.setKeystore(jobDataMap.getString("keystore")); sslConnector.setKeyPassword(jobDataMap.getString("keyPassword")); sslConnector.setTruststore(jobDataMap.getString("trustStore")); sslConnector.setTrustPassword(jobDataMap.getString("trustPassword")); sslConnector.setPassword(jobDataMap.getString("password")); server.addConnector(sslConnector); } if (authConfigFile != null && !(authConfigFile.equals(""))) { if (LOG.isDebugEnabled()) { LOG.debug("Requiring basic auth"); } Constraint constraint = new Constraint(); constraint.setName(Constraint.__BASIC_AUTH); ; constraint.setRoles(new String[] {"user", "grouper"}); constraint.setAuthenticate(true); ConstraintMapping cm = new ConstraintMapping(); cm.setConstraint(constraint); cm.setPathSpec("/*"); SecurityHandler sh = new SecurityHandler(); try { sh.setUserRealm(new HashUserRealm("Grouper", authConfigFile)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } sh.setConstraintMappings(new ConstraintMapping[] {cm}); Handler[] handlers = new Handler[] {sh, new EsbHttpHandler()}; server.setHandlers(handlers); } else { if (LOG.isDebugEnabled()) { LOG.debug("Not requiring basic auth"); } server.setHandler(new EsbHttpHandler()); } try { server.start(); LOG.info("HTTP server started on address " + bindAddress + " port " + port); server.join(); } catch (Exception e) { e.printStackTrace(); } }
private void deployWebApp() { try { Server server = new Server(); SelectChannelConnector connector = new SelectChannelConnector(); connector.setMaxIdleTime(MAX_IDLE_TIME_MILLIS); connector.setHeaderBufferSize(HEADER_BUFFER_SIZE); connector.setHost(getHost()); connector.setPort(getPort()); if (isHttpsEnabled()) { connector.setConfidentialPort(getHttpsPort()); } server.addConnector(connector); if (isHttpsEnabled()) { SslSocketConnector sslConnector = new SslSocketConnector(); sslConnector.setMaxIdleTime(MAX_IDLE_TIME_MILLIS); sslConnector.setHeaderBufferSize(HEADER_BUFFER_SIZE); sslConnector.setHost(getHost()); sslConnector.setPort(getHttpsPort()); sslConnector.setKeystore( System.getProperty( "subsonic.ssl.keystore", getClass().getResource("/subsonic.keystore").toExternalForm())); sslConnector.setPassword(System.getProperty("subsonic.ssl.password", "subsonic")); server.addConnector(sslConnector); } WebAppContext context = new WebAppContext(); context.setTempDirectory(getJettyDirectory()); context.setContextPath(getContextPath()); context.setWar(getWar()); context.setOverrideDescriptor("/web-jetty.xml"); if (isHttpsEnabled()) { // Allow non-https for streaming and cover art (for Chromecast, UPnP, Sonos etc) context .getSecurityHandler() .setConstraintMappings( new ConstraintMapping[] { createConstraintMapping("/stream", Constraint.DC_NONE), createConstraintMapping("/coverArt.view", Constraint.DC_NONE), createConstraintMapping("/ws/*", Constraint.DC_NONE), createConstraintMapping("/sonos/*", Constraint.DC_NONE), createConstraintMapping("/", Constraint.DC_CONFIDENTIAL) }); } server.addHandler(context); server.start(); System.err.println("Subsonic running on: " + getUrl()); if (isHttpsEnabled()) { System.err.println(" and: " + getHttpsUrl()); } } catch (Throwable x) { x.printStackTrace(); exception = x; } }