Skip to content
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5002a15
add guice dependencies
echarles Aug 24, 2016
0fd9096
Merge branch 'master' into inject-services
echarles Aug 25, 2016
1d2b80a
Initial working implemenation of service injection for WebSecurity an…
echarles Aug 25, 2016
28589fb
Merge branch 'master' into inject-services
echarles Aug 25, 2016
3641e5b
temporary comment governator - seems to give issues when zeppelin run…
echarles Aug 25, 2016
da097a7
Revert change made to zeppelin-web/pom.xml
echarles Aug 31, 2016
74adbd4
Fix format
echarles Sep 2, 2016
d855a8b
Merge branch 'master' into inject-services
echarles Sep 2, 2016
ebe7ebb
Automatic message for commit of samedi 18 mars 2017, 11:23:13 (UTC+0000)
echarles Mar 18, 2017
39543de
Merge branch 'master' of https://github.com/apache/zeppelin
echarles Mar 25, 2017
a2ec2f8
Merge branch 'master' into inject-services
echarles Mar 25, 2017
1fd0457
revert back to scala 2.10
echarles Apr 6, 2017
c744e41
Merge branch 'master' into inject-services
echarles Apr 9, 2017
0befa1b
Merge branch 'master' into inject-services
echarles Apr 16, 2017
85e6572
Use com.google.inject.Inject instead of javax.inject.Inject to avoid …
echarles Apr 18, 2017
0a51045
Merge branch 'master' into inject-services
echarles Apr 18, 2017
7836b89
Remove duplicate searchService field
echarles Apr 19, 2017
639d810
Merge branch 'master' into inject-services
echarles Apr 23, 2017
146bf62
merge master
echarles Apr 23, 2017
acdf249
Merge branch 'master' into inject-services
echarles May 3, 2017
724cac3
Merge branch 'master' into inject-services
echarles May 4, 2017
7065f50
fix typo when merging
echarles May 4, 2017
ea644c8
Merge branch 'master' into inject-services
echarles Jun 5, 2017
25d744e
Align to master change
echarles Jun 5, 2017
dff202a
fix compilation issue
echarles Jun 5, 2017
b57ca32
fix compilation issue
echarles Jun 5, 2017
bcd1356
Merge branch 'master' into inject-services
echarles Jul 21, 2017
3254490
update to master
echarles Jul 21, 2017
6139e99
Fix compilation issue:
echarles Jul 21, 2017
da0ede7
fix
echarles Sep 3, 2017
2e6d28f
fix
echarles Sep 3, 2017
7e196d5
Merge branch 'master' into inject-services
echarles Sep 3, 2017
f556dc4
Merge branch 'master' into inject-services
echarles Nov 6, 2017
58dec36
Merge branch 'master' into inject-services
echarles Dec 15, 2017
2831c49
Merge branch 'master' into inject-services
echarles Jan 3, 2018
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
22 changes: 22 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@
<slf4j.version>1.7.10</slf4j.version>
<log4j.version>1.2.17</log4j.version>
<libthrift.version>0.9.2</libthrift.version>
<governator.version>1.14.2</governator.version>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like governator is not used (all import are commented), I think it better to remove it instead of having bunch of commented code.

<gson.version>2.2</gson.version>
<guice.version>4.1.0</guice.version>
<guava.version>15.0</guava.version>
<jetty.version>9.2.15.v20160210</jetty.version>

Expand Down Expand Up @@ -206,6 +208,26 @@
<artifactId>shiro-config-core</artifactId>
<version>1.2.3</version>
</dependency>

<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>${guice.version}</version>
</dependency>
<!--
<dependency>
<groupId>com.netflix.governator</groupId>
<artifactId>governator</artifactId>
<version>${governator.version}</version>
</dependency>
-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>

</dependencies>
</dependencyManagement>

Expand Down
13 changes: 12 additions & 1 deletion zeppelin-interpreter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,19 @@
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-provider-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.sonatype.sisu</groupId>
<artifactId>sisu-guice</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>${guice.version}</version>
</dependency>

<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-provider-api</artifactId>
Expand Down Expand Up @@ -234,7 +244,7 @@
</excludes>
</configuration>
</plugin>

<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
Expand Down Expand Up @@ -265,6 +275,7 @@
</execution>
</executions>
</plugin>
-->
</plugins>
</build>
</project>
6 changes: 6 additions & 0 deletions zeppelin-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,12 @@
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-web</artifactId>
</dependency>
<!--
<dependency>
<groupId>com.netflix.governator</groupId>
<artifactId>governator</artifactId>
</dependency>
-->
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.zeppelin.inject;

import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.Provides;
import org.apache.zeppelin.conf.ZeppelinConfiguration;
import org.apache.zeppelin.search.SearchService;
import org.apache.zeppelin.server.ZeppelinServer;
import org.apache.zeppelin.web.WebSecurity;

/**
* Guice injection module.
*/
public class ZeppelinModule implements Module {
private ZeppelinConfiguration conf;

public ZeppelinModule(ZeppelinConfiguration conf) {
this.conf = conf;
}

@Override
public void configure(Binder binder) {

binder.bind(WebSecurity.class)
.to((Class<WebSecurity>) conf.getZeppelinWebSecurityClassname());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we add Singleton scope here? what do you think?


binder.bind(SearchService.class)
.to((Class<SearchService>) conf.getZeppelinSearchServiceClassname());

binder.requestStaticInjection(ZeppelinServer.class);

}

@Provides
public ZeppelinConfiguration getZeppelinConfiguration() {
return conf;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@

package org.apache.zeppelin.server;

import com.google.inject.Guice;
import com.google.inject.Injector;

import java.io.File;
import java.io.IOException;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ExecutorService;

import javax.net.ssl.SSLContext;
import javax.servlet.DispatcherType;
import javax.inject.Inject;
import javax.ws.rs.core.Application;

import org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet;
import org.apache.zeppelin.conf.ZeppelinConfiguration;
import org.apache.zeppelin.conf.ZeppelinConfiguration.ConfVars;
import org.apache.zeppelin.dep.DependencyResolver;
import org.apache.zeppelin.web.WebSecurity;
import org.apache.zeppelin.inject.ZeppelinModule;
import org.apache.zeppelin.helium.Helium;
import org.apache.zeppelin.helium.HeliumApplicationFactory;
import org.apache.zeppelin.interpreter.InterpreterFactory;
Expand All @@ -41,17 +43,14 @@
import org.apache.zeppelin.notebook.repo.NotebookRepoSync;
import org.apache.zeppelin.rest.*;
import org.apache.zeppelin.scheduler.SchedulerFactory;
import org.apache.zeppelin.search.LuceneSearch;
import org.apache.zeppelin.search.SearchService;
import org.apache.zeppelin.socket.NotebookServer;
import org.apache.zeppelin.user.Credentials;
import org.apache.zeppelin.utils.SecurityUtils;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.server.*;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.ssl.SslContextFactory;
Expand All @@ -70,17 +69,25 @@ public class ZeppelinServer extends Application {
public static NotebookServer notebookWsServer;
public static Helium helium;
public static HeliumApplicationFactory heliumApplicationFactory;
public static Injector injector;
@Inject
private static WebSecurity webSecurity;

private SchedulerFactory schedulerFactory;
private InterpreterFactory replFactory;
private NotebookRepo notebookRepo;
private SearchService notebookIndex;

@Inject
private SearchService searchService;
@Inject
private ZeppelinConfiguration conf;
private NotebookAuthorization notebookAuthorization;
private Credentials credentials;
private DependencyResolver depResolver;

public ZeppelinServer() throws Exception {
ZeppelinConfiguration conf = ZeppelinConfiguration.create();

injector.injectMembers(this);

this.depResolver = new DependencyResolver(
conf.getString(ConfVars.ZEPPELIN_INTERPRETER_LOCALREPO));
Expand All @@ -91,12 +98,11 @@ public ZeppelinServer() throws Exception {
this.replFactory = new InterpreterFactory(conf, notebookWsServer,
notebookWsServer, heliumApplicationFactory, depResolver);
this.notebookRepo = new NotebookRepoSync(conf);
this.notebookIndex = new LuceneSearch();
this.notebookAuthorization = new NotebookAuthorization(conf);
this.credentials = new Credentials(conf.credentialsPersist(), conf.getCredentialsPath());
notebook = new Notebook(conf,
notebookRepo, schedulerFactory, replFactory, notebookWsServer,
notebookIndex, notebookAuthorization, credentials);
searchService, notebookAuthorization, credentials);

// to update notebook from application event from remote process.
heliumApplicationFactory.setNotebook(notebook);
Expand All @@ -111,6 +117,8 @@ public static void main(String[] args) throws InterruptedException {
ZeppelinConfiguration conf = ZeppelinConfiguration.create();
conf.setProperty("args", args);

injector = Guice.createInjector(new ZeppelinModule(conf));

jettyWebServer = setupJettyServer(conf);

ContextHandlerCollection contexts = new ContextHandlerCollection();
Expand Down Expand Up @@ -253,14 +261,7 @@ private static void setupRestApiContextHandler(WebAppContext webapp,
webapp.setSessionHandler(new SessionHandler());
webapp.addServlet(cxfServletHolder, "/api/*");

webapp.setInitParameter("shiroConfigLocations",
new File(conf.getShiroPath()).toURI().toString());

SecurityUtils.initSecurityManager(conf.getShiroPath());
webapp.addFilter(org.apache.shiro.web.servlet.ShiroFilter.class, "/api/*",
EnumSet.allOf(DispatcherType.class));

webapp.addEventListener(new org.apache.shiro.web.env.EnvironmentLoaderListener());
webSecurity.addSecurityFilter(webapp);

}

Expand All @@ -287,8 +288,7 @@ private static WebAppContext setupWebAppContext(ContextHandlerCollection context
webApp.addServlet(new ServletHolder(new DefaultServlet()), "/*");
contexts.addHandler(webApp);

webApp.addFilter(new FilterHolder(CorsFilter.class), "/*",
EnumSet.allOf(DispatcherType.class));
webSecurity.addCorFilter(webApp);

return webApp;

Expand All @@ -308,7 +308,7 @@ public Set<Object> getSingletons() {
ZeppelinRestApi root = new ZeppelinRestApi();
singletons.add(root);

NotebookRestApi notebookApi = new NotebookRestApi(notebook, notebookWsServer, notebookIndex);
NotebookRestApi notebookApi = new NotebookRestApi(notebook, notebookWsServer, searchService);
singletons.add(notebookApi);

HeliumRestApi heliumApi = new HeliumRestApi(helium, heliumApplicationFactory, notebook);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.zeppelin.web;

import org.apache.zeppelin.conf.ZeppelinConfiguration;
import org.apache.zeppelin.server.CorsFilter;
import org.apache.zeppelin.utils.SecurityUtils;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.webapp.WebAppContext;

import javax.inject.Inject;
import javax.servlet.DispatcherType;
import java.io.File;
import java.util.EnumSet;

/**
* Default implementation of the actions to be taken
* by Zeppelin to secure the Web channel.
*/
public class DefaultWebSecurity implements WebSecurity {

@Inject
private ZeppelinConfiguration conf;

@Override
public void addCorFilter(WebAppContext webApp) {

webApp.addFilter(new FilterHolder(CorsFilter.class), "/*",
EnumSet.allOf(DispatcherType.class));

}

@Override
public void addSecurityFilter(WebAppContext webApp) {

webApp.setInitParameter("shiroConfigLocations",
new File(conf.getShiroPath()).toURI().toString());

SecurityUtils.initSecurityManager(conf.getShiroPath());
webApp.addFilter(org.apache.shiro.web.servlet.ShiroFilter.class, "/api/*",
EnumSet.allOf(DispatcherType.class));

webApp.addEventListener(new org.apache.shiro.web.env.EnvironmentLoaderListener());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldnt be cleaner to import org.apache.shiro.web.env and change this line with
webApp.addEventListener(new EnvironmentLoaderListener()); ?


}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.zeppelin.web;

import org.eclipse.jetty.webapp.WebAppContext;

/**
* Definition of the actions to be taken
* by Zeppelin to secure the Web channel.
*/
public interface WebSecurity {

void addCorFilter(WebAppContext webApp);

void addSecurityFilter(WebAppContext webApp);

}
Loading