[
https://issues.apache.org/jira/browse/HDFS-4983?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13841537#comment-13841537
]
Haohui Mai commented on HDFS-4983:
----------------------------------
Good patch. A couple comments:
{code}
+ static {
+ setUserPattern(DFS_WEBHDFS_USER_PATTERN_DEFAULT);
+ }
{code}
The execution of static code block for a class is fairly unpredictable. Since
you've initialized it explicitly (thus no NPE), you can delete it.
{code}
+ private static String userPattern = null;
+ private static Domain domain = null;
+ public static void setUserPattern(Configuration conf) {
+ String pattern = conf.get(DFS_WEBHDFS_USER_PATTERN_KEY,
DFS_WEBHDFS_USER_PATTERN_DEFAULT);
+ setUserPattern(pattern);
+ }
+ @VisibleForTesting
+ public static String getUserPattern() {
+ return userPattern;
+ }
+
+ @VisibleForTesting
+ public static void setUserPattern(String pattern) {
+ userPattern = pattern;
+ Pattern pt = Pattern.compile(userPattern);
+ domain = new Domain(NAME, pt);
+ }
{code}
A better way to do it is to change the signature to setUserPattern(String). By
doing this you can remove the userPattern field from the class, which reduces
the overhead as jersey will construct an instance of this class for each
request.
{code}
+<property>
+ <name>webhdfs.user.provider.user.pattern</name>
...
{code}
Can you rename the configuration to dfs.webhdfs.user.provider.user.pattern to
make things consistent?
> Numeric usernames do not work with WebHDFS FS
> ---------------------------------------------
>
> Key: HDFS-4983
> URL: https://issues.apache.org/jira/browse/HDFS-4983
> Project: Hadoop HDFS
> Issue Type: Improvement
> Components: webhdfs
> Affects Versions: 2.0.0-alpha
> Reporter: Harsh J
> Assignee: Yongjun Zhang
> Labels: patch
> Attachments: HDFS-4983.001.patch, HDFS-4983.002.patch,
> HDFS-4983.003.patch, HDFS-4983.004.patch, HDFS-4983.005.patch
>
>
> Per the file
> hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/resources/UserParam.java,
> the DOMAIN pattern is set to: {{^[A-Za-z_][A-Za-z0-9._-]*[$]?$}}.
> Given this, using a username such as "123" seems to fail for some reason
> (tried on insecure setup):
> {code}
> [123@host-1 ~]$ whoami
> 123
> [123@host-1 ~]$ hadoop fs -fs webhdfs://host-2.domain.com -ls /
> -ls: Invalid value: "123" does not belong to the domain
> ^[A-Za-z_][A-Za-z0-9._-]*[$]?$
> Usage: hadoop fs [generic options] -ls [-d] [-h] [-R] [<path> ...]
> {code}
--
This message was sent by Atlassian JIRA
(v6.1#6144)