Search in sources :

Example 1 with Directory

use of sample.dms.Directory in project spring-security by spring-projects.

the class DmsIntegrationTests method process.

protected void process(String username, String password, boolean shouldBeFiltered) {
    SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(username, password));
    System.out.println("------ Test for username: " + username + " ------");
    AbstractElement[] rootElements = this.documentDao.findElements(Directory.ROOT_DIRECTORY);
    assertThat(rootElements.length).isEqualTo(3);
    Directory homeDir = null;
    Directory nonHomeDir = null;
    for (int i = 0; i < rootElements.length; i++) {
        if (rootElements[i].getName().equals(username)) {
            homeDir = (Directory) rootElements[i];
        } else {
            nonHomeDir = (Directory) rootElements[i];
        }
    }
    System.out.println("Home directory......: " + homeDir.getFullName());
    System.out.println("Non-home directory..: " + nonHomeDir.getFullName());
    AbstractElement[] homeElements = this.documentDao.findElements(homeDir);
    // confidential and shared
    assertThat(homeElements.length).isEqualTo(12);
    // directories,
    // plus 10 files
    AbstractElement[] nonHomeElements = this.documentDao.findElements(nonHomeDir);
    // cannot
    assertThat(nonHomeElements.length).isEqualTo(shouldBeFiltered ? 11 : 12);
    // see
    // the user's
    // "confidential"
    // sub-directory
    // when
    // filtering
    // Attempt to read the other user's confidential directory from the returned
    // results
    // Of course, we shouldn't find a "confidential" directory in the results if we're
    // filtering
    Directory nonHomeConfidentialDir = null;
    for (int i = 0; i < nonHomeElements.length; i++) {
        if (nonHomeElements[i].getName().equals("confidential")) {
            nonHomeConfidentialDir = (Directory) nonHomeElements[i];
        }
    }
    if (shouldBeFiltered) {
        assertThat(nonHomeConfidentialDir).withFailMessage("Found confidential directory when we should not have").isNull();
    } else {
        System.out.println("Inaccessible dir....: " + nonHomeConfidentialDir.getFullName());
        assertThat(this.documentDao.findElements(nonHomeConfidentialDir).length).isEqualTo(// 10
        10);
    // files
    // (no
    // sub-directories)
    }
    SecurityContextHolder.clearContext();
}
Also used : AbstractElement(sample.dms.AbstractElement) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Directory(sample.dms.Directory)

Aggregations

UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 AbstractElement (sample.dms.AbstractElement)1 Directory (sample.dms.Directory)1