/** * Sets the java.security.policy system property to point at the location of the security policy * file, which is assumed to be at "provided\rmiUtils\server.policy" (file separators adjusted to * match operating system). the security manager is then started. This method must be called * before starting the class server. */ private void configSecurityManager() { // file.separator is "\" in Windows and "/" in Unix/Linux/Mac. String sep = System.getProperty("file.separator"); System.setProperty( "java.security.policy", "provided" + sep + "rmiUtils" + sep + "server.policy"); outputCmd.apply("java.security.policy: " + System.getProperty("java.security.policy")); // Start the security manager if (System.getSecurityManager() == null) { outputCmd.apply("Installing new Security Manager...\n"); System.setSecurityManager(new SecurityManager()); outputCmd.apply("Security Manager = " + System.getSecurityManager()); } }
public static void main(String[] args) { String host = args[0]; int port = Integer.parseInt(args[1]); long id = Long.parseLong(args[2]); String character = args[3]; long actorId = Long.parseLong(args[4]); // Install an RMISecurityManager, if there is not a // SecurityManager already installed if (System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager()); } String name = "rmi://" + host + ":" + port + "/MovieDatabase"; try { MovieDatabase db = (MovieDatabase) Naming.lookup(name); db.noteCharacter(id, character, actorId); Movie movie = db.getMovie(id); out.println(movie.getTitle()); for (Map.Entry entry : movie.getCharacters().entrySet()) { out.println(" " + entry.getKey() + "\t" + entry.getValue()); } } catch (RemoteException | NotBoundException | MalformedURLException ex) { ex.printStackTrace(System.err); } }
public VINDecoderServer() { try { // Start the RMI Server // Registry registry = LocateRegistry.createRegistry(1099); // Assign a security manager, in the event that dynamic // classes are loaded if (System.getSecurityManager() == null) System.setSecurityManager( new RMISecurityManager() { public void checkConnect(String host, int port) {} public void checkConnect(String host, int port, Object context) {} public void checkAccept(String host, int port) {} }); System.out.println("Set the security manager"); // Create an instance of our power service server ... VINDecoderImpl vd = new VINDecoderImpl(); vd.setDB("/usr/local/vendor/bea/user_projects/matson/lib/jato_matson.jar"); System.out.println("Decoding vin..."); System.out.println(vd.decode("1GTDL19W5YB530809", null)); System.out.println("End Decoding vin..."); // ... and bind it with the RMI Registry // Naming.bind ("VINDecoderService", vd); System.out.println("VINDecoderService bound...."); } catch (Exception e) { e.printStackTrace(); } }
public RMIConnection createConnection() { RMIServerManager serverManager = null; Context initialNamingContext = null; try { initialNamingContext = new InitialContext(); } catch (NamingException exception) { System.out.println("Naming Exception " + exception.toString()); } ; // Set the client security manager try { System.setSecurityManager(new RMISecurityManager()); } catch (Exception exception) { System.out.println("Security violation " + exception.toString()); } // Get the remote factory object from the Registry try { serverManager = (RMIServerManager) initialNamingContext.lookup("SERVER-MANAGER"); } catch (Exception exception) { throw new TestProblemException(exception.toString()); } RMIConnection rmiConnection = null; try { rmiConnection = new RMIConnection(serverManager.createRemoteSessionController()); } catch (RemoteException exception) { System.out.println("Error in invocation " + exception.toString()); } return rmiConnection; }
public static void main(String[] argv) { try { System.setSecurityManager(new RMISecurityManager()); Addition Hello = new Addition(); Naming.rebind("rmi://localhost/ABCD", Hello); System.out.println("Addition Server is ready."); } catch (Exception e) { System.out.println("Addition Server failed: " + e); } }
// we define the method for getting a video link when pressing enter public String getvidlink() { try { System.setSecurityManager(new SecurityManager()); ipadd = tfIP.getText(); Interface client = (Interface) Naming.lookup("rmi://" + ipadd + "/getvid"); // Get the String entered into the TextField tfInput, convert to int link = tfInput.getText(); vlink = client.getvid(link); } catch (Exception e) { System.out.println("[System] Server failed: " + e); } return vlink; }
// private static final String HOST = "localhost"; public static void main(String[] args) throws Exception { if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); } ClientImpt client = new ClientImpt(args); LocateRegistry.createRegistry(6600); String rmiObjectName = "rmi://localhost:6600/Client"; Naming.rebind(rmiObjectName, client); System.out.println(args[0] + " Broker server run...\n"); }
public TransactionManagerAccessor(String propFileName) { LookupLocator locator = null; ServiceRegistrar registrar = null; // Security manager try { System.setSecurityManager(new RMISecurityManager()); } catch (Exception e) { e.printStackTrace(); } // Get properties from property file initProperties(propFileName); try { // Get lookup service locator at "jini://hostname" // use default port and register of the locator locator = new LookupLocator(jiniURL); registrar = locator.getRegistrar(); // Space name provided in property file ServiceTemplate template; // Specify the service requirement, array (length 1) of // instances of Class Class[] types = new Class[] {TransactionManager.class}; template = new ServiceTemplate(null, types, null); // Get manager, 10 attempts! for (int i = 0; i < 10; i++) { Object obj = registrar.lookup(template); if (obj instanceof TransactionManager) { manager = (TransactionManager) obj; break; } System.out.println("BasicService. TransactionManager not " + "available. Trying again..."); Thread.sleep(MAX_LOOKUP_WAIT); } } catch (Exception e) { e.printStackTrace(); } }
public static void main(String[] args) throws NamingException, RemoteException { System.setProperty("java.security.policy", "client.policy"); System.setSecurityManager(new SecurityManager()); Context namingContext = new InitialContext(); System.out.print("RMI registry bindings: "); NamingEnumeration<NameClassPair> e = namingContext.list("rmi://localhost/"); while (e.hasMore()) System.out.println(e.next().getName()); String url = "rmi://localhost/central_warehouse"; Warehouse centralWarehouse = (Warehouse) namingContext.lookup(url); Scanner in = new Scanner(System.in); System.out.print("Enter keywords: "); List<String> keywords = Arrays.asList(in.nextLine().split("\\s+")); Product prod = centralWarehouse.getProduct(keywords); System.out.println(prod.getDescription() + ": " + prod.getPrice()); }
private static void setup() { try { NotActivatableInterface rsi; // Remote server interface System.setSecurityManager(new RMISecurityManager()); rsi = (NotActivatableInterface) Activatable.register(ACTIVATION_DESC); System.out.println("Got stub for " + SERVER_OBJECT + " implementation"); Naming.rebind(SERVER_OBJECT, rsi); System.out.println("Exported " + SERVER_OBJECT + " implementation"); } catch (Exception e) { System.err.println("Exception: " + e); e.printStackTrace(); } }
public static void main(String args[]) { /* * Create and install a security manager */ if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); } try { Registry registry = LocateRegistry.getRegistry(2002); Hello obj = (Hello) registry.lookup("Hello"); String message = obj.sayHello(); System.out.println(message); } catch (Exception e) { System.out.println("HelloClient exception: " + e.getMessage()); e.printStackTrace(); } }
public static void main(String[] args) { String host = args[0]; int port = Integer.parseInt(args[1]); if (System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager()); } String name = "//" + host + ":" + port + "/EquationSolver"; double[][] A = { {4.0, 3.0, 1.0}, {2.0, -6.0, 4.0}, {7.0, 5.0, 3.0} }; double[] b = {17.0, 8.0, 32.0}; try { EquationSolver solver = (EquationSolver) Naming.lookup(name); double[] x = solver.solve(A, b); StringBuffer sb = new StringBuffer(); for (int i = 0; i < x.length; i++) { sb.append(x[i]); sb.append(' '); } System.out.println(sb); } catch (RemoteException ex) { ex.printStackTrace(System.err); } catch (NotBoundException ex) { ex.printStackTrace(System.err); } catch (MalformedURLException ex) { ex.printStackTrace(System.err); } }
// we define the method for downloading when pressing on the download button public void qrvidlink() { try { System.setSecurityManager(new SecurityManager()); ipadd = tfIP.getText(); Interface client = (Interface) Naming.lookup("rmi://" + ipadd + "/getvid"); // Get the String entered into the TextField tfInput, convert to int link = tfInput.getText(); vlink = client.getvid(link); // here we receive the image serialized into bytes from the server and // saved it on the client as png image byte[] bytimg = client.qrvid(vlink); BufferedImage img = ImageIO.read(new ByteArrayInputStream(bytimg)); File outputfile = new File("qrcode.png"); ImageIO.write(img, "png", outputfile); // img= new ImageIcon(bytimg.toByteArray()); } catch (Exception e) { System.out.println("[System] Server failed: " + e); } }
public static void main(String args[]) throws RemoteException, InvalidTransactionException, TransactionAbortedException { System.setSecurityManager(new RMISecurityManager()); String rmiPort = System.getProperty("rmiPort"); if (rmiPort == null) { rmiPort = ""; } else if (!rmiPort.equals("")) { rmiPort = "//:" + rmiPort + "/"; } try { TransactionManagerImpl obj = new TransactionManagerImpl(); Naming.rebind(rmiPort + TransactionManager.RMIName, obj); System.out.println("TM bound"); } catch (Exception e) { System.err.println("TM not bound:" + e); System.exit(1); } enlistList = new HashMap<Integer, Set<ResourceManager>>(); File f = new File(enlistFile); if (f.exists()) { try { ObjectInputStream fin = new ObjectInputStream(new FileInputStream(f)); enlistList = (HashMap<Integer, Set<ResourceManager>>) fin.readObject(); fin.close(); } catch (Exception e) { e.printStackTrace(); } } protocolDB = new HashMap<Integer, Map<String, TwoPC_ST>>(); File f2 = new File(protocolDBFile); if (f2.exists()) { try { ObjectInputStream fin2 = new ObjectInputStream(new FileInputStream(f2)); protocolDB = (HashMap<Integer, Map<String, TwoPC_ST>>) fin2.readObject(); fin2.close(); } catch (Exception e) { e.printStackTrace(); } // recovery for (Integer i : protocolDB.keySet()) { if (i > xidCounter) { xidCounter = i + 1; } Map<String, TwoPC_ST> lastST = protocolDB.get(i); boolean re1 = true; for (TwoPC_ST st : lastST.values()) re1 &= (st == TwoPC_ST.Committed); if (re1) { protocolDB.remove(i); enlistList.remove(i); continue; } System.out.println("TM recovery xid: " + i + " from half commit."); Set<ResourceManager> commitSet = enlistList.get(i); boolean re2 = true; Set<ResourceManager> commitSet2 = new HashSet<ResourceManager>(); for (ResourceManager r : commitSet) { if (r.getStatus(i) == TwoPC_ST.Prepared) { System.out.println("TM recovery " + i + " in " + r.getMyRMIName()); commitSet2.add(r); } else if (r.getStatus(i) == TwoPC_ST.Committed) ; else re2 = false; } System.out.println("here 1"); if (re2) { for (ResourceManager r : commitSet2) { r.commit(i); } protocolDB.remove(i); enlistList.remove(i); } } } }
public static void main(String args[]) { if (args.length != 2) { System.err.println("Uso: ObservadorCentralita hostregistro numPuertoRegistro"); return; } // Instancia gestor de seguridad if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); } try { // Obtiene referencia remota del servicio de rmiregistry ServicioCentralita srv = (ServicioCentralita) Naming.lookup("//" + args[0] + ":" + args[1] + "/Centralita"); // | |-> Número de // puerto escucha // |-> Host en el que se ejecuta el // servicio String nombreServicio = "default"; while (nombreServicio == "default") { // Captura el nombre del servicio System.out.println( "Elija el servicio:\n\t[1] Bomberos\n\t[2] Sanitarios\n\t[3] Policía\n\t[4] Guardia Civil"); Scanner input = new Scanner(System.in); String tipoServicio = input.nextLine(); switch (tipoServicio) { case "1": nombreServicio = "Bomberos"; break; case "2": nombreServicio = "Sanitarios"; break; case "3": nombreServicio = "Policia"; break; case "4": nombreServicio = "Guardia Civil"; break; default: nombreServicio = "default"; break; } } // Crea nuevo observador y lo registra en la lista ObservadorImpl o = new ObservadorImpl(nombreServicio); // Llamada al método remoto 'addObservador' del servicio srv.addObservador(o, nombreServicio); // Comrpeuba el nombre del servicio para imprimir código de color if (nombreServicio.equals("Bomberos")) { System.out.println( "\u001B[31mObservador " + nombreServicio + " registrado en la centralita\u001B[0m\n"); } else if (nombreServicio.equals("Sanitarios")) { System.out.println( "\u001B[35mObservador " + nombreServicio + " registrado en la centralita\u001B[0m\n"); } else if (nombreServicio.equals("Policia")) { System.out.println( "\u001B[34mObservador " + nombreServicio + " registrado en la centralita\u001B[0m\n"); } else if (nombreServicio.equals("Guardia Civil")) { System.out.println( "\u001B[32mObservador " + nombreServicio + " registrado en la centralita\u001B[0m\n"); } // Se mantiene esperando hasta que se para con Ctrl+D System.out.println("Para salir, pulsar Ctrl+D\n"); Scanner sleep = new Scanner(System.in); while (sleep.hasNextInt()) {} // Elimina de la lista al observador. Llamada al método remoto 'delObservador' del servicio srv.delObservador(o, nombreServicio); System.exit(0); } // Excepción RMI catch (RemoteException e) { System.err.println("Error de comunicación: " + e.toString()); } // Excepción cliente catch (Exception e) { System.err.println("Excepción en ObservadorCentralita: "); e.printStackTrace(); } }