Search in sources :

Example 11 with RepositoryFileAclAceDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclAceDto 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();
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) StringKeyStringValueDto(org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto) IRepositoryFileData(org.pentaho.platform.api.repository2.unified.IRepositoryFileData) Serializable(java.io.Serializable) RepositoryFileAclAceDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclAceDto) RepositoryFileAclDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto) GeneralSecurityException(java.security.GeneralSecurityException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

Example 12 with RepositoryFileAclAceDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclAceDto 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);
}
Also used : RepositoryFileAclAceDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclAceDto) LinkedList(java.util.LinkedList)

Example 13 with RepositoryFileAclAceDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclAceDto in project pentaho-platform by pentaho.

the class RepositoryFileAclAdapter method unmarshal.

@Override
public RepositoryFileAcl unmarshal(final RepositoryFileAclDto v) {
    RepositoryFileAcl.Builder builder = null;
    if (v.getOwnerType() != -1) {
        if (v.getId() != null) {
            builder = new RepositoryFileAcl.Builder(v.getId(), v.getOwner(), RepositoryFileSid.Type.values()[v.getOwnerType()]);
        } else {
            builder = new RepositoryFileAcl.Builder(v.getTenantPath(), v.getOwner(), RepositoryFileSid.Type.values()[v.getOwnerType()]);
        }
    } else {
        builder = new RepositoryFileAcl.Builder((Serializable) v.getId(), null);
    }
    builder.entriesInheriting(v.isEntriesInheriting());
    for (RepositoryFileAclAceDto fileAclAceDto : v.getAces()) {
        builder.ace(RepositoryFileAclAceAdapter.toAce(fileAclAceDto));
    }
    return builder.build();
}
Also used : Serializable(java.io.Serializable) RepositoryFileAclAceDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclAceDto) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

Example 14 with RepositoryFileAclAceDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclAceDto in project pentaho-platform by pentaho.

the class FileResourceTest method usersOrRolesExist_RecipientUserExists.

@Test
public void usersOrRolesExist_RecipientUserExists() {
    RepositoryFileAclDto acl = new RepositoryFileAclDto();
    acl.setOwner(ACL_OWNER);
    RepositoryFileAclAceDto recipient = mock(RepositoryFileAclAceDto.class);
    doReturn(USERNAME).when(recipient).getRecipient();
    acl.setAces(Arrays.asList(new RepositoryFileAclAceDto[] { recipient }), false);
    assertTrue(fileResource.validateUsersAndRoles(acl));
}
Also used : RepositoryFileAclAceDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclAceDto) RepositoryFileAclDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto) Test(org.junit.Test)

Aggregations

RepositoryFileAclAceDto (org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclAceDto)12 RepositoryFileAclDto (org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto)8 Test (org.junit.Test)6 Serializable (java.io.Serializable)5 RepositoryFileDto (org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto)5 ArrayList (java.util.ArrayList)4 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)4 GeneralSecurityException (java.security.GeneralSecurityException)3 Map (java.util.Map)3 IRepositoryFileData (org.pentaho.platform.api.repository2.unified.IRepositoryFileData)3 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)3 StringKeyStringValueDto (org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto)3 HashMap (java.util.HashMap)2 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)2 RepositoryFileAclAceDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAceDto)2 RepositoryFileAclDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 WebResource (com.sun.jersey.api.client.WebResource)1 JerseyTest (com.sun.jersey.test.framework.JerseyTest)1 FileNotFoundException (java.io.FileNotFoundException)1