3

我们可以在 acl_sid 中​​同时执行 Principle 和 GratedAuthority 并在 spring acl security 中授予对象权限吗?

4

1 回答 1

3

是的,我们可以做到。ACL_SID 表可以采用角色或用户的 SID。

这是角色时的示例插入:

insert into acl_sid (principal, sid) values (false, 'ROLE_ADMIN');

如果它是用户主体,则插入将是:

insert into acl_sid (principal, sid) values (true, 'bob');

您还可以使用可变 ACL 对 ACL 字段进行运行时操作。

这是一个示例:

// Prepare the information we'd like in our access control entry (ACE)
ObjectIdentity oi1 = new ObjectIdentityImpl(Foo.class, new Long(44));
ObjectIdentity oi2 = new ObjectIdentityImpl(Bar.class, new Long(44));
Sid user = new PrincipalSid("bob");
Sid adminRole = new GrantedAuthoritySid("ROLE_ADMIN");
Permission p1 = BasePermission.READ;
Permission p2 = BasePermission.ADMINISTRATION;

// Create or update the relevant ACL
MutableAcl acl1 = null;
MutableAcl acl2 = null;
try {
  acl1 = mutableAclService.readAclById(oi1);
} catch (NotFoundException nfe) {
  acl1 = mutableAclService.createAcl(oi1);
}

try {
  acl2 = mutableAclService.readAclById(oi2);
} catch (NotFoundException nfe) {
  acl2 = mutableAclService.createAcl(oi2);
}

// Now grant some permissions via an access control entry (ACE)
acl1.setOwner(user);
acl1.insertAce(0, p1, user, true);
aclService.updateAcl(acl1);
acl2.setOwner(adminRole);
acl2.insertAce(0, p2, adminRole, true);
aclService.updateAcl(acl2);
于 2012-06-28T03:11:32.087 回答