private List<Statement> newBucketStatement(PolicyType policy,String prefix){
  List<Statement> statements=new ArrayList<Statement>();
  if (policy == PolicyType.NONE || bucketName == null || bucketName.isEmpty()) {
    return statements;
  }
  Resources resources=new Resources(Constants.AWS_RESOURCE_PREFIX + bucketName);
  Statement statement=new Statement();
  statement.setActions(Constants.COMMON_BUCKET_ACTIONS);
  statement.setEffect("Allow");
  statement.setPrincipal(new Principal("*"));
  statement.setResources(resources);
  statement.setSid("");
  statements.add(statement);
  if (policy == PolicyType.READ_ONLY || policy == PolicyType.READ_WRITE) {
    statement=new Statement();
    statement.setActions(Constants.READ_ONLY_BUCKET_ACTIONS);
    statement.setEffect("Allow");
    statement.setPrincipal(new Principal("*"));
    statement.setResources(resources);
    statement.setSid("");
    if (prefix != null && !prefix.isEmpty()) {
      statement.setConditions(new ConditionMap("StringEquals",new ConditionKeyMap("s3:prefix",prefix)));
    }
    statements.add(statement);
  }
  if (policy == PolicyType.WRITE_ONLY || policy == PolicyType.READ_WRITE) {
    statement=new Statement();
    statement.setActions(Constants.WRITE_ONLY_BUCKET_ACTIONS);
    statement.setEffect("Allow");
    statement.setPrincipal(new Principal("*"));
    statement.setResources(resources);
    statement.setSid("");
    statements.add(statement);
  }
  return statements;
}

private List < Statement > newBucketStatement ( PolicyType policy , String prefix ) { List < Statement > statements = new ArrayList < Statement > ( ) ; if ( policy == PolicyType . NONE || bucketName == null || bucketName . isEmpty ( ) ) { return statements ; } Resources resources = new Resources ( Constants . AWS_RESOURCE_PREFIX + bucketName ) ; Statement statement = new Statement ( ) ; statement . setActions ( Constants . COMMON_BUCKET_ACTIONS ) ; statement . setEffect ( "Allow" ) ; statement . setPrincipal ( new Principal ( "*" ) ) ; statement . setResources ( resources ) ; statement . setSid ( "" ) ; statements . add ( statement ) ; if ( policy == PolicyType . READ_ONLY || policy == PolicyType . READ_WRITE ) { statement = new Statement ( ) ; statement . setActions ( Constants . READ_ONLY_BUCKET_ACTIONS ) ; statement . setEffect ( "Allow" ) ; statement . setPrincipal ( new Principal ( "*" ) ) ; statement . setResources ( resources ) ; statement . setSid ( "" ) ; if ( prefix != null && ! prefix . isEmpty ( ) ) { statement . setConditions ( new ConditionMap ( "StringEquals" , new ConditionKeyMap ( "s3:prefix" , prefix ) ) ) ; } statements . add ( statement ) ; } if ( policy == PolicyType . WRITE_ONLY || policy == PolicyType . READ_WRITE ) { statement = new Statement ( ) ; statement . setActions ( Constants . WRITE_ONLY_BUCKET_ACTIONS ) ; statement . setEffect ( "Allow" ) ; statement . setPrincipal ( new Principal ( "*" ) ) ; statement . setResources ( resources ) ; statement . setSid ( "" ) ; statements . add ( statement ) ; } return statements ; }
returns new bucket statements for given policy type .
