securitymanager

Spring Boot整合Shiro

耗尽温柔 提交于 2019-11-27 19:14:45
概述 4A(认证Authentication、授权Authorization、账号Account、审计Audit)是现代任何IT系统中很基础但非常重要的部分,无论是传统管理信息系统还是互联网项目,出于保护业务数据和应用自身的安全,都会设计自己的登录和资源授权策略。最近项目中需要登录和权限相关的功能,项目为spring-boot工程,现在流行的权限验证框架有shiro和spring-security,shiro相对spring-security来说学习难度要低一点,也是比较成熟的产品,因此选择shiro作为项目的权限验证框架。 步骤 添加依赖 spring boot的版本为2.1.7.RELEASE。如果大量依赖spring的项目,可以用https://start.spring.io/ patchca是验证码部分 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.7.RELEASE</version> </parent> shiro-spring是用的最新的版本。patchca是用于验证码。 <dependencies> <dependency> <groupId>org

Java security: Sandboxing plugins loaded via URLClassLoader

倖福魔咒の 提交于 2019-11-27 11:28:25
Question summary: How do I modify the code below so that untrusted, dynamically-loaded code runs in a security sandbox while the rest of the application remains unrestricted? Why doesn't URLClassLoader just handle it like it says it does? EDIT: Updated to respond to Ani B. EDIT 2: Added updated PluginSecurityManager. My application has a plug-in mechanism where a third party can provide a JAR containing a class which implements a particular interface. Using URLClassLoader, I am able to load that class and instantiate it, no problem. Because the code is potentially untrusted, I need to prevent

springboot + shiro 构建权限模块

最后都变了- 提交于 2019-11-27 08:29:58
  权限模块基本流程   权限模块的基本流程:用户申请账号和权限 -->登陆认证 -->安全管控模块认证 -->调用具体权限模块(基于角色的权限控制) --> 登陆成功 -->访问资源 -->安全模块鉴权 -->通过后获取资源。整个流程如下图   常用的两个安全管控模块比较   JAAS,java验证和授权模块,jdk提供的一套标准的方法,对于有异构分布式的大型企业推荐这个框架,很多开源项目的安全框架就是JAAS,例如CAS 、tomcat、activemq等。   spring security,市场占有率最高的框架,支持范围广、功能更强大,但是学习比较复杂,成本比较高,跟spring框架绑定,无法在非spring项目中使用,对于安全需求复杂、支持范围广的项目可以使用。   shiro,简单易学,功能对于一般的web项目已经足够,相对独立,可用于非Spring的项目。   shiro基础知识   shiro扩展性很强,我们可以实现自己的realms、sessionDao、cachemanager以及自定义过滤器来实现个性化需求,其架构图如下:   shiro的核心概念有:   subject:用户,这个用户不一定使人,而是指任何与当前系统交互的对象   principal:身份标示,表示主体的抽象概念,可以用来表示任何实体,如username、ID、phone等  

why java security manager doesn't forbid neither creating new Thread() nor starting it?

雨燕双飞 提交于 2019-11-27 04:52:58
do you happen to know explanation why java security manager doesn't forbid creating new threads or starting them? new FileWriter is under security manager, but neither new Thread(), nor threadInstance.start() isn't uneder security manager, and are possible to call. Wouldn't it be usefull to forbid it ? Would it be hard to implement ? Or creating and starting new Thread isn't so relevant to forbid it? There is an access check performed in the Thread constructor to see if the caller has permission to change the ThreadGroup that the new thread would be added to. That is how you would implement a

Disable Java reflection for the current thread

青春壹個敷衍的年華 提交于 2019-11-27 04:31:19
I need to call some semi-trustworthy Java code and want to disable the ability to use reflection for the duration of that code's execution. try{ // disable reflection somehow someObject.method(); } finally{ // enable reflection again } Can this be done with a SecurityManager, and if so, how? Clarification/Context: This is a follow-up to another question about restricting the packages that can be called from JavaScript/Rhino. The accepted answer references a blog entry on how to do that, and it requires two steps, the first one using a Rhino API (ClassShutter), the second one turning off

Shiro安全框架(二)——身份认证

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 02:23:08
Shiro使用指定的验证Realm 1.Subject认证主体 Subject认证 包含两个信息: Principals:身份,可以是用户名,邮件,手机号码等等,用来标识一个登录主体身份; Credentials:凭证,常见有密码,数字证书等等; 2.身份认证流程 3.Realm&JdbcRealm Realm:域,Shiro从Realm中获取验证数据; Realm有很多种类,例如常见的JdbcRealm,JndiRealm,TextRealm; 这里我们使用JdbcRealm。 首先,创建数据库和表: 添加druid,mysql 驱动依赖坐标: <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.6</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.0.26</version> </dependency> 在resources目录下创建jdbc_realm.ini配置文件 [main] jdbcRealm=org.apache.shiro.realm.jdbc

Reflection Security

早过忘川 提交于 2019-11-27 01:46:31
问题 How to enforce reflection security by not allow the Method , Field , Constructor object to call setAccessible(true) ? SecurityPolicy File or something else? Normally for stand-alone Java applications there is no SecurityManager registered. I using this System.setSecurityManager(new SecurityManager()); This approach will work for calling methods. I would like to enforce the whole jar or client code that uses the jar is not allow to call setAccessible(true); Any better approach ? Thanks. 回答1:

Java: no security manager: RMI class loader disabled

谁说我不能喝 提交于 2019-11-27 01:33:56
Hi I have RMI application and now I try to invoke some methods at server from my client. I have following code: public static void main(final String[] args) { try { //Setting the security manager System.setSecurityManager(new RMISecurityManager()); IndicatorsService server = (IndicatorsService) Naming .lookup("rmi://localhost/" + IndicatorsService.SERVICE_NAME); DataProvider provider = new OHLCProvider(server); server.registerOHLCProvider(provider); } catch (MalformedURLException e) { e.printStackTrace(); } catch (RemoteException e) { e.printStackTrace(); } catch (NotBoundException e) { e

Is there a way for a SecurityManager in java to selectively grant ReflectPermission(“suppressAccessChecks”)?

两盒软妹~` 提交于 2019-11-26 21:23:36
问题 Is there any way for a SecurityManager in Java to selectively grant ReflectPermission("suppressAccessChecks") depending on the details of what setAccessible() is being called on? I don't see any way for this to be done. For some sandboxed code, it would be very useful (such as for running various dynamic JVM languages) to allow the setAccessible() reflection API to be called, but only when setAccessible() is called on a method/field of a class that originates in the sandboxed code. Does

SpringBoot2.0集成Shiro

混江龙づ霸主 提交于 2019-11-26 20:49:46
1、shiro的三个核心概念:   1)Subject:代表当前正在执行操作的用户,但Subject代表的可以是人,也可以是任何第三方系统帐号。当然每个subject实例都会被绑定到SercurityManger上。   2)SecurityManger:SecurityManager是Shiro核心,主要协调Shiro内部的各种安全组件,这个我们不需要太关注,只需要知道可以设置自定的Realm。   3)Realm:用户数据和Shiro数据交互的桥梁。比如需要用户身份认证、权限认证。都是需要通过Realm来读取数据。 2、springboot中集成shiro相对简单,只需要两个类:一个是ShiroConfig类,一个是自定义Realm类。   1)ShiroConfig类:shiro的一些配置,相对于之前的xml配置。包括: ShiroFilter 的配置,密码加密的算法,支持注解的配置等功能。   2)自定义Realm类:继承AuthorizingRealm。并且重写父类中的doGetAuthorizationInfo(权限认证)、doGetAuthenticationInfo(身份认证)这两个方法。 3、demo   项目结构:      依赖: <dependency> <groupId>org.apache.shiro</groupId> <artifactId