use of org.springframework.extensions.jcr.JcrCallback in project pentaho-platform by pentaho.
the class DefaultBackingRepositoryLifecycleManager method createCustomPrivilege.
private void createCustomPrivilege() {
txnTemplate.execute(new TransactionCallbackWithoutResult() {
public void doInTransactionWithoutResult(final TransactionStatus status) {
adminJcrTemplate.execute(new JcrCallback() {
@Override
public Object doInJcr(Session session) throws IOException, RepositoryException {
PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
Workspace workspace = session.getWorkspace();
PrivilegeManager privilegeManager = ((JackrabbitWorkspace) workspace).getPrivilegeManager();
try {
privilegeManager.getPrivilege(pentahoJcrConstants.getPHO_ACLMANAGEMENT_PRIVILEGE());
} catch (AccessControlException ace) {
privilegeManager.registerPrivilege(pentahoJcrConstants.getPHO_ACLMANAGEMENT_PRIVILEGE(), false, new String[0]);
}
session.save();
return null;
}
});
}
});
}
use of org.springframework.extensions.jcr.JcrCallback in project pentaho-platform by pentaho.
the class JcrRoleAuthorizationPolicyRoleBindingDao method setRoleBindings.
@Override
public void setRoleBindings(final ITenant tenant, final String runtimeRoleName, final List<String> logicalRoleNames) {
ITenant tempTenant = tenant;
if (tenant == null) {
tempTenant = JcrTenantUtils.getTenant(runtimeRoleName, false);
}
if (!TenantUtils.isAccessibleTenant(tempTenant)) {
throw new NotFoundException("Tenant " + tenant.getId() + " not found");
}
Assert.notNull(logicalRoleNames);
jcrTemplate.execute(new JcrCallback() {
@Override
public Object doInJcr(final Session session) throws RepositoryException, IOException {
setRoleBindings(session, tenant, runtimeRoleName, logicalRoleNames);
return null;
}
});
}
use of org.springframework.extensions.jcr.JcrCallback in project pentaho-kettle by pentaho.
the class PurRepositoryIT method setAclManagement.
private void setAclManagement() {
JcrCallback callback = PurRepositoryTestingUtils.setAclManagementCallback();
testJcrTemplate.execute(callback);
}
use of org.springframework.extensions.jcr.JcrCallback in project pentaho-platform by pentaho.
the class JcrRepositoryFileAclDao method getEffectiveAces.
// ~ Methods
// =========================================================================================================
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
public List<RepositoryFileAce> getEffectiveAces(final Serializable id, final boolean forceEntriesInheriting) {
return (List<RepositoryFileAce>) jcrTemplate.execute(new JcrCallback() {
public Object doInJcr(final Session session) throws RepositoryException, IOException {
Node node = session.getNodeByIdentifier(id.toString());
if (node == null) {
throw new RepositoryException(Messages.getInstance().getString("JackrabbitRepositoryFileAclDao.ERROR_0001_NODE_NOT_FOUND", // $NON-NLS-1$
id.toString()));
}
// consult the parent node's effective policy if force is true and parent is not null
if (forceEntriesInheriting && session.getNodeByIdentifier(id.toString()).getParent() != null) {
node = node.getParent();
}
String absPath = node.getPath();
AccessControlPolicy[] acPolicies = session.getAccessControlManager().getEffectivePolicies(absPath);
// logic assumes policies are ordered from leaf to root
for (AccessControlPolicy policy : acPolicies) {
Assert.isTrue(policy instanceof AccessControlList);
AccessControlList acList = ((AccessControlList) policy);
if (!isEntriesInheriting(session, absPath, acList)) {
List<RepositoryFileAce> aces = new ArrayList<RepositoryFileAce>();
AccessControlEntry[] acEntries = acList.getAccessControlEntries();
List<AccessControlEntry> cleanedAcEntries = JcrRepositoryFileAclUtils.removeAclMetadata(Arrays.asList(acEntries));
for (AccessControlEntry acEntry : cleanedAcEntries) {
if (!acEntry.getPrincipal().equals(new SpringSecurityRolePrincipal(JcrTenantUtils.getTenantedRole(tenantAdminAuthorityName)))) {
aces.add(toAce(session, acEntry));
}
}
return aces;
}
}
// none are entriesInheriting=false so root aces are the effective aces
AccessControlList acList = (AccessControlList) acPolicies[acPolicies.length - 1];
List<RepositoryFileAce> aces = new ArrayList<RepositoryFileAce>();
AccessControlEntry[] acEntries = acList.getAccessControlEntries();
List<AccessControlEntry> cleanedAcEntries = JcrRepositoryFileAclUtils.removeAclMetadata(Arrays.asList(acEntries));
for (AccessControlEntry acEntry : cleanedAcEntries) {
if (!acEntry.getPrincipal().equals(new SpringSecurityRolePrincipal(JcrTenantUtils.getTenantedRole(tenantAdminAuthorityName)))) {
aces.add(toAce(session, acEntry));
}
}
return aces;
}
});
}
use of org.springframework.extensions.jcr.JcrCallback in project pentaho-platform by pentaho.
the class JcrRepositoryFileDao method permanentlyDeleteFile.
/**
* {@inheritDoc}
* <p/>
* <p>
* No checkout needed as .trash is not versioned.
* </p>
*/
@Override
public void permanentlyDeleteFile(final Serializable fileId, final String versionMessage) {
if (isKioskEnabled()) {
// $NON-NLS-1$
throw new RuntimeException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED"));
}
Assert.notNull(fileId);
jcrTemplate.execute(new JcrCallback() {
@Override
public Object doInJcr(final Session session) throws RepositoryException, IOException {
RepositoryFile fileToBeDeleted = getFileById(fileId);
// Get repository file info and acl info of parent
if (fileToBeDeleted != null) {
RepositoryFileAcl toBeDeletedFileAcl = aclDao.getAcl(fileToBeDeleted.getId());
// Invoke accessVoterManager to see if we have access to perform this operation
if (!accessVoterManager.hasAccess(fileToBeDeleted, RepositoryFilePermission.DELETE, toBeDeletedFileAcl, PentahoSessionHolder.getSession())) {
return null;
}
}
PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
deleteHelper.permanentlyDeleteFile(session, pentahoJcrConstants, fileId);
session.save();
return null;
}
});
}
Aggregations