Search in sources :

Example 6 with RepositoryFileAclAceDto

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

the class FileResourceTest method usersOrRolesExist_RecipientRoleExists.

@Test
public void usersOrRolesExist_RecipientRoleExists() {
    RepositoryFileAclDto acl = new RepositoryFileAclDto();
    acl.setOwner(ACL_OWNER);
    RepositoryFileAclAceDto recipient = mock(RepositoryFileAclAceDto.class);
    doReturn(ROLENAME).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)

Example 7 with RepositoryFileAclAceDto

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

the class RepositoryFileAclAceAdapter method toAceDto.

public static RepositoryFileAclAceDto toAceDto(RepositoryFileAce v) {
    RepositoryFileAclAceDto aceDto = new RepositoryFileAclAceDto();
    RepositoryFileSid sid = v.getSid();
    aceDto.setRecipient(sid.getName());
    aceDto.setRecipientType(sid.getType().ordinal());
    aceDto.setPermissions(toIntPerms(v.getPermissions()));
    return aceDto;
}
Also used : RepositoryFileSid(org.pentaho.platform.api.repository2.unified.RepositoryFileSid) RepositoryFileAclAceDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclAceDto)

Example 8 with RepositoryFileAclAceDto

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

the class RepositoryFileAdapter method toFileDto.

public static RepositoryFileDto toFileDto(final RepositoryFile v, Set<String> memberSet, boolean exclude, boolean includeAcls) {
    if (v == null) {
        return null;
    }
    RepositoryFileDto f = new RepositoryFileDto();
    // no longer exists, so it returns null
    try {
        if (include("name", memberSet, exclude)) {
            f.setName(v.getName());
        }
        if (include("path", memberSet, exclude)) {
            f.setPath(v.getPath());
        }
        if (include("hidden", memberSet, exclude)) {
            f.setHidden(v.isHidden());
        }
        if (include("aclNode", memberSet, exclude)) {
            f.setAclNode(v.isAclNode());
        }
        if (include("createDate", memberSet, exclude)) {
            f.setCreatedDate(marshalDate(v.getCreatedDate()));
        }
        if (include("creatorId", memberSet, exclude)) {
            f.setCreatorId(v.getCreatorId());
        }
        if (include("fileSize", memberSet, exclude)) {
            f.setFileSize(v.getFileSize());
        }
        if (include("description", memberSet, exclude)) {
            f.setDescription(v.getDescription());
        }
        if (include("folder", memberSet, exclude)) {
            f.setFolder(v.isFolder());
        }
        // it must be present or the tree rest service call will error
        if (v.getId() != null) {
            f.setId(v.getId().toString());
        }
        if (include("lastModifiedDate", memberSet, exclude)) {
            f.setLastModifiedDate(marshalDate(v.getLastModifiedDate()));
        }
        if (include("locale", memberSet, exclude)) {
            f.setLocale(v.getLocale());
        }
        if (include("originalParentFolderPath", memberSet, exclude)) {
            f.setOriginalParentFolderPath(v.getOriginalParentFolderPath());
        }
        if (include("deletedDate", memberSet, exclude)) {
            f.setDeletedDate(marshalDate(v.getDeletedDate()));
        }
        if (include("lockDate", memberSet, exclude)) {
            f.setLockDate(marshalDate(v.getLockDate()));
        }
        if (include("locked", memberSet, exclude)) {
            f.setLocked(v.isLocked());
        }
        if (include("lockMessage", memberSet, exclude)) {
            f.setLockMessage(v.getLockMessage());
        }
        if (include("lockOwner", memberSet, exclude)) {
            f.setLockOwner(v.getLockOwner());
        }
        if (include("title", memberSet, exclude)) {
            f.setTitle(v.getTitle());
        }
        if (include("versioned", memberSet, exclude)) {
            f.setVersioned(v.isVersioned());
        }
        if (include("versionId", memberSet, exclude)) {
            if (v.getVersionId() != null) {
                f.setVersionId(v.getVersionId().toString());
            }
        }
    } catch (NullPointerException e) {
        getLogger().warn("NullPointerException while reading file attributes, returning null. Probable cause: File does not" + "exist anymore: ");
        return null;
    }
    if (includeAcls) {
        if (v.getId() != null) {
            try {
                String id = v.getId().toString();
                f.setRepositoryFileAclDto(getRepoWs().getAcl(id));
                if (f.getRepositoryFileAclDto().isEntriesInheriting()) {
                    List<RepositoryFileAclAceDto> aces = getRepoWs().getEffectiveAces(id);
                    f.getRepositoryFileAclDto().setAces(aces, f.getRepositoryFileAclDto().isEntriesInheriting());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (include("owner", memberSet, exclude)) {
            Serializable id = v.getId();
            if (id != null) {
                RepositoryFileAclDto acl = getRepoWs().getAcl("" + id);
                if (acl != null) {
                    f.setOwner(acl.getOwner());
                }
            }
        }
    }
    if (include("locales", memberSet, exclude)) {
        if (v.getLocalePropertiesMap() != null) {
            f.setLocalePropertiesMapEntries(new ArrayList<LocaleMapDto>());
            for (Map.Entry<String, Properties> entry : v.getLocalePropertiesMap().entrySet()) {
                LocaleMapDto localeMapDto = new LocaleMapDto();
                List<StringKeyStringValueDto> valuesDto = new ArrayList<StringKeyStringValueDto>();
                Properties properties = entry.getValue();
                if (properties != null) {
                    for (String propertyName : properties.stringPropertyNames()) {
                        valuesDto.add(new StringKeyStringValueDto(propertyName, properties.getProperty(propertyName)));
                    }
                }
                localeMapDto.setLocale(entry.getKey());
                localeMapDto.setProperties(valuesDto);
                f.getLocalePropertiesMapEntries().add(localeMapDto);
            }
        }
    }
    IRepositoryVersionManager repositoryVersionManager;
    try {
        repositoryVersionManager = JcrRepositoryFileUtils.getRepositoryVersionManager();
        // Not found, must be in Spoon
        if (repositoryVersionManager == null) {
            return f;
        }
    } catch (NoClassDefFoundError ex) {
        // support tree and child calls.
        return f;
    }
    if (include("versioningEnabled", memberSet, exclude)) {
        f.setVersioningEnabled(repositoryVersionManager.isVersioningEnabled(v.getPath()));
    }
    if (include("versionCommentEnabled", memberSet, exclude)) {
        f.setVersionCommentEnabled(repositoryVersionManager.isVersionCommentEnabled(v.getPath()));
    }
    return f;
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) StringKeyStringValueDto(org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto) Serializable(java.io.Serializable) LocaleMapDto(org.pentaho.platform.api.repository2.unified.webservices.LocaleMapDto) RepositoryFileAclAceDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclAceDto) RepositoryFileAclDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto) ArrayList(java.util.ArrayList) Properties(java.util.Properties) IRepositoryVersionManager(org.pentaho.platform.api.repository2.unified.IRepositoryVersionManager) Map(java.util.Map)

Example 9 with RepositoryFileAclAceDto

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

the class DataSourcePublishIT method generateACL.

private RepositoryFileAclDto generateACL(String userOrRole, RepositoryFileSid.Type type) {
    final RepositoryFileAclDto aclDto = new RepositoryFileAclDto();
    aclDto.setOwnerType(RepositoryFileSid.Type.USER.ordinal());
    aclDto.setOwner(singleTenantAdminUserName);
    aclDto.setEntriesInheriting(false);
    final ArrayList<RepositoryFileAclAceDto> aces = new ArrayList<RepositoryFileAclAceDto>();
    final RepositoryFileAclAceDto aceDto = new RepositoryFileAclAceDto();
    aceDto.setRecipient(userOrRole);
    aceDto.setRecipientType(type.ordinal());
    final ArrayList<Integer> permissions = new ArrayList<Integer>();
    permissions.add(RepositoryFilePermission.ALL.ordinal());
    aceDto.setPermissions(permissions);
    aces.add(aceDto);
    aclDto.setAces(aces);
    return aclDto;
}
Also used : RepositoryFileAclAceDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAceDto) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) ArrayList(java.util.ArrayList)

Example 10 with RepositoryFileAclAceDto

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

the class FileResourceIT method testFileAcls.

@Test
public void testFileAcls() throws InterruptedException {
    loginAsRepositoryAdmin();
    ITenant systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), adminAuthorityName, authenticatedAuthorityName, "Anonymous");
    userRoleDao.createUser(systemTenant, sysAdminUserName, "password", "", new String[] { adminAuthorityName });
    ITenant mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, adminAuthorityName, authenticatedAuthorityName, "Anonymous");
    userRoleDao.createUser(mainTenant_1, "admin", "password", "", new String[] { adminAuthorityName });
    try {
        login("admin", mainTenant_1, new String[] { authenticatedAuthorityName });
        mp.defineInstance(IUnifiedRepository.class, repo);
        String publicFolderPath = ClientRepositoryPaths.getPublicFolderPath();
        createTestFile(publicFolderPath.replaceAll("/", ":") + ":" + "aclFile.txt", "abcdefg");
        WebResource webResource = resource();
        RepositoryFileAclDto fileAcls = webResource.path("repo/files/public:aclFile.txt/acl").accept(APPLICATION_XML).get(RepositoryFileAclDto.class);
        List<RepositoryFileAclAceDto> aces = fileAcls.getAces();
        assertEquals(2, aces.size());
        RepositoryFileAclAceDto ace = aces.get(0);
        assertEquals(authenticatedAuthorityName, ace.getRecipient());
        List<Integer> permissions = ace.getPermissions();
        assertEquals(1, permissions.size());
        Assert.assertTrue(permissions.contains(new Integer(0)));
        String authenticated = authenticatedAuthorityName;
        aces = new ArrayList<RepositoryFileAclAceDto>();
        ace = new RepositoryFileAclAceDto();
        ace.setRecipient(authenticated);
        ace.setRecipientType(1);
        permissions = new ArrayList<Integer>();
        permissions.add(2);
        ace.setPermissions(permissions);
        aces.add(ace);
        fileAcls.setAces(aces);
        ClientResponse putResponse2 = webResource.path("repo/files/public:aclFile.txt/acl").type(APPLICATION_XML).put(ClientResponse.class, fileAcls);
        assertResponse(putResponse2, Status.OK);
    } catch (Throwable ex) {
        TestCase.fail();
    } finally {
        cleanupUserAndRoles(mainTenant_1);
        cleanupUserAndRoles(systemTenant);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ITenant(org.pentaho.platform.api.mt.ITenant) RepositoryFileAclAceDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclAceDto) RepositoryFileAclDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto) WebResource(com.sun.jersey.api.client.WebResource) JerseyTest(com.sun.jersey.test.framework.JerseyTest) 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