Search in sources :

Example 31 with RepositoryAdminException

use of org.apache.archiva.admin.model.RepositoryAdminException in project archiva by apache.

the class ArchivaLdapRoleMapperConfiguration method removeLdapMapping.

@Override
public void removeLdapMapping(String group) throws MappingException {
    try {
        RedbackRuntimeConfiguration redbackRuntimeConfiguration = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration();
        boolean removed = redbackRuntimeConfiguration.getLdapGroupMappings().remove(new LdapGroupMapping(group));
        redbackRuntimeConfigurationAdmin.updateRedbackRuntimeConfiguration(redbackRuntimeConfiguration);
        logger.debug("removeLdapMapping ldapGroup: {}, removed: {}", group, removed);
    } catch (RepositoryAdminException e) {
        throw new MappingException(e.getMessage(), e);
    }
}
Also used : LdapGroupMapping(org.apache.archiva.admin.model.beans.LdapGroupMapping) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) MappingException(org.apache.archiva.redback.common.ldap.MappingException)

Example 32 with RepositoryAdminException

use of org.apache.archiva.admin.model.RepositoryAdminException in project archiva by apache.

the class ArchivaRbacManager method initialize.

@Override
public void initialize() {
    try {
        List<String> rbacManagerIds = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration().getRbacManagerImpls();
        clearCaches();
        if (rbacManagerIds.isEmpty()) {
            rbacManagerIds.add(RedbackRuntimeConfigurationAdmin.DEFAULT_RBAC_MANAGER_IMPL);
        }
        log.info("use rbacManagerIds: '{}'", rbacManagerIds);
        this.rbacManagersPerId = new LinkedHashMap<>(rbacManagerIds.size());
        for (String id : rbacManagerIds) {
            if (StringUtils.equalsIgnoreCase("jdo", id)) {
                id = RedbackRuntimeConfigurationAdmin.DEFAULT_RBAC_MANAGER_IMPL;
            }
            RBACManager rbacManager = applicationContext.getBean("rbacManager#" + id, RBACManager.class);
            rbacManagersPerId.put(id, rbacManager);
        }
    } catch (RepositoryAdminException e) {
        log.error(e.getMessage(), e);
        throw new RuntimeException(e.getMessage(), e);
    }
}
Also used : AbstractRBACManager(org.apache.archiva.redback.rbac.AbstractRBACManager) RBACManager(org.apache.archiva.redback.rbac.RBACManager) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 33 with RepositoryAdminException

use of org.apache.archiva.admin.model.RepositoryAdminException in project archiva by apache.

the class DefaultFileUploadService method saveFile.

protected void saveFile(String repositoryId, FileMetadata fileMetadata, boolean generatePom, String groupId, String artifactId, String version, String packaging) throws ArchivaRestServiceException {
    try {
        ManagedRepository repoConfig = managedRepositoryAdmin.getManagedRepository(repositoryId);
        ArtifactReference artifactReference = new ArtifactReference();
        artifactReference.setArtifactId(artifactId);
        artifactReference.setGroupId(groupId);
        artifactReference.setVersion(version);
        artifactReference.setClassifier(fileMetadata.getClassifier());
        artifactReference.setType(StringUtils.isEmpty(fileMetadata.getPackaging()) ? packaging : fileMetadata.getPackaging());
        ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent(repositoryId);
        String artifactPath = repository.toPath(artifactReference);
        int lastIndex = artifactPath.lastIndexOf('/');
        String path = artifactPath.substring(0, lastIndex);
        Path targetPath = Paths.get(repoConfig.getLocation(), path);
        log.debug("artifactPath: {} found targetPath: {}", artifactPath, targetPath);
        Date lastUpdatedTimestamp = Calendar.getInstance().getTime();
        int newBuildNumber = -1;
        String timestamp = null;
        Path versionMetadataFile = targetPath.resolve(MetadataTools.MAVEN_METADATA);
        ArchivaRepositoryMetadata versionMetadata = getMetadata(versionMetadataFile);
        if (VersionUtil.isSnapshot(version)) {
            TimeZone timezone = TimeZone.getTimeZone("UTC");
            DateFormat fmt = new SimpleDateFormat("yyyyMMdd.HHmmss");
            fmt.setTimeZone(timezone);
            timestamp = fmt.format(lastUpdatedTimestamp);
            if (versionMetadata.getSnapshotVersion() != null) {
                newBuildNumber = versionMetadata.getSnapshotVersion().getBuildNumber() + 1;
            } else {
                newBuildNumber = 1;
            }
        }
        if (!Files.exists(targetPath)) {
            Files.createDirectories(targetPath);
        }
        String filename = artifactPath.substring(lastIndex + 1);
        if (VersionUtil.isSnapshot(version)) {
            filename = filename.replaceAll(VersionUtil.SNAPSHOT, timestamp + "-" + newBuildNumber);
        }
        boolean fixChecksums = !(archivaAdministration.getKnownContentConsumers().contains("create-missing-checksums"));
        try {
            Path targetFile = targetPath.resolve(filename);
            if (Files.exists(targetFile) && !VersionUtil.isSnapshot(version) && repoConfig.isBlockRedeployments()) {
                throw new ArchivaRestServiceException("Overwriting released artifacts in repository '" + repoConfig.getId() + "' is not allowed.", Response.Status.BAD_REQUEST.getStatusCode(), null);
            } else {
                copyFile(Paths.get(fileMetadata.getServerFileName()), targetPath, filename, fixChecksums);
                triggerAuditEvent(repository.getId(), path + "/" + filename, AuditEvent.UPLOAD_FILE);
                queueRepositoryTask(repository.getId(), targetFile);
            }
        } catch (IOException ie) {
            log.error("IOException copying file: {}", ie.getMessage(), ie);
            throw new ArchivaRestServiceException("Overwriting released artifacts in repository '" + repoConfig.getId() + "' is not allowed.", Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), ie);
        }
        if (generatePom) {
            String pomFilename = filename;
            if (StringUtils.isNotEmpty(fileMetadata.getClassifier())) {
                pomFilename = StringUtils.remove(pomFilename, "-" + fileMetadata.getClassifier());
            }
            pomFilename = FilenameUtils.removeExtension(pomFilename) + ".pom";
            try {
                Path generatedPomFile = createPom(targetPath, pomFilename, fileMetadata, groupId, artifactId, version, packaging);
                triggerAuditEvent(repoConfig.getId(), path + "/" + pomFilename, AuditEvent.UPLOAD_FILE);
                if (fixChecksums) {
                    fixChecksums(generatedPomFile);
                }
                queueRepositoryTask(repoConfig.getId(), generatedPomFile);
            } catch (IOException ie) {
                throw new ArchivaRestServiceException("Error encountered while writing pom file: " + ie.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), ie);
            }
        }
        // explicitly update only if metadata-updater consumer is not enabled!
        if (!archivaAdministration.getKnownContentConsumers().contains("metadata-updater")) {
            updateProjectMetadata(targetPath.toAbsolutePath().toString(), lastUpdatedTimestamp, timestamp, newBuildNumber, fixChecksums, fileMetadata, groupId, artifactId, version, packaging);
            if (VersionUtil.isSnapshot(version)) {
                updateVersionMetadata(versionMetadata, versionMetadataFile, lastUpdatedTimestamp, timestamp, newBuildNumber, fixChecksums, fileMetadata, groupId, artifactId, version, packaging);
            }
        }
    } catch (RepositoryNotFoundException re) {
        throw new ArchivaRestServiceException("Target repository cannot be found: " + re.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), re);
    } catch (RepositoryException rep) {
        throw new ArchivaRestServiceException("Repository exception: " + rep.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), rep);
    } catch (RepositoryAdminException e) {
        throw new ArchivaRestServiceException("RepositoryAdmin exception: " + e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    } catch (IOException e) {
        throw new ArchivaRestServiceException("Repository exception " + e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    }
}
Also used : Path(java.nio.file.Path) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) RepositoryException(org.apache.archiva.repository.RepositoryException) IOException(java.io.IOException) RepositoryNotFoundException(org.apache.archiva.repository.RepositoryNotFoundException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) Date(java.util.Date) TimeZone(java.util.TimeZone) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata) ArtifactReference(org.apache.archiva.model.ArtifactReference) SimpleDateFormat(java.text.SimpleDateFormat)

Example 34 with RepositoryAdminException

use of org.apache.archiva.admin.model.RepositoryAdminException in project archiva by apache.

the class DefaultFileUploadService method savePomFile.

protected void savePomFile(String repositoryId, FileMetadata fileMetadata, String groupId, String artifactId, String version, String packaging) throws ArchivaRestServiceException {
    try {
        boolean fixChecksums = !(archivaAdministration.getKnownContentConsumers().contains("create-missing-checksums"));
        ManagedRepository repoConfig = managedRepositoryAdmin.getManagedRepository(repositoryId);
        ArtifactReference artifactReference = new ArtifactReference();
        artifactReference.setArtifactId(artifactId);
        artifactReference.setGroupId(groupId);
        artifactReference.setVersion(version);
        artifactReference.setClassifier(fileMetadata.getClassifier());
        artifactReference.setType(packaging);
        ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent(repositoryId);
        String artifactPath = repository.toPath(artifactReference);
        int lastIndex = artifactPath.lastIndexOf('/');
        String path = artifactPath.substring(0, lastIndex);
        Path targetPath = Paths.get(repoConfig.getLocation(), path);
        String pomFilename = artifactPath.substring(lastIndex + 1);
        if (StringUtils.isNotEmpty(fileMetadata.getClassifier())) {
            pomFilename = StringUtils.remove(pomFilename, "-" + fileMetadata.getClassifier());
        }
        pomFilename = FilenameUtils.removeExtension(pomFilename) + ".pom";
        copyFile(Paths.get(fileMetadata.getServerFileName()), targetPath, pomFilename, fixChecksums);
        triggerAuditEvent(repoConfig.getId(), path + "/" + pomFilename, AuditEvent.UPLOAD_FILE);
        queueRepositoryTask(repoConfig.getId(), targetPath.resolve(pomFilename));
    } catch (IOException ie) {
        throw new ArchivaRestServiceException("Error encountered while uploading pom file: " + ie.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), ie);
    } catch (RepositoryException rep) {
        throw new ArchivaRestServiceException("Repository exception: " + rep.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), rep);
    } catch (RepositoryAdminException e) {
        throw new ArchivaRestServiceException("RepositoryAdmin exception: " + e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    }
}
Also used : Path(java.nio.file.Path) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) RepositoryException(org.apache.archiva.repository.RepositoryException) IOException(java.io.IOException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) ArtifactReference(org.apache.archiva.model.ArtifactReference)

Example 35 with RepositoryAdminException

use of org.apache.archiva.admin.model.RepositoryAdminException in project archiva by apache.

the class ArchivaLdapConnectionFactory method initialize.

@PostConstruct
@Override
public void initialize() {
    try {
        LdapConfiguration ldapConfiguration = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration().getLdapConfiguration();
        ldapConnectionConfiguration = new LdapConnectionConfiguration();
        ldapConnectionConfiguration.setHostname(ldapConfiguration.getHostName());
        ldapConnectionConfiguration.setPort(ldapConfiguration.getPort());
        ldapConnectionConfiguration.setSsl(ldapConfiguration.isSsl());
        ldapConnectionConfiguration.setBaseDn(ldapConfiguration.getBaseDn());
        ldapConnectionConfiguration.setContextFactory(ldapConfiguration.getContextFactory());
        ldapConnectionConfiguration.setBindDn(ldapConfiguration.getBindDn());
        ldapConnectionConfiguration.setPassword(ldapConfiguration.getPassword());
        ldapConnectionConfiguration.setAuthenticationMethod(ldapConfiguration.getAuthenticationMethod());
        ldapConnectionConfiguration.setExtraProperties(toProperties(ldapConfiguration.getExtraProperties()));
        valid = true;
    } catch (InvalidNameException e) {
        log.error("Error during initialization of LdapConnectionFactory {}", e.getMessage(), e);
    // throw new RuntimeException( "Error while initializing connection factory.", e );
    } catch (RepositoryAdminException e) {
        throw new RuntimeException("Error while initializing ldapConnectionConfiguration: " + e.getMessage(), e);
    }
}
Also used : InvalidNameException(javax.naming.InvalidNameException) LdapConfiguration(org.apache.archiva.admin.model.beans.LdapConfiguration) LdapConnectionConfiguration(org.apache.archiva.redback.common.ldap.connection.LdapConnectionConfiguration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) PostConstruct(javax.annotation.PostConstruct)

Aggregations

RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)67 Configuration (org.apache.archiva.configuration.Configuration)18 Path (java.nio.file.Path)15 RedbackRuntimeConfiguration (org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration)14 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)14 RepositoryException (org.apache.archiva.repository.RepositoryException)13 IOException (java.io.IOException)12 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)10 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)10 ArrayList (java.util.ArrayList)9 RepositoryGroupConfiguration (org.apache.archiva.configuration.RepositoryGroupConfiguration)7 NetworkProxy (org.apache.archiva.admin.model.beans.NetworkProxy)6 ProxyConnectorConfiguration (org.apache.archiva.configuration.ProxyConnectorConfiguration)6 IndexUpdateFailedException (org.apache.archiva.indexer.IndexUpdateFailedException)6 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)6 RemoteRepository (org.apache.archiva.repository.RemoteRepository)6 Date (java.util.Date)5 RemoteIndexFeature (org.apache.archiva.repository.features.RemoteIndexFeature)5 PostConstruct (javax.annotation.PostConstruct)4 LdapGroupMapping (org.apache.archiva.admin.model.beans.LdapGroupMapping)4