【问题标题】:How to secure multiple war files in tomcat 7如何保护tomcat 7中的多个war文件
【发布时间】:2013-07-23 07:11:57
【问题描述】:

我需要有关如何在当前 Java 网站上获得最大安全性的建议。

我已将这两个应用程序部署在 Centos6 服务器上端口 8080 上的一个 tomcat-7 实例下。

.war 文件

  • website.war(上下文名称为 ROOT)
  • processor.war(上下文名称是处理器)

批处理罐

  • batch.jar

安全要求

  • website.war 可公开访问。无需安保
  • processor.war 从 website.war 获取 HTTP 请求并返回结果供网站显示给用户。
  • batch.jar 在服务器的后台运行,所以我想除了安全服务器之外不需要任何安全措施。

目前我已添加到 processor.war 的 web.xml 以保护以下内容

  • 只有在 tomcat-users.xml 文件中设置了 user 和 pass 并设置了 'user' 角色的请求才能访问 /process url。
  • 只有在 tomcat-users.xml 文件中设置了“admin”角色的 user 和 pass 的请求才能访问 /admin url。

这是我对 processor.war 的 web.xml 文件的配置。

  <security-constraint> 
    <web-resource-collection> 
        <web-resource-name>Admin</web-resource-name> 
        <url-pattern>/*</url-pattern> 
    </web-resource-collection>
    <auth-constraint> 
        <role-name>admin</role-name> 
    </auth-constraint>
 </security-constraint> 
  <security-constraint> 
    <web-resource-collection> 
        <web-resource-name>Public</web-resource-name> 
        <url-pattern>/processor/process*</url-pattern> 
    </web-resource-collection>
    <auth-constraint>
        <role-name>user</role-name>
        <role-name>admin</role-name>
    </auth-constraint>
  </security-constraint>

这足够安全吗?我读过攻击者可以欺骗请求并读取 HTTP 请求中的密码。我只想真正保护processor.war,以便

  • 只有 website.war (localhost:8080) 可以将请求发送到 processor.war localhost:8080/processor/process
  • 并且只有管理员用户可以访问 localhost:8080/processor/admin 页面。

有人可以告诉我是否需要更多的安全性,如果是,我能做些什么来保护它?

【问题讨论】:

  • 如果您还不熟悉该主题,可能会对这篇文章感兴趣:Tomcat – Digest Authentication
  • 我不知道这个。非常感谢保罗。我将实现 DIGEST auth-method 而不是 BASIC。这应该是吧?我需要更多的安全保障吗?
  • 这更像是一个系统管理员任务:带有反向代理(如 Apache)的“前端”tomcat,它打开端口 80(或更好的 443)和代理到您的网站战争,如果需要,管理页面你的processor.war。将端口 8080 阻止给除本地呼叫之外的所有人。一旦你有了基本的安全,你就不能调整授权

标签: java security tomcat7


【解决方案1】:

我是如何理解架构上的,您已将前端与后端分开。前端没有安全漏洞,但你想保护你的后端服务(或一些 html、css、js 文件,如果存在)

如果您能以可理解的方式做到这一点,请解释为什么需要这种方法?

Tomcat 是一个 Servlet 容器,这意味着这里的所有东西都是纯 Java。这就是您可以轻松保护您喜欢的任何 URL 的原因。或者您可以构建自我(自定义)角色或基于权限的安全系统。此外,在过滤器接口的帮助下,您可以过滤应用服务器特定应用程序 (WAR) 中任何请求的文件的任何 URL。

这是一个简单的例子:

@WebFilter("/secured/*")
public class LoginFilter implements Filter {

    /**
     * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
     */
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println(" loginFilter servlet begin ");
          HttpServletResponse httpResponse = (HttpServletResponse) response;
          HttpServletRequest httpRequest = (HttpServletRequest) request;
          String URI = ((HttpServletRequest)request).getRequestURI();
          HttpSession session =httpRequest.getSession(false);
          String emailFromWeb = null;
          String loginURL = httpRequest.getContextPath() + "/login.html";
          String rootURL = httpRequest.getContextPath() + "/secured/root.html";
          String userURL = httpRequest.getContextPath() + "/secured/user.html";
          String logoutURL=httpRequest.getContextPath() + "/logout";

          if(session==null){
              System.out.println("false inquery session is null");
              httpResponse.sendRedirect(loginURL);
              return;

          }
          emailFromWeb  = session.getAttribute("email").toString();     

          System.out.println(" email from Session "+emailFromWeb);


              if  (httpRequest.getRequestURI().equals(loginURL)){
                  System.out.println("login page inquery");
                  chain.doFilter(request, response);
                  return;
              } 
              if(httpRequest.getRequestURI().matches(".*(css|jpg|png|gif|js)")){
                    System.out.println(" inquery by "+httpRequest.getRequestURI());
                    chain.doFilter(request, response);
                    return;
                }

              if (httpRequest.getRequestURI().equals(rootURL)&&Authentication.isPermitted(emailFromWeb, "RootPage")) {
                  System.out.println("root page inquery");
                  chain.doFilter(request, response);
                  return;
              } 

              else if(httpRequest.getRequestURI().equals(userURL)&&Authentication.isPermitted(emailFromWeb, "UserPage")){
                  System.out.println("user page inquery");
                  chain.doFilter(request, response);
                  return;
              }
              else if(httpRequest.getRequestURI().equals(logoutURL)){
                  System.out.println("logout inquery");
                  httpResponse.sendRedirect(loginURL);
                  return;
              }
              else {
                  System.out.println("false inquery");
                  httpResponse.sendRedirect(loginURL);
                  return;
              }



    }
}

【讨论】:

    猜你喜欢
    • 2011-07-03
    • 1970-01-01
    • 2014-05-02
    • 1970-01-01
    • 1970-01-01
    • 2013-10-25
    • 2018-02-13
    • 1970-01-01
    相关资源
    最近更新 更多