- 浏览: 427118 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
Glogo:
楼主您好,我在试验您的代码的时候发现新开的三个子线程并没有一直 ...
java 高并发 ReentrantLock -- 可重入的锁 -
univasity:
最近发觉也被限速了,投诉一下就好一会~~ 看来明天又要和电信M ...
ADSL上网速度慢 都是帐号限速惹的祸 -
liuyuanhui0301:
java 高并发 ReentrantLock -- 可重入的锁 -
dang_java:
呵.很好的说明文档.
JXTA技术与应用发展 -
helloqidi:
谢谢,学习了
SQL中exists和in的区别
Why use a SecurityManager?
The Java SecurityManager is what allows a web browser to run an applet in its own sandbox to prevent untrusted code from accessing files on the local system, connecting to a host other than the one the applet was loaded from, etc.
In the same way the SecurityManager protects you from an untrusted applet running in your browser, use of a SecurityManager while running Tomcat can protect your server from trojan servlets, JSP's, JSP beans, and tag libraries. Or even inadvertent mistakes.
Imagine if someone who is authorized to publish JSP's on your site inadvertently included the following in their JSP:
<% System.exit(1); %>
Every time that JSP was executed by Tomcat, Tomcat would exit.
Using the Java SecurityManager is just one more line of defense a system administrator can use to keep the server secure and reliable.
System Requirements
Use of the SecurityManager requires a JVM that supports JDK 1.2.
Precautions
Implementation of a SecurityManager in Tomcat has not been fully tested to ensure the security of Tomcat. No special Permissions have been created to prevent access to internal Tomcat classes by JSP's, web applications, servlets, beans, or tag libraries. Make sure that you are satisfied with your SecurityManager configuration before allowing untrusted users to publish web applications, JSP's, servlets, beans, or tag libraries.
Still, running with a SecurityManager is definitely better than running without one.
Types of Permissions
Permission classes are used to define what Permissions a class loaded by Tomcat will have. There are a number of Permission classes as part of the JDK and you can even create your own Permission class for use in your own web applications.
This is just a short summary of the System SecurityManager Permission classes applicable to Tomcat. Please refer to the JDK documentation for more information on using the below Permissions.
java.util.PropertyPermission
Controls read/write access to JVM properties such as java.home.
java.lang.RuntimePermission
Controls use of some System/Runtime functions like exit() and exec().
java.io.FilePermission
Controls read/write/execute access to files and directories.
java.net.SocketPermission
Controls use of network sockets.
java.net.NetPermission
Controls use of multicast network connections.
java.lang.reflect.ReflectPermission
Controls use of reflection to do class introspection.
java.security.SecurityPermission
Controls access to Security methods.
java.security.AllPermission
Allows access to all permissions, just as if you were running Tomcat without a SecurityManager.
Configuring Tomcat for use with a SecurityManager
tomcat.policy
The security policies implemented by the Java SecurityManager are configured in the tomcat.policy file located in the tomcat conf
directory. The tomcat.policy file replaces any system java.policy file. The tomcat.policy file can be edited by hand or you can use the policytool application that comes with Java 1.2, or later.
Entries in the tomcat.policy file use the standard java.policy file format as follows:
// Example policy file entry grant [signedBy <signer> [,codeBase <code source>] { permission <class> [<name> [, <action list>]]; }; |
The signedBy and codeBase entries are optional when granting permissions. Comment lines begin with // and end at a new line.
The codeBase is in the form of a URL and for a file URL can use the ${java.home} and ${tomcat.home} properties which are expanded out to the directory paths defined for them.
Default tomcat.policy file
// Permissions for tomcat. // javac needs this grant codeBase "file:${java.home}/lib/-" { permission java.security.AllPermission; }; // Tomcat gets all permissions grant codeBase "file:${tomcat.home}/lib/-" { permission java.security.AllPermission; }; grant codeBase "file:${tomcat.home}/classes/-" { permission java.security.AllPermission; }; // Example webapp policy // By default we grant read access on webapp dir // and read of the line.separator PropertyPermission grant codeBase "file:${tomcat.home}/webapps/examples" { permission java.net.SocketPermission "localhost:1024-","listen"; permission java.util.PropertyPermission "*","read"; }; |
Here is an example where in addition to the above, we want to grant the examples web application the ability to connect to the localhost smtp port so that it can send mail.
grant codeBase "file:${tomcat.home}/webapps/examples" { permission java.net.SocketPermission "localhost:25","connect"; permission java.net.SocketPermission "localhost:1024","listen"; permission java.util.PropertyPermission "*","read"; }; |
Now what if we wanted to give all contexts not configured by their own grant entry some default permissions in addition to what Tomcat assigns by default.
grant { permission java.net.SocketPermission "localhost:1024","listen"; permission java.util.PropertyPermission "*","read"; }; |
Finally, a more complex tomcat.policy file. In this case we are using Tomcat as an app server for a number of remote web servers. We want to limit what remote web servers can connect to Tomcat by using the Java SecurityManager.
// Permissions for tomcat. // javac needs this grant codeBase "file:${java.home}/lib/-" { permission java.security.AllPermission; }; // Tomcat with IP filtering grant codeBase "file:${tomcat.home}/lib/-" { // Tomcat should be able to read/write all properties permission java.util.PropertyPermission "*","read,write"; // Tomcat needs to be able to read files in its own directory permission java.io.FilePermission "${tomcat.home}/-","read"; // Tomcat has to be able to write its logs permission java.io.FilePermission "${tomcat.home}/logs/-","read,write"; // Tomcat has to be able to write to the conf directory permission java.io.FilePermission "${tomcat.home}/conf/-","read,write"; // Tomcat has to be able to compile JSP's permission java.io.FilePermission "${tomcat.home}/work/-","read,write,delete"; // Tomcat needs all the RuntimePermission's permission java.lang.RuntimePermission "*"; // Needed so Tomcat can set security policy for a Context permission java.security.SecurityPermission "*"; // Needed so that Tomcat will accept connections from a remote web server // Replace XXX.XXX.XXX.XXX with the IP address of the remote web server permission java.net.SocketPermission "XXX.XXX.XXX.XXX:1024-","accept,listen,resolve"; // Tomcat has to be able to use its port on the localhost permission java.net.SocketPermission "localhost:1024-","connect,accept,listen,resolve"; }; // Example webapp policy // By default we grant read access on webapp dir // and read of the line.separator PropertyPermission grant codeBase "file:${tomcat.home}/webapps/examples" { permission java.net.SocketPermission "localhost:1024-","listen"; permission java.util.PropertyPermission "*","read"; }; |
Starting Tomcat with a SecurityManager
Once you have configured the tomcat.policy for use with a SecurityManager, Tomcat can be started with the SecurityManager in place by adding the "-security" option to bin/startup.bat or bin/startup.
What happens when the SecurityManager detects a Security violation?
The JVM will throw an AccessControlException or a SecurityException when the SecurityManager detects a security policy violation.
Trouble shooting tomcat.policy configuration and Security Violations
You can turn on Java SecurityManager debug logging by setting the environmental variable:
TOMCAT_OPTS=-Djava.security.debug=all
The debug output will be written to Tomcat's log file, or the console if no log file is defined.
Note: This gives the most complete debugging information, but generates many MB's of output, for less verbose security debug output, use:
TOMCAT_OPTS=-Djava.security.debug=access,failure
Use the following shell command to determine all the security debug options available: java -Djava.security.debug=help
JSP Compile using JVM internal javac fails with AccessControlException for RuntimePermission accessClassInPackage sun.tools.javac.
Check your JAVA_HOME/jre/lib/security/java.security file configuration. Comment out the line "package.access=sun.".
发表评论
-
深入JVM锁机制
2011-09-19 01:00 971目前在Java中存在两种 ... -
java 正则表达式 非捕获组(特殊构造)Special Constructs(Non-Capturing)
2011-06-20 23:15 1640针对Java API文档中的正则表达式关于特殊构造(非捕获组) ... -
Java文件映射[mmap]揭秘
2011-06-08 20:10 1169前言 相信现在 ... -
原创 java的Mmap二三事
2011-06-08 19:46 1195转自 :http://blog.csdn.net/kabini ... -
java 安全沙箱模型详解
2011-04-18 16:29 936起到第一道安全保障作 ... -
非阻塞算法-ReentrantLock代码剖析之ReentrantLock.lock
2011-04-15 13:59 1078ReentrantLock是java.util.concurr ... -
CyclicBarrier与CountDownLatch、栅栏与计数器
2011-04-15 10:39 1460在多线程设计中,我猜常常会遇到线程间相互等待以及某个线程等待1 ... -
Java KeyStore
2011-04-13 17:17 1463简介Java自带的keytool工具是个密钥和证书管理工具。它 ... -
Security Managers and the JavaTM 2 SDK
2011-04-12 13:37 771The original Link : http://do ... -
Something about SecurityManager
2011-04-12 13:33 779The Java Security was made up o ... -
Java安全管理器(Security Manager)(
2011-04-11 14:54 881转载自: http://blog.sina.com.cn/s/ ... -
Java对象的强、软、弱和虚引用(1)
2011-04-01 08:44 795本文介绍Java对象的强 ... -
Java对象的强引用、软引用、弱引用和虚引用
2011-04-01 08:39 902在JDK1.2以前的版本中, ... -
java 高并发 ReentrantLock -- 可重入的锁
2011-03-30 08:09 2364ReentrantLock -- 可重入的锁 可重入锁指 ... -
线程运行栈信息的获取
2011-03-24 17:23 1306线程运行栈信息的获取 ... -
java序列化——Serializable
2011-03-15 23:17 1068类通过实现 java.io.Serializable 接口 ... -
Java aio(异步网络IO)初探
2011-03-11 16:34 1560按照《Unix网络编程》的 ... -
JAVA NIO 简介
2011-03-11 13:38 11121. 基本 概念 IO 是主存和外部设备 ( 硬盘、终 ... -
[字节码系列]ObjectWeb ASM构建Method Monitor
2011-03-08 18:08 894在前面的篇章中,我们看到Java Instru ... -
深入了解Java ClassLoader、Bytecode 、ASM、cglib
2011-03-08 16:35 855一、Java ClassLoader 1,什 ...
相关推荐
在Java编程语言中,`SecurityManager`(安全管理器)是一个重要的安全组件,它允许开发者对应用程序的安全性进行精细控制。`SecurityManager`是Java虚拟机(JVM)的一部分,用于实施一套安全策略,以防止代码执行...
Tomcat 7.0是Apache软件基金会的Jakarta项目下的一个开源Java Servlet容器,它实现了Java Servlet和JavaServer Pages(JSP)规范,为Web应用程序提供服务。本笔记主要涵盖了在Linux环境下安装和配置Tomcat 7.0以及...
5. 与Apache Web Server的集成(第5章:Integration with the Apache Web Server): - 探讨了集成的优缺点。 - 提供了安装和配置Apache与Tomcat集成的具体步骤。 - 讨论了通过APR(Apache Portable Runtime)...
Advanced Programming for the Java 2 Platform.chm 里边有很多不怎么为人所知的东西,时常参考,还是蛮有好处的 Chapter 1: Matching Project Requirements with Technology <br>Project Requirements ...
Tomcat,作为Apache软件基金会的顶级项目,是Java Servlet和JavaServer Pages(JSP)的开源Web应用服务器,被广泛应用于中小型企业的Web服务部署。7.0.59版本是Tomcat的一个稳定版本,提供了良好的性能和兼容性。...
Apache Tomcat是一个开源的软件应用服务器,主要用于运行Java Servlet和JavaServer Pages(JSP)应用程序。它是Apache软件基金会Jakarta项目的一部分,以其轻量级、高效和稳定的性能而受到广泛欢迎。标题中的"apache...
在IT行业中,Tomcat是一个广泛使用的开源Web服务器和Java应用服务器,特别适合于运行Servlet和JSP应用。这里我们关注的是Tomcat 6版本,它在2009年发布,是许多企业和个人开发者的选择。在Linux环境中部署Tomcat6时...
Tomcat 6.0.14提供了安全管理器功能,通过修改conf/server.xml中的`<SecurityManager>`元素启用,并配置相应的角色和权限,确保只有授权用户才能访问特定资源。 五、监控与优化 Tomcat内置的JMX(Java Management ...
【标题】"Tomcat6.0程序包"是Apache软件基金会开发的一款开源的Java Servlet容器,主要用于运行Java Web应用程序。这个版本的Tomcat是6.0.26,发布于2010年,它是对早期版本的改进,提供了一些新特性和性能优化。 ...
在Java 7及更高版本中,可以使用try-with-resources语句自动关闭资源。 这个实例的代码可能包含了这些步骤的实现,以展示如何在Java中进行文件权限控制。通过分析和学习这个源码,你可以更好地理解Java的安全模型...
- **SecurityManager配置**:Tomcat提供了一个内置的SecurityManager组件,它可以控制Java安全策略文件中的策略设置,从而增强安全性。 - **Valve组件**:Valve是Tomcat的一个组件,用于实现过滤器功能。可以通过...
Apache Tomcat是一款开源的Java Servlet容器,它实现了Java EE中的Web应用服务器规范,特别是Servlet和JSP标准。源代码分析是深入理解Tomcat工作原理、性能优化和自定义配置的关键。下面将对Tomcat源码进行详细的...
Java的权限模型在1.6中进一步完善,包括了Policy类、SecurityManager类和Permission类,用于控制代码的执行权限。 这个“Java API 1.6中文手册.chm”文件提供了所有这些知识点的详细文档,便于开发者查询和学习。...
此外,Java安全经理(SecurityManager)可以进一步定制安全策略,控制程序的运行行为。 多线程在网络编程中尤为重要,Java提供了丰富的多线程支持。通过继承Thread类或者实现Runnable接口,开发者可以创建并管理多...
同时,我们也可以使用 Tomcat 的安全机制,例如使用 SecurityManager 来限制访问权限。 本文对 Servlet 内存马的工作原理和实现机制进行了详细的分析和解释,并对其实现机制进行了详细的分析和解释。
在Java中,安全管理器(SecurityManager)是控制权限的核心组件。如果一个应用程序设置了安全管理器,那么所有可能引起安全问题的操作都会被检查,看是否拥有执行该操作的相应权限。如果没有,将会抛出...
Apache Shiro 是一个强大且易用的 Java 安全框架,提供认证、授权、加密和会话管理功能,简化了企业级应用的安全实现。在 Shiro 中,`SecurityManager` 是核心组件,它负责整个安全体系的管理和协调工作。本文将深入...
如AccessController、Permission和SecurityManager等类,用于控制代码的执行权限,防止恶意代码的运行。 10. **JavaBeans**:JavaBeans是一种可重用的软件组件,可以通过JavaBeans API进行序列化和属性访问,常用于...
Java提供了丰富的安全相关的API,如java.security包下的Permission、SecurityManager、Policy等类。Permission类用于表示特定的操作权限,SecurityManager是实现自定义安全策略的接口,Policy类则用来存储和管理系统...
Java 对通过网络下载的类具有一个安全防范机制(类 ClassLoader),如分配不同的名字空间以防替代本地的同名类、字节代码检查,并提供安全管理机制(类 SecurityManager)让 Java 应用设置安全哨兵。 Java 语言是可...