本文整理汇总了Java中org.jets3t.service.acl.AccessControlList.grantPermission方法的典型用法代码示例。如果您正苦于以下问题:Java AccessControlList.grantPermission方法的具体用法?Java AccessControlList.grantPermission怎么用?Java AccessControlList.grantPermission使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jets3t.service.acl.AccessControlList
的用法示例。
在下文中一共展示了AccessControlList.grantPermission方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setConfiguration
import org.jets3t.service.acl.AccessControlList; //导入方法依赖的package包/类
@Override
public void setConfiguration(final Path container, final LoggingConfiguration configuration) throws BackgroundException {
try {
// Logging target bucket
final GSBucketLoggingStatus status = new GSBucketLoggingStatus(
StringUtils.isNotBlank(configuration.getLoggingTarget()) ? configuration.getLoggingTarget() : container.getName(), null);
if(configuration.isEnabled()) {
status.setLogfilePrefix(PreferencesFactory.get().getProperty("google.logging.prefix"));
}
// Grant write for Google to logging target bucket
final AccessControlList acl = session.getClient().getBucketAcl(container.getName());
final GroupByEmailAddressGrantee grantee = new GroupByEmailAddressGrantee(
"[email protected]");
if(!acl.getPermissionsForGrantee(grantee).contains(Permission.PERMISSION_WRITE)) {
acl.grantPermission(grantee, Permission.PERMISSION_WRITE);
session.getClient().putBucketAcl(container.getName(), acl);
}
session.getClient().setBucketLoggingStatusImpl(container.getName(), status);
}
catch(ServiceException e) {
throw new S3ExceptionMappingService().map("Failure to write attributes of {0}", e);
}
}
示例2: deploy
import org.jets3t.service.acl.AccessControlList; //导入方法依赖的package包/类
public void deploy(File jarFile) {
String deployBucket = getOrCry("deployBucket");
String deployFilename = getOrCry("deployFilename");
try {
getStorage().getOrCreateBucket(deployBucket);
AccessControlList bucketAcl = getStorage().getBucketAcl(
deployBucket);
bucketAcl.grantPermission(GroupGrantee.ALL_USERS,
Permission.PERMISSION_READ);
S3Object statFileObject = new S3Object(jarFile);
statFileObject.setKey(deployFilename);
statFileObject.setAcl(bucketAcl);
getStorage().putObject(deployBucket, statFileObject);
log.info("File " + jarFile + " now accessible at " + getJarUrl());
} catch (Exception e) {
log.warn("Failed to deploy or set permissions in bucket "
+ deployBucket + ", key " + deployFilename, e);
}
}
示例3: saveImage
import org.jets3t.service.acl.AccessControlList; //导入方法依赖的package包/类
private void saveImage(String filename, MultipartFile image)
throws ImageUploadException {
try {
AWSCredentials awsCredentials =
new AWSCredentials(s3AccessKey, s3SecretKey);
S3Service s3 = new RestS3Service(awsCredentials);
S3Bucket imageBucket = s3.getBucket("spitterImages");
S3Object imageObject = new S3Object(filename);
imageObject.setDataInputStream(
new ByteArrayInputStream(image.getBytes()));
imageObject.setContentLength(image.getBytes().length);
imageObject.setContentType("image/jpeg");
AccessControlList acl = new AccessControlList();
acl.setOwner(imageBucket.getOwner());
acl.grantPermission(GroupGrantee.ALL_USERS,
Permission.PERMISSION_READ);
imageObject.setAcl(acl);
s3.putObject(imageBucket, imageObject);
} catch (Exception e) {
throw new ImageUploadException("Unable to save image", e);
}
}
示例4: grantAcl
import org.jets3t.service.acl.AccessControlList; //导入方法依赖的package包/类
public boolean grantAcl(S3Object object) throws ServiceException, InterruptedException {
if(Strings.isNullOrEmpty(s3Acl)){
return true;
}
for (int i = 0; i < s3AclRetries; ++i) {
try {
AccessControlList acl = s3Service.getObjectAcl(object.getBucketName(), object.getKey());
for (String id : s3Acl.split(",")) {
acl.grantPermission(new CanonicalGrantee(id), Permission.PERMISSION_READ);
}
s3Service.putObjectAcl(object.getBucketName(), object.getKey(), acl);
return true;
} catch (Exception e) {
log.error("Exception while granting ACL: " + e.getMessage(), e);
Thread.sleep(1000 * (i + 1));
}
}
return false;
}
示例5: makeBucketPublic
import org.jets3t.service.acl.AccessControlList; //导入方法依赖的package包/类
public void makeBucketPublic(String bkt) throws ServiceException {
// Retrieve the bucket's ACL and modify it to grant public access,
// ie READ access to the ALL_USERS group.
S3Bucket privateBket = s3service.getBucket(bkt);
AccessControlList bucketAcl = s3service.getBucketAcl(privateBket);
bucketAcl.grantPermission(GroupGrantee.ALL_USERS,
Permission.PERMISSION_READ);
// Update the bucket's ACL. Now anyone can view the list of objects in
// this bucket.
privateBket.setAcl(bucketAcl);
s3service.putBucketAcl(privateBket);
Logger.log("View bucket's object listing here: http://s3.amazonaws.com/"
+ privateBket.getName());
}
示例6: uploadFile
import org.jets3t.service.acl.AccessControlList; //导入方法依赖的package包/类
public static void uploadFile(final File file, final String fileName, final ContentTypeEnum contentType, final boolean rewrite) {
try {
s3Service = new RestS3Service(AWSCREDENTIALS);
AccessControlList bucketAcl = s3Service.getBucketAcl("pubanywhere");
bucketAcl.grantPermission(GroupGrantee.ALL_USERS, Permission.PERMISSION_READ);
pubanywhere = s3Service.getBucket("pubanywhere");
if (pubanywhere != null) {
S3Object object = new S3Object(pubanywhere, file);
object.setContentLength(file.length());
object.setContentType(contentType.getDescricao());
object.setName(fileName);
object.setAcl(bucketAcl);
if (rewrite) {
s3Service.putObject(pubanywhere, object);
} else {
if (!isFileOnAmazon(fileName)) {
s3Service.putObject(pubanywhere, object);
}
}
log.info("Uploading file: " + fileName + " on amazon");
}
} catch (Exception e) {
log.error("Error uploading file: " + fileName, e.getMessage());
}
}
示例7: convert
import org.jets3t.service.acl.AccessControlList; //导入方法依赖的package包/类
/**
* Convert ACL for writing to service.
*
* @param acl Edited ACL
* @return ACL to write to server
*/
protected AccessControlList convert(final Acl acl) {
if(Acl.EMPTY.equals(acl)) {
return null;
}
final AccessControlList list = new AccessControlList();
final Acl.CanonicalUser owner = acl.getOwner();
if(null != owner) {
list.setOwner(new S3Owner(owner.getIdentifier(), owner.getDisplayName()));
list.grantPermission(new CanonicalGrantee(owner.getIdentifier()), Permission.PERMISSION_FULL_CONTROL);
}
for(Acl.UserAndRole userAndRole : acl.asList()) {
if(!userAndRole.isValid()) {
continue;
}
if(userAndRole.getUser() instanceof Acl.EmailUser) {
list.grantPermission(new EmailAddressGrantee(userAndRole.getUser().getIdentifier()),
Permission.parsePermission(userAndRole.getRole().getName()));
}
else if(userAndRole.getUser() instanceof Acl.GroupUser) {
if(userAndRole.getUser().getIdentifier().equals(GroupGrantee.ALL_USERS.getIdentifier())
|| userAndRole.getUser().getIdentifier().equals(Acl.GroupUser.EVERYONE)) {
list.grantPermission(GroupGrantee.ALL_USERS,
Permission.parsePermission(userAndRole.getRole().getName()));
}
else if(userAndRole.getUser().getIdentifier().equals(Acl.GroupUser.AUTHENTICATED)) {
list.grantPermission(GroupGrantee.AUTHENTICATED_USERS,
Permission.parsePermission(userAndRole.getRole().getName()));
}
else {
list.grantPermission(new GroupGrantee(userAndRole.getUser().getIdentifier()),
Permission.parsePermission(userAndRole.getRole().getName()));
}
}
else if(userAndRole.getUser() instanceof Acl.CanonicalUser) {
list.grantPermission(new CanonicalGrantee(userAndRole.getUser().getIdentifier()),
Permission.parsePermission(userAndRole.getRole().getName()));
}
else {
log.warn(String.format("Unsupported user %s", userAndRole.getUser()));
}
}
if(log.isDebugEnabled()) {
try {
log.debug(list.toXml());
}
catch(ServiceException e) {
log.error(e.getMessage());
}
}
return list;
}
示例8: setBucketLoggingStatus
import org.jets3t.service.acl.AccessControlList; //导入方法依赖的package包/类
/**
* Applies logging settings to a bucket, optionally modifying the ACL permissions for the
* logging target bucket to ensure log files can be written to it. Only the owner of
* a bucket may change its logging status.
*
* @param bucketName
* the name of the bucket the logging settings will apply to.
* @param status
* the logging status settings to apply to the bucket.
* @param updateTargetACLifRequired
* if true, when logging is enabled the method will check the target bucket to ensure it has the
* necessary ACL permissions set to allow logging (that is, WRITE and READ_ACP for the group
* <tt>http://acs.amazonaws.com/groups/s3/LogDelivery</tt>). If the target bucket does not
* have the correct permissions the bucket's ACL will be updated to have the correct
* permissions. If this parameter is false, no ACL checks or updates will occur.
*
* @throws S3ServiceException
*/
public void setBucketLoggingStatus(String bucketName, S3BucketLoggingStatus status,
boolean updateTargetACLifRequired)
throws S3ServiceException
{
try {
if (status.isLoggingEnabled() && updateTargetACLifRequired) {
// Check whether the target bucket has the ACL permissions necessary for logging.
if (log.isDebugEnabled()) {
log.debug("Checking whether the target logging bucket '" +
status.getTargetBucketName() + "' has the appropriate ACL settings");
}
boolean isSetLoggingGroupWrite = false;
boolean isSetLoggingGroupReadACP = false;
String groupIdentifier = GroupGrantee.LOG_DELIVERY.getIdentifier();
AccessControlList logBucketACL = getBucketAcl(status.getTargetBucketName());
for (GrantAndPermission gap: logBucketACL.getGrantAndPermissions()) {
if (groupIdentifier.equals(gap.getGrantee().getIdentifier())) {
// Found a Group Grantee.
if (gap.getPermission().equals(Permission.PERMISSION_WRITE)) {
isSetLoggingGroupWrite = true;
if (log.isDebugEnabled()) {
log.debug("Target bucket '" + status.getTargetBucketName() + "' has ACL "
+ "permission " + Permission.PERMISSION_WRITE + " for group " +
groupIdentifier);
}
} else if (gap.getPermission().equals(Permission.PERMISSION_READ_ACP)) {
isSetLoggingGroupReadACP = true;
if (log.isDebugEnabled()) {
log.debug("Target bucket '" + status.getTargetBucketName() + "' has ACL "
+ "permission " + Permission.PERMISSION_READ_ACP + " for group " +
groupIdentifier);
}
}
}
}
// Update target bucket's ACL if necessary.
if (!isSetLoggingGroupWrite || !isSetLoggingGroupReadACP) {
if (log.isWarnEnabled()) {
log.warn("Target logging bucket '" + status.getTargetBucketName()
+ "' does not have the necessary ACL settings, updating ACL now");
}
logBucketACL.grantPermission(GroupGrantee.LOG_DELIVERY, Permission.PERMISSION_WRITE);
logBucketACL.grantPermission(GroupGrantee.LOG_DELIVERY, Permission.PERMISSION_READ_ACP);
putBucketAcl(status.getTargetBucketName(), logBucketACL);
} else {
if (log.isDebugEnabled()) {
log.debug("Target logging bucket '" + status.getTargetBucketName()
+ "' has the necessary ACL settings");
}
}
}
setBucketLoggingStatusImpl(bucketName, status);
} catch (ServiceException se) {
throw new S3ServiceException(se);
}
}
示例9: setBucketLoggingStatus
import org.jets3t.service.acl.AccessControlList; //导入方法依赖的package包/类
/**
* Applies logging settings to a bucket, optionally modifying the ACL permissions for the
* logging target bucket to ensure log files can be written to it. Only the owner of
* a bucket may change its logging status.
*
* @param bucketName
* the name of the bucket the logging settings will apply to.
* @param status
* the logging status settings to apply to the bucket.
* @param updateTargetACLifRequired
* if true, when logging is enabled the method will check the target bucket to ensure it has the
* necessary ACL permissions set to allow logging (that is, WRITE and READ_ACP for the group
* <tt>http://acs.amazonaws.com/groups/s3/LogDelivery</tt>). If the target bucket does not
* have the correct permissions the bucket's ACL will be updated to have the correct
* permissions. If this parameter is false, no ACL checks or updates will occur.
*
* @throws S3ServiceException
*/
public void setBucketLoggingStatus(String bucketName, S3BucketLoggingStatus status,
boolean updateTargetACLifRequired)
throws S3ServiceException
{
if (status.isLoggingEnabled() && updateTargetACLifRequired) {
// Check whether the target bucket has the ACL permissions necessary for logging.
if (log.isDebugEnabled()) {
log.debug("Checking whether the target logging bucket '" +
status.getTargetBucketName() + "' has the appropriate ACL settings");
}
boolean isSetLoggingGroupWrite = false;
boolean isSetLoggingGroupReadACP = false;
String groupIdentifier = GroupGrantee.LOG_DELIVERY.getIdentifier();
AccessControlList logBucketACL = getBucketAcl(status.getTargetBucketName());
Iterator grantIter = logBucketACL.getGrants().iterator();
while (grantIter.hasNext()) {
GrantAndPermission gap = (GrantAndPermission) grantIter.next();
if (groupIdentifier.equals(gap.getGrantee().getIdentifier())) {
// Found a Group Grantee.
if (gap.getPermission().equals(Permission.PERMISSION_WRITE)) {
isSetLoggingGroupWrite = true;
if (log.isDebugEnabled()) {
log.debug("Target bucket '" + status.getTargetBucketName() + "' has ACL "
+ "permission " + Permission.PERMISSION_WRITE + " for group " +
groupIdentifier);
}
} else if (gap.getPermission().equals(Permission.PERMISSION_READ_ACP)) {
isSetLoggingGroupReadACP = true;
if (log.isDebugEnabled()) {
log.debug("Target bucket '" + status.getTargetBucketName() + "' has ACL "
+ "permission " + Permission.PERMISSION_READ_ACP + " for group " +
groupIdentifier);
}
}
}
}
// Update target bucket's ACL if necessary.
if (!isSetLoggingGroupWrite || !isSetLoggingGroupReadACP) {
if (log.isWarnEnabled()) {
log.warn("Target logging bucket '" + status.getTargetBucketName()
+ "' does not have the necessary ACL settings, updating ACL now");
}
logBucketACL.grantPermission(GroupGrantee.LOG_DELIVERY, Permission.PERMISSION_WRITE);
logBucketACL.grantPermission(GroupGrantee.LOG_DELIVERY, Permission.PERMISSION_READ_ACP);
putBucketAcl(status.getTargetBucketName(), logBucketACL);
} else {
if (log.isDebugEnabled()) {
log.debug("Target logging bucket '" + status.getTargetBucketName()
+ "' has the necessary ACL settings");
}
}
}
setBucketLoggingStatusImpl(bucketName, status);
}