securitymanager

前后端分离 springboot整合shiro

耗尽温柔 提交于 2019-12-07 15:43:27
实现前后端的跨域,我是在后端配置类里实现 创建配置类 WebMvcConfig import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; // 配置全局跨域 @Configuration public class WebMvcConfig implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowedOrigins("http://localhost:8081") .allowedMethods("*") .allowedHeaders("*") .allowCredentials(true); } } Shiro的配置 创建配置类 ShiroConfig import cn.xej.util

NoClassDefFoundError when creating objects under SecurityManager

牧云@^-^@ 提交于 2019-12-07 07:32:26
问题 I'm trying to secure my application by running the bits of code that deal with user-provided content under a very restrictive SecurityManager. It's AccessController.doPrivileged() turned on its head - normally this is used to provide a block of code with extra permissions but I'm using it to constrain a block of code to a very small sandbox. Everything is fine until I need to call a constructor. Then I need read-access to the world. (Or at least to all of the .jar, .class and .property files

带你揭秘Shiro(二)

无人久伴 提交于 2019-12-06 15:07:44
授权流程 1、对subject进行授权,调用方法isPermitted("permission串") 2、SecurityManager执行授权,通过ModularRealmAuthorizer执行授权 3、ModularRealmAuthorizer执行realm(自定义的Realm)从数据库查询权限数据,调用realm的doGetAuthorizationInfo授权方法 4、realm从数据库查询权限数据,返回ModularRealmAuthorizer 5、ModularRealmAuthorizer调用PermissionResolver进行权限串比对 6、如果比对后,isPermitted中"permission串"在realm查询到权限数据中,说明用户访问permission串有权限,否则 没有权限,抛出异常。 修改之前realmDemo.java中的doGetAuthorizationInfo方法 // 用于授权 @Override protected AuthorizationInfo doGetAuthorizationInfo( PrincipalCollection principals) { // 从 principals获取主身份信息 // 将getPrimaryPrincipal方法返回值转为真实身份类型

JVM Security Manager File permissions - custom policy

£可爱£侵袭症+ 提交于 2019-12-06 14:27:26
I've found a somehow unexpected behaviour using JVM Security Manager custom policies. repo: https://github.com/pedrorijo91/jvm-sec-manager in branch master, go into the /code folder: custom policy file grants File read permission for file ../allow/allow.txt no permission for the file ../deny/deny.txt the code in the HelloWorld.java tries to read both files There's a run.sh script to run the command Now everything works as expected: the allowed file reads, but the other throws a security exception: java.security.AccessControlException: access denied ("java.io.FilePermission" "../deny/deny.txt"

Shiro-Subject 分析(转)

六眼飞鱼酱① 提交于 2019-12-06 13:54:02
Subject反正就好像呈现的视图。所有Subject 都绑定到SecurityManager,与Subject的所有交互都会委托给SecurityManager;可以把Subject认为是一个门面;SecurityManager才是实际的执行者; 对于上面这句话的理解呢?怎么去理解这个很重要,看看别人的代码设计的流程也是比较的清楚的,Subject都绑定到了SecurityManager,因此我们在创建Subject的时候,必须给框架的内部绑定了一个SecurityManager,在前一个博客,我们已经基本的看了SecurityManager,大致的主要的架构,现在来看看Subject的主要的源码,学习一下别人这么写的用意何在?自己也是多多的总结很有很好,看看别人的优秀代码。 和上一个一样的 shrio.ini [users] zhang=123 wang=123 Factory<org.apache.shiro.mgt.SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini"); //2、得到SecurityManager实例 并绑定给SecurityUtils org.apache.shiro.mgt.SecurityManager securityManager =

带你揭秘Shiro(一)

蹲街弑〆低调 提交于 2019-12-06 13:11:40
提到Shiro,不得不先介绍RBAC介绍 RBAC介绍:   RBAC是基于角色的访问控制(Role-Based Access Control )在 RBAC 中,权限与角色相关联,用户通过成为适当角色的成员而得到这些角色的权限。这就极大地简化了权限的管理。这样管理都是层级相互依赖的,权限赋予给角色,而把角色又赋予用户,这样的权限设计很清楚,管理起来很方便。 在RBAC模型里面,有3个基础组成部分,分别是:用户、角色和权限。 RBAC通过定义角色的权限,并对用户授予某个角色从而来控制用户的权限,实现了用户和权限的逻辑分离,极大地方便了权限的管理,在讲解之前,先介绍一些名词: User(用户):每个用户都有唯一的UID识别,并被授予不同的角色 Role(角色):不同角色具有不同的权限 Permission(权限):访问权限 用户-角色映射:用户和角色之间的映射关系 角色-权限映射:角色和权限之间的映射 权限管理:(包含两部分:用户认证,用户授权)   只要有用户参与的管理系统一般都有权限管理,权限管理实现对用户访问系统的控制,按照安全规则实现用户可以访问自己被授权的资源。 用户认证: 关键对象: subject:主体,理解为用户,可能是程序,都要去访问系统的资源,系统需要对subject进行身份认证。 principal:身份信息,通常是唯一的,一个主体还有多个身份信息

spring boot 使用 shiro+redis管理权限

岁酱吖の 提交于 2019-12-06 06:59:38
spring boot中比较简单的权限管理选择了使用shiro 然后用shiro-redis管理session,如下: 创建个shiroConfing,里面设置ShiroFilterFactoryBean------SecurityManager------myShiroRealm 然后在securityManager中设置缓存和session管理的方式如定义一个sessionManager指定用redis来操作session 然后开启shiro AOP注解支持。 创建自己的realm继承AuthorizingRealm做登陆跟权限的认证过程。 代码如下 @Configuration public class ShiroConfig { @Bean public ShiroFilterFactoryBean shirFile(SecurityManager securityManager) { log.info("ShiroConfiguration.shirFilter()"); ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); shiroFilterFactoryBean.setSecurityManager(securityManager); //拦截器 Map

How to unit test Java code that is expected to run within an applet Security Manager

北战南征 提交于 2019-12-05 21:37:11
I have some Java library code which sometimes runs as an unsigned applet. Because of this it is not always allowed to do some operations (for instance checking for system properties). I would like to run some unit tests with an Applet-like security manager so that I can verify that the code is either not performing any restricted operations, or correctly handling any security exceptions. What is the best way to run these unit-tests with a realistic Security-Manager configuration? Preferable the solution would be something that can integrate with JUnit. Not a solution as such, but couldn't you

SpringBoot整合shiro

让人想犯罪 __ 提交于 2019-12-05 16:33:58
在 Spring Boot 中做权限管理,一般来说,主流的方案是 Spring Security ,但是,仅仅从技术角度来说,也可以使用 Shiro。 一般来说,Spring Security 和 Shiro 的比较如下: Spring Security 是一个重量级的安全管理框架;Shiro 则是一个轻量级的安全管理框架 Spring Security 概念复杂,配置繁琐;Shiro 概念简单、配置简单 Spring Security 功能强大;Shiro 功能简单 ... 虽然 Shiro 功能简单,但是也能满足大部分的业务场景。所以在传统的 SSM 项目中,一般来说,可以整合 Shiro。 在 Spring Boot 中,由于 Spring Boot 官方提供了大量的非常方便的开箱即用的 Starter ,当然也提供了 Spring Security 的 Starter ,使得在 Spring Boot 中使用 Spring Security 变得更加容易,甚至只需要添加一个依赖就可以保护所有的接口,所以,如果是 Spring Boot 项目,一般选择 Spring Security 。 这只是一个建议的组合,单纯从技术上来说,无论怎么组合,都是没有问题的。 在 Spring Boot 中整合 Shiro ,有两种不同的方案: 第一种就是原封不动的,将 SSM 整合

NoClassDefFoundError when creating objects under SecurityManager

冷暖自知 提交于 2019-12-05 15:26:58
I'm trying to secure my application by running the bits of code that deal with user-provided content under a very restrictive SecurityManager. It's AccessController.doPrivileged() turned on its head - normally this is used to provide a block of code with extra permissions but I'm using it to constrain a block of code to a very small sandbox. Everything is fine until I need to call a constructor. Then I need read-access to the world. (Or at least to all of the .jar, .class and .property files on my classpath.) I can't just grant read access to <> since that's what I'm trying to avoid. (E.g., an