Filter is an special class which participate in Java servlet lifecycle and is called on each request (and even response). Using filter a resource can be protected by basic authentication from unauthorized access. According to documentation the filter must be implemented and then passed (full name) as a parameter. Let's pass valid username and password through environment variables, it must be good enough, as it equals to the approach used to pass AWS credentials for instance. Obviously, this env variable must be set on the instance where driver is supposed to be run. Another option is to pass them as arguments into filter using spark.
Let's imagine our class in the package my.company.filters (and using several helpers, like commons-codec, commons-lang)
public class BasicAuthFilter implements Filter {
private String login;
private String pass;
// this method is called one time on Filter creation
public void init(FilterConfig config) {
this.login = System.getenv("SPARK_LOGIN");
this.pass = System.getenv("SPARK_PASS");
}
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletRequest hreq = (HttpServletRequest) req;
HttpServletResponse hres = (HttpServletResponse) res;
String auth = hreq.getHeader( "Authorization" );
if ( auth != null ) {
int index = auth.indexOf(' ');
if ( index > 0 ) {
String[] creds = StringUtils.split( new String( Base64(auth.substring(index)), Charset.UTF_8), ':' );
if ( creds.length == 2 && login.equals(creds[0]) && pass.equals( creds[1] ) ) {
// auth passed successfully
return;
}
}
}
hres.setHeader( "WWW-Authenticate", "Basic realm=\"ProtectedSpark\"" );
hres.sendError( HttpServletResponse.SC_UNAUTHORIZED );
}
}
Ok, next step is to build JAR (pack this filter into JAR). After that, we can run our job in secured manner: execute spark-submit and pass newly assembled jar with flag --jars and through configuration (*.conf file or --conf param) pass full class path: spark.ui.filters=my.company.filters.BasicAuthFilter
horace@mail.postmanllc.net
ВідповістиВидалитиAngularJS is a toolset for building the framework most suited to your application development. It is fully extensible and works well with other libraries. Every feature can be modified or replaced to suit your unique development workflow and feature needs. Read on to find out how.
ВідповістиВидалитиAngularJS Training in Chennai
AngularJS Training Institute in Chennai
AngularJS Certification Training in Chennai
kuşadası
ВідповістиВидалитиmilas
çeşme
bağcılar
sinop
5HSVN