throw new AccessDeniedException("Content can only be accessed in live");
}
}
}
if (!"studiomode".equals(renderContext.getEditModeConfigName())) {
JahiaUser aliasedUser = JCRSessionFactory.getInstance().getCurrentAliasedUser();
if (node.hasProperty("j:requiredPermissions")) {
chain.pushAttribute(renderContext.getRequest(),"cache.dynamicRolesAcls",Boolean.TRUE);
final Value[] values = node.getProperty("j:requiredPermissions").getValues();
final List<String> perms = JCRTemplate.getInstance().doExecuteWithSystemSession(null, new JCRCallback<List<String>>() {
public List<String> doInJCR(JCRSessionWrapper session) throws RepositoryException {
List<String> permissionNames = new ArrayList<String>();
for (Value value : values) {
permissionNames.add(session.getNodeByUUID(value.getString()).getName());
}
return permissionNames;
}
});
JCRNodeWrapper contextNode = renderContext.getMainResource().getNode();
try {
if (node.hasProperty("j:contextNodePath")) {
String contextPath = node.getProperty("j:contextNodePath").getString();
if (!StringUtils.isEmpty(contextPath)) {
if (contextPath.startsWith("/")) {
contextNode = JCRSessionFactory.getInstance().getCurrentUserSession().getNode(contextPath);
} else {
contextNode = contextNode.getNode(contextPath);
}
}
}
} catch (PathNotFoundException e) {
return "";
}
for (String perm : perms) {
if (!contextNode.hasPermission(perm)) {
return "";
}
}
if (aliasedUser != null) {
if (!JCRTemplate.getInstance().doExecuteWithUserSession(aliasedUser.getUsername(), node.getSession().getWorkspace().getName(),
new JCRCallback<Boolean>() {
public Boolean doInJCR(JCRSessionWrapper session) throws RepositoryException {
JCRNodeWrapper aliasedNode = session.getNode(resource.getNode().getPath());
for (String perm : perms) {
if (!aliasedNode.hasPermission(perm)) {
return false;
}
}
return true;
}
}
)) {
return "";
}
}
}
if (node.hasProperty("j:requireLoggedUser") && node.getProperty("j:requireLoggedUser").getBoolean()) {
if (!renderContext.isLoggedIn()) {
return "";
}
if (aliasedUser != null) {
if (JahiaUserManagerService.isGuest(aliasedUser)) {
return "";
}
}
}
if (node.hasProperty("j:requirePrivilegedUser") && node.getProperty("j:requirePrivilegedUser").getBoolean()) {
if (!renderContext.getUser().isMemberOfGroup(0,JahiaGroupManagerService.PRIVILEGED_GROUPNAME)) {
return "";
}
if (aliasedUser != null) {
if (!aliasedUser.isMemberOfGroup(0, JahiaGroupManagerService.PRIVILEGED_GROUPNAME)) {
return "";
}
}
}
}