adoroszlai commented on code in PR #5613: URL: https://github.com/apache/ozone/pull/5613#discussion_r1396104353
########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/security/acl/SharedTmpDirAuthorizer.java: ########## @@ -0,0 +1,92 @@ +/** + * 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.security.acl; + +import com.google.common.annotations.VisibleForTesting; +import org.apache.commons.lang.StringUtils; Review Comment: Use the one from `commons-lang3`. ```suggestion import org.apache.commons.lang3.StringUtils; ``` ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/security/acl/SharedTmpDirAuthorizer.java: ########## @@ -0,0 +1,92 @@ +/** + * 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.security.acl; + +import com.google.common.annotations.VisibleForTesting; Review Comment: ```suggestion ``` ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/security/acl/SharedTmpDirAuthorizer.java: ########## @@ -0,0 +1,92 @@ +/** + * 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.security.acl; + +import com.google.common.annotations.VisibleForTesting; +import org.apache.commons.lang.StringUtils; +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.ozone.om.OzoneManager; Review Comment: ```suggestion ``` ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/security/acl/SharedTmpDirAuthorizer.java: ########## @@ -0,0 +1,92 @@ +/** + * 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.security.acl; + +import com.google.common.annotations.VisibleForTesting; +import org.apache.commons.lang.StringUtils; +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.ozone.om.OzoneManager; +import org.apache.hadoop.ozone.om.exceptions.OMException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Objects; +import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ACL_AUTHORIZER_CLASS; +import static org.apache.hadoop.util.ReflectionUtils.newInstance; + + +/** + * SharedTmp implementation of {@link IAccessAuthorizer}. + */ +public class SharedTmpDirAuthorizer implements IAccessAuthorizer { + + private static final Logger LOG = + LoggerFactory.getLogger(SharedTmpDirAuthorizer.class); + private final OzoneNativeAuthorizer ozoneNativeAuthorizer; + private final IAccessAuthorizer authorizer; + + public SharedTmpDirAuthorizer(OzoneManager om, OzoneConfiguration conf) { + ozoneNativeAuthorizer = new OzoneNativeAuthorizer(); + ozoneNativeAuthorizer.setVolumeManager(om.getVolumeManager()); + ozoneNativeAuthorizer.setBucketManager(om.getBucketManager()); + ozoneNativeAuthorizer.setKeyManager(om.getKeyManager()); + ozoneNativeAuthorizer.setPrefixManager(om.getPrefixManager()); + ozoneNativeAuthorizer.setAdminCheck(om::isAdmin); + ozoneNativeAuthorizer.setReadOnlyAdminCheck(om::isReadOnlyAdmin); + ozoneNativeAuthorizer.setAllowListAllVolumes(om.getAllowListAllVolumes()); + + Class<? extends IAccessAuthorizer> clazz = + conf.getClass(OZONE_ACL_AUTHORIZER_CLASS, + OzoneAccessAuthorizer.class, + IAccessAuthorizer.class); + LOG.info("Initializing class {} from SharedTmpDirAuthorizer", clazz); + authorizer = newInstance(clazz, conf); + } + + @VisibleForTesting Review Comment: ```suggestion ``` ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/security/acl/SharedTmpDirAuthorizer.java: ########## @@ -0,0 +1,92 @@ +/** Review Comment: nit: ```suggestion /* ``` ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/security/acl/SharedTmpDirAuthorizer.java: ########## @@ -0,0 +1,92 @@ +/** + * 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.security.acl; + +import com.google.common.annotations.VisibleForTesting; +import org.apache.commons.lang.StringUtils; +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.ozone.om.OzoneManager; +import org.apache.hadoop.ozone.om.exceptions.OMException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Objects; +import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ACL_AUTHORIZER_CLASS; +import static org.apache.hadoop.util.ReflectionUtils.newInstance; Review Comment: ```suggestion ``` ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/security/acl/OzoneAuthorizerFactory.java: ########## @@ -78,6 +80,13 @@ private static IAccessAuthorizer create( return configure(authorizer, om, km, pm); } + // If authorizer isn't native and shareable tmp dir is enabled, + // then return the shared tmp hybrid authorizer. + if (conf.getBoolean(OZONE_OM_ENABLE_OFS_SHARED_TMP_DIR, + OZONE_OM_ENABLE_OFS_SHARED_TMP_DIR_DEFAULT)) { + return new SharedTmpDirAuthorizer(om, conf); + } + final IAccessAuthorizer authorizer = newInstance(clazz, conf); return authorizer instanceof OzoneNativeAuthorizer ? configure((OzoneNativeAuthorizer) authorizer, om, km, pm) Review Comment: By reording the conditions and passing ready-to-use instances to the hybrid one, we can get rid of the code duplicated in `SharedTmpDirAuthorizer` from this class. In addition to the suggested change, `configure()` needs to be updated to return `OzoneNativeAuthorizer`. ```suggestion final IAccessAuthorizer authorizer = newInstance(clazz, conf); if (authorizer instanceof OzoneNativeAuthorizer) { return configure((OzoneNativeAuthorizer) authorizer, om, km, pm); } // If authorizer isn't native and shareable tmp dir is enabled, // then return the shared tmp hybrid authorizer. if (conf.getBoolean(OZONE_OM_ENABLE_OFS_SHARED_TMP_DIR, OZONE_OM_ENABLE_OFS_SHARED_TMP_DIR_DEFAULT)) { return new SharedTmpDirAuthorizer( configure(new OzoneNativeAuthorizer(), om, km, pm), authorizer); } return authorizer; ``` -- 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]
