Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.bouncycastle.operator.ContentSigner;
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.security.ConstraintMapping;
import org.eclipse.jetty.security.ConstraintSecurityHandler;
import org.eclipse.jetty.security.DefaultIdentityService;
import org.eclipse.jetty.security.DefaultUserIdentity;
Expand Down Expand Up @@ -109,7 +108,7 @@ public WebServer(Dispatcher dispatcher) {
/**
* Start the web server including setup.
*
* @throws Exception
* @throws Exception in case of error during start
*/
public void start() throws Exception {
if (jettyServer == null) {
Expand Down Expand Up @@ -223,7 +222,7 @@ private void setupStaticResources(
}

public static class AMUserPrincipal implements Principal {
public final String userName;
private final String userName;

public AMUserPrincipal(String userName) {
this.userName = userName;
Expand All @@ -236,7 +235,7 @@ public String getName() {
}

public static class AmLoginService implements LoginService {
private AMSecurityManager securityMgr;
private final AMSecurityManager securityMgr;
protected IdentityService identityService = new DefaultIdentityService();

public AmLoginService(AMSecurityManager securityMgr) {
Expand Down Expand Up @@ -274,18 +273,6 @@ public void setIdentityService(IdentityService service) {
@Override
public void logout(UserIdentity user) {
}

// @Override
// protected UserIdentity loadUser(String username) {
// // TODO Auto-generated method stub
// return null;
// }
//
// @Override
// protected void loadUsers() throws IOException {
// putUser( "fred", new Password( "wilma" ), new String[] { ADMIN_ROLE } );
// }

}

/**
Expand All @@ -298,8 +285,7 @@ private ConstraintSecurityHandler createSecurityHandler() {
ConstraintSecurityHandler security = new ConstraintSecurityHandler();

Set<String> knownRoles = ImmutableSet.of(ADMIN_ROLE);
security.setConstraintMappings(Collections.<ConstraintMapping> emptyList(),
knownRoles);
security.setConstraintMappings(Collections.emptyList(), knownRoles);

security.setAuthenticator(new FormAuthenticator("/login", "/login", true));
security
Expand Down Expand Up @@ -350,13 +336,11 @@ public void sessionDestroyed(HttpSessionEvent se) {
* Create HTTP connector.
*
* @return Initialized {@link ServerConnector} instance for HTTP connections.
* @throws Exception
*/
private ServerConnector createHttpConnector(Config config) throws Exception {
private ServerConnector createHttpConnector(Config config) {
LOG.info("Setting up HTTP connector for web server");
final HttpConfiguration httpConfig = new HttpConfiguration();
final ServerConnector httpConnector = new ServerConnector(jettyServer,
new HttpConnectionFactory(httpConfig));
new HttpConnectionFactory(baseHttpConfig()));
httpConnector.setPort(config.getInt(DrillOnYarnConfig.HTTP_PORT));

return httpConnector;
Expand All @@ -368,12 +352,12 @@ private ServerConnector createHttpConnector(Config config) throws Exception {
* certificate is generated and used.
* <p>
* This is a shameless copy of
* {@link org.apache.drill.exec.server.rest.WebServer#createHttpsConnector(int, int, int)}.
* org.apache.drill.exec.server.rest.WebServer#createHttpsConnector(int, int, int).
* The two should be merged at some point. The primary issue is that the Drill
* version is tightly coupled to Drillbit configuration.
*
* @return Initialized {@link ServerConnector} for HTTPS connections.
* @throws Exception
* @throws Exception when unable to create HTTPS connector
*/
private ServerConnector createHttpsConnector(Config config) throws Exception {
LOG.info("Setting up HTTPS connector for web server");
Expand Down Expand Up @@ -446,7 +430,7 @@ private ServerConnector createHttpsConnector(Config config) throws Exception {
sslContextFactory.setKeyStorePassword(keyStorePasswd);
// }

final HttpConfiguration httpsConfig = new HttpConfiguration();
final HttpConfiguration httpsConfig = baseHttpConfig();
httpsConfig.addCustomizer(new SecureRequestCustomizer());

// SSL Connector
Expand All @@ -459,6 +443,12 @@ private ServerConnector createHttpsConnector(Config config) throws Exception {
return sslConnector;
}

private HttpConfiguration baseHttpConfig() {
HttpConfiguration httpConfig = new HttpConfiguration();
httpConfig.setSendServerVersion(false);
return httpConfig;
}

@Override
public void close() throws Exception {
if (jettyServer != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
import java.util.stream.Stream;

/**
* Wrapper class around jetty based webserver.
* Wrapper class around jetty based web server.
*/
public class WebServer implements AutoCloseable {
private static final String ACE_MODE_SQL_TEMPLATE_JS = "ace.mode-sql.template.js";
Expand Down Expand Up @@ -270,7 +270,7 @@ private ServletContextHandler createServletContextHandler(final boolean authEnab
/**
* It creates A {@link SessionHandler} which contains a {@link HashSessionManager}
*
* @param securityHandler Set of initparameters that are used by the Authentication
* @param securityHandler Set of init parameters that are used by the Authentication
* @return session handler
*/
private SessionHandler createSessionHandler(final SecurityHandler securityHandler) {
Expand Down Expand Up @@ -354,7 +354,7 @@ private ServerConnector createHttpsConnector(int port, int acceptors, int select
.initializeSSLContext(false)
.validateKeyStore(true)
.build();
if(ssl.isSslValid()){
if (ssl.isSslValid()) {
logger.info("Using configured SSL settings for web server");

sslContextFactory.setKeyStorePath(ssl.getKeyStorePath());
Expand Down Expand Up @@ -419,7 +419,7 @@ private ServerConnector createHttpsConnector(int port, int acceptors, int select
sslContextFactory.setKeyStorePassword(keyStorePasswd);
}

final HttpConfiguration httpsConfig = new HttpConfiguration();
final HttpConfiguration httpsConfig = baseHttpConfig();
httpsConfig.addCustomizer(new SecureRequestCustomizer());

// SSL Connector
Expand All @@ -439,14 +439,19 @@ private ServerConnector createHttpsConnector(int port, int acceptors, int select
*/
private ServerConnector createHttpConnector(int port, int acceptors, int selectors) {
logger.info("Setting up HTTP connector for web server");
final HttpConfiguration httpConfig = new HttpConfiguration();
final ServerConnector httpConnector =
new ServerConnector(embeddedJetty, null, null, null, acceptors, selectors, new HttpConnectionFactory(httpConfig));
new ServerConnector(embeddedJetty, null, null, null, acceptors, selectors, new HttpConnectionFactory(baseHttpConfig()));
httpConnector.setPort(port);

return httpConnector;
}

private HttpConfiguration baseHttpConfig() {
HttpConfiguration httpConfig = new HttpConfiguration();
httpConfig.setSendServerVersion(false);
return httpConfig;
}

@Override
public void close() throws Exception {
if (embeddedJetty != null) {
Expand All @@ -458,7 +463,7 @@ public void close() throws Exception {

/**
* Creates if not exists, and returns File for temporary Javascript directory
* @return File handle
* @return file handle
*/
public File getOrCreateTmpJavaScriptDir() {
if (tmpJavaScriptDir == null && this.drillbit.getContext() != null) {
Expand All @@ -468,7 +473,7 @@ public File getOrCreateTmpJavaScriptDir() {
generateOptionsDescriptionJSFile();
generateFunctionJS();
} catch (IOException e) {
logger.error("Unable to create temp dir for JavaScripts. {}", e);
logger.error("Unable to create temp dir for JavaScripts: {}", tmpJavaScriptDir.getPath(), e);
}
}
return tmpJavaScriptDir;
Expand All @@ -477,7 +482,7 @@ public File getOrCreateTmpJavaScriptDir() {

/**
* Generate Options Description JavaScript to serve http://drillhost/options ACE library search features
* @throws IOException
* @throws IOException when unable to generate functions JS file
*/
private void generateOptionsDescriptionJSFile() throws IOException {
// Obtain list of Options & their descriptions
Expand All @@ -491,12 +496,12 @@ private void generateOptionsDescriptionJSFile() throws IOException {
int numLeftToWrite = options.size();

// Template source Javascript file
InputStream optionsDescripTemplateStream = Resource.newClassPathResource(OPTIONS_DESCRIBE_TEMPLATE_JS).getInputStream();
InputStream optionsDescribeTemplateStream = Resource.newClassPathResource(OPTIONS_DESCRIBE_TEMPLATE_JS).getInputStream();
// Generated file
File optionsDescriptionFile = new File(getOrCreateTmpJavaScriptDir(), OPTIONS_DESCRIBE_JS);
final String file_content_footer = "};";
// Create a copy of a template and write with that!
java.nio.file.Files.copy(optionsDescripTemplateStream, optionsDescriptionFile.toPath());
java.nio.file.Files.copy(optionsDescribeTemplateStream, optionsDescriptionFile.toPath());
logger.info("Will write {} descriptions to {}", numLeftToWrite, optionsDescriptionFile.getAbsolutePath());

try (BufferedWriter writer = new BufferedWriter(new FileWriter(optionsDescriptionFile, true))) {
Expand All @@ -521,7 +526,7 @@ private void generateOptionsDescriptionJSFile() throws IOException {

/**
* Generates ACE library javascript populated with list of available SQL functions
* @throws IOException
* @throws IOException when unable to generate JS file with functions
*/
private void generateFunctionJS() throws IOException {
// Naturally ordered set of function names
Expand All @@ -530,7 +535,7 @@ private void generateFunctionJS() throws IOException {
List<FunctionHolder> builtInFuncHolderList = this.drillbit.getContext().getFunctionImplementationRegistry().getLocalFunctionRegistry()
.getAllJarsWithFunctionsHolders().get(LocalFunctionRegistry.BUILT_IN);

// Build List of 'usable' functions (i.e. functions that start with an alphabet and can be autocompleted by the ACE library)
// Build List of 'usable' functions (i.e. functions that start with an alphabet and can be auto-completed by the ACE library)
// Example of 'unusable' functions would be operators like '<', '!'
int skipCount = 0;
for (FunctionHolder builtInFunctionHolder : builtInFuncHolderList) {
Expand Down