Package com.cloud.bridge.model

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");
                 }
View Full Code Here


    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

            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

    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");
View Full Code Here

        String delimiter = request.getDelimiter();
        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;
View Full Code Here

    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

    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

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

        S3PutObjectInlineResponse response = new S3PutObjectInlineResponse()
        String bucketName = request.getBucketName();
        String nameKey = request.getKey();

        // -> does the bucket exist and can we write to it?
        SBucketVO bucket = bucketDao.getByName(bucketName);
        if (bucket == null) {
            logger.error( "initiateMultipartUpload failed since " + bucketName + " does not exist" );
            response.setResultCode(404);
        }

        S3PolicyContext context = new S3PolicyContext( PolicyActions.PutObject, bucketName );
        context.setKeyName( nameKey );
        context.setEvalParam( ConditionKeys.Acl, request.getCannedAccess());
        verifyAccess( context, "SBucket", bucket.getId(), SAcl.PERMISSION_WRITE );

        createUploadFolder( bucketName );

        try {
            MultipartLoadDao uploadDao = new MultipartLoadDao();
View Full Code Here

        S3PutObjectInlineResponse response = new S3PutObjectInlineResponse()
        String bucketName = request.getBucketName();

        // -> 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( "saveUploadedPart failed since " + bucketName + " does not exist" );
            response.setResultCode(404);
        }
        S3PolicyContext context = new S3PolicyContext( PolicyActions.PutObject, bucketName );
        context.setKeyName( request.getKey());
        verifyAccess( context, "SBucket", bucket.getId(), SAcl.PERMISSION_WRITE );

        OrderedPair<SHostVO, String> host_storagelocation_pair = getBucketStorageHost(bucket);   
        S3BucketAdapter bucketAdapter = getStorageHostBucketAdapter(host_storagelocation_pair.getFirst());
        String itemFileName = new String( uploadId + "-" + partNumber );
        InputStream is = null;
View Full Code Here

TOP

Related Classes of com.cloud.bridge.model.SBucketVO

Copyright © 2018 www.massapicom. 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.