xBis7 commented on code in PR #4116: URL: https://github.com/apache/ozone/pull/4116#discussion_r1211561123
########## hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OzoneIdentityProvider.java: ########## @@ -0,0 +1,66 @@ +/** + * 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.ozone.om.helpers; + +import io.netty.util.internal.StringUtil; +import org.apache.hadoop.ipc.CallerContext; +import org.apache.hadoop.ipc.IdentityProvider; +import org.apache.hadoop.ipc.Schedulable; +import org.apache.hadoop.ipc.Server; +import org.apache.hadoop.security.UserGroupInformation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Objects; + +/** + * Ozone implementation of IdentityProvider used by + * Hadoop DecayRpcScheduler. + */ +public class OzoneIdentityProvider implements IdentityProvider { + + private static final Logger LOG = LoggerFactory + .getLogger(OzoneIdentityProvider.class); + + public OzoneIdentityProvider() { + } + + /** + * If schedulable isn't instance of {@link Server.Call}, + * then trying to access getCallerContext() method, will + * result in an exception. + * + * @param schedulable Schedulable object + * @return string with the identity of the user + */ + @Override + public String makeIdentity(Schedulable schedulable) { + UserGroupInformation ugi = schedulable.getUserGroupInformation(); + try { + CallerContext callerContext = schedulable.getCallerContext(); + if (Objects.nonNull(callerContext) && + !StringUtil.isNullOrEmpty(callerContext.getContext())) { + return callerContext.getContext(); Review Comment: @symious Thanks for the review. It was my understanding that CallerContext isn't used in Ozone. Α prefix like `"S3Auth:S3g"` would be best. Thanks for the suggestion. I'll make the change. -- 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]
