/*
 * 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());

  }

}

@@ -1648,24 +1648,120 @@
 App) %7B%0A%0A
+    String shiroIniPath = conf.getShiroPath();%0A%0A    if (!StringUtils.isBlank(shiroIniPath)) %7B%0A  
     web
-A
+a
 pp.setIn
@@ -1795,28 +1795,16 @@
 ations%22,
-%0A           
  new Fil
@@ -1805,35 +1805,28 @@
 ew File(
-conf.getS
+s
 hiro
+Ini
 Path
-()
 ).toURI(
@@ -1836,25 +1836,26 @@
 oString());%0A
-%0A
+  
     Security
@@ -1884,38 +1884,33 @@
 ger(
-conf.getS
+s
 hiro
+Ini
 Path
-()
 );%0A    
+  
 web
-A
+a
 pp.a
@@ -1953,25 +1953,24 @@
 t.ShiroFilte
-r
 .class, %22/ap
@@ -1970,36 +1970,24 @@
 s, %22/api/*%22,
-%0A           
  EnumSet.all
@@ -2013,25 +2013,26 @@
 lass));%0A
-%0A
+  
     web
-A
+a
 pp.addEv
@@ -2101,16 +2101,22 @@
 ener());
+%0A    %7D
 %0A%0A  %7D%0A%0A%7D

Align to master change