我试图授权Spring Data REST公开api.到目前为止,我能够进行基于角色的授权,即:
@RepositoryRestResource(path = "book")
public interface BookRepository extends JpaRepository<Book, Long> {
@PreAuthorize("hasRole('ROLE_ADMIN')")
<S extends Book> Book save(Book book);
}
Run Code Online (Sandbox Code Playgroud)
同样在同一个项目中我有一个带ACL机制的服务层,它正在工作.
我无法在Spring Data REST中使用PostFilter表达式,即:
@PostFilter("hasPermission(filterObject, 'read') or hasPermission(filterObject, admin)")
List<Book> findAll();
Run Code Online (Sandbox Code Playgroud)
如果有人在Spring Data REST中使用ACL,那将会有很大的帮助.
注意:我知道以下未解决的问题:
Spring Security ACL看起来非常强大,并且在您可以坚持其数据库实现时易于实现.然而,当你必须实现自己的时候看起来会变得复杂得多(例如Acl,AclService参见这个(旧的)非常基本的教程只有~26页)并且似乎很难找到它的参考和示例(该教程来自2008年) ).
例如,在我们的应用程序中,用户具有角色并属于部门.大多数情况下,他们可以根据角色对属于其部门的对象执行某些操作.在所有情况下,department + role足以决定是否应该授予用户对特定对象的特定操作.
用户,角色和部门由外部应用程序管理,我们在用户连接时从中检索它们(我们使用的是REST服务,但它也可以是LDAP服务器).
我们希望依靠@PreAuthorize('hasPermission(…)')实现域对象安全性.因此可以看到2种解决方案:
PermissionEvaluator整个检查的自定义; 要么AclService构建ACL正常工作所必需的对象结构.似乎实现整体AclService比实现整体更困难,更复杂PermissionEvaluator,但ACL似乎更标准.
根据您应该实施哪一个标准?
我们刚刚迁移到春季安全3.0.8从2.0.8(可"升级到latestversion这是3.2.X作为我们的核心Spring库仍然在3.0.x的,我们计划以后升级时,经营许可证).
据我所知,我们现在有注释为确保类似的方法@PreAuthorize,@PostAuthorize,@Secured,@PreFilter和@PostFilter.
我理解使用@PreAuthorize,这真的很有意义.但是不能想到你曾经使用@PostAuthorize或@PostFilter注释的任何有效用例?
使用它的人可以向我解释使用它们的合理用例吗?
提前致谢!
我读过有关Spring ACL的内容,但它看起来并不是很有能力.例如:
您使用什么ACL?将ACL与域模型分离是否巧妙?
我们在spring安全性中遇到意外缺少按位权限检查.我们想确认这是否是预期的行为,如果是,那么历史是什么和/或理由是什么.
我们使用的是grails插件spring-security-acl-1.1.1,它使用spring-security-acl 3.0.7.RELEASE.
我们正在尝试的方法涉及一个具有ACL的对象,以便aclUtilService.readAcl(obj)返回授予角色:
PrincipalSid[sampleuser]; permission: BasePermission[...........................A....=16]
GrantedAuthoritySid[ROLE_RWD]; permission: CumulativePermission[............................D.WR=11]
GrantedAuthoritySid[ROLE_RW]; permission: CumulativePermission[..............................WR=3]
GrantedAuthoritySid[ROLE_R]; permission: BasePermission[...............................R=1]
Run Code Online (Sandbox Code Playgroud)
随后我们希望检查像WRITE这样的单一权限并让它返回true.但是,似乎不支持此功能.例如,对于具有在上述对象上定义的所有角色的用户,执行:
READ?: ${aclUtilService.hasPermission(springSecurityService.authentication, obj, BasePermission.READ)}
WRITE?: ${aclUtilService.hasPermission(springSecurityService.authentication, obj, BasePermission.WRITE)}
DELETE?: ${aclUtilService.hasPermission(springSecurityService.authentication, obj, BasePermission.DELETE)}
READ-WRITE?: ${aclUtilService.hasPermission(springSecurityService.authentication, obj, new BasePermission(BasePermission.READ.getMask() | BasePermission.WRITE.getMask()))}
Run Code Online (Sandbox Code Playgroud)
返回输出:
READ?: true
WRITE?: false
DELETE?: false
READ-WRITE?: true
Run Code Online (Sandbox Code Playgroud)
而我们希望所有这些都返回真实.查看源代码后,我们可以看到最终在AclImpl中检查了权限,其中包含该行
if ((ace.getPermission().getMask() == p.getMask()) && ace.getSid().equals(sid)) {
Run Code Online (Sandbox Code Playgroud)
这解释了为什么只有精确的面具匹配.
只更改了这一行,我们发现在spring-security-acl 3.1中,这个代码被重构为允许定义权限授予策略 - https://jira.spring.io/browse/SEC-1166
但是,默认授权策略仍然只检查确切的掩码.所以:
感谢您的任何解释或指导.
我是春天安全的新手.我怎么解释这个?
@PreAuthorize("hasPermission(null, 'opetussuunnitelma', 'LUONTI')")
OpetussuunnitelmaDto addOpetussuunnitelma(OpetussuunnitelmaDto opetussuunnitelmaDto);
Run Code Online (Sandbox Code Playgroud)
来自权限评估程序的哪种方法会被调用?我想在这种情况下会调用带有三个参数的那个.它正在检查当前用户是否对类型目标''opetussuunnitelma'具有'LUONTI'权限.我对吗?我们不能只包括"null"并且只传递两个参数.我读到没有提供第一个参数(Authentication对象).
+public class PermissionEvaluator implements org.springframework.security.access.PermissionEvaluator {
+
+ @Override
+ public boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission) {
+ LOG.error(" *** ei toteutettu *** ");
+ return true;
+ }
+
+ @Override
+ public boolean hasPermission(Authentication authentication, Serializable targetId, String targetType, Object permission) {
+ LOG.error(" *** ei toteutettu *** ");
+ return true;
+ }
+
+ private static final Logger LOG = LoggerFactory.getLogger(PermissionEvaluator.class);
+}
Run Code Online (Sandbox Code Playgroud) 基于Spring安全框架实现安全解决方案,尤其是acl模块.
应用程序中有数百万个域对象和数百个用户.
使用Spring Security Acl模块,acl_sid和其他相关表中的条目增长到10亿,这会影响应用程序的性能.
想知道处理此类场景的最佳实践.
是否有任何替代安全框架可以有效地处理类似情况.
performance authorization spring-security user-permissions spring-security-acl
我尝试更新到 EhCache 3,但注意到我的 spring-security-acl 的 AclConfig 不再有效。原因是EhCacheBasedAclCache还在用import net.sf.ehcache.Ehcache。EhCacheorg.ehcache从第 3 版开始迁移,因此不再有效。spring 是否为 EhCache 3 提供了替换类,或者我是否需要实现自己的 Acl 缓存?这是代码,不再起作用:
@Bean
public EhCacheBasedAclCache aclCache() {
return new EhCacheBasedAclCache(aclEhCacheFactoryBean().getObject(),
permissionGrantingStrategy(), aclAuthorizationStrategy());
}
Run Code Online (Sandbox Code Playgroud) 我正在阅读关于Spring Security的内容,并想知道是否可以将Spring ACL与hibernate和分页一起使用.生成的SQL肯定是可怕的,但可以自动生成.如果数据库支持递归查询评估,甚至可以使用分层ACL.
使用后置过滤器不是解决方案,因为它破坏了分页,与数据库内的ACL过滤相比,这是一种不必要的开销.
所以我实际上已经有了建立解决方案的部分.我想知道是否有人已经这样做了.
链接:
pagination hibernate spring-security recursive-query spring-security-acl
我正在设计一个对用户管理/权限有很多要求的系统,因此我决定使用Spring Security ACL来管理Domain Objects级别的权限.
虽然,使用ACL来维护用户和实体之间的关系迫使我们依赖它来在UI上呈现数据.
Spring Security提供的PostFilter解决方案很好地过滤了用户可以/看不到的对象,但是当我们处理具有数百/数千个条目的实体时,它有很大的性能问题,因为我们需要从数据库加载所有内容,然后丢弃不允许用户"查看"的对象.
这个问题在这里描述 - SEC-2409 - 但是这个功能可用还需要一些时间.所以,我正在尝试找到一种使用Spring Security ACL的解决方法,但避免了性能问题.
我考虑实现一些代码来检索用户可以访问的对象(在身份验证过程之后)并保持该信息可用于每个请求,以允许开发人员使用该信息来执行查询而不依赖于PostFilter .
为了实现这一点,我试图找到一种方法来检索给定主体/授权权限的权限列表,但我无法找到使用可用的AclService实现的方法.
示例:aclService.getObjectIdentityList(<sid>,<acl_class>)
注意:该方法应使用继承结构并包括从父条目继承的所有ObjectIdentities
有任何建议来获取数据或其他方法来解决这个问题吗?
UPDATE
我已经找到了一种方法来检索用户可以访问的对象列表.
List<ObjectIdentity> childObjects = aclService.findChildren(objectIdentity);
Map<ObjectIdentity, Acl> result = aclService.readAclsById(childObjects, sids);
Run Code Online (Sandbox Code Playgroud)
这种方法对我们有用,因为我们只有几个实体,访问权限由ACL控制,因此我们可以构造User具有访问权限的ObjectsIdentities列表.
虽然,正在返回的Map正在返回正在传递的ObjectIdentities的所有ACL,然后我需要检查用户是否有权访问正在返回的每个ObjectIdentity.
你有一个简单的方法来做到这一点或简化所有这些逻辑吗?
当我尝试使用MutableAclService.createAcl(ObjectIdentity objectIdentity).
问题是ObjectIdentity使用Serializable类型作为标识符。同时,我的域String为此目的使用类型。Id 以这种方式生成:
String id = UUID.randomUUID().toString();
Run Code Online (Sandbox Code Playgroud)
然后我尝试使用以下结构添加 ACL:
ObjectIdentity identity = new ObjectIdentityImpl(clazz, id);
aclService.createAcl(identity);
Run Code Online (Sandbox Code Playgroud)
之后,我收到以下异常:
java.lang.NumberFormatException:对于输入字符串:“ad169805-a2d1-4324-ba11-c98cc679e594”
我发现 Spring Security ACL 使用Long类型作为标识符。
所以,问题是:
Serializable到处都提到,但实际上它必须很长?PS 标识符的 SQL 数据类型也是数字 - bigserial。
我正在使用 Spring 开发应用程序。在访问控制访问部分,我想使用 Spring Security Acl(我是 Acl 的新手)。我想基于 2 点在我的应用程序中实现 ACL:
read,create、modify、delete和Administrator。create权限,它应该能够read,或者当它有modify权限,它应该可以read,create和modify等。是否可以?如何?
更新:
我的应用程序基于 Spring MVC RESTFUL。当用户想要修改自己的信息时,他用ajax发送一些json数据。json数据示例如下:
{
"id": 1,//user Id
"name": "my name",
"password": "my password",
"email": "email@email.com",
...
}
Run Code Online (Sandbox Code Playgroud)
现在,恶意用户可以登录自己的帐户。该用户可以modify像所有其他用户一样拥有自己的数据。在他发送数据之前,更改他的id,以及modify另一个帐户的用户信息。我想用 ACL 来防止这种颠覆性的工作。并且用户可以访问其他人可以修改他的信息的其他人。
如何使用 mutableAclService 删除 spring security acl 中的用户访问权限。这段代码可以吗
private void deleteEntry(Long id){
ObjectIdentity objectIdentity = new ObjectIdentityImpl(OrganizationStructure.class, id);
Sid user = new PrincipalSid("admin");
Permission p1 = BasePermission.READ;
try {
MutableAcl acl = (MutableAcl) mutableAclService.readAclById(objectIdentity);
acl.getEntries().forEach(c->{
System.out.println(c.toString());
if(c.getSid().equals(user))
acl.getEntries().remove(c);
});
mutableAclService.updateAcl(acl);
} catch (NotFoundException nfe) {
}
}
Run Code Online (Sandbox Code Playgroud) spring-security ×11
spring ×6
java ×5
acl ×3
security ×2
ehcache ×1
ehcache-3 ×1
grails ×1
hibernate ×1
pagination ×1
performance ×1