Search in sources :

Example 1 with RoleManagementService

use of org.apache.archiva.redback.rest.api.services.RoleManagementService in project archiva by apache.

the class AbstractDownloadTest method getRoleManagementService.

protected RoleManagementService getRoleManagementService(String authzHeader) {
    RoleManagementService service = JAXRSClientFactory.create("http://localhost:" + port + "/" + getRestServicesPath() + "/redbackServices/", RoleManagementService.class, Collections.singletonList(new JacksonJaxbJsonProvider()));
    WebClient.client(service).header("Referer", "http://localhost:" + port);
    // for debuging purpose
    WebClient.getConfig(service).getHttpConduit().getClient().setReceiveTimeout(3000000L);
    if (authzHeader != null) {
        WebClient.client(service).header("Authorization", authzHeader);
    }
    return service;
}
Also used : RoleManagementService(org.apache.archiva.redback.rest.api.services.RoleManagementService) JacksonJaxbJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider)

Example 2 with RoleManagementService

use of org.apache.archiva.redback.rest.api.services.RoleManagementService in project archiva by apache.

the class DownloadSnapshotTest method downloadSNAPSHOT.

@Test
public void downloadSNAPSHOT() throws Exception {
    Path tmpIndexDir = Paths.get(System.getProperty("java.io.tmpdir") + "/tmpIndex");
    if (Files.exists(tmpIndexDir)) {
        org.apache.archiva.common.utils.FileUtils.deleteDirectory(tmpIndexDir);
    }
    String id = Long.toString(System.currentTimeMillis());
    ManagedRepository managedRepository = new ManagedRepository(Locale.getDefault());
    managedRepository.setId(id);
    managedRepository.setName("name of " + id);
    managedRepository.setLocation(System.getProperty("basedir") + "/src/test/repositories/snapshot-repo");
    managedRepository.setIndexDirectory(System.getProperty("java.io.tmpdir") + "/tmpIndex/" + id);
    ManagedRepositoriesService managedRepositoriesService = getManagedRepositoriesService();
    if (managedRepositoriesService.getManagedRepository(id) != null) {
        managedRepositoriesService.deleteManagedRepository(id, false);
    }
    getManagedRepositoriesService().addManagedRepository(managedRepository);
    RoleManagementService roleManagementService = getRoleManagementService(authorizationHeader);
    if (!roleManagementService.templatedRoleExists(ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, id)) {
        roleManagementService.createTemplatedRole(ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, id);
    }
    getUserService(authorizationHeader).createGuestUser();
    roleManagementService.assignRole(ArchivaRoleConstants.TEMPLATE_GUEST, "guest");
    roleManagementService.assignTemplatedRole(ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, id, "guest");
    getUserService(authorizationHeader).removeFromCache("guest");
    Path file = Paths.get("target/archiva-model-1.4-M4-SNAPSHOT.jar");
    Files.deleteIfExists(file);
    HttpWagon httpWagon = new HttpWagon();
    httpWagon.connect(new Repository("foo", "http://localhost:" + port));
    httpWagon.get("/repository/" + id + "/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-SNAPSHOT.jar", file.toFile());
    ZipFile zipFile = new ZipFile(file.toFile());
    List<String> entries = getZipEntriesNames(zipFile);
    ZipEntry zipEntry = zipFile.getEntry("org/apache/archiva/model/ArchivaArtifact.class");
    assertNotNull("cannot find zipEntry org/apache/archiva/model/ArchivaArtifact.class, entries: " + entries + ", content is: " + FileUtils.readFileToString(file.toFile(), Charset.forName("UTF-8")), zipEntry);
    zipFile.close();
    file.toFile().deleteOnExit();
}
Also used : Path(java.nio.file.Path) Repository(org.apache.maven.wagon.repository.Repository) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) HttpWagon(org.apache.maven.wagon.providers.http.HttpWagon) ZipFile(java.util.zip.ZipFile) RoleManagementService(org.apache.archiva.redback.rest.api.services.RoleManagementService) ZipEntry(java.util.zip.ZipEntry) Test(org.junit.Test)

Example 3 with RoleManagementService

use of org.apache.archiva.redback.rest.api.services.RoleManagementService in project archiva by apache.

the class DownloadArtifactsTest method downloadWithRemoteRedirect.

@Test
public void downloadWithRemoteRedirect() throws Exception {
    RemoteRepository remoteRepository = getRemoteRepositoriesService().getRemoteRepository("central");
    remoteRepository.setUrl("http://localhost:" + redirectPort);
    getRemoteRepositoriesService().updateRemoteRepository(remoteRepository);
    RoleManagementService roleManagementService = getRoleManagementService(authorizationHeader);
    if (!roleManagementService.templatedRoleExists(ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, "internal")) {
        roleManagementService.createTemplatedRole(ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, "internal");
    }
    getUserService(authorizationHeader).createGuestUser();
    roleManagementService.assignRole(ArchivaRoleConstants.TEMPLATE_GUEST, "guest");
    roleManagementService.assignTemplatedRole(ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, "internal", "guest");
    getUserService(authorizationHeader).removeFromCache("guest");
    Path file = Paths.get("target/junit-4.9.jar");
    Files.deleteIfExists(file);
    HttpWagon httpWagon = new HttpWagon();
    httpWagon.connect(new Repository("foo", "http://localhost:" + port));
    httpWagon.get("repository/internal/junit/junit/4.9/junit-4.9.jar", file.toFile());
    ZipFile zipFile = new ZipFile(file.toFile());
    List<String> entries = getZipEntriesNames(zipFile);
    ZipEntry zipEntry = zipFile.getEntry("org/junit/runners/JUnit4.class");
    assertNotNull("cannot find zipEntry org/junit/runners/JUnit4.class, entries: " + entries + ", content is: " + FileUtils.readFileToString(file.toFile(), Charset.forName("UTF-8")), zipEntry);
    zipFile.close();
    file.toFile().deleteOnExit();
}
Also used : Path(java.nio.file.Path) Repository(org.apache.maven.wagon.repository.Repository) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) HttpWagon(org.apache.maven.wagon.providers.http.HttpWagon) ZipFile(java.util.zip.ZipFile) RoleManagementService(org.apache.archiva.redback.rest.api.services.RoleManagementService) ZipEntry(java.util.zip.ZipEntry) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) Test(org.junit.Test)

Aggregations

RoleManagementService (org.apache.archiva.redback.rest.api.services.RoleManagementService)3 Path (java.nio.file.Path)2 ZipEntry (java.util.zip.ZipEntry)2 ZipFile (java.util.zip.ZipFile)2 HttpWagon (org.apache.maven.wagon.providers.http.HttpWagon)2 Repository (org.apache.maven.wagon.repository.Repository)2 Test (org.junit.Test)2 JacksonJaxbJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider)1 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)1 RemoteRepository (org.apache.archiva.admin.model.beans.RemoteRepository)1 ManagedRepositoriesService (org.apache.archiva.rest.api.services.ManagedRepositoriesService)1