为了在Tomcat下进行SSL配置测试,这一切都是强制性的吗?
以下行来自网站:
为了对我们的测试执行此操作,请使用已在Tomcat中成功部署的任何应用程序,并首先通过http和https访问它以查看它是否正常工作.如果是,则打开该应用程序的web.xml,然后在web-app结束之前添加此XML片段,即
</web-app>
:Run Code Online (Sandbox Code Playgroud)<security-constraint> <web-resource-collection> <web-resource-name>securedapp</web-resource-name> <url-pattern>/*</url-pattern> </web-resource-collection> <user-data-constraint> <transport-guarantee>CONFIDENTIAL</transport-guarantee> </user-data-constraint> </security-constraint>
这个配置是否必须在web.xml文件中执行?
我正在使用Tomcat作为我的Struts2应用程序.在web.xml
如下所示具有一定的条目:
<security-constraint>
<web-resource-collection>
<web-resource-name>restricted methods</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>PUT</http-method>
<http-method>DELETE</http-method>
<http-method>TRACE</http-method>
</web-resource-collection>
<auth-constraint />
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>no_access</web-resource-name>
<url-pattern>/jsp/*</url-pattern>
</web-resource-collection>
<auth-constraint/>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>no_access</web-resource-name>
<url-pattern>/myrrunner/*</url-pattern>
</web-resource-collection>
<auth-constraint/>
</security-constraint>
Run Code Online (Sandbox Code Playgroud)
如何更改上面列入黑名单的部分只使用白名单部分...例如,我需要将其他方法列入白名单,而不是黑名单PUT
,DELTE
但我不确定将它们列入白名单的语法以及将它们列入白名单的方法.
对于我上面的web.xml
片段,我会很感激,如果有人可以为我提供whitelisitng对应部分xml
.
编辑:另外,我如何真正验证解决方案是否有效?
谢谢
我在web.xml中输入了以下安全约束.我的目标是XML文件位于Public区域.这适用于该/images/*
文件夹.但是url-pattern *.xml
似乎不起作用.有任何想法吗 ?
<security-constraint>
<web-resource-collection>
<web-resource-name>Public Area</web-resource-name>
<url-pattern>/xyz</url-pattern>
<url-pattern>/images/*</url-pattern>
<url-pattern>/yyz/*</url-pattern>
<url-pattern>*.xml</url-pattern>
</web-resource-collection>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>Super User Area</web-resource-name>
<url-pattern>/test/list1</url-pattern>
<url-pattern>/test/list2</url-pattern>
<url-pattern>/test/list3</url-pattern>
<url-pattern>/test/admin.html</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>SUPER_USER</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>Protected Area</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>ADMIN</role-name>
<role-name>END_USER</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<description>Super User</description>
<role-name>SUPER_USER</role-name>
</security-role>
<security-role>
<description>Admin User</description>
<role-name>ADMIN</role-name>
</security-role>
<security-role>
<description>End User</description>
<role-name>END_USER</role-name>
</security-role>
Run Code Online (Sandbox Code Playgroud) 我在缓存我的应用程序时遇到问题.
当此代码添加到tomcat的web.xml时:
<security-constraint>
<web-resource-collection>
<web-resource-name>HTTPSOnly</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
Run Code Online (Sandbox Code Playgroud)
我收到了这个回复:
Cache-Control private
Date Tue, 18 Feb 2014 01:18:17 GMT
Etag W/"200-1391558564593"
Expires Thu, 01 Jan 1970 00:00:00 WET
Server Apache-Coyote/1.1
Run Code Online (Sandbox Code Playgroud)
没有这个代码一切都很好:
Accept-Ranges bytes
Cache-Control max-age=604800
Content-Length 1496
Content-Type text/css
Date Tue, 18 Feb 2014 01:21:26 GMT
Etag W/"1496-1391558561359"
Expires Tue, 25 Feb 2014 01:21:27 GMT
Last-Modified Wed, 05 Feb 2014 00:02:41 GMT
Server Apache-Coyote/1.1
Run Code Online (Sandbox Code Playgroud)
谁能说出问题的原因?以及为什么这段代码将cache-controle更改为我的应用程序的私有.非常感谢
Tomcat 7.0
JDK : 1.6
Run Code Online (Sandbox Code Playgroud) 我需要在我的Application Server,Apache Tomcat 6.0上禁用PUT,DELETE和TRACE HTTP请求.
所有其他来源,我已经搜索到现在,已经指示我走向httpd.conf中的limit参数,因此我事先说明我没有使用Apache Web Server,并且请求直接由Tomcat处理,并且所以图片中没有httpd.conf.
请建议我如何在Tomcat上进行操作?
我正在尝试保护tomcat中的资源,以便只有"有效用户"(在域中具有有效登录名和密码的用户)才能访问它.它们不一定属于该领域的一个群体.我已尝试使用该<security-constraint>
指令的许多组合但未成功.有任何想法吗?
在研究servlet中的安全性约束和过滤器时,我在web.xml文件中做了以下声明,这些声明无法正常工作:
<security-constraint>
<web-resource-collection>
<web-resource-name>BeerSelector</web-resource-name>
<url-pattern>/SelectBeer.do</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>Admin</role-name>
</auth-constraint>
</security-constraint>
<filter>
<filter-name>LoginFilter</filter-name>
<filter-class>model.MyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>/SelectBeer.do</url-pattern>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)
根据我读到的内容:在请求到达某个url 之前应该遇到过滤器,那么,为什么首先调用security-constraint呢?
我知道从安全方面来说这是有意义的(要达到你认证的过滤器),但我想知道请求触发的序列.
容器是否首先搜索安全资源,从而触发安全约束?
但这与Head First Servlets和Jsp引用的以下段落相矛盾"
请记住,在DD中,是关于请求后发生的事情.换句话说,当Container开始查看元素以决定如何响应时,客户端已经发出请求.请求数据已通过网络发送
或者请求只是触发两者:filter和security-constraint,但是安全约束比过滤器更受青睐?
我已经使用Apache的htpasswd命令创建了一个用户数据库文件.此文件现在被其他几个应用程序使用,如apache和subversion.
用户是这样创建的:
htpasswd /path/to/users.htpasswd peter
Run Code Online (Sandbox Code Playgroud)
此用户文件是全局的,而不是每个目录.
如何让Tomcat 6使用同一个文件作为安全领域?
我正在开发的Web应用程序包含一些servlet以及JAX-RS Web服务.到目前为止,我使用ContainerRequestFilter来验证REST方法调用,但现在我还需要保护servlet,所以我决定使用web.xml来定义安全性约束.我的web.xml看起来像这样:
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<security-constraint>
<web-resource-collection>
<web-resource-name>rest</web-resource-name>
<url-pattern>/rest/*</url-pattern>
</web-resource-collection>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>protected</web-resource-name>
<url-pattern>/protected/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<role-name>admin</role-name>
</security-role>
<security-role>
<role-name>user</role-name>
</security-role>
<!-- Configure login to be HTTP Basic -->
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Restricted Zone</realm-name>
</login-config>
</web-app>
Run Code Online (Sandbox Code Playgroud)
如果我正确理解了web.xml的语法,我定义的意味着对于/ rest/*(我所有的JAX-RS方法都是)的访问权限就LoginModule而言是无限制的,并且对/ protected的访问权限都是/*path(我保留我的安全servlet)需要基本授权.
当我尝试打开其中一个安全servlet时,例如/ protected/test,我在浏览器中获得了基本的auth登录对话框,行为是正确的 - 如果我输入'admin'用户的凭据,我就可以访问.否则,我会收到"禁止"消息.
此外,当我尝试访问/ rest/path上的任何内容时,我没有得到任何基本的auth对话框,这就是我所期望的.但是,我在ContainerRequestFilter中获取的Authorization标头不是我在REST请求中发送的那个,而是我之前用于进入/ protected/servlet的那个.
以下是这个难题的其他部分:
standalone.xml(security-domains部分)
<security-domain name="PaloSecurityDomain" cache-type="default">
<authentication>
<login-module code="com.palo.security.PaloLoginModule" flag="required"/>
</authentication>
</security-domain>
Run Code Online (Sandbox Code Playgroud)
的jboss-web.xml中
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<security-domain>PaloSecurityDomain</security-domain>
</jboss-web>
Run Code Online (Sandbox Code Playgroud)
PaloLoginModule.java
package com.palo.security;
import java.security.acl.Group;
import java.util.Set;
import javax.inject.Inject; …
Run Code Online (Sandbox Code Playgroud) 我对安全约束的ajax重定向有这个奇怪的问题:
在会话超时后,在角色安全页面上进行ajax调用(通过单击可排序p:dataTable
列或p:poll
触发器)时,<partial-response><redirect-url=...
屏幕上会显示OmniFaces中的XML.
当我删除OmniFaces时,ajax调用似乎无声地失败,我没有显示XML.
安全性在web.xml中配置如下:
<security-constraint>
<web-resource-collection>
<web-resource-name>Pages</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>user</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>Resources</web-resource-name>
<url-pattern>/javax.faces.resource/*</url-pattern>
</web-resource-collection>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>myRealm</realm-name>
<form-login-config>
<form-login-page>/login.xhtml</form-login-page>
<form-error-page>/login.xhtml?error=true</form-error-page>
</form-login-config>
</login-config>
<security-role>
<role-name>user</role-name>
</security-role>
Run Code Online (Sandbox Code Playgroud)