javax.jcr.security.Privilege.isAbstract()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(103)

本文整理了Java中javax.jcr.security.Privilege.isAbstract()方法的一些代码示例,展示了Privilege.isAbstract()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Privilege.isAbstract()方法的具体详情如下:
包路径:javax.jcr.security.Privilege
类名称:Privilege
方法名:isAbstract

Privilege.isAbstract介绍

[英]Returns whether this privilege is an abstract privilege.
[中]返回此权限是否为抽象权限。

代码示例

代码示例来源:origin: apache/jackrabbit

public boolean isAbstract() {
  return privilege.isAbstract();
}

代码示例来源:origin: apache/jackrabbit

private void checkAbstract(Privilege[] privileges) throws AccessControlException {
  for (Privilege privilege : privileges) {
    if (privilege.isAbstract()) {
      throw new AccessControlException("An Entry cannot contain abstract privileges.");
    }
  }
}

代码示例来源:origin: org.apache.jackrabbit/jackrabbit-jcr2spi

private void checkAbstract(Privilege[] privileges) throws AccessControlException {
  for (Privilege privilege : privileges) {
    if (privilege.isAbstract()) {
      throw new AccessControlException("An Entry cannot contain abstract privileges.");
    }
  }
}

代码示例来源: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-oak

@Test
public void testIsAbstract() {
  assertFalse(privilege.isAbstract());
  assertFalse(allPrivilege.isAbstract());
  assertFalse(aggrPrivilege.isAbstract());
  assertTrue(abstractPrivilege.isAbstract());
}

代码示例来源: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: org.apache.jackrabbit/oak-core

private void checkValidPrivileges(@NotNull Tree aceNode) throws CommitFailedException {
  Iterable<String> privilegeNames = TreeUtil.getStrings(aceNode, REP_PRIVILEGES);
  if (privilegeNames == null || Iterables.isEmpty(privilegeNames)) {
    throw accessViolation(9, "Missing privileges at " + aceNode.getPath());
  }
  for (String privilegeName : privilegeNames) {
    try {
      Privilege privilege = privilegeManager.getPrivilege(privilegeName);
      if (privilege.isAbstract()) {
        throw accessViolation(11, "Abstract privilege " + privilegeName + " at " + aceNode.getPath());
      }
    } catch (AccessControlException e) {
      throw accessViolation(10, "Invalid privilege " + privilegeName + " at " + aceNode.getPath());
    } catch (RepositoryException e) {
      throw new IllegalStateException("Failed to read privileges", e);
    }
  }
}

代码示例来源:origin: apache/jackrabbit-oak

private void checkValidPrivileges(@NotNull Tree aceNode) throws CommitFailedException {
  Iterable<String> privilegeNames = TreeUtil.getStrings(aceNode, REP_PRIVILEGES);
  if (privilegeNames == null || Iterables.isEmpty(privilegeNames)) {
    throw accessViolation(9, "Missing privileges at " + aceNode.getPath());
  }
  for (String privilegeName : privilegeNames) {
    try {
      Privilege privilege = privilegeManager.getPrivilege(privilegeName);
      if (privilege.isAbstract()) {
        throw accessViolation(11, "Abstract privilege " + privilegeName + " at " + aceNode.getPath());
      }
    } catch (AccessControlException e) {
      throw accessViolation(10, "Invalid privilege " + privilegeName + " at " + aceNode.getPath());
    } catch (RepositoryException e) {
      throw new IllegalStateException("Failed to read privileges", e);
    }
  }
}

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

private void checkValidPrivileges(@Nonnull Tree aceNode) throws CommitFailedException {
  Iterable<String> privilegeNames = TreeUtil.getStrings(aceNode, REP_PRIVILEGES);
  if (privilegeNames == null || Iterables.isEmpty(privilegeNames)) {
    throw accessViolation(9, "Missing privileges at " + aceNode.getPath());
  }
  for (String privilegeName : privilegeNames) {
    try {
      Privilege privilege = privilegeManager.getPrivilege(privilegeName);
      if (privilege.isAbstract()) {
        throw accessViolation(11, "Abstract privilege " + privilegeName + " at " + aceNode.getPath());
      }
    } catch (AccessControlException e) {
      throw accessViolation(10, "Invalid privilege " + privilegeName + " at " + aceNode.getPath());
    } catch (RepositoryException e) {
      throw new IllegalStateException("Failed to read privileges", e);
    }
  }
}

代码示例来源: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 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: 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

public void testAddAbstractPrivilege() throws NotExecutableException, RepositoryException {
  checkCanModifyAc(path);
  Privilege abstractPriv = null;
  Privilege[] allPrivs = acMgr.privilegeFromName(Privilege.JCR_ALL).getAggregatePrivileges();
  for (int i = 0; i < allPrivs.length; i++) {
    if (allPrivs[i].isAbstract()) {
      abstractPriv = allPrivs[i];
      break;
    }
  }
  if (abstractPriv == null) {
    throw new NotExecutableException("No abstract privilege found.");
  }
  AccessControlList acl = getList(acMgr, path);
  try {
    acl.addAccessControlEntry(testPrincipal, new Privilege[] {abstractPriv});
    fail("Adding an ACE with an abstract privilege must fail.");
  } catch (AccessControlException e) {
    // success
  }
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void testCustomPrivilege() {
  Set<String> expected = null; //EXERCISE
  assertEqualPrivileges(expected, customAggrPriv.getDeclaredAggregatePrivileges());
  expected = null; // EXERCISE
  assertEqualPrivileges(expected, customAggrPriv.getAggregatePrivileges());
  Boolean expectedIsAbstract = null; // EXERCISE
  assertEquals(expectedIsAbstract.booleanValue(), customAggrPriv.isAbstract());
}

代码示例来源:origin: apache/jackrabbit-oak

void assertPrivilege(Privilege priv, String name, boolean isAggregate, boolean isAbstract) {
    assertNotNull(priv);
    String privName = priv.getName();
    assertEquals(privName, privName, name);
    assertEquals(privName, isAggregate, priv.isAggregate());
    assertEquals(privName,isAbstract, priv.isAbstract());
  }
}

代码示例来源:origin: apache/jackrabbit

private void assertPrivilege(Privilege priv, String name, boolean isAggregate, boolean isAbstract) throws NamespaceException, IllegalNameException {
  assertNotNull(priv);
  assertPrivilegeName(name, priv.getName());
  assertEquals(isAggregate, priv.isAggregate());
  assertEquals(isAbstract, priv.isAbstract());
}

代码示例来源:origin: apache/jackrabbit

private static void assertPrivilege(PrivilegeRegistry registry, NameResolver resolver, PrivilegeDefinition def) throws RepositoryException {
  PrivilegeManagerImpl pmgr = new PrivilegeManagerImpl(registry, resolver);
  Privilege p = pmgr.getPrivilege(resolver.getJCRName(def.getName()));
  assertNotNull(p);
  assertEquals(def.isAbstract(), p.isAbstract());
  Set<Name> danames = def.getDeclaredAggregateNames();
  assertEquals(danames.size() > 0, p.isAggregate());
  assertEquals(danames.size(), p.getDeclaredAggregatePrivileges().length);
}

代码示例来源:origin: apache/jackrabbit-oak

/**
 * @since oak
 */
@Test
public void testCustomPrivilegeVisibleToNewSession() throws RepositoryException {
  boolean isAbstract = false;
  String privName = "testCustomPrivilegeVisibleToNewSession";
  privilegeManager.registerPrivilege(privName, isAbstract, new String[0]);
  Session s2 = getAdminSession();
  try {
    PrivilegeManager pm = getPrivilegeManager(s2);
    Privilege priv = pm.getPrivilege(privName);
    assertEquals(privName, priv.getName());
    assertEquals(isAbstract, priv.isAbstract());
    assertFalse(priv.isAggregate());
  } finally {
    s2.logout();
  }
}

代码示例来源:origin: apache/jackrabbit-oak

/**
 * @since oak
 */
@Test
public void testCustomPrivilegeVisibleAfterRefresh() throws RepositoryException {
  Session s2 = getAdminSession();
  PrivilegeManager pm = getPrivilegeManager(s2);
  try {
    boolean isAbstract = false;
    String privName = "testCustomPrivilegeVisibleAfterRefresh";
    privilegeManager.registerPrivilege(privName, isAbstract, new String[0]);
    // before refreshing: privilege not visible
    try {
      Privilege priv = pm.getPrivilege(privName);
      fail("Custom privilege will show up after Session#refresh()");
    } catch (AccessControlException e) {
      // success
    }
    // latest after refresh privilege manager must be updated
    s2.refresh(true);
    Privilege priv = pm.getPrivilege(privName);
    assertEquals(privName, priv.getName());
    assertEquals(isAbstract, priv.isAbstract());
    assertFalse(priv.isAggregate());
  } finally {
    s2.logout();
  }
}

代码示例来源:origin: apache/jackrabbit

public void testCustomPrivilege() throws RepositoryException, FileSystemException {
  boolean isAbstract = false;
  Name name = ((SessionImpl) superuser).getQName("test");
  privilegeRegistry.registerDefinition(name, isAbstract, Collections.<Name>emptySet());
  PrivilegeManagerImpl pm = new PrivilegeManagerImpl(privilegeRegistry, resolver);
  String privName = resolver.getJCRName(name);
  Privilege priv = pm.getPrivilege(privName);
  assertEquals(privName, priv.getName());
  assertEquals(isAbstract, priv.isAbstract());
  assertFalse(priv.isAggregate());
  assertFalse(pm.getBits(priv).isEmpty());
  Privilege jcrWrite = pm.getPrivilege(Privilege.JCR_WRITE);
  assertFalse(pm.getBits(jcrWrite).equals(pm.getBits(priv, jcrWrite)));
}

相关文章