本文整理了Java中javax.jcr.security.Privilege
类的一些代码示例,展示了Privilege
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Privilege
类的具体详情如下:
包路径:javax.jcr.security.Privilege
类名称:Privilege
[英]A privilege represents the capability of performing a particular set of operations on items in the JCR repository. Each privilege is identified by a JCR name. JCR defines a set of standard privileges in the jcr
namespace. Implementations may add additional privileges in namespaces other than jcr
.
A privilege may be an aggregate privilege. Aggregate privileges are sets of other privileges. Granting, denying, or testing an aggregate privilege is equivalent to individually granting, denying, or testing each privilege it contains. The privileges contained by an aggregate privilege may themselves be aggregate privileges if the resulting privilege graph is acyclic.
A privilege may be an abstract privilege. Abstract privileges cannot themselves be granted or denied, but can be composed into aggregate privileges which are granted or denied.
A privilege can be both aggregate and abstract.
[中]特权表示对JCR存储库中的项执行特定操作集的能力。每个特权都由一个JCR名称标识。JCR在jcr
命名空间中定义了一组标准权限。实现可能会在jcr
以外的名称空间中添加其他权限。
特权可以是聚合特权。聚合权限是其他权限的集合。授予、拒绝或测试聚合特权相当于单独授予、拒绝或测试其包含的每个特权。如果生成的特权图是非循环的,则聚合特权包含的特权本身可能是聚合特权。
特权可以是抽象的特权。抽象权限本身不能被授予或拒绝,但可以组合成授予或拒绝的聚合权限。
特权既可以是聚合的,也可以是抽象的。
代码示例来源:origin: com.github.livesense/org.liveSense.service.securityManager
public SerializablePrivilege(Privilege privilege) {
this.name = privilege.getName();
this.abstract_ = privilege.isAbstract();
Privilege[] privs = privilege.getDeclaredAggregatePrivileges();
for (int i = 0; i < privs.length; i++) {
declaredAggregatePrivileges.add(new SerializablePrivilege(privs[i]));
}
privs = privilege.getAggregatePrivileges();
for (int i = 0; i < privs.length; i++) {
aggregatePrivileges.add(new SerializablePrivilege(privs[i]));
}
}
代码示例来源:origin: apache/jackrabbit
public void testAllPrivilegeContainsAll() throws RepositoryException, NotExecutableException {
Privilege[] supported = acMgr.getSupportedPrivileges(testRootNode.getPath());
Privilege all = acMgr.privilegeFromName(Privilege.JCR_ALL);
Set<Privilege> allSet = new HashSet<Privilege>();
allSet.addAll(Arrays.asList(all.getAggregatePrivileges()));
String msg = "The all privilege must also contain ";
for (int i=0; i < supported.length; i++) {
Privilege sp = supported[i];
if (sp.isAggregate()) {
Collection<Privilege> col = Arrays.asList(sp.getAggregatePrivileges());
assertTrue(msg + sp.getName(), allSet.containsAll(col));
} else {
assertTrue(msg + sp.getName(), allSet.contains(sp));
}
}
}
代码示例来源:origin: org.apache.sling/org.apache.sling.jcr.base
/**
* Transform an aggregated privilege into a set of disaggregated privilege
* names. If the privilege is not an aggregate, the set will contain the
* original name.
*/
private static Set<String> disaggregateToPrivilegeNames(Privilege privilege) {
Set<String> disaggregatedPrivilegeNames = new HashSet<String>();
if (privilege.isAggregate()) {
Privilege[] privileges = privilege.getAggregatePrivileges();
for (Privilege disaggregate : privileges) {
if (disaggregate.isAggregate()) {
continue; //nested aggregate, so skip it since the privileges are already included.
}
disaggregatedPrivilegeNames.add(disaggregate.getName());
}
} else {
disaggregatedPrivilegeNames.add(privilege.getName());
}
return disaggregatedPrivilegeNames;
}
代码示例来源:origin: org.apache.jackrabbit/jackrabbit-jcr2spi
private int getPrivilegesHashCode() {
if (privsHashCode == -1) {
Set<Privilege> prvs = new HashSet<Privilege>(Arrays.asList(privileges));
for (Privilege p : privileges) {
if (p.isAggregate()) {
prvs.addAll(Arrays.asList(p.getAggregatePrivileges()));
}
}
privsHashCode = prvs.hashCode();
}
return privsHashCode;
}
代码示例来源:origin: apache/jackrabbit
private SupportedPrivilege createSupportedPrivilege(Privilege privilege) throws RepositoryException {
String privilegeName = privilege.getName();
String localName = Text.getLocalName(privilegeName);
String prefix = Text.getNamespacePrefix(privilegeName);
Namespace ns = (prefix.isEmpty()) ? Namespace.EMPTY_NAMESPACE : Namespace.getNamespace(prefix, session.getNamespaceURI(prefix));
org.apache.jackrabbit.webdav.security.Privilege davPrivilege = org.apache.jackrabbit.webdav.security.Privilege.getPrivilege(localName, ns);
SupportedPrivilege[] aggregates = (privilege.isAggregate()) ? getDeclaredAggregates(privilege) : null;
SupportedPrivilege sp = new SupportedPrivilege(davPrivilege, null, null, privilege.isAbstract(), aggregates);
if (!aggregated.contains(privilegeName)) {
supportedPrivileges.put(privilegeName, sp);
}
return sp;
}
代码示例来源:origin: ModeShape/modeshape
acl.addAccessControlEntry(SimplePrincipal.EVERYONE, new Privilege[] {accessControlManager.privilegeFromName(Privilege.JCR_ALL)});
accessControlManager.setPolicy("/aclNode", acl);
session.save();
assertEquals(1, accessControlManager.getPolicies("/aclNodeCopy").length);
Privilege[] privileges = accessControlManager.getPrivileges("/aclNodeCopy");
assertEquals(1, privileges.length);
assertEquals("jcr:all", privileges[0].getName());
代码示例来源:origin: org.apache.jackrabbit/jackrabbit-spi2jcr
public PrivilegeDefinition[] getSupportedPrivileges(SessionInfo sessionInfo, NodeId nodeId) throws RepositoryException {
SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
String path = (nodeId == null) ? null : pathForId(nodeId, sInfo);
Privilege[] privs = sInfo.getSession().getAccessControlManager().getSupportedPrivileges(path);
PrivilegeDefinition[] pDefs = new PrivilegeDefinition[privs.length];
NamePathResolver npResolver = sInfo.getNamePathResolver();
for (int i = 0; i < privs.length; i++) {
Set<Name> aggrnames = null;
if (privs[i].isAggregate()) {
aggrnames = new HashSet<Name>();
for (Privilege dap : privs[i].getDeclaredAggregatePrivileges()) {
aggrnames.add(npResolver.getQName(dap.getName()));
}
}
PrivilegeDefinition def = new PrivilegeDefinitionImpl(npResolver.getQName(privs[i].getName()), privs[i].isAbstract(), aggrnames);
pDefs[i] = def;
}
return pDefs;
}
代码示例来源:origin: apache/jackrabbit
/**
*
* @throws RepositoryException If an error occurs.
* @throws NotExecutableException If the test cannot be executed.
*/
public void testNotHasPrivileges() throws RepositoryException, NotExecutableException {
Privilege[] privs = acMgr.getPrivileges(testRootNode.getPath());
Privilege all = acMgr.privilegeFromName(Privilege.JCR_ALL);
// remove all privileges that are granted.
Set<Privilege> notGranted = new HashSet<Privilege>(Arrays.asList(all.getAggregatePrivileges()));
for (int i = 0; i < privs.length; i++) {
if (privs[i].isAggregate()) {
notGranted.removeAll(Arrays.asList(privs[i].getAggregatePrivileges()));
} else {
notGranted.remove(privs[i]);
}
}
// make sure that either 'all' are granted or the 'diff' is denied.
if (notGranted.isEmpty()) {
assertTrue(acMgr.hasPrivileges(testRootNode.getPath(), new Privilege[] {all}));
} else {
Privilege[] toTest = notGranted.toArray(new Privilege[notGranted.size()]);
assertTrue(!acMgr.hasPrivileges(testRootNode.getPath(), toTest));
}
}
代码示例来源:origin: apache/jackrabbit
public void testGetPrivilegesFromBits2() throws RepositoryException {
String[] names = new String[] {
Privilege.JCR_ADD_CHILD_NODES,
Privilege.JCR_REMOVE_CHILD_NODES,
Privilege.JCR_REMOVE_NODE,
Privilege.JCR_MODIFY_PROPERTIES
};
PrivilegeBits writeBits = getPrivilegeManagerImpl().getBits(privilegesFromNames(names));
Set<Privilege> pvs = getPrivilegeManagerImpl().getPrivileges(writeBits);
assertTrue(pvs != null);
assertTrue(pvs.size() == 1);
Privilege p = pvs.iterator().next();
assertSamePrivilegeName(p.getName(), Privilege.JCR_WRITE);
assertTrue(p.isAggregate());
assertTrue(p.getDeclaredAggregatePrivileges().length == names.length);
}
代码示例来源:origin: apache/jackrabbit
/**
* Test the jcr:all privilege.
*
* @throws RepositoryException
* @throws NotExecutableException
*/
public void testAllPrivilege() throws RepositoryException, NotExecutableException {
Privilege all = acMgr.privilegeFromName(Privilege.JCR_ALL);
assertFalse("All privilege must be not be abstract.", all.isAbstract());
assertTrue("All privilege must be an aggregate privilege.", all.isAggregate());
String expected = getJCRName(Privilege.JCR_ALL, superuser);
assertEquals("The name of the all privilege must be " + expected, expected, all.getName());
}
代码示例来源:origin: apache/jackrabbit
public void testEquals() throws RepositoryException, NotExecutableException {
Map<AccessControlEntry, AccessControlEntry> equalAces = new HashMap<AccessControlEntry, AccessControlEntry>();
JackrabbitAccessControlEntry ace = createEntry(new String[] {Privilege.JCR_ALL}, true);
// create same entry again
equalAces.put(ace, createEntry(new String[] {Privilege.JCR_ALL}, true));
// create entry with declared aggregate privileges
Privilege[] declaredAllPrivs = acMgr.privilegeFromName(Privilege.JCR_ALL).getDeclaredAggregatePrivileges();
equalAces.put(ace, createEntry(testPrincipal, declaredAllPrivs, true));
// create entry with aggregate privileges
Privilege[] aggregateAllPrivs = acMgr.privilegeFromName(Privilege.JCR_ALL).getAggregatePrivileges();
equalAces.put(ace, createEntry(testPrincipal, aggregateAllPrivs, true));
// create entry with different privilege order
List<Privilege> reordered = new ArrayList<Privilege>(Arrays.asList(aggregateAllPrivs));
reordered.add(reordered.remove(0));
equalAces.put(createEntry(testPrincipal, reordered.toArray(new Privilege[reordered.size()]), true),
createEntry(testPrincipal, aggregateAllPrivs, true));
// even if entries are build with aggregated or declared aggregate privileges
equalAces.put(createEntry(testPrincipal, declaredAllPrivs, true),
createEntry(testPrincipal, aggregateAllPrivs, true));
for (AccessControlEntry entry : equalAces.keySet()) {
assertEquals(entry, equalAces.get(entry));
}
}
代码示例来源:origin: apache/jackrabbit
/**
* Test the jcr:write privilege.
*
* @throws RepositoryException If an error occurs.
* @throws NotExecutableException If the test cannot be executed.
*/
public void testWritePrivilege() throws RepositoryException, NotExecutableException {
Privilege w = acMgr.privilegeFromName(Privilege.JCR_WRITE);
assertTrue("Write privilege must be an aggregate privilege.", w.isAggregate());
String expected = getJCRName(Privilege.JCR_WRITE, superuser);
assertEquals("The name of the write privilege must be " + expected, expected, w.getName());
}
代码示例来源:origin: apache/jackrabbit
public void testPrivilegeFromName() throws RepositoryException {
Privilege[] privileges = acMgr.getSupportedPrivileges(testRootNode.getPath());
for (int i = 0; i < privileges.length; i++) {
Privilege p = acMgr.privilegeFromName(privileges[i].getName());
assertEquals("Expected equal privilege name.", privileges[i].getName(), p.getName());
assertEquals("Expected equal privilege.", privileges[i], p);
}
}
代码示例来源:origin: apache/jackrabbit
/**
* Test some simple characteristics of the known aggregate privileges (jcr:write and jcr:all).
*
* @throws RepositoryException
*/
public void testAggregregatePrivileges() throws RepositoryException {
List<String> l = new ArrayList<String>();
l.add(getJCRName(Privilege.JCR_WRITE, superuser));
l.add(getJCRName(Privilege.JCR_ALL, superuser));
for (Iterator<String> it = l.iterator(); it.hasNext();) {
String privName = it.next();
Privilege p = acMgr.privilegeFromName(privName);
assertTrue("write and all must always be aggregate privileges.", p.isAggregate());
Privilege[] aggregatedPrvs = p.getAggregatePrivileges();
Privilege[] declaredPrvs = p.getDeclaredAggregatePrivileges();
assertNotNull("An aggregate privilege must return the aggregated privileges", aggregatedPrvs);
assertTrue("An aggregate privilege must return the aggregated privileges", aggregatedPrvs.length > 0);
assertNotNull("An aggregate privilege must return the declared aggregated privileges", declaredPrvs);
assertTrue("An aggregate privilege must return the declared aggregated privileges", declaredPrvs.length > 0);
assertTrue("The may be at least the same amount of declared aggregated privileges.", aggregatedPrvs.length >= declaredPrvs.length);
}
}
代码示例来源:origin: stackoverflow.com
roles.add(new GrantedAuthorityImpl(p.getName()));
代码示例来源:origin: apache/jackrabbit
@Override
public Name[] getPrivilegeNames(SessionInfo sessionInfo, NodeId nodeId) throws RepositoryException {
SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
String path = (nodeId == null) ? null : pathForId(nodeId, sInfo);
NamePathResolver npResolver = sInfo.getNamePathResolver();
Privilege[] privs = sInfo.getSession().getAccessControlManager().getPrivileges(path);
List<Name> names = new ArrayList<Name>(privs.length);
for (Privilege priv : privs) {
names.add(npResolver.getQName(priv.getName()));
}
return names.toArray(new Name[names.size()]);
}
代码示例来源:origin: apache/jackrabbit
private SupportedPrivilege[] getDeclaredAggregates(Privilege privilege) throws RepositoryException {
List<SupportedPrivilege> declAggr = new ArrayList<SupportedPrivilege>();
for (Privilege decl : privilege.getDeclaredAggregatePrivileges()) {
String name = decl.getName();
if (aggregated.add(name)) {
if (supportedPrivileges.containsKey(name)) {
declAggr.add(supportedPrivileges.remove(name));
} else {
declAggr.add(createSupportedPrivilege(decl));
}
}
}
return declAggr.toArray(new SupportedPrivilege[declAggr.size()]);
}
}
代码示例来源:origin: apache/jackrabbit
public void testGetPrivilegeFromName() throws AccessControlException, RepositoryException {
Privilege p = privilegeMgr.getPrivilege(Privilege.JCR_READ);
assertTrue(p != null);
assertSamePrivilegeName(Privilege.JCR_READ, p.getName());
assertFalse(p.isAggregate());
p = privilegeMgr.getPrivilege(Privilege.JCR_WRITE);
assertTrue(p != null);
assertSamePrivilegeName(p.getName(), Privilege.JCR_WRITE);
assertTrue(p.isAggregate());
}
代码示例来源:origin: apache/jackrabbit
public void testMandatoryPrivilegeFromName() throws RepositoryException {
List<String> l = new ArrayList<String>();
l.add(getJCRName(Privilege.JCR_READ, superuser));
l.add(getJCRName(Privilege.JCR_ADD_CHILD_NODES, superuser));
l.add(getJCRName(Privilege.JCR_REMOVE_CHILD_NODES, superuser));
l.add(getJCRName(Privilege.JCR_MODIFY_PROPERTIES, superuser));
l.add(getJCRName(Privilege.JCR_REMOVE_NODE, superuser));
l.add(getJCRName(Privilege.JCR_READ_ACCESS_CONTROL, superuser));
l.add(getJCRName(Privilege.JCR_MODIFY_ACCESS_CONTROL, superuser));
l.add(getJCRName(Privilege.JCR_WRITE, superuser));
l.add(getJCRName(Privilege.JCR_ALL, superuser));
for (Iterator<String> it = l.iterator(); it.hasNext();) {
String privName = it.next();
Privilege p = acMgr.privilegeFromName(privName);
assertEquals("Expected equal privilege name.", privName, p.getName());
}
}
代码示例来源:origin: apache/jackrabbit-oak
/**
* @see <a href="https://issues.apache.org/jira/browse/OAK-1026">OAK-1026</a>
*/
@Test
public void testEntryWithAggregatePrivileges() throws Exception {
Privilege write = acMgr.privilegeFromName(Privilege.JCR_WRITE);
acl.addEntry(testPrincipal, write.getAggregatePrivileges(), true);
AccessControlEntry[] entries = acl.getAccessControlEntries();
assertEquals(1, entries.length);
assertArrayEquals(new Privilege[]{write}, entries[0].getPrivileges());
acMgr.setPolicy(acl.getPath(), acl);
AccessControlPolicy policy = AccessControlUtils.getAccessControlList(acMgr, acl.getPath());
assertNotNull(policy);
entries = acl.getAccessControlEntries();
assertEquals(1, entries.length);
assertArrayEquals(new Privilege[]{write}, entries[0].getPrivileges());
}
内容来源于网络,如有侵权,请联系作者删除!