public void actionPerformed(ActionEvent e) { if (e.getSource() == Connect) { if (nbr < 3) { if (nom.getText().length() == 0 || pwd.getPassword().length == 0 || jTextField1.getText().length() == 0) { JOptionPane.showMessageDialog( null, "Vous devez donner votre pseudonyme, votre mot de passe ainsi que l'adresse du serveur de chat", "Informations manquantes", JOptionPane.WARNING_MESSAGE); nbr++; } else { try { J = (Contrat) Naming.lookup("rmi://" + jTextField1.getText() + ":1099/JChat"); } catch (RemoteException ex4) { JOptionPane.showMessageDialog( null, "La connexion au serveur a échoué", "Serveur non démarré", JOptionPane.WARNING_MESSAGE); System.out.println(ex4); nbr++; } catch (MalformedURLException ex4) { JOptionPane.showMessageDialog( null, "Connexion 2", "Erreur de connexion", JOptionPane.WARNING_MESSAGE); nbr++; } catch (NotBoundException ex4) { JOptionPane.showMessageDialog( null, "Serveur non joignable", "Erreur de connexion", JOptionPane.WARNING_MESSAGE); System.out.println(ex4); System.exit(0); } if (J != null) { try { // de la méthode connect distante // Récupération de l'adresse de la machine du client try { adr = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException ex3) { } // Si le nom et le mot de passe fournies par le client sont valides // Envoi du nom et mot de passe pour la vérification de la validité de ce client // ainsi que le num de port // , adresse de la machine du client et nom de l'objet distant du client pour // pouvoir l'invoquer ultérieurementulté num_port = J.get_num_port(); if (J.connect(nom.getText(), new String(pwd.getPassword()), adr, num_port)) { srv_Adr = jTextField1.getText(); srv_state = true; // fermeture de la fenetre de connexion fermer(); try { java.rmi.registry.LocateRegistry.createRegistry(num_port); System.out.println("Ecoute sur le port : " + num_port); // Placement de l'objet distant du client sur sa machine : localhost dans le // registre pour le numéro de port spécifié Naming.rebind("//" + adr + ":" + num_port + "/" + nom.getText(), retourObj()); System.out.println(Naming.list("//" + adr + ":" + num_port)[0]); } catch (MalformedURLException ex2) { System.out.println(ex2); } catch (RemoteException ex1) { System.out.println(ex1); } // Constructeur graphique de la classe Client C = new Client(nom.getText(), new String(pwd.getPassword())); Essai essai = new Essai(); SplashWindowApp splash = new SplashWindowApp(C, 2000, essai); if (J.getnbrcon() >= 2) { System.out.println("Mise à jour de la liste du nouveau connecté"); // Mise à jour de la liste des destinataires du nouveau connecté for (int i = 0; i < J.getnbrcon(); i++) if (J.list_con()[i].compareTo(nom.getText()) != 0) C.ajout(J.list_con()[i]); } } else { JOptionPane.showMessageDialog( null, "Vérifiez votre pseudonyme ou mot de passe"); nbr++; } } catch (RemoteException ex) { System.out.println(ex); } } } if (nbr == 3) { JOptionPane.showMessageDialog(null, "Nombre maximum d'essai est atteint"); System.exit(0); } } } else { if (e.getSource() == Annuler) System.exit(0); } }
public static void main(String args[]) { sameGroup = true; RMID rmid = null; System.err.println("\nRegression test for bug/rfe 4179055\n"); try { TestLibrary.suggestSecurityManager("java.lang.SecurityManager"); registry = java.rmi.registry.LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); // must run with java.lang.SecurityManager or the test // result will be nullified if running with a build where // 4180392 has not been fixed. String smClassName = System.getSecurityManager().getClass().getName(); if (!smClassName.equals("java.lang.SecurityManager")) { TestLibrary.bomb("Test must run with java.lang.SecurityManager"); } // start an rmid. RMID.removeLog(); rmid = RMID.createRMID(); rmid.start(); // rmid.addOptions(new String[] {"-C-Djava.rmi.server.logCalls=true"}); // Ensure that activation groups run with the correct // security manager. // Properties p = new Properties(); p.put("java.security.policy", TestParams.defaultGroupPolicy); p.put("java.security.manager", "java.lang.SecurityManager"); // This action causes the following classes to be created // in this VM (RMI must permit the creation of these classes): // // sun.rmi.server.Activation$ActivationSystemImpl_Stub // sun.rmi.server.Activation$ActivationMonitorImpl_Stub // System.err.println("Create activation group, in a new VM"); ActivationGroupDesc groupDesc = new ActivationGroupDesc(p, null); ActivationSystem system = ActivationGroup.getSystem(); ActivationGroupID groupID = system.registerGroup(groupDesc); System.err.println("register activatable"); // Fix for: 4271615: make sure activation group runs in a new VM ActivationDesc desc = new ActivationDesc(groupID, "StubClassesPermitted", null, null); canCreateStubs = (CanCreateStubs) Activatable.register(desc); // ensure registry stub can be passed in a remote call System.err.println("getting the registry"); registry = canCreateStubs.getRegistry(); // make sure a client cant load just any sun.* class, just // as a sanity check, try to create a class we are not // allowed to access but which was passed in a remote call try { System.err.println("accessing forbidden class"); Object secureRandom = canCreateStubs.getForbiddenClass(); TestLibrary.bomb( "test allowed to access forbidden class," + " sun.security.provider.SecureRandom"); } catch (java.security.AccessControlException e) { // Make sure we received a *local* AccessControlException ByteArrayOutputStream bout = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(bout); e.printStackTrace(ps); ps.flush(); String trace = new String(bout.toByteArray()); if ((trace.indexOf("exceptionReceivedFromServer") >= 0) || trace.equals("")) { throw e; } System.err.println("received expected local access control exception"); } // make sure that an ActivationGroupID can be passed in a // remote call; this is slightly more inclusive than // just passing a reference to the activation system System.err.println("returning group desc"); canCreateStubs.returnGroupID(); // Clean up object System.err.println("Deactivate object via method call"); canCreateStubs.shutdown(); System.err.println("\nsuccess: StubClassesPermitted test passed "); } catch (Exception e) { TestLibrary.bomb("\nfailure: unexpected exception ", e); } finally { try { Thread.sleep(4000); } catch (InterruptedException e) { } canCreateStubs = null; ActivationLibrary.rmidCleanup(rmid); System.err.println("rmid shut down"); } }