Question / Symptoms

How do I check if a user has privilege to perform a specific action?

Answer / Resolution

To check if a user has write access to a page:

public boolean hasWriteAccess(Node pageNode, Session userSession) throws RepositoryException {
  String path = pageNode.getPath();
  try {
    userSession.checkPermission(path, "add_node,set_property");
    if(pageNode.hasNode(JcrConstants.JCR_CONTENT)) {
      String contentNodePath = path + "/" + "jcr:content";
      userSession.checkPermission(contentNodePath, "add_node,set_property");
  } catch( e) {
    return false;
  return true;

To check if a user can activate pages:

final User u = resourceResolver.adaptTo(User.class);
// alternatively: final User u = SecurityUtil.resolveUser(session);
return u.hasPermission(Replicator.REPLICATION_PERMISSION);


See 5.2 API for User

Applies to

CQ5.1, CQ5.2

이 작업에는 Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License의 라이센스가 부여되었습니다.  Twitter™ 및 Facebook 게시물은 Creative Commons 약관을 적용받지 않습니다.

법적 고지 사항   |   온라인 개인 정보 보호 정책