Search in sources :

Example 26 with AccessDeniedException

use of ch.cyberduck.core.exception.AccessDeniedException in project cyberduck by iterate-ch.

the class AmazonServiceExceptionMappingService method map.

@Override
public BackgroundException map(final AmazonClientException e) {
    final StringBuilder buffer = new StringBuilder();
    if (e instanceof AmazonServiceException) {
        final AmazonServiceException failure = (AmazonServiceException) e;
        this.append(buffer, failure.getErrorMessage());
        if (null != failure.getErrorCode()) {
            switch(failure.getStatusCode()) {
                case HttpStatus.SC_BAD_REQUEST:
                    switch(failure.getErrorCode()) {
                        case "Throttling":
                            return new RetriableAccessDeniedException(buffer.toString(), e);
                        case "AccessDeniedException":
                            return new AccessDeniedException(buffer.toString(), e);
                        case "UnrecognizedClientException":
                            return new LoginFailureException(buffer.toString(), e);
                    }
                case HttpStatus.SC_FORBIDDEN:
                    switch(failure.getErrorCode()) {
                        case "SignatureDoesNotMatch":
                        case "InvalidAccessKeyId":
                        case "InvalidClientTokenId":
                        case "InvalidSecurity":
                        case "MissingClientTokenId":
                        case "MissingAuthenticationToken":
                            return new LoginFailureException(buffer.toString(), e);
                    }
            }
        }
        return new DefaultHttpResponseExceptionMappingService().map(new HttpResponseException(failure.getStatusCode(), buffer.toString()));
    }
    this.append(buffer, e.getMessage());
    return this.wrap(e, buffer);
}
Also used : RetriableAccessDeniedException(ch.cyberduck.core.exception.RetriableAccessDeniedException) RetriableAccessDeniedException(ch.cyberduck.core.exception.RetriableAccessDeniedException) AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) DefaultHttpResponseExceptionMappingService(ch.cyberduck.core.http.DefaultHttpResponseExceptionMappingService) LoginFailureException(ch.cyberduck.core.exception.LoginFailureException) AmazonServiceException(com.amazonaws.AmazonServiceException) HttpResponseException(org.apache.http.client.HttpResponseException)

Example 27 with AccessDeniedException

use of ch.cyberduck.core.exception.AccessDeniedException in project cyberduck by iterate-ch.

the class CloudFrontDistributionConfiguration method readStreamingDistribution.

private Distribution readStreamingDistribution(final AmazonCloudFront client, final StreamingDistributionSummary summary, final Path container, final Distribution.Method method) throws BackgroundException {
    // Retrieve distributions configuration to access current logging status settings.
    try {
        final GetStreamingDistributionConfigResult response = client.getStreamingDistributionConfig(new GetStreamingDistributionConfigRequest(summary.getId()));
        final StreamingDistributionConfig configuration = response.getStreamingDistributionConfig();
        final Distribution distribution = new Distribution(method, this.getName(), this.getOrigin(container, method), summary.isEnabled());
        distribution.setId(summary.getId());
        distribution.setDeployed("Deployed".equals(summary.getStatus()));
        distribution.setUrl(URI.create(String.format("%s://%s%s", method.getScheme(), summary.getDomainName(), method.getContext())));
        distribution.setSslUrl(method.equals(Distribution.DOWNLOAD) || method.equals(Distribution.CUSTOM) ? URI.create(String.format("https://%s%s", summary.getDomainName(), method.getContext())) : null);
        distribution.setReference(configuration.getCallerReference());
        distribution.setEtag(response.getETag());
        distribution.setStatus(LocaleFactory.localizedString(summary.getStatus(), "S3"));
        distribution.setCNAMEs(configuration.getAliases().getItems().toArray(new String[configuration.getAliases().getItems().size()]));
        distribution.setLogging(configuration.getLogging().isEnabled());
        distribution.setLoggingContainer(StringUtils.isNotBlank(configuration.getLogging().getBucket()) ? ServiceUtils.findBucketNameInHostname(configuration.getLogging().getBucket(), new S3Protocol().getDefaultHostname()) : null);
        if (this.getFeature(Purge.class, method) != null) {
            distribution.setInvalidationStatus(this.readInvalidationStatus(client, distribution));
        }
        if (this.getFeature(DistributionLogging.class, method) != null) {
            try {
                distribution.setContainers(new S3BucketListService(session, new S3LocationFeature.S3Region(bookmark.getRegion())).list(new Path(String.valueOf(Path.DELIMITER), EnumSet.of(Path.Type.volume, Path.Type.directory)), new DisabledListProgressListener()).toList());
            } catch (AccessDeniedException | InteroperabilityException e) {
                log.warn(String.format("Failure listing buckets. %s", e.getMessage()));
            }
        }
        return distribution;
    } catch (AmazonClientException e) {
        throw new AmazonServiceExceptionMappingService().map("Cannot read CDN configuration", e);
    }
}
Also used : Path(ch.cyberduck.core.Path) AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) InteroperabilityException(ch.cyberduck.core.exception.InteroperabilityException) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) S3BucketListService(ch.cyberduck.core.s3.S3BucketListService) AmazonClientException(com.amazonaws.AmazonClientException) DistributionLogging(ch.cyberduck.core.cdn.features.DistributionLogging) AmazonServiceExceptionMappingService(ch.cyberduck.core.aws.AmazonServiceExceptionMappingService) S3Protocol(ch.cyberduck.core.s3.S3Protocol) Purge(ch.cyberduck.core.cdn.features.Purge) Distribution(ch.cyberduck.core.cdn.Distribution)

Example 28 with AccessDeniedException

use of ch.cyberduck.core.exception.AccessDeniedException in project cyberduck by iterate-ch.

the class BookmarkTableDataSource method tableView_acceptDrop_row_dropOperation.

/**
 * @param info contains details on this dragging operation.
 * @param row  The proposed location is row and action is operation. The data source should incorporate the data
 *             from the dragging pasteboard at this time.
 * @see NSTableView.DataSource Invoked by view when the mouse button is released over a table view that previously
 * decided to allow a drop.
 */
@Override
public boolean tableView_acceptDrop_row_dropOperation(final NSTableView view, final NSDraggingInfo info, final NSInteger row, final NSUInteger operation) {
    NSPasteboard draggingPasteboard = info.draggingPasteboard();
    if (log.isDebugEnabled()) {
        log.debug(String.format("Accept drop at row %s", row));
    }
    view.deselectAll(null);
    final AbstractHostCollection source = this.getSource();
    if (draggingPasteboard.availableTypeFromArray(NSArray.arrayWithObject(NSPasteboard.StringPboardType)) != null) {
        String o = draggingPasteboard.stringForType(NSPasteboard.StringPboardType);
        if (null == o) {
            return false;
        }
        final Host h;
        try {
            h = HostParser.parse(o);
        } catch (HostParserException e) {
            return false;
        }
        source.add(row.intValue(), h);
        view.selectRowIndexes(NSIndexSet.indexSetWithIndex(row), false);
        view.scrollRowToVisible(row);
        return true;
    } else if (draggingPasteboard.availableTypeFromArray(NSArray.arrayWithObject(NSPasteboard.FilenamesPboardType)) != null) {
        // We get a drag from another application e.g. Finder.app proposing some files
        final NSObject object = draggingPasteboard.propertyListForType(NSPasteboard.FilenamesPboardType);
        if (object != null) {
            if (object.isKindOfClass(NSArray.CLASS)) {
                final NSArray elements = Rococoa.cast(object, NSArray.class);
                // If regular files are dropped, these will be uploaded to the dropped bookmark location
                final List<TransferItem> uploads = new ArrayList<TransferItem>();
                Host host = null;
                for (int i = 0; i < elements.count().intValue(); i++) {
                    final String filename = elements.objectAtIndex(new NSUInteger(i)).toString();
                    final Local f = LocalFactory.get(filename);
                    if (filename.endsWith(".duck")) {
                        // Adding a previously exported bookmark file from the Finder
                        try {
                            source.add(row.intValue(), HostReaderFactory.get().read(f));
                            view.selectRowIndexes(NSIndexSet.indexSetWithIndex(row), true);
                            view.scrollRowToVisible(row);
                        } catch (AccessDeniedException e) {
                            log.error(String.format("Failure reading bookmark from %s. %s", f, e.getMessage()));
                            continue;
                        }
                    } else {
                        // The bookmark this file has been dropped onto
                        final Host h = source.get(row.intValue());
                        if (null == host) {
                            host = h;
                        }
                        // Upload to the remote host this bookmark points to
                        uploads.add(new TransferItem(new Path(new Path(PathNormalizer.normalize(h.getDefaultPath()), EnumSet.of(Path.Type.directory)), f.getName(), EnumSet.of(Path.Type.file)), f));
                    }
                }
                if (!uploads.isEmpty()) {
                    // If anything has been added to the queue, then process the queue
                    final Transfer t = new UploadTransfer(host, uploads);
                    TransferControllerFactory.get().start(t, new TransferOptions());
                }
                return true;
            }
        }
    } else if (draggingPasteboard.availableTypeFromArray(NSArray.arrayWithObject(NSPasteboard.URLPboardType)) != null) {
        final NSObject object = draggingPasteboard.propertyListForType(NSPasteboard.URLPboardType);
        if (object != null) {
            if (object.isKindOfClass(NSArray.CLASS)) {
                final NSArray elements = Rococoa.cast(object, NSArray.class);
                for (int i = 0; i < elements.count().intValue(); i++) {
                    final String url = elements.objectAtIndex(new NSUInteger(i)).toString();
                    if (StringUtils.isNotBlank(url)) {
                        final Host h;
                        try {
                            h = HostParser.parse(url);
                        } catch (HostParserException e) {
                            log.warn(e);
                            continue;
                        }
                        source.add(row.intValue(), h);
                        view.selectRowIndexes(NSIndexSet.indexSetWithIndex(row), true);
                        view.scrollRowToVisible(row);
                    }
                }
                return true;
            }
        }
        return false;
    } else if (!pasteboard.isEmpty()) {
        if (info.draggingSourceOperationMask().intValue() == NSDraggingInfo.NSDragOperationCopy.intValue()) {
            List<Host> duplicates = new ArrayList<Host>();
            for (Host bookmark : pasteboard) {
                final Host duplicate = new HostDictionary().deserialize(bookmark.serialize(SerializerFactory.get()));
                // Make sure a new UUID is assigned for duplicate
                duplicate.setUuid(null);
                source.add(row.intValue(), duplicate);
                duplicates.add(duplicate);
            }
            for (Host bookmark : duplicates) {
                int index = source.indexOf(bookmark);
                view.selectRowIndexes(NSIndexSet.indexSetWithIndex(new NSInteger(index)), true);
                view.scrollRowToVisible(new NSInteger(index));
            }
        } else {
            int insert = row.intValue();
            for (Host bookmark : pasteboard) {
                int previous = source.indexOf(bookmark);
                if (previous == insert) {
                    // No need to move
                    continue;
                }
                source.remove(previous);
                int moved;
                if (previous < insert) {
                    moved = insert - 1;
                } else {
                    moved = insert;
                }
                source.add(moved, bookmark);
            }
            for (Host bookmark : pasteboard) {
                int index = source.indexOf(bookmark);
                view.selectRowIndexes(NSIndexSet.indexSetWithIndex(new NSInteger(index)), true);
                view.scrollRowToVisible(new NSInteger(index));
            }
        }
        return true;
    }
    return false;
}
Also used : NSObject(ch.cyberduck.binding.foundation.NSObject) AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) NSArray(ch.cyberduck.binding.foundation.NSArray) HostDictionary(ch.cyberduck.core.serializer.HostDictionary) NSPasteboard(ch.cyberduck.binding.application.NSPasteboard) NSUInteger(org.rococoa.cocoa.foundation.NSUInteger) HostParserException(ch.cyberduck.core.exception.HostParserException) NSPoint(org.rococoa.cocoa.foundation.NSPoint) NSInteger(org.rococoa.cocoa.foundation.NSInteger) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) Transfer(ch.cyberduck.core.transfer.Transfer) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) ArrayList(java.util.ArrayList) List(java.util.List) TransferItem(ch.cyberduck.core.transfer.TransferItem)

Example 29 with AccessDeniedException

use of ch.cyberduck.core.exception.AccessDeniedException in project cyberduck by iterate-ch.

the class BookmarkTableDataSource method namesOfPromisedFilesDroppedAtDestination.

/**
 * @return the names (not full paths) of the files that the receiver promises to create at dropDestination. This
 * method is invoked when the drop has been accepted by the destination and the destination, in the case of another
 * Cocoa application, invokes the NSDraggingInfo method namesOfPromisedFilesDroppedAtDestination. For long
 * operations, you can cache dropDestination and defer the creation of the files until the finishedDraggingImage
 * method to avoid blocking the destination application.
 * @see NSTableView.DataSource
 */
@Override
public NSArray namesOfPromisedFilesDroppedAtDestination(final NSURL dropDestination) {
    if (log.isDebugEnabled()) {
        log.debug(String.format("Query promised files dropped dat destination %s", dropDestination.path()));
    }
    final NSMutableArray promisedDragNames = NSMutableArray.array();
    if (null != dropDestination) {
        for (Host bookmark : pasteboard) {
            final Local file = LocalFactory.get(dropDestination.path(), String.format("%s.duck", StringUtils.replace(BookmarkNameProvider.toString(bookmark), "/", ":")));
            try {
                HostWriterFactory.get().write(bookmark, file);
            } catch (AccessDeniedException e) {
                log.warn(e.getMessage());
            }
            // Adding the filename that is promised to be created at the dropDestination
            promisedDragNames.addObject(file.getName());
        }
        pasteboard.clear();
    }
    return promisedDragNames;
}
Also used : AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) NSMutableArray(ch.cyberduck.binding.foundation.NSMutableArray)

Example 30 with AccessDeniedException

use of ch.cyberduck.core.exception.AccessDeniedException in project cyberduck by iterate-ch.

the class S3CopyFeature method copy.

@Override
public Path copy(final Path source, final Path target, final TransferStatus status, final ConnectionCallback callback, final StreamListener listener) throws BackgroundException {
    if (null == status.getStorageClass()) {
        // Keep same storage class
        status.setStorageClass(new S3StorageClassFeature(session).getClass(source));
    }
    if (Encryption.Algorithm.NONE == status.getEncryption()) {
        // Keep encryption setting
        status.setEncryption(new S3EncryptionFeature(session).getEncryption(source));
    }
    if (Acl.EMPTY == status.getAcl()) {
        // Apply non standard ACL
        try {
            status.setAcl(accessControlListFeature.getPermission(source));
        } catch (AccessDeniedException | InteroperabilityException e) {
            log.warn(String.format("Ignore failure %s", e));
        }
    }
    final S3Object destination = new S3WriteFeature(session).getDetails(target, status);
    destination.setAcl(accessControlListFeature.toAcl(status.getAcl()));
    final Path bucket = containerService.getContainer(target);
    destination.setBucketName(bucket.isRoot() ? StringUtils.EMPTY : bucket.getName());
    destination.replaceAllMetadata(new HashMap<>(new S3MetadataFeature(session, accessControlListFeature).getMetadata(source)));
    final String version = this.copy(source, destination, status, listener);
    target.attributes().setVersionId(version);
    target.attributes().setMetadata(source.attributes().getMetadata());
    target.attributes().setModificationDate(source.attributes().getModificationDate());
    return target;
}
Also used : Path(ch.cyberduck.core.Path) AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) InteroperabilityException(ch.cyberduck.core.exception.InteroperabilityException) S3Object(org.jets3t.service.model.S3Object)

Aggregations

AccessDeniedException (ch.cyberduck.core.exception.AccessDeniedException)71 Path (ch.cyberduck.core.Path)27 IOException (java.io.IOException)23 InteroperabilityException (ch.cyberduck.core.exception.InteroperabilityException)19 Local (ch.cyberduck.core.Local)18 Test (org.junit.Test)18 NotfoundException (ch.cyberduck.core.exception.NotfoundException)14 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)14 BackgroundException (ch.cyberduck.core.exception.BackgroundException)12 LoginFailureException (ch.cyberduck.core.exception.LoginFailureException)11 IntegrationTest (ch.cyberduck.test.IntegrationTest)9 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)8 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)8 Delete (ch.cyberduck.core.features.Delete)8 InputStream (java.io.InputStream)8 ServiceException (org.jets3t.service.ServiceException)8 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)7 PathAttributes (ch.cyberduck.core.PathAttributes)7 BandwidthThrottle (ch.cyberduck.core.io.BandwidthThrottle)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7