|
@@ -17,8 +17,10 @@
|
|
|
*/
|
|
|
package org.apache.hadoop.hdfs.web.resources;
|
|
|
|
|
|
+import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_WEBHDFS_USER_PATTERN_DEFAULT;
|
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
|
-
|
|
|
+import com.google.common.annotations.VisibleForTesting;
|
|
|
+
|
|
|
import java.text.MessageFormat;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
@@ -29,8 +31,21 @@ public class UserParam extends StringParam {
|
|
|
/** Default parameter value. */
|
|
|
public static final String DEFAULT = "";
|
|
|
|
|
|
- private static final Domain DOMAIN = new Domain(NAME,
|
|
|
- Pattern.compile("^[A-Za-z_][A-Za-z0-9._-]*[$]?$"));
|
|
|
+ private static Domain domain = new Domain(NAME, Pattern.compile(DFS_WEBHDFS_USER_PATTERN_DEFAULT));
|
|
|
+
|
|
|
+ @VisibleForTesting
|
|
|
+ public static Domain getUserPatternDomain() {
|
|
|
+ return domain;
|
|
|
+ }
|
|
|
+
|
|
|
+ @VisibleForTesting
|
|
|
+ public static void setUserPatternDomain(Domain dm) {
|
|
|
+ domain = dm;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void setUserPattern(String pattern) {
|
|
|
+ domain = new Domain(NAME, Pattern.compile(pattern));
|
|
|
+ }
|
|
|
|
|
|
private static String validateLength(String str) {
|
|
|
if (str == null) {
|
|
@@ -50,7 +65,7 @@ public class UserParam extends StringParam {
|
|
|
* @param str a string representation of the parameter value.
|
|
|
*/
|
|
|
public UserParam(final String str) {
|
|
|
- super(DOMAIN, str == null || str.equals(DEFAULT)? null : validateLength(str));
|
|
|
+ super(domain, str == null || str.equals(DEFAULT)? null : validateLength(str));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -64,4 +79,4 @@ public class UserParam extends StringParam {
|
|
|
public String getName() {
|
|
|
return NAME;
|
|
|
}
|
|
|
-}
|
|
|
+}
|