Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在tomcat 7中保护多个war文件_Java_Security_Tomcat7 - Fatal编程技术网

Java 如何在tomcat 7中保护多个war文件

Java 如何在tomcat 7中保护多个war文件,java,security,tomcat7,Java,Security,Tomcat7,我需要关于如何在我当前的Java网站上获得最大安全性的建议 我已经将这两个应用程序部署在Centos6服务器的8080端口上的tomcat-7的一个实例下 .war文件 website.war(上下文名称为ROOT) processor.war(上下文名称为processor) 批处理罐 batch.jar 安全要求 website.war可以公开访问。不需要保安 processor.war从website.war获取HTTP请求,并返回结果以供网站显示给用户 batch.jar在服务

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

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

.war文件

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

  • 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文件中将user和pass设置为“admin”角色的请求才能访问/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请求中的密码。我只想真正确保处理器的安全。所以

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

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

我是如何理解您在架构上将前端和后端分开的。前端没有安全漏洞,但您希望保护后端服务(或一些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;
              }



    }
}

如果您还不熟悉这一主题,那么本文可能会引起您的兴趣:我不知道这一点。谢谢你,保罗。我将实现摘要auth方法,而不是BASIC方法。应该是这样吧?我需要更多的安全性吗?这更像是一个系统管理任务:“front”tomcat,带有一个反向代理(如Apache),它打开端口80(或更好的443),代理您的网站war,如果需要,还可以访问processor.war的管理页面。将端口8080阻塞到除本地呼叫之外的所有端口。一旦有了基本的安全性,就无法调整授权