Examples of SAclDao


Examples of com.cloud.bridge.persist.dao.SAclDao

    {
      Tuple<SHost, String> shostTuple = null;
      boolean success = false;
      try {
        SBucketDao bucketDao = new SBucketDao();
        SAclDao    aclDao    = new SAclDao();
       
        if (bucketDao.getByName(request.getBucketName()) != null)
          throw new ObjectAlreadyExistsException("Bucket already exists");
         
        shostTuple = allocBucketStorageHost(request.getBucketName(), null);
       
        SBucket sbucket = new SBucket();
        sbucket.setName(request.getBucketName());
        sbucket.setCreateTime(DateHelper.currentGMTTime());
        sbucket.setOwnerCanonicalId( UserContext.current().getCanonicalUserId());
        sbucket.setShost(shostTuple.getFirst());
        shostTuple.getFirst().getBuckets().add(sbucket);
        bucketDao.save(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 );
     
        // explicitly commit the transaction
        PersistContext.commitTransaction();
        success = true;       
View Full Code Here

Examples of com.cloud.bridge.persist.dao.SAclDao

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

      SAclDao aclDao = new SAclDao();
      aclDao.save("SBucket", sbucket.getId(), request.getAcl());
    
      response.setResultCode(200);
      response.setResultDescription("OK");
      return response;
    }
View Full Code Here

Examples of com.cloud.bridge.persist.dao.SAclDao

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

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

Examples of com.cloud.bridge.persist.dao.SAclDao

    else context = new S3PolicyContext( PolicyActions.PutObjectAcl, bucketName );   
    context.setKeyName( nameKey );
    verifyAccess( context, "SObjectItem", item.getId(), SAcl.PERMISSION_WRITE_ACL );   

    // -> the acl always goes on the instance of the object
      SAclDao aclDao = new SAclDao();
      aclDao.save("SObjectItem", item.getId(), request.getAcl());
     
      response.setResultCode(200);
      response.setResultDescription("OK");
      return response;
    }
View Full Code Here

Examples of com.cloud.bridge.persist.dao.SAclDao

      owner.setID(sobject.getOwnerCanonicalId());
      owner.setDisplayName("");
      policy.setOwner(owner);
    policy.setResultCode(200);
    
      SAclDao aclDao = new SAclDao();
      List<SAcl> grants = aclDao.listGrants( "SObjectItem", item.getId());
      policy.setGrants(S3Grant.toGrants(grants));   
      return policy;
    }
View Full Code Here

Examples of com.cloud.bridge.persist.dao.SAclDao

        }
    }
  }

  private void deleteObjectAcls( String target, long itemId ) {
      SAclDao aclDao = new SAclDao();
      List<SAcl> itemAclData = aclDao.listGrants( target, itemId );
      if (null != itemAclData)
      {
          ListIterator it = itemAclData.listIterator();
        while( it.hasNext()) {
           SAcl oneTag = (SAcl)it.next();
           aclDao.delete( oneTag );
        }
    }
  }
View Full Code Here

Examples of com.cloud.bridge.persist.dao.SAclDao

        }
    }
  }

  private void deleteBucketAcls( long bucketId ) {
      SAclDao aclDao = new SAclDao();
      List<SAcl> bucketAclData = aclDao.listGrants( "SBucket", bucketId );
      if (null != bucketAclData)
      {
          ListIterator it = bucketAclData.listIterator();
        while( it.hasNext()) {
           SAcl oneTag = (SAcl)it.next();
           aclDao.delete( oneTag );
        }
    }
  }
View Full Code Here

Examples of com.cloud.bridge.persist.dao.SAclDao

  public Tuple<SObject, SObjectItem> allocObjectItem(SBucket bucket, String nameKey, S3MetaDataEntry[] meta, S3AccessControlList acl, String cannedAccessPolicy)
  {
    SObjectDao     objectDao     = new SObjectDao();
    SObjectItemDao objectItemDao = new SObjectItemDao();
    SMetaDao       metaDao       = new SMetaDao();
    SAclDao        aclDao        = new SAclDao();
    SObjectItem    item          = null;
    int            versionSeq    = 1;
    int      versioningStatus    = bucket.getVersioningStatus();
   
    Session session = PersistContext.getSession();
     
    // [A] To write into a bucket the user must have write permission to that bucket
    S3PolicyContext context = new S3PolicyContext( PolicyActions.PutObject, bucket.getName());
    context.setKeyName( nameKey );
    context.setEvalParam( ConditionKeys.Acl, cannedAccessPolicy);
    verifyAccess( context, "SBucket", bucket.getId(), SAcl.PERMISSION_WRITE );

    // [A] If versioning is off them we over write a null object item
    SObject object = objectDao.getByNameKey(bucket, nameKey);
    if ( object != null )
    {
       // -> if versioning is on create new object items
       if ( SBucket.VERSIONING_ENABLED == versioningStatus )
       {
            session.lock(object, LockMode.UPGRADE);
            versionSeq = object.getNextSequence();
            object.setNextSequence(versionSeq + 1);
             session.save(object);
           
            item = new SObjectItem();
            item.setTheObject(object);
            object.getItems().add(item);
            item.setVersion(String.valueOf(versionSeq));
            Date ts = DateHelper.currentGMTTime();
            item.setCreateTime(ts);
            item.setLastAccessTime(ts);
            item.setLastModifiedTime(ts);
            session.save(item);
       }
       else
       {    // -> find an object item with a null version, can be null
          //    if bucket started out with versioning enabled and was then suspended
          item = objectItemDao.getByObjectIdNullVersion( object.getId());
          if (item == null)
          {
              item = new SObjectItem();
              item.setTheObject(object);
              object.getItems().add(item);
              Date ts = DateHelper.currentGMTTime();
              item.setCreateTime(ts);
              item.setLastAccessTime(ts);
              item.setLastModifiedTime(ts);
              session.save(item);     
          }
       }
    }
    else
    {    // -> there is no object nor an object item
       object = new SObject();
       object.setBucket(bucket);
       object.setNameKey(nameKey);
       object.setNextSequence(2);
       object.setCreateTime(DateHelper.currentGMTTime());
       object.setOwnerCanonicalId(UserContext.current().getCanonicalUserId());
       session.save(object);
   
         item = new SObjectItem();
         item.setTheObject(object);
         object.getItems().add(item);
         if (SBucket.VERSIONING_ENABLED  == versioningStatus) item.setVersion(String.valueOf(versionSeq));
         Date ts = DateHelper.currentGMTTime();
         item.setCreateTime(ts);
         item.setLastAccessTime(ts);
         item.setLastModifiedTime(ts);
         session.save(item);
    }
     
   
    // [C] We will use the item DB id as the file name, MD5/contentLength will be stored later
    String suffix = null;
    int dotPos = nameKey.lastIndexOf('.');
    if (dotPos >= 0) suffix = nameKey.substring(dotPos);
    if ( suffix != null )
       item.setStoredPath(String.valueOf(item.getId()) + suffix);
    else item.setStoredPath(String.valueOf(item.getId()));
   
    metaDao.save("SObjectItem", item.getId(), meta);
   
   
    // [D] Are we setting an ACL along with the object
    //  -> the ACL is ALWAYS set on a particular instance of the object (i.e., a version)
    if ( null != cannedAccessPolicy )
    {
       setCannedAccessControls( cannedAccessPolicy, "SObjectItem", item.getId(), bucket );
    }
    else if (null == acl || 0 == acl.size())
    {
       // -> this is termed the "private" or default ACL, "Owner gets FULL_CONTROL"
       setSingleAcl( "SObjectItem", item.getId(), SAcl.PERMISSION_FULL );
    }
    else if (null != acl) {
       aclDao.save( "SObjectItem", item.getId(), acl );
    }
   
    session.update(item);   
    return new Tuple<SObject, SObjectItem>(object, item);
  }
View Full Code Here

Examples of com.cloud.bridge.persist.dao.SAclDao

  }

 
  private void setSingleAcl( String target, long targetId, int permission )
  { 
    SAclDao aclDao  = new SAclDao();
        S3AccessControlList defaultAcl = new S3AccessControlList();
       
    // -> if an annoymous request, then do not rewrite the ACL
    String userId = UserContext.current().getCanonicalUserId();
        if (0 < userId.length())
        {
            S3Grant defaultGrant = new S3Grant();
            defaultGrant.setGrantee(SAcl.GRANTEE_USER);
            defaultGrant.setCanonicalUserID( userId );
            defaultGrant.setPermission( permission );
            defaultAcl.addGrant( defaultGrant );      
            aclDao.save( target, targetId, defaultAcl );
        }
  }
View Full Code Here

Examples of com.cloud.bridge.persist.dao.SAclDao

   *                (a) '*' - any principal authenticated user (i.e., any user with a registered Cloud Access Key)
   *                (b) 'A' - any anonymous principal (i.e., S3 request without an Authorization header)
   */
  private void setDefaultAcls( String target, long objectId, int permission1, int permission2, String owner  )
  {
    SAclDao aclDao = new SAclDao();
    S3AccessControlList defaultAcl = new S3AccessControlList();    
   
    // -> object owner
        S3Grant defaultGrant = new S3Grant();
        defaultGrant.setGrantee(SAcl.GRANTEE_USER);
        defaultGrant.setCanonicalUserID( UserContext.current().getCanonicalUserId());
        defaultGrant.setPermission( permission1 );
        defaultAcl.addGrant( defaultGrant )
   
        // -> bucket owner
        defaultGrant = new S3Grant();
        defaultGrant.setGrantee(SAcl.GRANTEE_USER);
        defaultGrant.setCanonicalUserID( owner );
        defaultGrant.setPermission( permission2 );
        defaultAcl.addGrant( defaultGrant );      
        aclDao.save( target, objectId, defaultAcl );
  }
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.