Search in sources :

Example 66 with GWException

use of com.pspace.ifs.ksan.gw.exception.GWException in project ksan by infinistor.

the class S3Request method updateBucketAcl.

protected void updateBucketAcl(String bucket, String aclXml) throws GWException {
    try {
        setObjManager();
        objManager.updateBucketAcl(bucket, aclXml);
    } catch (Exception e) {
        logger.error(e.getMessage());
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    } finally {
        try {
            releaseObjManager();
        } catch (Exception e) {
            PrintStack.logging(logger, e);
            throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
        }
    }
}
Also used : GWException(com.pspace.ifs.ksan.gw.exception.GWException) GWException(com.pspace.ifs.ksan.gw.exception.GWException) ResourceAlreadyExistException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceAlreadyExistException) XMLStreamException(javax.xml.stream.XMLStreamException) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Example 67 with GWException

use of com.pspace.ifs.ksan.gw.exception.GWException in project ksan by infinistor.

the class S3Request method getSomeBucket.

protected Bucket getSomeBucket(String bucket) throws GWException {
    checkBucket(bucket);
    Bucket bucketInfo = null;
    try {
        setObjManager();
        bucketInfo = objManager.getBucket(bucket);
        if (bucketInfo != null) {
            if (!bucketInfo.getAcl().startsWith(GWConstants.XML_VERSION)) {
                bucketInfo.setAcl(GWUtils.makeOriginalXml(bucketInfo.getAcl(), s3Parameter));
            }
        }
    } catch (ResourceNotFoundException e) {
        throw new GWException(GWErrorCode.NO_SUCH_BUCKET, s3Parameter);
    } catch (Exception e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    } finally {
        try {
            releaseObjManager();
        } catch (Exception e) {
            PrintStack.logging(logger, e);
            throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
        }
    }
    if (bucketInfo == null) {
        logger.info(GWConstants.LOG_BUCKET_IS_NOT_EXIST, bucket);
        throw new GWException(GWErrorCode.NO_SUCH_BUCKET, s3Parameter);
    }
    return bucketInfo;
}
Also used : Bucket(com.pspace.ifs.ksan.objmanager.Bucket) GWException(com.pspace.ifs.ksan.gw.exception.GWException) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException) GWException(com.pspace.ifs.ksan.gw.exception.GWException) ResourceAlreadyExistException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceAlreadyExistException) XMLStreamException(javax.xml.stream.XMLStreamException) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Example 68 with GWException

use of com.pspace.ifs.ksan.gw.exception.GWException in project ksan by infinistor.

the class S3Request method updateBucketReplication.

protected void updateBucketReplication(String bucket, String replica) throws GWException {
    try {
        setObjManager();
        objManager.updateBucketReplication(bucket, replica);
    } catch (Exception e) {
        logger.error(e.getMessage());
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    } finally {
        try {
            releaseObjManager();
        } catch (Exception e) {
            PrintStack.logging(logger, e);
            throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
        }
    }
}
Also used : GWException(com.pspace.ifs.ksan.gw.exception.GWException) GWException(com.pspace.ifs.ksan.gw.exception.GWException) ResourceAlreadyExistException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceAlreadyExistException) XMLStreamException(javax.xml.stream.XMLStreamException) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Example 69 with GWException

use of com.pspace.ifs.ksan.gw.exception.GWException in project ksan by infinistor.

the class S3Request method checkGrant.

protected boolean checkGrant(String id, String s3grant, AccessControlPolicy acp) throws GWException {
    switch(s3grant) {
        case GWConstants.GRANT_READ:
            for (Grant grant : acp.aclList.grants) {
                if (grant.permission.compareTo(GWConstants.GRANT_FULL_CONTROL) == 0) {
                    if (grant.grantee.type.compareTo(GWConstants.GROUP) == 0) {
                        if (grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_ALL_USERS) == 0 || grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_AUTHENTICATED_USERS) == 0) {
                            return true;
                        }
                    } else if (grant.grantee.type.compareTo(GWConstants.CANONICAL_USER) == 0) {
                        if (grant.grantee.id.compareTo(id) == 0) {
                            return true;
                        }
                    }
                } else if (grant.permission.compareTo(GWConstants.GRANT_READ) == 0) {
                    if (grant.grantee.type.compareTo(GWConstants.GROUP) == 0) {
                        if (grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_ALL_USERS) == 0 || grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_AUTHENTICATED_USERS) == 0) {
                            return true;
                        }
                    } else if (grant.grantee.type.compareTo(GWConstants.CANONICAL_USER) == 0) {
                        if (grant.grantee.id.compareTo(id) == 0) {
                            return true;
                        }
                    }
                }
            }
            break;
        case GWConstants.GRANT_WRITE:
            for (Grant grant : acp.aclList.grants) {
                if (grant.permission.compareTo(GWConstants.GRANT_FULL_CONTROL) == 0) {
                    if (grant.grantee.type.compareTo(GWConstants.GROUP) == 0) {
                        if (grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_ALL_USERS) == 0 || grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_AUTHENTICATED_USERS) == 0) {
                            return true;
                        }
                    } else if (grant.grantee.type.compareTo(GWConstants.CANONICAL_USER) == 0) {
                        if (grant.grantee.id.compareTo(id) == 0) {
                            return true;
                        }
                    }
                } else if (grant.permission.compareTo(GWConstants.GRANT_WRITE) == 0) {
                    if (grant.grantee.type.compareTo(GWConstants.GROUP) == 0) {
                        if (grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_ALL_USERS) == 0 || grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_AUTHENTICATED_USERS) == 0) {
                            return true;
                        }
                    } else if (grant.grantee.type.compareTo(GWConstants.CANONICAL_USER) == 0) {
                        if (grant.grantee.id.compareTo(id) == 0) {
                            return true;
                        }
                    }
                }
            }
            break;
        case GWConstants.GRANT_READ_ACP:
            for (Grant grant : acp.aclList.grants) {
                if (grant.permission.compareTo(GWConstants.GRANT_FULL_CONTROL) == 0) {
                    if (grant.grantee.type.compareTo(GWConstants.GROUP) == 0) {
                        if (grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_ALL_USERS) == 0 || grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_AUTHENTICATED_USERS) == 0) {
                            return true;
                        }
                    } else if (grant.grantee.type.compareTo(GWConstants.CANONICAL_USER) == 0) {
                        if (grant.grantee.id.compareTo(id) == 0) {
                            return true;
                        }
                    }
                } else if (grant.permission.compareTo(GWConstants.GRANT_READ_ACP) == 0) {
                    if (grant.grantee.type.compareTo(GWConstants.GROUP) == 0) {
                        if (grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_ALL_USERS) == 0 || grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_AUTHENTICATED_USERS) == 0) {
                            return true;
                        }
                    } else if (grant.grantee.type.compareTo(GWConstants.CANONICAL_USER) == 0) {
                        if (grant.grantee.id.compareTo(id) == 0) {
                            return true;
                        }
                    }
                }
            }
            break;
        case GWConstants.GRANT_WRITE_ACP:
            for (Grant grant : acp.aclList.grants) {
                if (grant.permission.compareTo(GWConstants.GRANT_FULL_CONTROL) == 0) {
                    if (grant.grantee.type.compareTo(GWConstants.GROUP) == 0) {
                        if (grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_ALL_USERS) == 0 || grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_AUTHENTICATED_USERS) == 0) {
                            return true;
                        }
                    } else if (grant.grantee.type.compareTo(GWConstants.CANONICAL_USER) == 0) {
                        if (grant.grantee.id.compareTo(id) == 0) {
                            return true;
                        }
                    }
                } else if (grant.permission.compareTo(GWConstants.GRANT_WRITE_ACP) == 0) {
                    if (grant.grantee.type.compareTo(GWConstants.GROUP) == 0) {
                        if (grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_ALL_USERS) == 0 || grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_AUTHENTICATED_USERS) == 0) {
                            return true;
                        }
                    } else if (grant.grantee.type.compareTo(GWConstants.CANONICAL_USER) == 0) {
                        if (grant.grantee.id.compareTo(id) == 0) {
                            return true;
                        }
                    }
                }
            }
            break;
        case GWConstants.GRANT_FULL_CONTROL:
            for (Grant grant : acp.aclList.grants) {
                if (grant.grantee.type.compareTo(GWConstants.GROUP) == 0) {
                    if (grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_ALL_USERS) == 0 || grant.grantee.uri.compareTo(GWConstants.AWS_GRANT_URI_AUTHENTICATED_USERS) == 0) {
                        return true;
                    }
                } else if (grant.grantee.type.compareTo(GWConstants.CANONICAL_USER) == 0) {
                    if (grant.grantee.id.compareTo(id) == 0) {
                        return true;
                    }
                }
            }
            break;
        default:
            logger.error(GWConstants.LOG_REQUEST_GRANT_NOT_DEFINED, s3grant);
            new GWException(GWErrorCode.INTERNAL_SERVER_ERROR, s3Parameter);
    }
    return false;
}
Also used : Grant(com.pspace.ifs.ksan.gw.format.AccessControlPolicy.AccessControlList.Grant) GWException(com.pspace.ifs.ksan.gw.exception.GWException)

Example 70 with GWException

use of com.pspace.ifs.ksan.gw.exception.GWException in project ksan by infinistor.

the class S3Request method deleteBucket.

protected void deleteBucket(String bucket) throws GWException {
    boolean result = false;
    try {
        setObjManager();
        result = objManager.isBucketDelete(bucket);
        if (result) {
            objManager.removeBucket(bucket);
        }
    } catch (Exception e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    } finally {
        try {
            releaseObjManager();
        } catch (Exception e) {
            PrintStack.logging(logger, e);
            throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
        }
    }
    if (!result) {
        logger.info(GWConstants.LOG_REQUEST_BUCKET_IS_NOT_EMPTY);
        throw new GWException(GWErrorCode.BUCKET_NOT_EMPTY, s3Parameter);
    }
}
Also used : GWException(com.pspace.ifs.ksan.gw.exception.GWException) GWException(com.pspace.ifs.ksan.gw.exception.GWException) ResourceAlreadyExistException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceAlreadyExistException) XMLStreamException(javax.xml.stream.XMLStreamException) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Aggregations

GWException (com.pspace.ifs.ksan.gw.exception.GWException)130 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)61 S3Bucket (com.pspace.ifs.ksan.gw.identity.S3Bucket)58 XMLStreamException (javax.xml.stream.XMLStreamException)48 IOException (java.io.IOException)46 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)45 ResourceNotFoundException (com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException)43 ResourceAlreadyExistException (com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceAlreadyExistException)32 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)23 Metadata (com.pspace.ifs.ksan.objmanager.Metadata)23 S3Metadata (com.pspace.ifs.ksan.gw.identity.S3Metadata)17 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)16 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)15 AccessControlPolicy (com.pspace.ifs.ksan.gw.format.AccessControlPolicy)14 Writer (java.io.Writer)13 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)13 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)11 Grant (com.pspace.ifs.ksan.gw.format.AccessControlPolicy.AccessControlList.Grant)10 S3ObjectOperation (com.pspace.ifs.ksan.gw.object.S3ObjectOperation)10 Date (java.util.Date)8