-
Notifications
You must be signed in to change notification settings - Fork 997
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
90fbad2
commit 68e98d9
Showing
9 changed files
with
1,347 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
sdk/java/src/main/java/io/juicefs/utils/FsPermissionExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* 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 io.juicefs.utils; | ||
|
||
import org.apache.hadoop.classification.InterfaceAudience; | ||
import org.apache.hadoop.fs.permission.FsPermission; | ||
|
||
/** | ||
* HDFS permission subclass used to indicate an ACL is present and/or that the | ||
* underlying file/dir is encrypted. The ACL/encrypted bits are not visible | ||
* directly to users of {@link FsPermission} serialization. This is | ||
* done for backwards compatibility in case any existing clients assume the | ||
* value of FsPermission is in a particular range. | ||
*/ | ||
@InterfaceAudience.Private | ||
public class FsPermissionExtension extends FsPermission { | ||
private final static short ACL_BIT = 1 << 12; | ||
private final static short ENCRYPTED_BIT = 1 << 13; | ||
private final boolean aclBit; | ||
private final boolean encryptedBit; | ||
|
||
/** | ||
* Constructs a new FsPermissionExtension based on the given FsPermission. | ||
* | ||
* @param perm FsPermission containing permission bits | ||
*/ | ||
public FsPermissionExtension(FsPermission perm, boolean hasAcl, | ||
boolean isEncrypted) { | ||
super(perm.toShort()); | ||
aclBit = hasAcl; | ||
encryptedBit = isEncrypted; | ||
} | ||
|
||
@Override | ||
public short toExtendedShort() { | ||
return (short) (toShort() | | ||
(aclBit ? ACL_BIT : 0) | (encryptedBit ? ENCRYPTED_BIT : 0)); | ||
} | ||
|
||
public boolean getAclBit() { | ||
return aclBit; | ||
} | ||
|
||
@Override | ||
public boolean getEncryptedBit() { | ||
return encryptedBit; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
sdk/java/src/main/java/io/juicefs/utils/ReflectionUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* JuiceFS, Copyright 2024 Juicedata, Inc. | ||
* | ||
* Licensed 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 io.juicefs.utils; | ||
|
||
import java.lang.reflect.Constructor; | ||
|
||
public class ReflectionUtil { | ||
public static boolean hasMethod(String className, String method, String[] params) { | ||
try { | ||
Class<?>[] classes = null; | ||
if (params != null) { | ||
classes = new Class[params.length]; | ||
for (int i = 0; i < params.length; i++) { | ||
classes[i] = Class.forName(params[i], false, Thread.currentThread().getContextClassLoader()); | ||
} | ||
} | ||
return hasMethod(className, method, classes); | ||
} catch (ClassNotFoundException e) { | ||
return false; | ||
} | ||
} | ||
|
||
public static boolean hasMethod(String className, String method, Class<?>[] params) { | ||
try { | ||
Class<?> clazz = Class.forName(className, false, Thread.currentThread().getContextClassLoader()); | ||
clazz.getDeclaredMethod(method, params); | ||
} catch (ClassNotFoundException | NoSuchMethodException e) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public static <T> Constructor<T> getConstructor(Class<T> clazz, Class<?>... params) { | ||
try { | ||
return clazz.getConstructor(params); | ||
} catch (NoSuchMethodException e) { | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* 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 io.juicefs.acl; | ||
|
||
import org.apache.hadoop.cli.CLITestHelperDFS; | ||
import org.apache.hadoop.cli.util.CLICommand; | ||
import org.apache.hadoop.cli.util.CommandExecutor.Result; | ||
import org.apache.hadoop.hdfs.DFSConfigKeys; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class TestAclCLI extends CLITestHelperDFS { | ||
private String vol = null; | ||
private String username = null; | ||
|
||
protected void initConf() { | ||
conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_ACLS_ENABLED_KEY, true); | ||
conf.setBoolean( | ||
DFSConfigKeys.DFS_NAMENODE_POSIX_ACL_INHERITANCE_ENABLED_KEY, false); | ||
} | ||
|
||
@Before | ||
@Override | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
initConf(); | ||
vol = "jfs://dev/"; | ||
username = System.getProperty("user.name"); | ||
} | ||
|
||
@After | ||
@Override | ||
public void tearDown() throws Exception { | ||
super.tearDown(); | ||
} | ||
|
||
@Override | ||
protected String getTestFile() { | ||
return "testAclCLI.xml"; | ||
} | ||
|
||
@Override | ||
protected String expandCommand(final String cmd) { | ||
String expCmd = cmd; | ||
expCmd = expCmd.replaceAll("NAMENODE", vol); | ||
expCmd = expCmd.replaceAll("USERNAME", username); | ||
expCmd = expCmd.replaceAll("#LF#", | ||
System.getProperty("line.separator")); | ||
expCmd = super.expandCommand(expCmd); | ||
return expCmd; | ||
} | ||
|
||
@Override | ||
protected Result execute(CLICommand cmd) throws Exception { | ||
return cmd.getExecutor(vol, conf).executeCommand(cmd.getCmd()); | ||
} | ||
|
||
@Test | ||
@Override | ||
public void testAll() { | ||
super.testAll(); | ||
} | ||
} |
Oops, something went wrong.