我是一名新开发人员,试图解决Jackrabbit / JCR库。我的团队和我已经使用EveryonePrincipal几个月了,但是我们一直希望为每个用户角色/主体实现更多功能,因此我们可以向他们授予对每个节点的必要读/写访问权限。但是,我们在弄清楚如何创建新的Principal对象方面遇到了一些困难。
我一直在使用:
PrincipalImpl newPrincipal = new PrincipalImpl("MyPrincipal");
然后创建一个与EveryonePrincipal匹配的新RolePrincipal类,不同的是RolePrincipal类中的名称为“ MyPrincipal”。不幸的是,此方法无效。我们还缺少什么吗?以及“每个人”主体如何存储?
EveryonePrincipal.java
public final class EveryonePrincipal implements JackrabbitPrincipal, java.security.acl.Group {
public static final String NAME = "everyone";
private static final EveryonePrincipal INSTANCE = new EveryonePrincipal();
private EveryonePrincipal() { }
public static EveryonePrincipal getInstance() {
return INSTANCE;
}
//----------------------------------------------------------< Principal >---
@Override
public String getName() {
return NAME;
}
//--------------------------------------------------------------< Group >---
@Override
public boolean addMember(Principal user) {
return false;
}
@Override
public boolean removeMember(Principal user) {
throw new UnsupportedOperationException("Cannot remove a member from the everyone group.");
}
@Override
public boolean isMember(Principal member) {
return !member.equals(this);
}
@Override
public Enumeration<? extends Principal> members() {
throw new UnsupportedOperationException("Not implemented.");
}
//-------------------------------------------------------------< Object >---
@Override
public int hashCode() {
return NAME.hashCode();
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
} else if (obj instanceof JackrabbitPrincipal && obj instanceof Group) {
JackrabbitPrincipal other = (JackrabbitPrincipal) obj;
return NAME.equals(other.getName());
}
return false;
}
@Override
public String toString() {
return NAME + " principal";
}
}