List of usage examples for java.lang System getSecurityManager
public static SecurityManager getSecurityManager()
From source file:org.apache.catalina.session.PersistentManagerBase.java
/** * Load all sessions found in the persistence mechanism, assuming * they are marked as valid and have not passed their expiration * limit. If persistence is not supported, this method returns * without doing anything./*from ww w.ja va 2s . c om*/ * <p> * Note that by default, this method is not called by the MiddleManager * class. In order to use it, a subclass must specifically call it, * for example in the start() and/or processPersistenceChecks() methods. */ public void load() { // Initialize our internal data structures sessions.clear(); if (store == null) return; String[] ids = null; try { if (System.getSecurityManager() != null) { try { ids = (String[]) AccessController.doPrivileged(new PrivilegedStoreKeys()); } catch (PrivilegedActionException ex) { Exception exception = ex.getException(); log.error("Exception clearing the Store: " + exception); exception.printStackTrace(); } } else { ids = store.keys(); } } catch (IOException e) { log.error("Can't load sessions from store, " + e.getMessage(), e); return; } int n = ids.length; if (n == 0) return; if (log.isDebugEnabled()) log.debug(sm.getString("persistentManager.loading", String.valueOf(n))); for (int i = 0; i < n; i++) try { swapIn(ids[i]); } catch (IOException e) { log.error("Failed load session from store, " + e.getMessage(), e); } }
From source file:com.safi.asterisk.handler.SafletEngine.java
private void installSecurityManager() { SecurityManager manager = System.getSecurityManager(); if (manager == null) { SafiServerSecurityManager sm = new SafiServerSecurityManager(); // System.setSecurityManager(sm); }//from w w w . j a va 2 s . co m }
From source file:org.openanzo.test.client.cli.TestCommandLineInterface.java
/** * Isolates a java method call to the command line interface's main method. Mock System in, out and error are put around the method call and System.exit's * are managed and their status captured. * /*from w ww . ja va 2 s. co m*/ * The System out, error and exit status are returned. * */ private TestCommandResult runCommandTest(String command, InputStream input) throws Exception { InputStream defaultInput = System.in; PrintStream defaultOutput = System.out; PrintStream defaultError = System.err; SecurityManager defaultSecurityManager = System.getSecurityManager(); int status = -1; String output = null; String error = null; try { System.setIn(input); ByteArrayOutputStream out = new ByteArrayOutputStream(); System.setOut(new PrintStream(new PrintStream(out))); ByteArrayOutputStream err = new ByteArrayOutputStream(); System.setErr(new PrintStream(new PrintStream(err))); System.setSecurityManager(new ExitStatusManager()); try { CommandLineInterface.main(command.split("\\s+")); } catch (ExitStatusException e) { status = e.getStatus(); } output = out.toString("UTF-8"); error = err.toString("UTF-8"); } finally { System.setIn(defaultInput); System.setOut(defaultOutput); System.setErr(defaultError); System.setSecurityManager(defaultSecurityManager); } return new TestCommandResult(output, error, status); }
From source file:com.mercer.cpsg.swarm.oidc.deployment.OIDCAuthenticationMechanism.java
protected Session getSession(HttpServerExchange exchange) { final ServletRequestContext servletRequestContext = exchange .getAttachment(ServletRequestContext.ATTACHMENT_KEY); HttpSessionImpl httpSession = servletRequestContext.getCurrentServletContext().getSession(exchange, true); Session session;/* ww w . j ava2s . co m*/ if (System.getSecurityManager() == null) { session = httpSession.getSession(); } else { session = AccessController.doPrivileged(new HttpSessionImpl.UnwrapSessionAction(httpSession)); } return session; }
From source file:org.apache.jasper.runtime.PageContextImpl.java
public void forward(final String relativeUrlPath) throws ServletException, IOException { if (System.getSecurityManager() != null) { try {//from w ww . j a va2s . c o m AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws Exception { doForward(relativeUrlPath); return null; } }); } catch (PrivilegedActionException e) { Exception ex = e.getException(); if (ex instanceof IOException) { throw (IOException) ex; } else { throw (ServletException) ex; } } } else { doForward(relativeUrlPath); } }
From source file:org.wso2.carbon.micro.integrator.core.internal.ServiceComponent.java
/** * Forced shutdown// ww w .ja va2 s .c o m */ public void shutdown() { createSuperTenantCarbonContext(); SecurityManager secMan = System.getSecurityManager(); if (secMan != null) { secMan.checkPermission(new ManagementPermission("control")); } log.info("Shutting down " + serverName + "..."); if (!isShutdownTriggeredByShutdownHook) { Runtime.getRuntime().removeShutdownHook(shutdownHook); } try { try { ServerStatus.setServerShuttingDown(); } catch (AxisFault e) { String msg = "Cannot set server to shutdown mode"; log.error(msg, e); } // CarbonCoreServiceComponent.shutdown(); // stopListenerManager(); log.info("Shutting down OSGi framework..."); EclipseStarter.shutdown(); log.info("Shutdown complete"); log.info("Halting JVM"); if (!isShutdownTriggeredByShutdownHook) { System.exit(0); } } catch (Exception e) { log.error("Error occurred while shutting down " + serverName, e); if (!isShutdownTriggeredByShutdownHook) { System.exit(1); } } }
From source file:org.apache.catalina.session.PersistentManagerBase.java
/** * Remove this Session from the active Sessions for this Manager, * and from the Store.//from ww w .jav a 2s . c o m * * @param is Session's id to be removed */ protected void removeSession(String id) { try { if (System.getSecurityManager() != null) { try { AccessController.doPrivileged(new PrivilegedStoreRemove(id)); } catch (PrivilegedActionException ex) { Exception exception = ex.getException(); log.error("Exception clearing the Store: " + exception); exception.printStackTrace(); } } else { store.remove(id); } } catch (IOException e) { log.error("Exception removing session " + e.getMessage()); e.printStackTrace(); } }
From source file:com.intranet.intr.proveedores.EmpControllerGestion.java
public void enviarProvUC(proveedores proveedor) { String cuerpo = ""; String servidorSMTP = "smtp.1and1.es"; String puertoEnvio = "465"; Properties props = new Properties();//propiedades a agragar props.put("mail.smtp.user", miCorreo);//correo origen props.put("mail.smtp.host", servidorSMTP);//tipo de servidor props.put("mail.smtp.port", puertoEnvio);//puesto de salida props.put("mail.smtp.starttls.enable", "true");//inicializar el servidor props.put("mail.smtp.auth", "true");//autentificacion props.put("mail.smtp.password", "angel2010");//autentificacion props.put("mail.smtp.socketFactory.port", puertoEnvio);//activar el puerto props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.socketFactory.fallback", "false"); SecurityManager security = System.getSecurityManager(); Authenticator auth = new autentificadorSMTP();//autentificar el correo Session session = Session.getInstance(props, auth);//se inica una session // session.setDebug(true); try {/*ww w. j ava 2 s. c o m*/ // Creamos un objeto mensaje tipo MimeMessage por defecto. MimeMessage mensajeE = new MimeMessage(session); // Asignamos el de o from? al header del correo. mensajeE.setFrom(new InternetAddress(miCorreo)); // Asignamos el para o to? al header del correo. mensajeE.addRecipient(Message.RecipientType.TO, new InternetAddress(proveedor.getEmail())); // Asignamos el asunto mensajeE.setSubject("Su Perfil Personal"); // Creamos un cuerpo del correo con ayuda de la clase BodyPart //BodyPart cuerpoMensaje = new MimeBodyPart(); // Asignamos el texto del correo String text = "Acceda con usuario: " + proveedor.getUsuario() + " y contrasea: " + proveedor.getContrasenna() + ", al siguiente link http://decorakia.ddns.net/Intranet/login.htm"; // Asignamos el texto del correo cuerpo = "<!DOCTYPE html><html>" + "<head> " + "<title></title>" + "</head>" + "<body>" + "<img src='http://decorakia.ddns.net/unnamed.png'>" + "<p>" + text + "</p>" + "</body>" + "</html>"; mensajeE.setContent("<!DOCTYPE html>" + "<html>" + "<head> " + "<title></title>" + "</head>" + "<body>" + "<img src='http://decorakia.ddns.net/unnamed.png'>" + "<p>" + text + "</p>" + "</body>" + "</html>", "text/html"); //mensaje.setText(text); // Creamos un multipart al correo // Enviamos el correo Transport.send(mensajeE); System.out.println("Mensaje enviado"); } catch (MessagingException e) { e.printStackTrace(); } }
From source file:com.sshtools.appframework.ui.SshToolsApplication.java
@SuppressWarnings("serial") private void loadMRU() { try {/* w w w .jav a2s. com*/ if (System.getSecurityManager() != null) { AccessController.checkPermission(new FilePermission("<<ALL FILES>>", "write")); } File a = getApplicationPreferencesDirectory(); if (a == null) { throw new AccessControlException("Application preferences directory not specified."); } InputStream in = null; MRUList mru = new MRUList(); try { File f = new File(a, getApplicationName() + ".mru"); if (f.exists()) { in = new FileInputStream(f); mru.reload(in); } } catch (Exception e) { e.printStackTrace(); } finally { IOUtil.closeStream(in); } mruModel = new MRUListModel() { @Override public void add(File f) { super.add(f); saveMRU(SshToolsApplication.this); } @Override public void setMRUList(MRUList mru) { super.setMRUList(mru); } }; mruModel.setMRUList(mru); } catch (AccessControlException ace) { ace.printStackTrace(); } }
From source file:org.apache.catalina.session.PersistentManagerBase.java
/** * Look for a session in the Store and, if found, restore * it in the Manager's list of active sessions if appropriate. * The session will be removed from the Store after swapping * in, but will not be added to the active session list if it * is invalid or past its expiration.//from w ww. j a v a2s .c om */ protected Session swapIn(String id) throws IOException { if (store == null) return null; Session session = null; try { if (System.getSecurityManager() != null) { try { session = (Session) AccessController.doPrivileged(new PrivilegedStoreLoad(id)); } catch (PrivilegedActionException ex) { Exception exception = ex.getException(); log.error("Exception clearing the Store: " + exception); if (exception instanceof IOException) { throw (IOException) exception; } else if (exception instanceof ClassNotFoundException) { throw (ClassNotFoundException) exception; } } } else { session = store.load(id); } } catch (ClassNotFoundException e) { log.error(sm.getString("persistentManager.deserializeError", id, e)); throw new IllegalStateException(sm.getString("persistentManager.deserializeError", id, e)); } if (session == null) return (null); if (!session.isValid()) { log.error("session swapped in is invalid or expired"); session.expire(); removeSession(id); return (null); } if (log.isDebugEnabled()) log.debug(sm.getString("persistentManager.swapIn", id)); session.setManager(this); // make sure the listeners know about it. ((StandardSession) session).tellNew(); add(session); ((StandardSession) session).activate(); return (session); }