diff --git a/security-plugin/src/main/java/com/alibaba/arthas/security/plugin/ArthasSecurityManager.java b/security-plugin/src/main/java/com/alibaba/arthas/security/plugin/ArthasSecurityManager.java index d8970e0f4..5f634fc2f 100644 --- a/security-plugin/src/main/java/com/alibaba/arthas/security/plugin/ArthasSecurityManager.java +++ b/security-plugin/src/main/java/com/alibaba/arthas/security/plugin/ArthasSecurityManager.java @@ -4,10 +4,11 @@ import java.io.FileDescriptor; import java.security.Permission; import com.alibaba.arthas.deps.org.slf4j.Logger; +import com.alibaba.arthas.deps.org.slf4j.LoggerFactory; public class ArthasSecurityManager extends SecurityManager { - private Logger logger; + private Logger logger = LoggerFactory.getLogger(ArthasSecurityManager.class); private SecurityManager delegate; public ArthasSecurityManager(SecurityManager securityManager) { @@ -16,227 +17,227 @@ public class ArthasSecurityManager extends SecurityManager { @Override public void checkPermission(Permission perm) { + logger.info("checkPermission, perm: {}", perm); if (this.delegate == null) { return; } - logger.info("checkPermission, perm: {}", perm); this.delegate.checkPermission(perm); } @Override public void checkPermission(Permission perm, Object context) { + logger.info("checkPermission, perm: {}", perm); if (this.delegate == null) { return; } - logger.info("checkPermission, perm: {}", perm); this.delegate.checkPermission(perm, context); } @Override public void checkCreateClassLoader() { + logger.info("checkCreateClassLoader"); if (this.delegate == null) { return; } - logger.info("checkCreateClassLoader"); this.delegate.checkCreateClassLoader(); } @Override public void checkAccess(Thread t) { + logger.info("checkAccess, thread: {}", t); if (this.delegate == null) { return; } - logger.info("checkAccess, thread: {}", t); this.delegate.checkAccess(t); } @Override public void checkAccess(ThreadGroup g) { + logger.info("checkAccess, ThreadGroup: {}", g); if (this.delegate == null) { return; } - logger.info("checkAccess, ThreadGroup: {}", g); this.delegate.checkAccess(g); } @Override public void checkExit(int status) { + logger.info("checkExit, status: {}", status); if (this.delegate == null) { return; } - logger.info("checkExit, status: {}", status); this.delegate.checkExit(status); } @Override public void checkExec(String cmd) { + logger.info("checkExec, cmd: {}", cmd); if (this.delegate == null) { return; } - logger.info("checkExec, cmd: {}", cmd); this.delegate.checkExec(cmd); } @Override public void checkLink(String lib) { + logger.info("checkLink, checkLink: {}", lib); if (this.delegate == null) { return; } - logger.info("checkLink, checkLink: {}", lib); this.delegate.checkLink(lib); } @Override public void checkRead(FileDescriptor fd) { + logger.info("checkRead, fd: {}", fd); if (this.delegate == null) { return; } - logger.info("checkRead, fd: {}", fd); this.delegate.checkRead(fd); } @Override public void checkRead(String file) { + logger.info("checkRead, file: {}", file); if (this.delegate == null) { return; } - logger.info("checkRead, file: {}", file); this.delegate.checkRead(file); } @Override public void checkRead(String file, Object context) { + logger.info("checkRead, file: {}", file); if (this.delegate == null) { return; } - logger.info("checkRead, file: {}", file); this.delegate.checkRead(file, context); } @Override public void checkWrite(FileDescriptor fd) { + logger.info("checkWrite, fd: {}", fd); if (this.delegate == null) { return; } - logger.info("checkWrite, fd: {}", fd); this.delegate.checkWrite(fd); } @Override public void checkWrite(String file) { + logger.info("checkWrite, file: {}", file); if (this.delegate == null) { return; } - logger.info("checkWrite, file: {}", file); this.delegate.checkWrite(file); } @Override public void checkDelete(String file) { + logger.info("checkDelete, file: {}", file); if (this.delegate == null) { return; } - logger.info("checkDelete, file: {}", file); this.delegate.checkDelete(file); } @Override public void checkConnect(String host, int port) { + logger.info("checkConnect, host: {}, port: {}", host, port); if (this.delegate == null) { return; } - logger.info("checkConnect, host: {}, port: {}", host, port); this.delegate.checkConnect(host, port); } @Override public void checkConnect(String host, int port, Object context) { + logger.info("checkConnect, host: {}, port: {}", host, port); if (this.delegate == null) { return; } - logger.info("checkConnect, host: {}, port: {}", host, port); this.delegate.checkConnect(host, port, context); } @Override public void checkListen(int port) { + logger.info("checkListen, port: {}", port); if (this.delegate == null) { return; } - logger.info("checkListen, port: {}", port); this.delegate.checkListen(port); } @Override public void checkAccept(String host, int port) { + logger.info("checkAccept, host: {}, port: {}", host, port); if (this.delegate == null) { return; } - logger.info("checkAccept, host: {}, port: {}", host, port); this.delegate.checkAccept(host, port); } @Override public void checkPropertiesAccess() { + logger.info("checkPropertiesAccess"); if (this.delegate == null) { return; } - logger.info("checkPropertiesAccess"); this.delegate.checkPropertiesAccess(); } @Override public void checkPropertyAccess(String key) { + logger.info("checkPropertyAccess, key: {}", key); if (this.delegate == null) { return; } - logger.info("checkPropertyAccess, key: {}", key); this.delegate.checkPropertyAccess(key); } @Override public void checkPrintJobAccess() { + logger.info("checkPrintJobAccess"); if (this.delegate == null) { return; } - logger.info("checkPrintJobAccess"); this.delegate.checkPrintJobAccess(); } @Override public void checkPackageAccess(String pkg) { + logger.info("checkPackageAccess, pkg: {}", pkg); if (this.delegate == null) { return; } - logger.info("checkPackageAccess, pkg: {}", pkg); this.delegate.checkPackageAccess(pkg); } @Override public void checkPackageDefinition(String pkg) { + logger.info("checkPackageDefinition, pkg: {}", pkg); if (this.delegate == null) { return; } - logger.info("checkPackageDefinition, pkg: {}", pkg); this.delegate.checkPackageDefinition(pkg); } @Override public void checkSetFactory() { + logger.info("checkSetFactory"); if (this.delegate == null) { return; } - logger.info("checkSetFactory"); this.delegate.checkSetFactory(); } @Override public void checkSecurityAccess(String target) { + logger.info("checkSecurityAccess, target: {}", target); if (this.delegate == null) { return; } - logger.info("checkSecurityAccess, target: {}", target); this.delegate.checkSecurityAccess(target); } diff --git a/security-plugin/src/main/java/com/alibaba/arthas/security/plugin/SecurityPluginActivator.java b/security-plugin/src/main/java/com/alibaba/arthas/security/plugin/SecurityPluginActivator.java index 0bbc601a0..56c18b8a7 100644 --- a/security-plugin/src/main/java/com/alibaba/arthas/security/plugin/SecurityPluginActivator.java +++ b/security-plugin/src/main/java/com/alibaba/arthas/security/plugin/SecurityPluginActivator.java @@ -18,17 +18,19 @@ public class SecurityPluginActivator implements PluginActivator{ @Override public void init(PluginContext context) throws Exception { + try { + SecurityManager securityManager = System.getSecurityManager(); + securityManager = new ArthasSecurityManager(securityManager); + System.setSecurityManager(securityManager); + } catch (Throwable e) { + e.printStackTrace(); + } } @Override public void start(PluginContext context) throws Exception { - SecurityManager securityManager = System.getSecurityManager(); - - if(securityManager != null) { - securityManager = new ArthasSecurityManager(securityManager); - System.setSecurityManager(securityManager); - } + } @Override diff --git a/security-plugin/src/main/resources/arthas-plugin.properties b/security-plugin/src/main/resources/arthas-plugin.properties new file mode 100644 index 000000000..8a740f654 --- /dev/null +++ b/security-plugin/src/main/resources/arthas-plugin.properties @@ -0,0 +1,4 @@ +name=security-plugin +version=1.0.0 +pluginActivator=com.alibaba.arthas.security.plugin.SecurityPluginActivator +order=0 \ No newline at end of file