Package com.cloud.bridge.service.core.s3

Examples of com.cloud.bridge.service.core.s3.S3ConditionalHeaders


    private void executeHeadObject(HttpServletRequest request, HttpServletResponse response) throws IOException
    {
        String bucket = (String) request.getAttribute(S3Constants.BUCKET_ATTR_KEY);
        String key    = (String) request.getAttribute(S3Constants.OBJECT_ATTR_KEY);

        S3GetObjectRequest engineRequest = new S3GetObjectRequest();
        engineRequest.setBucketName(bucket);
        engineRequest.setKey(key);
        engineRequest.setInlineData(true);    // -> need to set so we get ETag etc returned
        engineRequest.setReturnData(true);
        engineRequest.setReturnMetadata(true);
        engineRequest = setRequestByteRange( request, engineRequest );

        // -> is this a request for a specific version of the object?  look for "versionId=" in the query string
        String queryString = request.getQueryString();
        if (null != queryString) engineRequest.setVersion( returnParameter( queryString, "versionId=" ));

        S3GetObjectResponse engineResponse = ServiceProvider.getInstance().getS3Engine().handleRequest( engineRequest );   
        response.setStatus( engineResponse.getResultCode());

        //bucket lookup for non-existance key
View Full Code Here


        // -> is this a request for a specific version of the object?  look for "versionId=" in the query string
        String queryString = request.getQueryString();
        if (null != queryString) engineRequest.setVersion( returnParameter( queryString, "versionId=" ));

        S3GetObjectResponse engineResponse = ServiceProvider.getInstance().getS3Engine().handleRequest( engineRequest );     
        response.setStatus( engineResponse.getResultCode());

        if (engineResponse.getResultCode()  >=400 ) {
            return;
        }
        String deleteMarker = engineResponse.getDeleteMarker();
        if ( null != deleteMarker ) {
            response.addHeader( "x-amz-delete-marker", "true" )
            response.addHeader( "x-amz-version-id", deleteMarker );
        }
        else {
            String version = engineResponse.getVersion();
            if (null != version) response.addHeader( "x-amz-version-id", version );
        }

        // -> was the get conditional?
        if (!conditionPassed( request, response, engineResponse.getLastModified().getTime(), engineResponse.getETag()))
            return;


        // -> is there data to return
        // -> from the Amazon REST documentation it appears that Meta data is only returned as part of a HEAD request
        //returnMetaData( engineResponse, response );

        DataHandler dataHandler = engineResponse.getData();
        if (dataHandler != null) {
            response.addHeader("ETag", "\"" + engineResponse.getETag() + "\"");
            response.addHeader("Last-Modified", DateHelper.getDateDisplayString(
                    DateHelper.GMT_TIMEZONE, engineResponse.getLastModified().getTime(), "E, d MMM yyyy HH:mm:ss z"));

            response.setContentLength((int)engineResponse.getContentLength());     
            S3RestServlet.writeResponse(response, dataHandler.getInputStream());
        }
    }
View Full Code Here

        // -> is this a request for a specific version of the object?  look for "versionId=" in the query string
        String queryString = request.getQueryString();
        if (null != queryString) engineRequest.setVersion( returnParameter( queryString, "versionId=" ));

        S3GetObjectResponse engineResponse = ServiceProvider.getInstance().getS3Engine().handleRequest( engineRequest );   
        response.setStatus( engineResponse.getResultCode());

        //bucket lookup for non-existance key

        if ( engineResponse.getResultCode() == 404 )
            return;

        String deleteMarker = engineResponse.getDeleteMarker();
        if ( null != deleteMarker ) {
            response.addHeader( "x-amz-delete-marker", "true" )
            response.addHeader( "x-amz-version-id", deleteMarker );
        }
        else {
            String version = engineResponse.getVersion();
            if (null != version) response.addHeader( "x-amz-version-id", version );
        }

        // -> was the head request conditional?
        if (!conditionPassed( request, response, engineResponse.getLastModified().getTime(), engineResponse.getETag()))
            return


        // -> for a head request we return everything except the data
        returnMetaData( engineResponse, response );

        DataHandler dataHandler = engineResponse.getData();
        if (dataHandler != null) {
            response.addHeader("ETag", "\"" + engineResponse.getETag() + "\"");
            response.addHeader("Last-Modified", DateHelper.getDateDisplayString(
                    DateHelper.GMT_TIMEZONE, engineResponse.getLastModified().getTime(), "E, d MMM yyyy HH:mm:ss z"));

            response.setContentLength((int)engineResponse.getContentLength());     
       
    }
View Full Code Here

    Grant[] grants = acl.getGrant();
    if (grants != null)
    {
      for (Grant grant: grants)
      {
        S3Grant engineGrant = new S3Grant();

        Grantee grantee = grant.getGrantee();
        if (grantee instanceof CanonicalUser)
        {
          engineGrant.setGrantee(SAcl.GRANTEE_USER);
          engineGrant.setCanonicalUserID(((CanonicalUser)grantee).getID());
        }
        else if (grantee instanceof Group)
        {
           Group temp = (Group)grantee;
           String uri = temp.getURI();
           if ( uri.equalsIgnoreCase( "http://acs.amazonaws.com/groups/global/AllUsers" )) {
              // -> this allows all public unauthenticated access based on permission given
              engineGrant.setGrantee(SAcl.GRANTEE_ALLUSERS);
              engineGrant.setCanonicalUserID( "*" );
           }
           else if (uri.equalsIgnoreCase( "http://acs.amazonaws.com/groups/global/Authenticated" )) {
              // -> this allows any authenticated user access based on permission given
              engineGrant.setGrantee(SAcl.GRANTEE_AUTHENTICATED);
              engineGrant.setCanonicalUserID( "A" );
           }
           else throw new UnsupportedOperationException("Unsupported grantee group URI: " + uri );

        }
        else throw new UnsupportedOperationException("Unsupported grantee type: " + grantee.getClass().getCanonicalName());
       
        Permission permission = grant.getPermission();
        String permissionValue = permission.getValue();
        if(permissionValue.equalsIgnoreCase("READ")) {
          engineGrant.setPermission(SAcl.PERMISSION_READ);
        } else if(permissionValue.equalsIgnoreCase("WRITE")) {
          engineGrant.setPermission(SAcl.PERMISSION_WRITE);
        } else if(permissionValue.equalsIgnoreCase("READ_ACP")) {
          engineGrant.setPermission(SAcl.PERMISSION_READ_ACL);
        } else if(permissionValue.equalsIgnoreCase("WRITE_ACP")) {
          engineGrant.setPermission(SAcl.PERMISSION_WRITE_ACL);
        } else if(permissionValue.equalsIgnoreCase("FULL_CONTROL")) {
          engineGrant.setPermission(SAcl.PERMISSION_FULL);
        } else {
          throw new UnsupportedOperationException("Unsupported permission: " + permissionValue);
        }
        engineAcl.addGrant(engineGrant);
      }
View Full Code Here

        // [B] Obtain the grant request which applies to the acl request string.
        // This latter is supplied as the value of the x-amz-acl header.

        S3SetBucketAccessControlPolicyRequest engineRequest = new S3SetBucketAccessControlPolicyRequest();
        S3Grant grantRequest = new S3Grant();
        S3AccessControlList aclRequest = new S3AccessControlList();

        String aclRequestString = request.getHeader("x-amz-acl");
        OrderedPair<Integer, Integer> accessControlsForBucketOwner = SAclVO.getCannedAccessControls(aclRequestString, "SBucket");
        grantRequest.setPermission(accessControlsForBucketOwner.getFirst());
        grantRequest.setGrantee(accessControlsForBucketOwner.getSecond());
        grantRequest.setCanonicalUserID(owner);
        aclRequest.addGrant(grantRequest);
        engineRequest.setAcl(aclRequest);
        engineRequest.setBucketName(bucketName);

        // [C] Allow an S3Engine to handle the
View Full Code Here

            count = part.getLength();
            for( int i=0; i < count; i++ )
            {
                parent = part.item(i);
                S3Grant engineGrant = new S3Grant();

                // -> get a list of all the children elements of the 'Grant' parent element
                if (null != (children = parent.getChildNodes()))
                {
                    int numChildren = children.getLength();
                    for( int j=0; j < numChildren; j++ )
                    {
                        contents = children.item( j );
                        element  = contents.getNodeName().trim();
                        if ( element.endsWith( "Grantee" ))
                        {
                            NamedNodeMap attbs = contents.getAttributes();
                            if (null != attbs)
                            {
                                Node type = attbs.getNamedItemNS( "http://www.w3.org/2001/XMLSchema-instance", "type" );
                                if ( null != type )
                                    temp = type.getFirstChild().getNodeValue().trim();
                                else temp = null;

                                if ( null != temp && temp.equalsIgnoreCase( "CanonicalUser" ))
                                {
                                    engineGrant.setGrantee(SAcl.GRANTEE_USER);
                                    engineGrant.setCanonicalUserID( getChildNodeValue( contents, "ID" ));
                                }
                                else throw new UnsupportedOperationException( "Missing http://www.w3.org/2001/XMLSchema-instance:type value" );
                            }
                        }
                        else if (element.endsWith( "Permission" ))
                        {
                            temp = contents.getFirstChild().getNodeValue().trim();
                            if (temp.equalsIgnoreCase("READ"        )) engineGrant.setPermission(SAcl.PERMISSION_READ);
                            else if (temp.equalsIgnoreCase("WRITE"       )) engineGrant.setPermission(SAcl.PERMISSION_WRITE);
                            else if (temp.equalsIgnoreCase("READ_ACP"    )) engineGrant.setPermission(SAcl.PERMISSION_READ_ACL);
                            else if (temp.equalsIgnoreCase("WRITE_ACP"   )) engineGrant.setPermission(SAcl.PERMISSION_WRITE_ACL);
                            else if (temp.equalsIgnoreCase("FULL_CONTROL")) engineGrant.setPermission(SAcl.PERMISSION_FULL);
                            else throw new UnsupportedOperationException( "Unsupported permission: " + temp );
                        }
                    }
                    engineAcl.addGrant( engineGrant );
                }
View Full Code Here

        }

        // [B] Obtain the grant request which applies to the acl request string.  This latter is supplied as the value of the x-amz-acl header.

        S3SetObjectAccessControlPolicyRequest engineRequest = new S3SetObjectAccessControlPolicyRequest();
        S3Grant grantRequest = new S3Grant();
        S3AccessControlList aclRequest = new S3AccessControlList();

        String aclRequestString = request.getHeader("x-amz-acl");
        OrderedPair <Integer,Integer> accessControlsForObjectOwner = SAclVO.getCannedAccessControls(aclRequestString,"SObject");
        grantRequest.setPermission(accessControlsForObjectOwner.getFirst());
        grantRequest.setGrantee(accessControlsForObjectOwner.getSecond());
        grantRequest.setCanonicalUserID(owner);
        aclRequest.addGrant(grantRequest);
        engineRequest.setAcl(aclRequest);
        engineRequest.setBucketName(bucketName);
        engineRequest.setKey(key);
View Full Code Here

        String bucket = (String) request.getAttribute(S3Constants.BUCKET_ATTR_KEY);
        String key    = (String) request.getAttribute(S3Constants.OBJECT_ATTR_KEY);
        String accessKey = (String) request.getAttribute(S3Constants.PLAIN_POST_ACCESS_KEY);
        String signature = (String) request.getAttribute(S3Constants.PLAIN_POST_SIGNATURE);
        S3Grant grant = new S3Grant();
        grant.setCanonicalUserID(accessKey);
        grant.setGrantee(SAcl.GRANTEE_USER);
        grant.setPermission(SAcl.PERMISSION_FULL);
        S3AccessControlList acl = new S3AccessControlList();
        acl.addGrant(grant);
        S3PutObjectInlineRequest engineRequest = new S3PutObjectInlineRequest();
        engineRequest.setBucketName(bucket);
        engineRequest.setKey(key);
View Full Code Here

  public ListAllMyBucketsResponse listAllMyBuckets (ListAllMyBuckets listAllMyBuckets) {
    return toListAllMyBucketsResponse(engine.handleRequest(toEngineListAllMyBucketsRequest(listAllMyBuckets)));
    }
 
  private S3ListAllMyBucketsRequest toEngineListAllMyBucketsRequest(ListAllMyBuckets listAllMyBuckets) {
    S3ListAllMyBucketsRequest request = new S3ListAllMyBucketsRequest();
    request.setAccessKey(listAllMyBuckets.getAWSAccessKeyId());
    request.setRequestTimestamp(listAllMyBuckets.getTimestamp());
    request.setSignature(listAllMyBuckets.getSignature());
    return request;
  }
View Full Code Here

    public void executeGetAllBuckets(HttpServletRequest request,
            HttpServletResponse response) throws IOException,
            XMLStreamException {
        Calendar cal = Calendar.getInstance();
        cal.set(1970, 1, 1);
        S3ListAllMyBucketsRequest engineRequest = new S3ListAllMyBucketsRequest();
        engineRequest.setAccessKey(UserContext.current().getAccessKey());
        engineRequest.setRequestTimestamp(cal);
        engineRequest.setSignature("");

        S3ListAllMyBucketsResponse engineResponse = ServiceProvider
                .getInstance().getS3Engine().handleRequest(engineRequest);

        // To allow the all buckets list to be serialized via Axiom classes
View Full Code Here

TOP

Related Classes of com.cloud.bridge.service.core.s3.S3ConditionalHeaders

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.