ivanzlenko commented on code in PR #7268: URL: https://github.com/apache/ozone/pull/7268#discussion_r1794645589
########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/common/OmUserUtils.java: ########## @@ -0,0 +1,87 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.common; + +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.server.OzoneAdmins; + +import org.apache.hadoop.ozone.om.OzoneConfigUtil; +import org.apache.hadoop.security.UserGroupInformation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Collection; + +/** + * Utility class to store User related utilities. + */ +public final class OmUserUtils { + private static final Logger LOG = Review Comment: There is no need to have a line break here. We have 140 lines limit. ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/common/OmUserUtils.java: ########## @@ -0,0 +1,87 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.common; + +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.server.OzoneAdmins; + +import org.apache.hadoop.ozone.om.OzoneConfigUtil; +import org.apache.hadoop.security.UserGroupInformation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Collection; + +/** + * Utility class to store User related utilities. + */ +public final class OmUserUtils { + private static final Logger LOG = + LoggerFactory.getLogger(OmUserUtils.class); + + private OmUserUtils() { } + + /** + * Get the users and groups that are S3 admin. + * @param conf Stores the Ozone configuration being used + * @return an instance of {@link OzoneAdmins} containing the S3 admin users and groups + */ + public static OzoneAdmins getS3Admins(OzoneConfiguration conf) { + Collection<String> s3Admins; + try { + s3Admins = OzoneConfigUtil.getS3AdminsFromConfig(conf); + } catch (IOException ie) { + s3Admins = null; + } + Collection<String> s3AdminGroups = Review Comment: No need in line break here. ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/common/OmUserUtils.java: ########## @@ -0,0 +1,87 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.common; + +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.server.OzoneAdmins; + +import org.apache.hadoop.ozone.om.OzoneConfigUtil; +import org.apache.hadoop.security.UserGroupInformation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Collection; + +/** + * Utility class to store User related utilities. + */ +public final class OmUserUtils { + private static final Logger LOG = + LoggerFactory.getLogger(OmUserUtils.class); + + private OmUserUtils() { } + + /** + * Get the users and groups that are S3 admin. + * @param conf Stores the Ozone configuration being used Review Comment: an instance of the Ozone configuraiton. ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/common/OmUserUtils.java: ########## @@ -0,0 +1,87 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.common; + +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.server.OzoneAdmins; + +import org.apache.hadoop.ozone.om.OzoneConfigUtil; +import org.apache.hadoop.security.UserGroupInformation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Collection; + +/** + * Utility class to store User related utilities. + */ +public final class OmUserUtils { + private static final Logger LOG = + LoggerFactory.getLogger(OmUserUtils.class); + + private OmUserUtils() { } + + /** + * Get the users and groups that are S3 admin. + * @param conf Stores the Ozone configuration being used + * @return an instance of {@link OzoneAdmins} containing the S3 admin users and groups + */ + public static OzoneAdmins getS3Admins(OzoneConfiguration conf) { + Collection<String> s3Admins; + try { + s3Admins = OzoneConfigUtil.getS3AdminsFromConfig(conf); + } catch (IOException ie) { + s3Admins = null; + } + Collection<String> s3AdminGroups = + OzoneConfigUtil.getS3AdminsGroupsFromConfig(conf); + if (LOG.isDebugEnabled()) { + if (null == s3Admins) { + LOG.debug("S3 Admins are not set in configuration"); + } + if (null == s3AdminGroups) { + LOG.debug("S3 Admin Groups are not set in configuration"); + } + } + return new OzoneAdmins(s3Admins, s3AdminGroups); + } + + /** + * Check if the provided user is a part of the S3 admins. + * @param user Stores the user to verify Review Comment: instance of an {@link UserGroupInformation} with information about user to be verified. ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/common/OmUserUtils.java: ########## @@ -0,0 +1,87 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.common; + +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.server.OzoneAdmins; + +import org.apache.hadoop.ozone.om.OzoneConfigUtil; +import org.apache.hadoop.security.UserGroupInformation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Collection; + +/** + * Utility class to store User related utilities. + */ +public final class OmUserUtils { + private static final Logger LOG = + LoggerFactory.getLogger(OmUserUtils.class); + + private OmUserUtils() { } + + /** + * Get the users and groups that are S3 admin. + * @param conf Stores the Ozone configuration being used + * @return an instance of {@link OzoneAdmins} containing the S3 admin users and groups + */ + public static OzoneAdmins getS3Admins(OzoneConfiguration conf) { + Collection<String> s3Admins; + try { + s3Admins = OzoneConfigUtil.getS3AdminsFromConfig(conf); + } catch (IOException ie) { + s3Admins = null; + } + Collection<String> s3AdminGroups = + OzoneConfigUtil.getS3AdminsGroupsFromConfig(conf); + if (LOG.isDebugEnabled()) { + if (null == s3Admins) { + LOG.debug("S3 Admins are not set in configuration"); + } + if (null == s3AdminGroups) { + LOG.debug("S3 Admin Groups are not set in configuration"); + } + } + return new OzoneAdmins(s3Admins, s3AdminGroups); + } + + /** + * Check if the provided user is a part of the S3 admins. + * @param user Stores the user to verify + * @param conf Stores the Ozone configuration being used + * @return true if the provided user is an S3 admin else false + */ + public static boolean isS3Admin(UserGroupInformation user, + OzoneConfiguration conf) { + OzoneAdmins s3Admins = getS3Admins(conf); + return null != user && s3Admins.isAdmin(user); Review Comment: Please use overloaded method here ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/common/OmUserUtils.java: ########## @@ -0,0 +1,87 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.common; + +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.server.OzoneAdmins; + +import org.apache.hadoop.ozone.om.OzoneConfigUtil; +import org.apache.hadoop.security.UserGroupInformation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Collection; + +/** + * Utility class to store User related utilities. + */ +public final class OmUserUtils { + private static final Logger LOG = + LoggerFactory.getLogger(OmUserUtils.class); + + private OmUserUtils() { } + + /** + * Get the users and groups that are S3 admin. + * @param conf Stores the Ozone configuration being used + * @return an instance of {@link OzoneAdmins} containing the S3 admin users and groups + */ + public static OzoneAdmins getS3Admins(OzoneConfiguration conf) { + Collection<String> s3Admins; + try { + s3Admins = OzoneConfigUtil.getS3AdminsFromConfig(conf); + } catch (IOException ie) { + s3Admins = null; + } + Collection<String> s3AdminGroups = + OzoneConfigUtil.getS3AdminsGroupsFromConfig(conf); + if (LOG.isDebugEnabled()) { + if (null == s3Admins) { + LOG.debug("S3 Admins are not set in configuration"); + } + if (null == s3AdminGroups) { + LOG.debug("S3 Admin Groups are not set in configuration"); + } + } + return new OzoneAdmins(s3Admins, s3AdminGroups); + } + + /** + * Check if the provided user is a part of the S3 admins. Review Comment: is a S3 administrator ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/common/OmUserUtils.java: ########## @@ -0,0 +1,87 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.common; + +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.server.OzoneAdmins; + +import org.apache.hadoop.ozone.om.OzoneConfigUtil; +import org.apache.hadoop.security.UserGroupInformation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Collection; + +/** + * Utility class to store User related utilities. + */ +public final class OmUserUtils { + private static final Logger LOG = + LoggerFactory.getLogger(OmUserUtils.class); + + private OmUserUtils() { } + + /** + * Get the users and groups that are S3 admin. + * @param conf Stores the Ozone configuration being used + * @return an instance of {@link OzoneAdmins} containing the S3 admin users and groups + */ + public static OzoneAdmins getS3Admins(OzoneConfiguration conf) { + Collection<String> s3Admins; + try { + s3Admins = OzoneConfigUtil.getS3AdminsFromConfig(conf); + } catch (IOException ie) { + s3Admins = null; + } + Collection<String> s3AdminGroups = + OzoneConfigUtil.getS3AdminsGroupsFromConfig(conf); + if (LOG.isDebugEnabled()) { + if (null == s3Admins) { + LOG.debug("S3 Admins are not set in configuration"); + } + if (null == s3AdminGroups) { + LOG.debug("S3 Admin Groups are not set in configuration"); + } + } + return new OzoneAdmins(s3Admins, s3AdminGroups); + } + + /** + * Check if the provided user is a part of the S3 admins. + * @param user Stores the user to verify + * @param conf Stores the Ozone configuration being used + * @return true if the provided user is an S3 admin else false + */ + public static boolean isS3Admin(UserGroupInformation user, + OzoneConfiguration conf) { + OzoneAdmins s3Admins = getS3Admins(conf); + return null != user && s3Admins.isAdmin(user); + } + + /** + * Check if the provided user is a part of the S3 admins. Review Comment: is a S3 administrator ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/common/OmUserUtils.java: ########## @@ -0,0 +1,87 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.common; + +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.server.OzoneAdmins; + +import org.apache.hadoop.ozone.om.OzoneConfigUtil; +import org.apache.hadoop.security.UserGroupInformation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Collection; + +/** + * Utility class to store User related utilities. + */ +public final class OmUserUtils { + private static final Logger LOG = + LoggerFactory.getLogger(OmUserUtils.class); + + private OmUserUtils() { } + + /** + * Get the users and groups that are S3 admin. + * @param conf Stores the Ozone configuration being used + * @return an instance of {@link OzoneAdmins} containing the S3 admin users and groups + */ + public static OzoneAdmins getS3Admins(OzoneConfiguration conf) { + Collection<String> s3Admins; + try { + s3Admins = OzoneConfigUtil.getS3AdminsFromConfig(conf); + } catch (IOException ie) { + s3Admins = null; + } + Collection<String> s3AdminGroups = + OzoneConfigUtil.getS3AdminsGroupsFromConfig(conf); + if (LOG.isDebugEnabled()) { + if (null == s3Admins) { + LOG.debug("S3 Admins are not set in configuration"); + } + if (null == s3AdminGroups) { + LOG.debug("S3 Admin Groups are not set in configuration"); + } + } + return new OzoneAdmins(s3Admins, s3AdminGroups); + } + + /** + * Check if the provided user is a part of the S3 admins. + * @param user Stores the user to verify + * @param conf Stores the Ozone configuration being used + * @return true if the provided user is an S3 admin else false + */ + public static boolean isS3Admin(UserGroupInformation user, + OzoneConfiguration conf) { + OzoneAdmins s3Admins = getS3Admins(conf); + return null != user && s3Admins.isAdmin(user); + } + + /** + * Check if the provided user is a part of the S3 admins. + * @param user Stores the user to verify Review Comment: instance of an {@link UserGroupInformation} with information about user to be verified. ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/common/OmUserUtils.java: ########## @@ -0,0 +1,87 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.common; + +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.server.OzoneAdmins; + +import org.apache.hadoop.ozone.om.OzoneConfigUtil; +import org.apache.hadoop.security.UserGroupInformation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Collection; + +/** + * Utility class to store User related utilities. + */ +public final class OmUserUtils { + private static final Logger LOG = + LoggerFactory.getLogger(OmUserUtils.class); + + private OmUserUtils() { } + + /** + * Get the users and groups that are S3 admin. + * @param conf Stores the Ozone configuration being used + * @return an instance of {@link OzoneAdmins} containing the S3 admin users and groups + */ + public static OzoneAdmins getS3Admins(OzoneConfiguration conf) { + Collection<String> s3Admins; + try { + s3Admins = OzoneConfigUtil.getS3AdminsFromConfig(conf); + } catch (IOException ie) { + s3Admins = null; + } + Collection<String> s3AdminGroups = + OzoneConfigUtil.getS3AdminsGroupsFromConfig(conf); + if (LOG.isDebugEnabled()) { + if (null == s3Admins) { + LOG.debug("S3 Admins are not set in configuration"); + } + if (null == s3AdminGroups) { + LOG.debug("S3 Admin Groups are not set in configuration"); + } + } + return new OzoneAdmins(s3Admins, s3AdminGroups); + } + + /** + * Check if the provided user is a part of the S3 admins. + * @param user Stores the user to verify + * @param conf Stores the Ozone configuration being used + * @return true if the provided user is an S3 admin else false + */ + public static boolean isS3Admin(UserGroupInformation user, + OzoneConfiguration conf) { + OzoneAdmins s3Admins = getS3Admins(conf); + return null != user && s3Admins.isAdmin(user); + } + + /** + * Check if the provided user is a part of the S3 admins. + * @param user Stores the user to verify + * @param s3Admins Stores the users and groups that are admins Review Comment: an instance of {@link OzoneAdmins} containing information about all S3 administrator user and groups in the system. ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/common/OmUserUtils.java: ########## @@ -0,0 +1,87 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.common; + +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.server.OzoneAdmins; + +import org.apache.hadoop.ozone.om.OzoneConfigUtil; +import org.apache.hadoop.security.UserGroupInformation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Collection; + +/** + * Utility class to store User related utilities. + */ +public final class OmUserUtils { + private static final Logger LOG = + LoggerFactory.getLogger(OmUserUtils.class); + + private OmUserUtils() { } + + /** + * Get the users and groups that are S3 admin. + * @param conf Stores the Ozone configuration being used + * @return an instance of {@link OzoneAdmins} containing the S3 admin users and groups + */ + public static OzoneAdmins getS3Admins(OzoneConfiguration conf) { + Collection<String> s3Admins; + try { + s3Admins = OzoneConfigUtil.getS3AdminsFromConfig(conf); + } catch (IOException ie) { + s3Admins = null; + } + Collection<String> s3AdminGroups = + OzoneConfigUtil.getS3AdminsGroupsFromConfig(conf); + if (LOG.isDebugEnabled()) { + if (null == s3Admins) { + LOG.debug("S3 Admins are not set in configuration"); + } + if (null == s3AdminGroups) { + LOG.debug("S3 Admin Groups are not set in configuration"); + } + } + return new OzoneAdmins(s3Admins, s3AdminGroups); + } + + /** + * Check if the provided user is a part of the S3 admins. + * @param user Stores the user to verify + * @param conf Stores the Ozone configuration being used + * @return true if the provided user is an S3 admin else false Review Comment: {@code true} if the provided user is an S3 administrator or else {@code false}. ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/common/OmUserUtils.java: ########## @@ -0,0 +1,87 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.common; + +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.server.OzoneAdmins; + +import org.apache.hadoop.ozone.om.OzoneConfigUtil; +import org.apache.hadoop.security.UserGroupInformation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Collection; + +/** + * Utility class to store User related utilities. + */ +public final class OmUserUtils { + private static final Logger LOG = + LoggerFactory.getLogger(OmUserUtils.class); + + private OmUserUtils() { } + + /** + * Get the users and groups that are S3 admin. + * @param conf Stores the Ozone configuration being used + * @return an instance of {@link OzoneAdmins} containing the S3 admin users and groups + */ + public static OzoneAdmins getS3Admins(OzoneConfiguration conf) { + Collection<String> s3Admins; + try { + s3Admins = OzoneConfigUtil.getS3AdminsFromConfig(conf); + } catch (IOException ie) { + s3Admins = null; + } + Collection<String> s3AdminGroups = + OzoneConfigUtil.getS3AdminsGroupsFromConfig(conf); + if (LOG.isDebugEnabled()) { + if (null == s3Admins) { + LOG.debug("S3 Admins are not set in configuration"); + } + if (null == s3AdminGroups) { + LOG.debug("S3 Admin Groups are not set in configuration"); + } + } + return new OzoneAdmins(s3Admins, s3AdminGroups); + } + + /** + * Check if the provided user is a part of the S3 admins. + * @param user Stores the user to verify + * @param conf Stores the Ozone configuration being used Review Comment: an instance of the Ozone configuraiton. ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/common/OmUserUtils.java: ########## @@ -0,0 +1,87 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.common; + +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.server.OzoneAdmins; + +import org.apache.hadoop.ozone.om.OzoneConfigUtil; +import org.apache.hadoop.security.UserGroupInformation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Collection; + +/** + * Utility class to store User related utilities. + */ +public final class OmUserUtils { + private static final Logger LOG = + LoggerFactory.getLogger(OmUserUtils.class); + + private OmUserUtils() { } + + /** + * Get the users and groups that are S3 admin. + * @param conf Stores the Ozone configuration being used + * @return an instance of {@link OzoneAdmins} containing the S3 admin users and groups + */ + public static OzoneAdmins getS3Admins(OzoneConfiguration conf) { + Collection<String> s3Admins; + try { + s3Admins = OzoneConfigUtil.getS3AdminsFromConfig(conf); + } catch (IOException ie) { + s3Admins = null; + } + Collection<String> s3AdminGroups = + OzoneConfigUtil.getS3AdminsGroupsFromConfig(conf); + if (LOG.isDebugEnabled()) { + if (null == s3Admins) { + LOG.debug("S3 Admins are not set in configuration"); + } + if (null == s3AdminGroups) { + LOG.debug("S3 Admin Groups are not set in configuration"); + } + } + return new OzoneAdmins(s3Admins, s3AdminGroups); + } + + /** + * Check if the provided user is a part of the S3 admins. + * @param user Stores the user to verify + * @param conf Stores the Ozone configuration being used + * @return true if the provided user is an S3 admin else false + */ + public static boolean isS3Admin(UserGroupInformation user, Review Comment: No need to have line break here and annotate user with @Nullable please. ########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/common/OmUserUtils.java: ########## @@ -0,0 +1,87 @@ +/** + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.common; + +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.server.OzoneAdmins; + +import org.apache.hadoop.ozone.om.OzoneConfigUtil; +import org.apache.hadoop.security.UserGroupInformation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Collection; + +/** + * Utility class to store User related utilities. + */ +public final class OmUserUtils { + private static final Logger LOG = + LoggerFactory.getLogger(OmUserUtils.class); + + private OmUserUtils() { } + + /** + * Get the users and groups that are S3 admin. + * @param conf Stores the Ozone configuration being used + * @return an instance of {@link OzoneAdmins} containing the S3 admin users and groups + */ + public static OzoneAdmins getS3Admins(OzoneConfiguration conf) { + Collection<String> s3Admins; + try { + s3Admins = OzoneConfigUtil.getS3AdminsFromConfig(conf); + } catch (IOException ie) { + s3Admins = null; + } + Collection<String> s3AdminGroups = + OzoneConfigUtil.getS3AdminsGroupsFromConfig(conf); + if (LOG.isDebugEnabled()) { + if (null == s3Admins) { + LOG.debug("S3 Admins are not set in configuration"); + } + if (null == s3AdminGroups) { + LOG.debug("S3 Admin Groups are not set in configuration"); + } + } + return new OzoneAdmins(s3Admins, s3AdminGroups); + } + + /** + * Check if the provided user is a part of the S3 admins. + * @param user Stores the user to verify + * @param conf Stores the Ozone configuration being used + * @return true if the provided user is an S3 admin else false + */ + public static boolean isS3Admin(UserGroupInformation user, + OzoneConfiguration conf) { + OzoneAdmins s3Admins = getS3Admins(conf); + return null != user && s3Admins.isAdmin(user); + } + + /** + * Check if the provided user is a part of the S3 admins. + * @param user Stores the user to verify + * @param s3Admins Stores the users and groups that are admins + * @return true if the provided user is an S3 admin else false Review Comment: {@code true} if the provided user is an S3 administrator or else {@code false}. -- 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]
