Examples of SBucketVO


Examples of com.cloud.bridge.model.SBucketVO

            logger.error( "executeGetBucketVersioning - no bucket name given" );
            response.setStatus( 400 );
            return;
        }

        SBucketVO sbucket = bucketDao.getByName( bucketName );
        if (sbucket == null) {
            response.setStatus( 404 );
            return;
        }

        // [B] The owner may want to restrict the IP address at which this can be performed
        String client = UserContext.current().getCanonicalUserId();
        if (!client.equals( sbucket.getOwnerCanonicalId()))
            throw new PermissionDeniedException( "Access Denied - only the owner can read bucket versioning" );

        S3PolicyContext context = new S3PolicyContext( PolicyActions.GetBucketVersioning, bucketName );
        if (PolicyAccess.DENY == S3Engine.verifyPolicy( context )) {
            response.setStatus(403);
            return;
        }


        // [C]
        switch( sbucket.getVersioningStatus()) {
        default:
        case 0: versioningStatus = "";           break;
        case 1: versioningStatus = "Enabled";    break;
        case 2: versioningStatus = "Suspended"break;
        }
View Full Code Here

Examples of com.cloud.bridge.model.SBucketVO

    {
        // [A] Determine that there is an applicable bucket which might have an ACL set

        String bucketName = (String) request
                .getAttribute(S3Constants.BUCKET_ATTR_KEY);
        SBucketVO bucket = bucketDao.getByName(bucketName);
        String owner = null;
        if (null != bucket)
            owner = bucket.getOwnerCanonicalId();
        if (null == owner) {
            logger.error("ACL update failed since " + bucketName
                    + " does not exist");
            throw new IOException("ACL update failed");
        }
View Full Code Here

Examples of com.cloud.bridge.model.SBucketVO

            // Irrespective of what the ACLs say only the owner can turn on
            // versioning on a bucket.
            // The bucket owner may want to restrict the IP address from which
            // this can occur.

            SBucketVO sbucket = bucketDao.getByName(bucketName);

            String client = UserContext.current().getCanonicalUserId();
            if (!client.equals(sbucket.getOwnerCanonicalId()))
                throw new PermissionDeniedException(
                        "Access Denied - only the owner can turn on versioing on a bucket");

            S3PolicyContext context = new S3PolicyContext(
                    PolicyActions.PutBucketVersioning, bucketName);
            if (PolicyAccess.DENY == S3Engine.verifyPolicy(context)) {
                response.setStatus(403);
                return;
            }

            if (versioningStatus.equalsIgnoreCase("Enabled"))
                sbucket.setVersioningStatus(1);
            else if (versioningStatus.equalsIgnoreCase("Suspended"))
                sbucket.setVersioningStatus(2);
            else {
                logger.error("executePutBucketVersioning - unknown state: ["
                        + versioningStatus + "]");
                response.setStatus(400);
                return;
            }
            bucketDao.update(sbucket.getId(), sbucket);

        } catch (PermissionDeniedException e) {
            logger.error(
                    "executePutBucketVersioning - failed due to "
                            + e.getMessage(), e);
View Full Code Here

Examples of com.cloud.bridge.model.SBucketVO

        String uploadIdMarker = request.getParameter("upload-id-marker");
        if (null == keyMarker)
            uploadIdMarker = null;

        // -> does the bucket exist, we may need it to verify access permissions
        SBucketVO bucket = bucketDao.getByName(bucketName);
        if (bucket == null) {
            logger.error("listMultipartUpload failed since " + bucketName
                    + " does not exist");
            response.setStatus(404);
            return;
        }

        S3PolicyContext context = new S3PolicyContext(
                PolicyActions.ListBucketMultipartUploads, bucketName);
        context.setEvalParam(ConditionKeys.Prefix, prefix);
        context.setEvalParam(ConditionKeys.Delimiter, delimiter);
        S3Engine.verifyAccess(context, "SBucket", bucket.getId(),
                SAcl.PERMISSION_READ);

        // [B] Query the multipart table to get the list of current uploads
        try {
            MultipartLoadDao uploadDao = new MultipartLoadDao();
View Full Code Here

Examples of com.cloud.bridge.model.SBucketVO

            if (bucketDao.getByName(request.getBucketName()) != null)
                throw new ObjectAlreadyExistsException("Bucket already exists");

            shost_storagelocation_pair = allocBucketStorageHost(request.getBucketName(), null);
            SBucketVO sbucket =
                new SBucketVO(request.getBucketName(), DateHelper.currentGMTTime(), UserContext.current().getCanonicalUserId(), shost_storagelocation_pair.getFirst());

            shost_storagelocation_pair.getFirst().getBuckets().add(sbucket);
            // bucketDao.save(sbucket);
            sbucket = bucketDao.persist(sbucket);
            S3AccessControlList acl = request.getAcl();

            if (null != cannedAccessPolicy)
                setCannedAccessControls(cannedAccessPolicy, "SBucket", sbucket.getId(), sbucket);
            else if (null != acl)
                aclDao.save("SBucket", sbucket.getId(), acl);
            else
                setSingleAcl("SBucket", sbucket.getId(), SAcl.PERMISSION_FULL);

            success = true;
        } finally {
            if (!success && shost_storagelocation_pair != null) {
                S3BucketAdapter bucketAdapter = getStorageHostBucketAdapter(shost_storagelocation_pair.getFirst());
View Full Code Here

Examples of com.cloud.bridge.model.SBucketVO

    public S3Response handleRequest(S3DeleteBucketRequest request) {
        S3Response response = new S3Response();
        //
        String bucketName = request.getBucketName();
        SBucketVO sbucket = bucketDao.getByName(bucketName);

        TransactionLegacy txn = null;
        if (sbucket != null) {
            txn = TransactionLegacy.open(TransactionLegacy.AWSAPI_DB);
            txn.start();
            S3PolicyContext context = new S3PolicyContext(PolicyActions.DeleteBucket, bucketName);
            switch (verifyPolicy(context)) {
                case ALLOW:
                    // The bucket policy can give users permission to delete a
                    // bucket whereas ACLs cannot
                    break;

                case DENY:
                    throw new PermissionDeniedException("Access Denied - bucket policy DENY result");

                case DEFAULT_DENY:
                default:
                    // Irrespective of what the ACLs say, only the owner can delete
                    // a bucket
                    String client = UserContext.current().getCanonicalUserId();
                    if (!client.equals(sbucket.getOwnerCanonicalId())) {
                        throw new PermissionDeniedException("Access Denied - only the owner can delete a bucket");
                    }
                    break;
            }

            // Delete the file from its storage location
            OrderedPair<SHostVO, String> host_storagelocation_pair = getBucketStorageHost(sbucket);
            S3BucketAdapter bucketAdapter = getStorageHostBucketAdapter(host_storagelocation_pair.getFirst());
            bucketAdapter.deleteContainer(host_storagelocation_pair.getSecond(), request.getBucketName());

            // Cascade-deleting can delete related SObject/SObjectItem objects, but not SAcl, SMeta and policy objects.
            // To delete SMeta & SAcl objects:
            // (1)Get all the objects in the bucket,
            // (2)then all the items in each object,
            // (3) then all meta & acl data for each item
            Set<SObjectVO> objectsInBucket = sbucket.getObjectsInBucket();
            Iterator<SObjectVO> it = objectsInBucket.iterator();
            while (it.hasNext()) {
                SObjectVO oneObject = it.next();
                Set<SObjectItemVO> itemsInObject = oneObject.getItems();
                Iterator<SObjectItemVO> is = itemsInObject.iterator();
                while (is.hasNext()) {
                    SObjectItemVO oneItem = is.next();
                    deleteMetaData(oneItem.getId());
                    deleteObjectAcls("SObjectItem", oneItem.getId());
                }
            }

            // Delete all the policy state associated with the bucket
            try {
                ServiceProvider.getInstance().deleteBucketPolicy(bucketName);
                bPolicyDao.deletePolicy(bucketName);
            } catch (Exception e) {
                logger.error("When deleting a bucket we must try to delete its policy: ", e);
            }

            deleteBucketAcls(sbucket.getId());
            bucketDao.remove(sbucket.getId());

            response.setResultCode(204);
            response.setResultDescription("OK");

            txn.close();
View Full Code Here

Examples of com.cloud.bridge.model.SBucketVO

        int maxKeys = request.getMaxKeys();
        if (maxKeys <= 0)
            maxKeys = 1000;

        //
        SBucketVO sbucket = bucketDao.getByName(bucketName);
        if (sbucket == null)
            throw new NoSuchObjectException("Bucket " + bucketName + " does not exist");

        PolicyActions action = (includeVersions ? PolicyActions.ListBucketVersions : PolicyActions.ListBucket);
        S3PolicyContext context = new S3PolicyContext(action, bucketName);
        context.setEvalParam(ConditionKeys.MaxKeys, new String("" + maxKeys));
        context.setEvalParam(ConditionKeys.Prefix, prefix);
        context.setEvalParam(ConditionKeys.Delimiter, delimiter);
        verifyAccess(context, "SBucket", sbucket.getId(), SAcl.PERMISSION_READ);

        // Wen execting the query, request one more item so that we know how to set isTruncated flag
        List<SObjectVO> l = null;

        if (includeVersions)
View Full Code Here

Examples of com.cloud.bridge.model.SBucketVO

     */

    public S3Response handleRequest(S3SetBucketAccessControlPolicyRequest request) {
        S3Response response = new S3Response();
        String bucketName = request.getBucketName();
        SBucketVO sbucket = bucketDao.getByName(bucketName);
        if (sbucket == null) {
            response.setResultCode(404);
            response.setResultDescription("Bucket does not exist");
            return response;
        }

        S3PolicyContext context = new S3PolicyContext(PolicyActions.PutBucketAcl, bucketName);
        verifyAccess(context, "SBucket", sbucket.getId(), SAcl.PERMISSION_WRITE_ACL);

        aclDao.save("SBucket", sbucket.getId(), request.getAcl());

        response.setResultCode(200);
        response.setResultDescription("OK");
        return response;
    }
View Full Code Here

Examples of com.cloud.bridge.model.SBucketVO

     */

    public S3AccessControlPolicy handleRequest(S3GetBucketAccessControlPolicyRequest request) {
        S3AccessControlPolicy policy = new S3AccessControlPolicy();
        String bucketName = request.getBucketName();
        SBucketVO sbucket = bucketDao.getByName(bucketName);
        if (sbucket == null)
            throw new NoSuchObjectException("Bucket " + bucketName + " does not exist");

        S3CanonicalUser owner = new S3CanonicalUser();
        owner.setID(sbucket.getOwnerCanonicalId());
        owner.setDisplayName("");
        policy.setOwner(owner);

        S3PolicyContext context = new S3PolicyContext(PolicyActions.GetBucketAcl, bucketName);
        verifyAccess(context, "SBucket", sbucket.getId(), SAcl.PERMISSION_READ_ACL);

        List<SAclVO> grants = aclDao.listGrants("SBucket", sbucket.getId());
        policy.setGrants(S3Grant.toGrants(grants));
        return policy;
    }
View Full Code Here

Examples of com.cloud.bridge.model.SBucketVO

    public int freeUploadParts(String bucketName, int uploadId, boolean verifyPermission) {

        // -> we need to look up the final bucket to figure out which mount
        // point to use to save the part in
        // SBucketDao bucketDao = new SBucketDao();
        SBucketVO bucket = bucketDao.getByName(bucketName);
        if (bucket == null) {
            logger.error("initiateMultipartUpload failed since " + bucketName + " does not exist");
            return 404;
        }

        OrderedPair<SHostVO, String> host_storagelocation_pair = getBucketStorageHost(bucket);
        S3BucketAdapter bucketAdapter = getStorageHostBucketAdapter(host_storagelocation_pair.getFirst());

        try {
            MultipartLoadDao uploadDao = new MultipartLoadDao();
            OrderedPair<String, String> exists = uploadDao.multipartExits(uploadId);

            if (null == exists) {
                logger.error("initiateMultipartUpload failed since multipart upload" + uploadId + " does not exist");
                return 404;
            }

            // -> the multipart initiator or bucket owner can do this action by
            // default
            if (verifyPermission) {
                String initiator = uploadDao.getInitiator(uploadId);
                if (null == initiator || !initiator.equals(UserContext.current().getAccessKey())) {
                    // -> write permission on a bucket allows a PutObject /
                    // DeleteObject action on any object in the bucket
                    S3PolicyContext context = new S3PolicyContext(PolicyActions.AbortMultipartUpload, bucketName);
                    context.setKeyName(exists.getSecond());
                    verifyAccess(context, "SBucket", bucket.getId(), SAcl.PERMISSION_WRITE);
                }
            }

            // -> first get a list of all the uploaded files and delete one by
            // one
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.