use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.
the class RepositoryServlet method initServers.
public synchronized void initServers(ServletConfig servletConfig) throws RepositoryAdminException {
long start = System.currentTimeMillis();
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletConfig.getServletContext());
configuration = wac.getBean("archivaConfiguration#default", ArchivaConfiguration.class);
configuration.addListener(this);
managedRepositoryAdmin = wac.getBean(ManagedRepositoryAdmin.class);
repositoryMap = managedRepositoryAdmin.getManagedRepositoriesAsMap();
for (ManagedRepository repo : repositoryMap.values()) {
Path repoDir = Paths.get(repo.getLocation());
if (!Files.exists(repoDir)) {
try {
Files.createDirectories(repoDir);
} catch (IOException e) {
log.info("Unable to create missing directory for {}", repo.getLocation());
continue;
}
}
}
resourceFactory = wac.getBean("davResourceFactory#archiva", DavResourceFactory.class);
locatorFactory = new ArchivaDavLocatorFactory();
ServletAuthenticator servletAuth = wac.getBean(ServletAuthenticator.class);
HttpAuthenticator httpAuth = wac.getBean("httpAuthenticator#basic", HttpAuthenticator.class);
sessionProvider = new ArchivaDavSessionProvider(servletAuth, httpAuth);
long end = System.currentTimeMillis();
log.debug("initServers done in {} ms", (end - start));
}
use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.
the class ManagedRepositoriesServiceTest method addManagedRepo.
@Test
public void addManagedRepo() throws Exception {
ManagedRepositoriesService service = getManagedRepositoriesService(authorizationHeader);
ManagedRepository repo = getTestManagedRepository();
if (service.getManagedRepository(repo.getId()) != null) {
service.deleteManagedRepository(repo.getId(), true);
assertNull(service.getManagedRepository(repo.getId()));
}
service.addManagedRepository(repo);
repo = service.getManagedRepository(repo.getId());
assertNotNull(repo);
assertEquals(getTestManagedRepository().getDescription(), repo.getDescription());
RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
int timeout = 20000;
while (timeout > 0 && repositoriesService.alreadyScanning(repo.getId())) {
Thread.sleep(500);
timeout -= 500;
}
service.deleteManagedRepository(repo.getId(), true);
assertNull(service.getManagedRepository(repo.getId()));
}
use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.
the class ManagedRepositoriesServiceTest method updateManagedRepo.
@Test
public void updateManagedRepo() throws Exception {
ManagedRepositoriesService service = getManagedRepositoriesService(authorizationHeader);
ManagedRepository repo = getTestManagedRepository();
if (service.getManagedRepository(repo.getId()) != null) {
service.deleteManagedRepository(repo.getId(), true);
assertNull(service.getManagedRepository(repo.getId()));
}
service.addManagedRepository(repo);
RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
int timeout = 20000;
while (timeout > 0 && repositoriesService.alreadyScanning(repo.getId())) {
Thread.sleep(500);
timeout -= 500;
}
repo = service.getManagedRepository(repo.getId());
assertNotNull(repo);
assertEquals("test", repo.getName());
// toto is foo in French :-)
repo.setName("toto");
service.updateManagedRepository(repo);
repo = service.getManagedRepository(repo.getId());
assertNotNull(repo);
assertEquals("toto", repo.getName());
timeout = 20000;
while (timeout > 0 && repositoriesService.alreadyScanning(repo.getId())) {
Thread.sleep(500);
timeout -= 500;
}
service.deleteManagedRepository(repo.getId(), true);
assertNull(service.getManagedRepository(repo.getId()));
}
use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.
the class DefaultUserRepositories method getAccessibleRepositoryIds.
private List<String> getAccessibleRepositoryIds(String principal, String operation) throws ArchivaSecurityException, AccessDeniedException, PrincipalNotFoundException {
List<ManagedRepository> managedRepositories = getAccessibleRepositories(principal, operation);
List<String> repoIds = new ArrayList<>(managedRepositories.size());
for (ManagedRepository managedRepository : managedRepositories) {
repoIds.add(managedRepository.getId());
}
return repoIds;
}
use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.
the class DefaultUserRepositories method getAccessibleRepositories.
private List<ManagedRepository> getAccessibleRepositories(String principal, String operation) throws ArchivaSecurityException, AccessDeniedException, PrincipalNotFoundException {
SecuritySession securitySession = createSession(principal);
List<ManagedRepository> managedRepositories = new ArrayList<>();
try {
List<ManagedRepository> repos = managedRepositoryAdmin.getManagedRepositories();
for (ManagedRepository repo : repos) {
try {
String repoId = repo.getId();
if (securitySystem.isAuthorized(securitySession, operation, repoId)) {
managedRepositories.add(repo);
}
} catch (AuthorizationException e) {
// swallow.
log.debug("Not authorizing '{}' for repository '{}': {}", principal, repo.getId(), e.getMessage());
}
}
return managedRepositories;
} catch (RepositoryAdminException e) {
throw new ArchivaSecurityException(e.getMessage(), e);
}
}
Aggregations