Spring 安全性 - ACL readAclsById 未按 SID 过滤
Spring Security - ACL readAclsById not filtering by SIDs
我正尝试在 JdbcMutableAclService
中使用 Spring 安全性的 readAclsById 方法来检索由 SID 过滤的 ACL。但是,返回不适用于传入的 SID 的 ACL。
我正在使用以下用户名创建 ACL 条目:
public void add(Object domainObject, String username, List<Permission> permissions) {
MutableAcl acl;
ObjectIdentity oid = objectIdentityRetrievalStrategy
.getObjectIdentity(domainObject);
Sid receipient = new PrincipalSid(username);
try {
acl = (MutableAcl) aclService.readAclById(oid);
} catch (NotFoundException nfe) {
acl = aclService.createAcl(oid);
}
for(Permission permission:permissions) {
acl.insertAce(acl.getEntries().size(), permission, receipient, true);
}
aclService.updateAcl(acl);
}
我正在通过 Authentication
对象检索 ACL:
List<Sid> sids = sidRetrievalStrategy.getSids(authentication);
List<ObjectIdentity> identities = new ArrayList<>(domainObjects.size());
for (Object domainObject : domainObjects) {
identities.add(objectIdentityRetrievalStrategy.getObjectIdentity(domainObject));
}
Map<ObjectIdentity, Acl> acls = aclService.readAclsById(identities, sids);
//see what permissions the user has for these objects
for (Map.Entry<ObjectIdentity, Acl> entry : acls.entrySet()) {
Acl acl = entry.getValue();
//entries that are not applicable to the SIDs are returned
List<AccessControlEntry> entries = acl.getEntries();
}
如果我登录另一个用户名并尝试通过 readAclsById 检索 ACL,我也会得到属于其他用户名的 AccessControlEntry
值。我使用 AclService
正确吗?
我在深入研究源代码后找到了答案:默认实现使用 BasicLookupStrategy
,默认情况下会忽略 SID。
我正尝试在 JdbcMutableAclService
中使用 Spring 安全性的 readAclsById 方法来检索由 SID 过滤的 ACL。但是,返回不适用于传入的 SID 的 ACL。
我正在使用以下用户名创建 ACL 条目:
public void add(Object domainObject, String username, List<Permission> permissions) {
MutableAcl acl;
ObjectIdentity oid = objectIdentityRetrievalStrategy
.getObjectIdentity(domainObject);
Sid receipient = new PrincipalSid(username);
try {
acl = (MutableAcl) aclService.readAclById(oid);
} catch (NotFoundException nfe) {
acl = aclService.createAcl(oid);
}
for(Permission permission:permissions) {
acl.insertAce(acl.getEntries().size(), permission, receipient, true);
}
aclService.updateAcl(acl);
}
我正在通过 Authentication
对象检索 ACL:
List<Sid> sids = sidRetrievalStrategy.getSids(authentication);
List<ObjectIdentity> identities = new ArrayList<>(domainObjects.size());
for (Object domainObject : domainObjects) {
identities.add(objectIdentityRetrievalStrategy.getObjectIdentity(domainObject));
}
Map<ObjectIdentity, Acl> acls = aclService.readAclsById(identities, sids);
//see what permissions the user has for these objects
for (Map.Entry<ObjectIdentity, Acl> entry : acls.entrySet()) {
Acl acl = entry.getValue();
//entries that are not applicable to the SIDs are returned
List<AccessControlEntry> entries = acl.getEntries();
}
如果我登录另一个用户名并尝试通过 readAclsById 检索 ACL,我也会得到属于其他用户名的 AccessControlEntry
值。我使用 AclService
正确吗?
我在深入研究源代码后找到了答案:默认实现使用 BasicLookupStrategy
,默认情况下会忽略 SID。