Examples of SBucketVO


Examples of com.cloud.bridge.model.SBucketVO

    private void executeGetBucketPolicy(HttpServletRequest request, HttpServletResponse response) {
        String bucketName = (String)request.getAttribute(S3Constants.BUCKET_ATTR_KEY);

        // [A] Is there an owner of an existing policy or bucket?
        SBucketVO bucket = bucketDao.getByName(bucketName);
        String owner = null;

        if (null != bucket) {
            owner = bucket.getOwnerCanonicalId();
        } else {
            try {
                owner = bPolicyDao.getByName(bucketName).getOwnerCanonicalID();
            } catch (Exception e) {
            }
View Full Code Here

Examples of com.cloud.bridge.model.SBucketVO

    }

    private void executeDeleteBucketPolicy(HttpServletRequest request, HttpServletResponse response) {
        String bucketName = (String)request.getAttribute(S3Constants.BUCKET_ATTR_KEY);

        SBucketVO bucket = bucketDao.getByName(bucketName);
        if (bucket != null) {
            String client = UserContext.current().getCanonicalUserId();
            if (!client.equals(bucket.getOwnerCanonicalId())) {
                response.setStatus(405);
                return;
            }
        }
View Full Code Here

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:
View Full Code Here

Examples of com.cloud.bridge.model.SBucketVO

    public void executePutBucketAcl(HttpServletRequest request, HttpServletResponse response) throws IOException {
        // [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);
            throw 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();
            OrderedPair<S3MultipartUpload[], Boolean> result = uploadDao.getInitiatedUploads(bucketName, maxUploads, prefix, keyMarker, uploadIdMarker);
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);
        String key = (String)request.getAttribute(S3Constants.OBJECT_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");
        }
        if (null == key) {
View Full Code Here

Examples of com.cloud.bridge.model.SBucketVO

        temp = request.getParameter("part-number-marker");
        if (null != temp)
            partMarker = Integer.parseInt(temp);

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

        try {
            MultipartLoadDao uploadDao = new MultipartLoadDao();
            OrderedPair<String, String> exists = uploadDao.multipartExits(uploadId);
            if (null == exists) {
                response.setStatus(404);
                return;
            }
            owner = exists.getFirst();

            // -> the multipart initiator or bucket owner can do this action
            initiator = uploadDao.getInitiator(uploadId);
            if (null == initiator || !initiator.equals(UserContext.current().getAccessKey())) {
                try {
                    // -> write permission on a bucket allows a PutObject / DeleteObject action on any object in the bucket
                    S3PolicyContext context = new S3PolicyContext(PolicyActions.ListMultipartUploadParts, bucketName);
                    context.setKeyName(exists.getSecond());
                    S3Engine.verifyAccess(context, "SBucket", bucket.getId(), SAcl.PERMISSION_WRITE);
                } catch (PermissionDeniedException e) {
                    response.setStatus(403);
                    return;
                }
            }
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
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);
   
    Transaction txn = null;
    if ( sbucket != null )
    { 
        txn = Transaction.open(Transaction.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 = (SObjectVO)it.next();
        Set<SObjectItemVO> itemsInObject = oneObject.getItems();
        Iterator<SObjectItemVO> is = itemsInObject.iterator();
        while( is.hasNext())
        {
                    SObjectItemVO oneItem = (SObjectItemVO) 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");
      
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.