-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MYRIAD-243 Support Authentication in Myriad UI and REST APIs #96
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* 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 | ||
* <p/> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p/> | ||
* 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.myriad.webapp; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.security.AuthenticationFilterInitializer; | ||
import org.apache.hadoop.security.authentication.server.AuthenticationFilter; | ||
|
||
import javax.servlet.FilterConfig; | ||
import javax.servlet.ServletException; | ||
import java.util.Properties; | ||
|
||
/** | ||
* Filter to wrap AuthenticationFilter with specific prefix | ||
*/ | ||
public class MyriadAuthenticationFilter extends AuthenticationFilter { | ||
|
||
private static final String HTTP_AUTH_PREFIX = "hadoop.http.authentication."; | ||
|
||
private static Configuration conf; | ||
|
||
@Override | ||
protected Properties getConfiguration(String configPrefix, FilterConfig filterConfig) throws ServletException { | ||
Configuration localConf = new Configuration(); | ||
if (conf != null) { | ||
localConf = conf; | ||
} | ||
Properties props = new Properties(); | ||
props.putAll(AuthenticationFilterInitializer.getFilterConfigMap(localConf, HTTP_AUTH_PREFIX)); | ||
props.putAll(super.getConfiguration(configPrefix, filterConfig)); | ||
return props; | ||
} | ||
|
||
@VisibleForTesting | ||
static void setConfiguration(Configuration conf) { | ||
MyriadAuthenticationFilter.conf = conf; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ | |
|
||
import com.google.inject.servlet.GuiceFilter; | ||
import javax.inject.Inject; | ||
|
||
import org.apache.myriad.configuration.MyriadConfiguration; | ||
import org.mortbay.jetty.Connector; | ||
import org.mortbay.jetty.Handler; | ||
import org.mortbay.jetty.Server; | ||
|
@@ -36,17 +38,19 @@ public class MyriadWebServer { | |
private final Server jetty; | ||
private final Connector connector; | ||
private final GuiceFilter filter; | ||
private final MyriadConfiguration myriadConf; | ||
|
||
/** | ||
* Status codes for MyriadWebServer | ||
*/ | ||
public enum Status {STARTED, RUNNING, STOPPED, FAILED, UNKNOWN} | ||
|
||
@Inject | ||
public MyriadWebServer(Server jetty, Connector connector, GuiceFilter filter) { | ||
public MyriadWebServer(Server jetty, Connector connector, GuiceFilter filter, MyriadConfiguration myriadConf) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If all we're using is isSecurityEnabled maybe just pass a boolean, if you think we'll need more of the config later leave it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for now it is only for boolean, but we may need more from config later. WOuld be a pain to redo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then leave it. |
||
this.jetty = jetty; | ||
this.connector = connector; | ||
this.filter = filter; | ||
this.myriadConf = myriadConf; | ||
} | ||
|
||
public void start() throws Exception { | ||
|
@@ -65,6 +69,21 @@ public void start() throws Exception { | |
|
||
servletHandler.addFilter(holder, filterMapping); | ||
|
||
if (myriadConf.isSecurityEnabled()) { | ||
String authFilterName = "Authentication"; | ||
String authFilterClassName = MyriadAuthenticationFilter.class.getName(); | ||
FilterHolder authHolder = new FilterHolder(); | ||
authHolder.setName(authFilterName); | ||
authHolder.setClassName(authFilterClassName); | ||
|
||
FilterMapping authFmap = new FilterMapping(); | ||
authFmap.setPathSpec("/*"); | ||
authFmap.setDispatches(Handler.ALL); | ||
authFmap.setFilterName(authFilterName); | ||
|
||
servletHandler.addFilter(authHolder, authFmap); | ||
} | ||
|
||
Context context = new Context(); | ||
context.setServletHandler(servletHandler); | ||
context.addServlet(DefaultServlet.class, "/"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DEFAULT_AUTHENTICATION_ENABLED or DEFAULT_AUTH_ENABLED? "Security" is too vague, since encryption, authorization, and isolation are all parts of "security".