mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-14 04:22:16 +00:00
Promoting this common pattern into a convenience class
This commit is contained in:
1 parent
21ead8532a
commit
7d5b098bf2
2 files changed
+48
-21
No files matched your search
@@ -0,0 +1,45 @@
|
||||
package jenkins;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Convenient adapter for {@link FilePathFilter} that allows you to handle all
|
||||
* operations as a single string argument.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
* @since 1.THU
|
||||
*/
|
||||
public abstract class ReflectiveFilePathFilter extends FilePathFilter {
|
||||
|
||||
protected abstract boolean op(String name, File path) throws SecurityException;
|
||||
|
||||
@Override
|
||||
public boolean read(File f) throws SecurityException {
|
||||
return op("read", f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean write(File f) throws SecurityException {
|
||||
return op("write", f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mkdirs(File f) throws SecurityException {
|
||||
return op("mkdirs", f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean create(File f) throws SecurityException {
|
||||
return op("create", f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(File f) throws SecurityException {
|
||||
return op("delete", f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stat(File f) throws SecurityException {
|
||||
return op("stat", f);
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ package jenkins.security;
|
||||
|
||||
import hudson.Extension;
|
||||
import hudson.remoting.ChannelBuilder;
|
||||
import jenkins.FilePathFilter;
|
||||
import jenkins.ReflectiveFilePathFilter;
|
||||
import org.kohsuke.accmod.Restricted;
|
||||
import org.kohsuke.accmod.restrictions.DoNotUse;
|
||||
|
||||
@@ -65,8 +65,8 @@ import java.util.logging.Logger;
|
||||
|
||||
@Override
|
||||
public void onChannelBuilding(ChannelBuilder builder, Object context) {
|
||||
new FilePathFilter() {
|
||||
private boolean op(String op, File f) throws SecurityException {
|
||||
new ReflectiveFilePathFilter() {
|
||||
protected boolean op(String op, File f) throws SecurityException {
|
||||
if (BYPASS_LOG != null) {
|
||||
BYPASS_LOG.println(op + " " + f);
|
||||
return true;
|
||||
@@ -80,24 +80,6 @@ import java.util.logging.Logger;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@Override public boolean read(File f) throws SecurityException {
|
||||
return op("read", f);
|
||||
}
|
||||
@Override public boolean write(File f) throws SecurityException {
|
||||
return op("write", f);
|
||||
}
|
||||
@Override public boolean mkdirs(File f) throws SecurityException {
|
||||
return op("mkdirs", f);
|
||||
}
|
||||
@Override public boolean create(File f) throws SecurityException {
|
||||
return op("create", f);
|
||||
}
|
||||
@Override public boolean delete(File f) throws SecurityException {
|
||||
return op("delete", f);
|
||||
}
|
||||
@Override public boolean stat(File f) throws SecurityException {
|
||||
return op("stat", f);
|
||||
}
|
||||
}.installTo(builder);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user