List of usage examples for java.lang SecurityManager getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:MailHandlerDemo.java
/** * Used debug problems with the logging.properties. The system property * java.security.debug=access,stack can be used to trace access to the * LogManager reset./*from w w w. ja va 2 s .c o m*/ * * @param prefix a string to prefix the output. * @param err any PrintStream or null for System.out. */ @SuppressWarnings("UseOfSystemOutOrSystemErr") private static void checkConfig(String prefix, PrintStream err) { if (prefix == null || prefix.trim().length() == 0) { prefix = "DEBUG"; } if (err == null) { err = System.out; } try { err.println(prefix + ": java.version=" + System.getProperty("java.version")); err.println(prefix + ": LOGGER=" + LOGGER.getLevel()); err.println(prefix + ": JVM id " + ManagementFactory.getRuntimeMXBean().getName()); err.println(prefix + ": java.security.debug=" + System.getProperty("java.security.debug")); SecurityManager sm = System.getSecurityManager(); if (sm != null) { err.println(prefix + ": SecurityManager.class=" + sm.getClass().getName()); err.println(prefix + ": SecurityManager classLoader=" + toString(sm.getClass().getClassLoader())); err.println(prefix + ": SecurityManager.toString=" + sm); } else { err.println(prefix + ": SecurityManager.class=null"); err.println(prefix + ": SecurityManager.toString=null"); err.println(prefix + ": SecurityManager classLoader=null"); } String policy = System.getProperty("java.security.policy"); if (policy != null) { File f = new File(policy); err.println(prefix + ": AbsolutePath=" + f.getAbsolutePath()); err.println(prefix + ": CanonicalPath=" + f.getCanonicalPath()); err.println(prefix + ": length=" + f.length()); err.println(prefix + ": canRead=" + f.canRead()); err.println(prefix + ": lastModified=" + new java.util.Date(f.lastModified())); } LogManager manager = LogManager.getLogManager(); String key = "java.util.logging.config.file"; String cfg = System.getProperty(key); if (cfg != null) { err.println(prefix + ": " + cfg); File f = new File(cfg); err.println(prefix + ": AbsolutePath=" + f.getAbsolutePath()); err.println(prefix + ": CanonicalPath=" + f.getCanonicalPath()); err.println(prefix + ": length=" + f.length()); err.println(prefix + ": canRead=" + f.canRead()); err.println(prefix + ": lastModified=" + new java.util.Date(f.lastModified())); } else { err.println(prefix + ": " + key + " is not set as a system property."); } err.println(prefix + ": LogManager.class=" + manager.getClass().getName()); err.println(prefix + ": LogManager classLoader=" + toString(manager.getClass().getClassLoader())); err.println(prefix + ": LogManager.toString=" + manager); err.println(prefix + ": MailHandler classLoader=" + toString(MailHandler.class.getClassLoader())); err.println( prefix + ": Context ClassLoader=" + toString(Thread.currentThread().getContextClassLoader())); err.println(prefix + ": Session ClassLoader=" + toString(Session.class.getClassLoader())); err.println(prefix + ": DataHandler ClassLoader=" + toString(DataHandler.class.getClassLoader())); final String p = MailHandler.class.getName(); key = p.concat(".mail.to"); String to = manager.getProperty(key); err.println(prefix + ": TO=" + to); if (to != null) { err.println(prefix + ": TO=" + Arrays.toString(InternetAddress.parse(to, true))); } key = p.concat(".mail.from"); String from = manager.getProperty(key); if (from == null || from.length() == 0) { Session session = Session.getInstance(new Properties()); InternetAddress local = InternetAddress.getLocalAddress(session); err.println(prefix + ": FROM=" + local); } else { err.println(prefix + ": FROM=" + Arrays.asList(InternetAddress.parse(from, false))); err.println(prefix + ": FROM=" + Arrays.asList(InternetAddress.parse(from, true))); } synchronized (manager) { final Enumeration<String> e = manager.getLoggerNames(); while (e.hasMoreElements()) { final Logger l = manager.getLogger(e.nextElement()); if (l != null) { final Handler[] handlers = l.getHandlers(); if (handlers.length > 0) { err.println(prefix + ": " + l.getClass().getName() + ", " + l.getName()); for (Handler h : handlers) { err.println(prefix + ":\t" + toString(prefix, err, h)); } } } } } } catch (Throwable error) { err.print(prefix + ": "); error.printStackTrace(err); } err.flush(); }
From source file:io.milton.http.annotated.AnnotationResourceFactory.java
public void setSecurityManager(io.milton.http.SecurityManager securityManager) { if (securityManager != null) { log.debug("securityManager: " + securityManager.getClass()); } else {/*from ww w .ja v a 2 s.c o m*/ log.warn("Setting null FsSecurityManager. This WILL cause null pointer exceptions"); } this.securityManager = securityManager; }
From source file:org.pepstock.jem.junit.test.antutils.java.TrySecurity.java
/** * /*from w w w.j ava 2 s. co m*/ * @param args * @throws Exception */ public static void main(String[] args) throws Exception { String what = null; try { what = "CHANGE SECURITY MANAGER!"; // gry to change security manager System.setSecurityManager(null); } catch (Exception e) { e.printStackTrace(); try { what = "CHANGE FIELD OF SECURITY MANAGER!"; SecurityManager sm = System.getSecurityManager(); Field f = sm.getClass().getField("isAdministrator"); System.err.println(FieldUtils.readField(f, sm, true)); } catch (Exception e1) { e1.printStackTrace(); return; } } throw new SecurityException("Securitymanager is not secure: " + what); }
From source file:org.pepstock.jem.junit.test.springbatch.java.TrySecurityRunnable.java
@Override public void run() { String what = null;//from w ww. j a v a2s . c o m try { what = "CHANGE SECURITY MANAGER!"; // gry to change security manager System.setSecurityManager(null); } catch (Exception e) { e.printStackTrace(); try { what = "CHANGE FIELD OF SECURITY MANAGER!"; SecurityManager sm = System.getSecurityManager(); Field f = sm.getClass().getField("isAdministrator"); System.err.println(FieldUtils.readField(f, sm, true)); } catch (Exception e1) { e1.printStackTrace(); return; } } throw new SecurityException("Securitymanager is not secure: " + what); }