001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hdfs.web.resources; 019 020import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_WEBHDFS_ACL_PERMISSION_PATTERN_DEFAULT; 021 022import java.util.List; 023import java.util.regex.Pattern; 024 025import org.apache.hadoop.fs.permission.AclEntry; 026import org.apache.commons.lang.StringUtils; 027 028/** AclPermission parameter. */ 029public class AclPermissionParam extends StringParam { 030 /** Parameter name. */ 031 public static final String NAME = "aclspec"; 032 /** Default parameter value. */ 033 public static final String DEFAULT = ""; 034 035 private static final Domain DOMAIN = new Domain(NAME, 036 Pattern.compile(DFS_WEBHDFS_ACL_PERMISSION_PATTERN_DEFAULT)); 037 038 /** 039 * Constructor. 040 * 041 * @param str a string representation of the parameter value. 042 */ 043 public AclPermissionParam(final String str) { 044 super(DOMAIN, str == null || str.equals(DEFAULT) ? null : str); 045 } 046 047 public AclPermissionParam(List<AclEntry> acl) { 048 super(DOMAIN,parseAclSpec(acl).equals(DEFAULT) ? null : parseAclSpec(acl)); 049 } 050 051 @Override 052 public String getName() { 053 return NAME; 054 } 055 056 public List<AclEntry> getAclPermission(boolean includePermission) { 057 final String v = getValue(); 058 return (v != null ? AclEntry.parseAclSpec(v, includePermission) : AclEntry 059 .parseAclSpec(DEFAULT, includePermission)); 060 } 061 062 /** 063 * @return parse {@code aclEntry} and return aclspec 064 */ 065 private static String parseAclSpec(List<AclEntry> aclEntry) { 066 return StringUtils.join(aclEntry, ","); 067 } 068}