securitymanager

Should I use Security Manager in Java web applications?

强颜欢笑 提交于 2019-12-04 04:39:22
Is it sufficient to secure a Java web application with the rights of the user that is running the application server process or is it reasonable also to use SecurityManager with a suitable policy file? I have used to do the former and not the latter, but some customers would like us to also use SecurityManager that would explicitly give permissions to every third-party component to be sure there isn't any evil code lurking there. I've seen some Servlet containers, like Resin to propose not using SecurityManager to slow things up. Any thoughts? While I hate to ever recommend not using a

Tomcat console log to a file

安稳与你 提交于 2019-12-04 03:29:54
问题 Im using Apache Tomcat 7 . When I'm running Tomcat with security manager and with the -Djava.security.debug parameter I'm getting so much of text in console. I can't read the text in console. So I need the console log into some file . How can I achieve this? 回答1: Remove ConsoleHandler from logging configuration. In conf/logging.properties : Change this - .handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler To this - .handlers = 1catalina.org.apache.juli

SecurityException from I/O code in a parallel stream

让人想犯罪 __ 提交于 2019-12-04 02:38:24
I have no way to explain this one, but I found this phenomenon in somebody else's code: import java.io.IOException; import java.io.UncheckedIOException; import java.nio.file.Files; import java.util.stream.Stream; import org.junit.Test; public class TestDidWeBreakJavaAgain { @Test public void testIoInSerialStream() { doTest(false); } @Test public void testIoInParallelStream() { doTest(true); } private void doTest(boolean parallel) { Stream<String> stream = Stream.of("1", "2", "3"); if (parallel) { stream = stream.parallel(); } stream.forEach(name -> { try { Files.createTempFile(name, ".dat"); }

shiro与spring的整合

会有一股神秘感。 提交于 2019-12-04 00:58:59
shiro与spring的整合 上一期,我们分享了如何在项目中使用shiro,了解了shiro的基本用法,但毕竟学习shiro的目的就是在项目中应用shiro,更准确地说是在web项目中应用shiro。那么,今天我们就来探讨一下shiro在spring web项目中的应用,这里依然参考官方sample部分的代码。好了,废话少说,直接开战。 spring xml方式 首先当然是创建spring项目,这里提供两种方案,一种是通过xml配置的spring项目,一种是纯注解的spring项目。先来说xml配置的方式,为什么要说xml的方式,因为在实际项目应用中,很多公司目前运行的方式还是xml配置的方式,为了我们更好的上手,更好地工作,我们先将xml的方式,当然也是因为目前我们公司采用的就是xml配置的方式。好了,让我们还是吧! 一、创建spring项目(xml方式) 关于spring项目的创建,这里不做过多说明,但我会放上自己的项目结构和各类配置。 pom.xml文件 先创建web项目 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi

shiro异步请求返回JSON响应

蓝咒 提交于 2019-12-03 09:35:38
shiro异步请求返回JSON响应 需求1:当shiro请求资源,但是没有进行认证时,默认是进行重定向,现在需要返回JSON响应。注意异步请求,服务器重定向后,ajax拿到的是浏览器重定向后的到的页面源码。 解决2: 自定义FormAuthenticationFilter。覆盖onAccessDenied方法。返回JSON字符串。并将自定义的过滤器添加到ShiroFilterFactoryBean,键的名称为authc。 需求2:ShiroFilterFactoryBean用注解时,过滤的urls被写死在代码中,需要将urls的配置放到配置文件中。 解决2: 方法1:ShiroFilterFactoryBean不使用注解方法,而是xml配置注入。@ImportResource("classpath:shiro/shiro-config.xml") 方法2:自己通过shiro的Ini类加载ini配置文件。读取自定义的urls。 步骤 自定义 authc 对应过滤器 FormAuthenticationFilter。覆盖 onAccessDenied 方法返回JSON响应。 将自定义过滤器添加到 ShiroFilterFactoryBean。名称为 authc 。 ResultFormAuthenticationFilter package com.mozq.shiro.shiro01

shiro源码分析2

醉酒当歌 提交于 2019-12-03 09:08:07
简介 SecurityManager:安全管理器,Shiro最核心组件。Shiro通过SecurityManager来管理内部组件实例,并通过它来提供安全管理的各种服务。 Authenticator:认证器,认证AuthenticationToken是否有效。 Authorizer:授权器,处理角色和权限。 SessionManager:Session管理器,管理Session。 Subject:当前操作主体,表示当前操作用户。 SubjectContext:Subject上下文数据对象。 AuthenticationToken:认证的token信息(用户名、密码等)。 ThreadContext:线程上下文对象,负责绑定对象到当前线程。 在学习和使用Shiro过程中,我们都知道SecurityManager接口在Shiro中是最为核心的接口。我们就沿着这个接口进行分析。 下面的代码是SecurityManager接口的定义: public interface SecurityManager extends Authenticator, Authorizer, SessionManager { /** * 登录 */ Subject login(Subject subject, AuthenticationToken authenticationToken) throws

Running Java Security Manager without the default java.policy file

ⅰ亾dé卋堺 提交于 2019-12-03 08:43:21
I don't want to modify anything in my java home directory, however, I am afraid that sometimes my default java.policy file may be too permissive. Is there a way for me to use a specified policy file as the only policy file when I run java with the -Djava.security.manager option? If I add a -Djava.security.policy=myPolicy.policy option, it uses my policy file in addition to the default policy file -- which is bad because it looks like all permissions granted in the default policy file is still granted. A Common Mistake with Java SecurityManager : To run with SecurityManager and default Java

shiro源码分析

五迷三道 提交于 2019-12-03 08:15:54
简介 SecurityManager:安全管理器,Shiro最核心组件。Shiro通过SecurityManager来管理内部组件实例,并通过它来提供安全管理的各种服务。 Authenticator:认证器,认证AuthenticationToken是否有效。 Authorizer:授权器,处理角色和权限。 SessionManager:Session管理器,管理Session。 Subject:当前操作主体,表示当前操作用户。 SubjectContext:Subject上下文数据对象。 AuthenticationToken:认证的token信息(用户名、密码等)。 ThreadContext:线程上下文对象,负责绑定对象到当前线程。 在学习和使用Shiro过程中,我们都知道SecurityManager接口在Shiro中是最为核心的接口。我们就沿着这个接口进行分析。 下面的代码是SecurityManager接口的定义: public interface SecurityManager extends Authenticator, Authorizer, SessionManager { /** * 登录 */ Subject login(Subject subject, AuthenticationToken authenticationToken) throws

How to sanely configure security policy in Tomcat 6

佐手、 提交于 2019-12-03 02:55:15
I'm using Tomcat 6.0.24, as packaged for Ubuntu Karmic. The default security policy of Ubuntu's Tomcat package is pretty stringent, but appears straightforward. In /var/lib/tomcat6/conf/policy.d , there are a variety of files that establish default policy. Worth noting at the start: I've not changed the stock tomcat install at all -- no new jars into its common lib directory(ies), no server.xml changes, etc. Putting the .war file in the webapps directory is the only deployment action. the web application I'm deploying fails with thousands of access denials under this default policy (as

AccessController usage

匿名 (未验证) 提交于 2019-12-03 02:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying understand the basics of java security and AccessController.doPrivileged() usage i started with a sample program import java.security.AccessController; import java.security.PrivilegedAction; public class AccessSystemProperty { public static void main(String[] args) { System.out.println(System.getSecurityManager()); AccessController.doPrivileged( new PrivilegedAction<Boolean>(){ public Boolean run(){ System.out.println(System.getProperty("java.home")); return Boolean.TRUE; } } ); } } if i try to run above code using default