use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto in project pentaho-platform by pentaho.
the class FileService method doSetMetadata.
/**
* Set the metadata on a file
*
* @param pathId
* @param metadata
* @throws GeneralSecurityException
*/
public void doSetMetadata(String pathId, List<StringKeyStringValueDto> metadata) throws GeneralSecurityException {
RepositoryFileDto file = getRepoWs().getFile(idToPath(pathId));
RepositoryFileAclDto fileAcl = getRepoWs().getAcl(file.getId());
boolean canManage = getSession().getName().equals(fileAcl.getOwner()) || (getPolicy().isAllowed(RepositoryReadAction.NAME) && getPolicy().isAllowed(RepositoryCreateAction.NAME) && getPolicy().isAllowed(AdministerSecurityAction.NAME));
if (!canManage) {
if (fileAcl.isEntriesInheriting()) {
List<RepositoryFileAclAceDto> aces = getRepoWs().getEffectiveAces(file.getId());
fileAcl.setAces(aces, fileAcl.isEntriesInheriting());
}
for (int i = 0; i < fileAcl.getAces().size(); i++) {
RepositoryFileAclAceDto acl = fileAcl.getAces().get(i);
if (acl.getRecipient().equals(getSession().getName())) {
if (acl.getPermissions().contains(RepositoryFilePermission.ACL_MANAGEMENT.ordinal()) || acl.getPermissions().contains(RepositoryFilePermission.ALL.ordinal())) {
canManage = true;
break;
}
}
}
}
if (canManage) {
Map<String, Serializable> fileMetadata = getRepository().getFileMetadata(file.getId());
boolean isHidden = RepositoryFile.HIDDEN_BY_DEFAULT;
boolean isSchedulable = RepositoryFile.SCHEDULABLE_BY_DEFAULT;
fileMetadata.remove(RepositoryFile.HIDDEN_KEY);
for (StringKeyStringValueDto nv : metadata) {
// don't add hidden to the list because it is not actually part of the metadata node
String key = nv.getKey();
if (RepositoryFile.HIDDEN_KEY.equalsIgnoreCase(key)) {
isHidden = BooleanUtils.toBoolean(nv.getValue());
continue;
}
if (RepositoryFile.SCHEDULABLE_KEY.equalsIgnoreCase(key)) {
isSchedulable = BooleanUtils.toBoolean(nv.getValue());
}
fileMetadata.put(key, nv.getValue());
}
// now update the rest of the metadata
if (!file.isFolder()) {
getRepository().setFileMetadata(file.getId(), fileMetadata);
}
// handle hidden flag if it is different
if (file.isHidden() != isHidden) {
file.setHidden(isHidden);
file.setNotSchedulable(!isSchedulable);
/*
* Since we cannot simply set the new value, use the RepositoryFileAdapter to create a new instance and then
* update the original.
*/
RepositoryFile sourceFile = getRepository().getFileById(file.getId());
RepositoryFileDto destFileDto = toFileDto(sourceFile, null, false);
destFileDto.setHidden(isHidden);
destFileDto.setNotSchedulable(!isSchedulable);
RepositoryFile destFile = toFile(destFileDto);
// add the existing acls and file data
RepositoryFileAcl acl = getRepository().getAcl(sourceFile.getId());
if (!file.isFolder()) {
IRepositoryFileData data = RepositoryFileHelper.getFileData(sourceFile);
getRepository().updateFile(destFile, data, null);
getRepository().updateAcl(acl);
} else {
getRepository().updateFolder(destFile, null);
}
}
} else {
throw new GeneralSecurityException();
}
}
use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto in project pentaho-platform by pentaho.
the class FileService method doSetContentCreator.
/**
* Store content creator of the selected repository file
*
* @param pathId colon separated path for the repository file
* <pre function="syntax.xml">
* :path:to:file:id
* </pre>
* @param contentCreator repository file
* <pre function="syntax.xml">
* <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
* <repositoryFileDto>
* <createdDate>1402911997019</createdDate>
* <fileSize>3461</fileSize>
* <folder>false</folder>
* <hidden>false</hidden>
* <id>ff11ac89-7eda-4c03-aab1-e27f9048fd38</id>
* <lastModifiedDate>1406647160536</lastModifiedDate>
* <locale>en</locale>
* <localePropertiesMapEntries>
* <localeMapDto>
* <locale>default</locale>
* <properties>
* <stringKeyStringValueDto>
* <key>file.title</key>
* <value>myFile</value>
* </stringKeyStringValueDto>
* <stringKeyStringValueDto>
* <key>jcr:primaryType</key>
* <value>nt:unstructured</value>
* </stringKeyStringValueDto>
* <stringKeyStringValueDto>
* <key>title</key>
* <value>myFile</value>
* </stringKeyStringValueDto>
* <stringKeyStringValueDto>
* <key>file.description</key>
* <value>myFile Description</value>
* </stringKeyStringValueDto>
* </properties>
* </localeMapDto>
* </localePropertiesMapEntries>
* <locked>false</locked>
* <name>myFile.prpt</name></name>
* <originalParentFolderPath>/public/admin</originalParentFolderPath>
* <ownerType>-1</ownerType>
* <path>/public/admin/ff11ac89-7eda-4c03-aab1-e27f9048fd38</path>
* <title>myFile</title>
* <versionId>1.9</versionId>
* <versioned>true</versioned>
* </repositoryFileAclDto>
* </pre>
* @throws FileNotFoundException
*/
public void doSetContentCreator(String pathId, RepositoryFileDto contentCreator) throws FileNotFoundException {
RepositoryFileDto file = getRepoWs().getFile(idToPath(pathId));
if (file == null) {
throw new FileNotFoundException();
}
try {
Map<String, Serializable> fileMetadata = getRepository().getFileMetadata(file.getId());
fileMetadata.put(PentahoJcrConstants.PHO_CONTENTCREATOR, contentCreator.getId());
getRepository().setFileMetadata(file.getId(), fileMetadata);
} catch (Exception e) {
throw new InternalError();
}
}
use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto in project pentaho-platform by pentaho.
the class FileService method addAdminRole.
protected void addAdminRole(RepositoryFileAclDto fileAcl) {
String adminRoleName = PentahoSystem.get(String.class, "singleTenantAdminAuthorityName", PentahoSessionHolder.getSession());
if (fileAcl.getAces() == null) {
fileAcl.setAces(new LinkedList<RepositoryFileAclAceDto>());
}
for (RepositoryFileAclAceDto facl : fileAcl.getAces()) {
if (facl.getRecipient().equals(adminRoleName) && facl.getRecipientType() == 1) {
return;
}
}
RepositoryFileAclAceDto adminGroup = new RepositoryFileAclAceDto();
adminGroup.setRecipient(adminRoleName);
adminGroup.setRecipientType(1);
adminGroup.setModifiable(false);
List<Integer> perms = new LinkedList<Integer>();
perms.add(4);
adminGroup.setPermissions(perms);
fileAcl.getAces().add(adminGroup);
}
use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto in project pentaho-platform by pentaho.
the class FileServiceTest method doSetMetadataException.
@Test
public void doSetMetadataException() {
String pathId = "path:to:file:file1.ext";
List<StringKeyStringValueDto> stringKeyStringValueDtos = new ArrayList<StringKeyStringValueDto>();
doReturn("/path/to/file/file1.ext").when(fileService).idToPath(pathId);
doReturn(false).when(fileService.policy).isAllowed(RepositoryReadAction.NAME);
doReturn(false).when(fileService.policy).isAllowed(RepositoryCreateAction.NAME);
doReturn(false).when(fileService.policy).isAllowed(AdministerSecurityAction.NAME);
RepositoryFileDto file = mock(RepositoryFileDto.class);
doReturn(file).when(fileService.defaultUnifiedRepositoryWebService).getFile(anyString());
RepositoryFileAclDto repositoryFileAclDto = mock(RepositoryFileAclDto.class);
doReturn("sessionName").when(repositoryFileAclDto).getOwner();
doReturn(repositoryFileAclDto).when(fileService.defaultUnifiedRepositoryWebService).getAcl(anyString());
IPentahoSession pentahoSession = mock(IPentahoSession.class);
doReturn(pentahoSession).when(fileService).getSession();
doReturn("sessionName1").when(pentahoSession).getName();
try {
fileService.doSetMetadata(pathId, stringKeyStringValueDtos);
fail();
} catch (GeneralSecurityException e) {
// Should catch the exception
}
verify(fileService.defaultUnifiedRepositoryWebService).getFile(anyString());
verify(fileService.defaultUnifiedRepositoryWebService).getAcl(anyString());
verify(repositoryFileAclDto).getOwner();
verify(fileService.policy).isAllowed(anyString());
}
use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto in project pentaho-platform by pentaho.
the class FileServiceTest method testSetFileAclsException.
@Test
public void testSetFileAclsException() throws Exception {
String pathId = "/usr/folder/file.txt";
RepositoryFileAclDto acl = mock(RepositoryFileAclDto.class);
try {
fileService.setFileAcls(pathId, acl);
fail();
} catch (FileNotFoundException e) {
// expected exception
}
}
Aggregations