adoroszlai commented on code in PR #11067:
URL: https://github.com/apache/ozone/pull/11067#discussion_r3851666504


##########
hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/O3DtFetcher.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.fs.ozone;
+
+import java.net.URI;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.ozone.OzoneConsts;
+import org.apache.hadoop.security.Credentials;
+import org.apache.hadoop.security.token.Token;
+
+/**
+ * A DT fetcher for Ozone RPC URLs.
+ */
+public class O3DtFetcher extends AbstractOzoneDtFetcher {
+  @Override
+  public Text getServiceName() {
+    return new Text(OzoneConsts.OZONE_RPC_SCHEME);
+  }
+
+  @Override
+  public Token<?> addDelegationTokens(Configuration conf, Credentials creds,
+      String renewer, String url) throws Exception {
+    String serviceName = getServiceName().toString();
+    if (!url.startsWith(serviceName + "://")) {
+      url = serviceName + "://" + url;
+    }
+    URI uri = URI.create(url);
+    if (uri.getAuthority() == null) {
+      throw new IllegalArgumentException(
+          "OM authority is required in Ozone RPC URL: " + url);
+    }
+    URI ofsUri = new URI(OzoneConsts.OZONE_OFS_URI_SCHEME,
+        uri.getAuthority(), "/", null, null);
+    return addDelegationTokens(conf, creds, renewer, ofsUri);

Review Comment:
   Can `O3DtFetcher` override `protected addDelegationTokens` instead?



##########
hadoop-ozone/ozonefs-common/src/main/java/org/apache/hadoop/fs/ozone/AbstractOzoneDtFetcher.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.fs.ozone;
+
+import java.io.IOException;
+import java.net.URI;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.security.Credentials;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.security.token.DtFetcher;
+import org.apache.hadoop.security.token.Token;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Base DT fetcher for Ozone URL schemes.
+ */
+abstract class AbstractOzoneDtFetcher implements DtFetcher {
+  private static final Logger LOG =
+      LoggerFactory.getLogger(AbstractOzoneDtFetcher.class);
+
+  private static final String FETCH_FAILED =
+      "Fetch ozone delegation token failed";
+
+  @Override
+  public boolean isTokenRequired() {
+    return UserGroupInformation.isSecurityEnabled();
+  }
+
+  @Override
+  public Token<?> addDelegationTokens(Configuration conf, Credentials creds,
+      String renewer, String url) throws Exception {
+    if (!url.startsWith(getServiceName().toString())) {
+      url = getServiceName().toString() + "://" + url;

Review Comment:
   Please check `startsWith(serviceName + "://")` instead, since `o3` is prefix 
of `o3fs`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to