javax.jcr.Session.hasPermission()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(107)

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

Session.hasPermission介绍

[英]Returns true if this Session has permission to perform the specified actions at the specified absPath and false otherwise.

The actions parameter is a comma separated list of action strings. The following action strings are defined:

  • #ACTION_ADD_NODE: If hasPermission(path, "add_node") returns true, then this Session has permission to add a node at path.
  • #ACTION_SET_PROPERTY: If hasPermission(path, "set_property") returns true, then this Session has permission to set (add or change) a property at path.
  • #ACTION_REMOVE: If hasPermission(path, "remove") returns true, then this Session has permission to remove an item at path.
  • #ACTION_READ: If hasPermission(path, "read") returns true, then this Session has permission to retrieve (and read the value of, in the case of a property) an item at path.
    When more than one action is specified in the actions parameter, this method will only return true if this Session has permission to perform all of the listed actions at the specified path.

The information returned through this method will only reflect the access control status (both JCR defined and implementation-specific) and not other restrictions that may exist, such as node type constraints. For example, even though hasPermission may indicate that a particular Session may add a property at /A/B/C, the node type of the node at /A/B may prevent the addition of a property called C.
[中]如果此Session有权在指定的absPath位置执行指定操作,则返回true,否则返回false
actions参数是以逗号分隔的操作字符串列表。定义了以下操作字符串:
*#操作_添加_节点:如果hasPermission(path, "add_node")返回true,则该Session有权在[$8$]添加节点。
*#操作_设置_属性:如果hasPermission(path, "set_property")返回true,则该Session有权将属性设置(添加或更改)为path
*#操作_移除:如果hasPermission(path, "remove")返回true,则该Session有权移除[$16$]处的项目。
*#操作_READ:如果hasPermission(path, "read")返回true,则该Session有权在[$20$]处检索(并读取属性的值)。
actions参数中指定了多个操作时,如果该Session有权在指定路径上执行所有列出的操作,则此方法将只返回true
通过此方法返回的信息将只反映访问控制状态(JCR定义的和特定于实现的),而不反映可能存在的其他限制,例如节点类型限制。例如,尽管hasPermission可能表示特定Session可能会在/A/B/C处添加属性,但/A/B处节点的节点类型可能会阻止添加名为C的属性。

代码示例

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

/** {@inheritDoc} */
public boolean hasPermission(String path, String actions)
    throws RepositoryException, RemoteException {
  return session.hasPermission(path, actions);
}

代码示例来源:origin: info.magnolia/magnolia-templating

private boolean hasPermission(Node node) {
  try {
    return node.getSession().hasPermission(node.getPath(), Session.ACTION_SET_PROPERTY);
  } catch (RepositoryException e) {
    log.error("Could not determine permission for node {}", node);
  }
  return false;
}

代码示例来源:origin: info.magnolia/magnolia-core

@Override
public boolean hasPermission(String absPath, String actions) throws RepositoryException {
  return getWrappedSession().hasPermission(absPath, actions);
}

代码示例来源:origin: ModeShape/modeshape

@Override
public boolean hasPermission( String string,
               String string1 ) throws RepositoryException {
  return session().hasPermission(string, string1);
}

代码示例来源:origin: info.magnolia/magnolia-templating

private boolean hasPermission(Node node) {
  if (node == null) {
    node = currentContent();
  }
  try {
    return node.getSession().hasPermission(node.getPath(), Session.ACTION_SET_PROPERTY);
  } catch (RepositoryException e) {
    log.error("Could not determine permission for node {}", node);
  }
  return false;
}

代码示例来源:origin: org.apache.sling/org.apache.sling.distribution.core

boolean hasPermission(ResourceResolver resourceResolver, String resourcePath, String permission) {
  boolean hasPermission = false;
  Session session = resourceResolver.adaptTo(Session.class);
  if (session != null) {
    try {
      hasPermission = session.hasPermission(resourcePath, permission);
    } catch (RepositoryException e) {
      hasPermission = false;
    }
  }
  return hasPermission;
}

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

public boolean hasPermission(String arg0, String arg1)
    throws RepositoryException {
  return getSession().hasPermission(arg0, arg1);
}

代码示例来源:origin: Adobe-Consulting-Services/acs-aem-commons

@Override
default boolean hasPermission(final String absPath, final String actions) throws RepositoryException {
  return unwrapSession().hasPermission(absPath, actions);
}

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

public boolean hasPermission(String arg0, String arg1)
    throws RepositoryException {
  return getSession().hasPermission(arg0, arg1);
}

代码示例来源:origin: org.onehippo.cms7/hippo-cms-workflow-frontend

private static boolean isWritePermissionGranted(IModel<Node> model) {
  Node node = model != null ? model.getObject() : null;
  if (node != null) {
    try {
      return UserSession.get().getJcrSession().hasPermission(node.getPath(), JcrConstants.JCR_WRITE);
    } catch (RepositoryException ignore) {
    }
  }
  return false;
}

代码示例来源:origin: org.onehippo.cms7.hst.components/hst-core

@Override
public synchronized boolean canUserModifyChannels() {
  try {
    final Session session = getSession();
    return session.hasPermission(hstNodeLoadingCache.getRootPath() + "/accesstest", Session.ACTION_ADD_NODE);
  } catch (RepositoryException e) {
    log.error("Repository error when determining channel manager access", e);
  }
  return false;
}

代码示例来源:origin: info.magnolia/magnolia-core

/**
 * Checks whether given session has requested permission on provided path. Throws an exception if permission is not granted on given path.
 *
 * @throws AccessDeniedException when permission is not granted.
 */
public static void verifyIsGrantedOrThrowException(Session jcrSession, String path, String action) throws AccessDeniedException {
  try {
    if (!jcrSession.hasPermission(path, action)) {
      throw new AccessDeniedException("Not allowed to access " + path + " with permission " + action);
    }
  } catch (RepositoryException e) {
    throw new AccessDeniedException("Exception occurred while checking permissions for " + path + " with permission " + action, e);
  }
}

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

public void testModifyPermissions() throws RepositoryException {
  // EXERCISE: fill in the expected values
  Map<String, Boolean> modifyPropertyTests = ImmutableMap.of(
      "/jcr:primaryType", null,
      testRoot, null,
      propertyPath, null
  );
  for (String pPath : modifyPropertyTests.keySet()) {
    boolean canModifyProperty = modifyPropertyTests.get(pPath);
    assertEquals(canModifyProperty, testSession.hasPermission(pPath, Session.ACTION_SET_PROPERTY));
  }
}

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

@Test
public void testRemove() throws Exception {
  // add 'remove_child_nodes' privilege at 'path'
  Privilege[] rmChildNodes = privilegesFromName(Privilege.JCR_REMOVE_CHILD_NODES);
  allow(path, rmChildNodes);
  /*
   expected result:
   - neither node at path nor at childNPath can be removed since
    REMOVE_NODE privilege is missing.
   */
  assertFalse(testSession.hasPermission(path, javax.jcr.Session.ACTION_REMOVE));
  assertFalse(testSession.hasPermission(childNPath, javax.jcr.Session.ACTION_REMOVE));
}

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

@Test
public void testRemove2() throws Exception {
  // add 'remove_node' privilege at 'path'
  Privilege[] rmChildNodes = privilegesFromName(Privilege.JCR_REMOVE_NODE);
  allow(path, rmChildNodes);
  /*
   expected result:
   - neither node at path nor at childNPath can be removed permission
    due to missing remove_child_nodes privilege.
   */
  assertFalse(testSession.hasPermission(path, javax.jcr.Session.ACTION_REMOVE));
  assertFalse(testSession.hasPermission(childNPath, javax.jcr.Session.ACTION_REMOVE));
}

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

@Test
  public void testCancelInheritanceRestriction() throws Exception {
    allow(path, repWritePrivileges, createGlobRestriction(""));

    assertTrue(testAcMgr.hasPrivileges(path, repWritePrivileges));
    assertTrue(testSession.hasPermission(path, Session.ACTION_SET_PROPERTY));

    assertFalse(testAcMgr.hasPrivileges(childNPath, repWritePrivileges));
    assertFalse(testSession.hasPermission(childNPath, Session.ACTION_SET_PROPERTY));

    assertFalse(testAcMgr.hasPrivileges(childNPath2, repWritePrivileges));
    assertFalse(testSession.hasPermission(childNPath2, Session.ACTION_SET_PROPERTY));
  }
}

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

public void testEmpty() throws Exception {
  List<String> paths = ImmutableList.of(
      "/", path, childPPath, path + "/rep:policy",
      "/nonExisting", path + "/nonExisting");
  for (String p : paths) {
    assertTrue(testSession.hasPermission(p, ""));
    assertTrue(testSession.hasPermission(p, ",,"));
    assertTrue(((JackrabbitSession) testSession).hasPermission(p, new String[0]));
    assertTrue(((JackrabbitSession) testSession).hasPermission(p, new String[]{""}));
    assertTrue(((JackrabbitSession) testSession).hasPermission(p, new String[]{"", ""}));
    assertTrue(((JackrabbitSession) testSession).hasPermission(p, "", ""));
  }
}

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

@Test
public void testGroupPermissions() throws Exception {
  /* add privileges for the Group the test-user is member of */
  allow(path, testGroup.getPrincipal(), modPropPrivileges);
  /* testuser must get the permissions/privileges inherited from
    the group it is member of.
   */
  String actions = getActions(Session.ACTION_SET_PROPERTY, Session.ACTION_READ);
  assertTrue(testSession.hasPermission(path, actions));
  assertTrue(testAcMgr.hasPrivileges(path, modPropPrivileges));
}

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

@Test
public void testGlobRestriction4() throws Exception {
  Privilege[] addNode = privilegesFromName(Privilege.JCR_ADD_CHILD_NODES);
  allow(path, repWritePrivileges, createGlobRestriction("/*"+nodeName3));
  deny(childNPath2, addNode);
  assertFalse(testAcMgr.hasPrivileges(path, repWritePrivileges));
  assertFalse(testSession.hasPermission(path, javax.jcr.Session.ACTION_REMOVE));
  assertFalse(testAcMgr.hasPrivileges(childNPath, repWritePrivileges));
  assertFalse(testSession.hasPermission(childNPath, javax.jcr.Session.ACTION_REMOVE));
  assertFalse(testAcMgr.hasPrivileges(childNPath2, repWritePrivileges));
  assertTrue(testAcMgr.hasPrivileges(nodePath3, repWritePrivileges));
}

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

@Test
public void testMixedUserGroupPermissions() throws Exception {
  /* explicitly withdraw MODIFY_PROPERTIES for the user */
  deny(path, testUser.getPrincipal(), modPropPrivileges);
  /* give MODIFY_PROPERTIES privilege for a Group the test-user is member of */
  allow(path, testGroup.getPrincipal(), modPropPrivileges);
  /*
   since user-permissions overrule the group permissions, testuser must
   not have set_property action / modify_properties privilege.
   */
  assertFalse(testSession.hasPermission(path, Session.ACTION_SET_PROPERTY));
  assertFalse(testAcMgr.hasPrivileges(path, modPropPrivileges));
}

相关文章

微信公众号

最新文章

更多