public static void main(String[] args) throws Exception { System.setSecurityManager(new SecurityManager()); // Create an uninitialized class loader try { new ClassLoader(null) { @Override protected void finalize() { loader = this; } }; } catch (SecurityException exc) { // Expected } System.gc(); System.runFinalization(); // if 'loader' isn't null, need to ensure that it can't be used as // parent if (loader != null) { try { // Create a class loader with 'loader' being the parent URLClassLoader child = URLClassLoader.newInstance(new URL[0], loader); throw new RuntimeException("Test Failed!"); } catch (SecurityException se) { System.out.println("Test Passed: Exception thrown"); } } else { System.out.println("Test Passed: Loader is null"); } }
/** * Runs Runnable r with a security policy that permits precisely the specified permissions. If * there is no current security manager, the runnable is run twice, both with and without a * security manager. We require that any security manager permit getPolicy/setPolicy. */ public void runWithPermissions(Runnable r, Permission... permissions) { SecurityManager sm = System.getSecurityManager(); if (sm == null) { r.run(); Policy savedPolicy = Policy.getPolicy(); try { Policy.setPolicy(permissivePolicy()); System.setSecurityManager(new SecurityManager()); runWithPermissions(r, permissions); } finally { System.setSecurityManager(null); Policy.setPolicy(savedPolicy); } } else { Policy savedPolicy = Policy.getPolicy(); AdjustablePolicy policy = new AdjustablePolicy(permissions); Policy.setPolicy(policy); try { r.run(); } finally { policy.addPermission(new SecurityPermission("setPolicy")); Policy.setPolicy(savedPolicy); } } }
@TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "ClassLoader", args = {}) public void test_ClassLoader() { PublicClassLoader pcl = new PublicClassLoader(); SecurityManager sm = new SecurityManager() { RuntimePermission rp = new RuntimePermission("getProtectionDomain"); public void checkCreateClassLoader() { throw new SecurityException(); } public void checkPermission(Permission perm) { if (perm.equals(rp)) { throw new SecurityException(); } } }; SecurityManager oldSm = System.getSecurityManager(); System.setSecurityManager(sm); try { new PublicClassLoader(); fail("SecurityException should be thrown."); } catch (SecurityException e) { // expected } finally { System.setSecurityManager(oldSm); } }
/** Test an invalid directory name, see if an error occurs */ @Test public void testInvalidDirectory() { System.setSecurityManager(new NoExitSecurityManager()); boolean exceptionThrown = false; cobertura = new Cobertura(null); try { cobertura.executeCobertura(); } catch (ExitException e) { exceptionThrown = true; assertEquals( "Exit status invalid", OperiasStatus.ERROR_COBERTURA_TASK_CREATION.ordinal(), e.status); } exceptionThrown = false; cobertura = new Cobertura("src/../"); try { cobertura.executeCobertura(); } catch (ExitException e) { exceptionThrown = true; assertEquals( "Exit status invalid", OperiasStatus.ERROR_COBERTURA_TASK_OPERIAS_EXECUTION.ordinal(), e.status); } assertTrue("No exception was thrown", exceptionThrown); System.setSecurityManager(null); }
@TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "getParent", args = {}) public void test_getParent() { PublicClassLoader pcl = new PublicClassLoader(); assertNotNull(pcl.getParent()); ClassLoader cl = getClass().getClassLoader().getParent(); assertNotNull(cl); SecurityManager sm = new SecurityManager() { final String perName = "getClassLoader"; public void checkPermission(Permission perm) { if (perm.getName().equals(perName)) { throw new SecurityException(); } } }; SecurityManager oldSm = System.getSecurityManager(); System.setSecurityManager(sm); try { getClass().getClassLoader().getParent(); fail("Should throw SecurityException"); } catch (SecurityException e) { // expected } finally { System.setSecurityManager(oldSm); } }
public void execute(final ClassLoader classLoader) throws Exception { assert classLoader != null; final StreamSet streams = StreamSet.system(); final SecurityManager sm = System.getSecurityManager(); System.setSecurityManager(new NoExitSecurityManager()); try { final groovy.ui.Console console = new groovy.ui.Console(classLoader, new Binding()) { public void exit(final EventObject event) { try { super.exit(event); } finally { synchronized (lock) { lock.notifyAll(); } } } }; console.run(); synchronized (lock) { lock.wait(); } } finally { System.setSecurityManager(sm); StreamSet.system(streams); } }
/** @tests java.lang.ClassLoader#getSystemClassLoader() */ @TestTargetNew( level = TestLevel.SUFFICIENT, notes = "", method = "getSystemClassLoader", args = {}) public void test_getSystemClassLoader() { // Test for method java.lang.ClassLoader // java.lang.ClassLoader.getSystemClassLoader() ClassLoader cl = ClassLoader.getSystemClassLoader(); java.io.InputStream is = cl.getResourceAsStream(SYSTEM_RESOURCE_PATH); assertNotNull("Failed to find resource from system classpath", is); try { is.close(); } catch (java.io.IOException e) { } SecurityManager sm = new SecurityManager() { public void checkPermission(Permission perm) { if (perm.getName().equals("getClassLoader")) { throw new SecurityException(); } } }; SecurityManager oldManager = System.getSecurityManager(); System.setSecurityManager(sm); try { ClassLoader.getSystemClassLoader(); } catch (SecurityException se) { // expected } finally { System.setSecurityManager(oldManager); } /* * // java.lang.Error is not thrown on RI, but it's specified. * * String keyProp = "java.system.class.loader"; * String oldProp = System.getProperty(keyProp); * System.setProperty(keyProp, "java.test.UnknownClassLoader"); * boolean isFailed = false; * try { * ClassLoader.getSystemClassLoader(); * isFailed = true; * } catch(java.lang.Error e) { * //expected * } finally { * if(oldProp == null) { * System.clearProperty(keyProp); * } else { * System.setProperty(keyProp, oldProp); * } * } * assertFalse("java.lang.Error was not thrown.", isFailed); */ }
/** test main method. Import should print help and call System.exit */ @Test public void testImportMain() throws Exception { PrintStream oldPrintStream = System.err; SecurityManager SECURITY_MANAGER = System.getSecurityManager(); LauncherSecurityManager newSecurityManager = new LauncherSecurityManager(); System.setSecurityManager(newSecurityManager); ByteArrayOutputStream data = new ByteArrayOutputStream(); String[] args = {}; System.setErr(new PrintStream(data)); try { System.setErr(new PrintStream(data)); try { RowCounter.main(args); fail("should be SecurityException"); } catch (SecurityException e) { assertEquals(-1, newSecurityManager.getExitCode()); assertTrue(data.toString().contains("Wrong number of parameters:")); assertTrue( data.toString() .contains( "Usage: RowCounter [options] <tablename> " + "[--starttime=[start] --endtime=[end] " + "[--range=[startKey],[endKey]] " + "[<column1> <column2>...]")); assertTrue(data.toString().contains("-Dhbase.client.scanner.caching=100")); assertTrue(data.toString().contains("-Dmapreduce.map.speculative=false")); } data.reset(); try { args = new String[2]; args[0] = "table"; args[1] = "--range=1"; RowCounter.main(args); fail("should be SecurityException"); } catch (SecurityException e) { assertEquals(-1, newSecurityManager.getExitCode()); assertTrue( data.toString() .contains( "Please specify range in such format as \"--range=a,b\" or, with only one boundary," + " \"--range=,b\" or \"--range=a,\"")); assertTrue( data.toString() .contains( "Usage: RowCounter [options] <tablename> " + "[--starttime=[start] --endtime=[end] " + "[--range=[startKey],[endKey]] " + "[<column1> <column2>...]")); } } finally { System.setErr(oldPrintStream); System.setSecurityManager(SECURITY_MANAGER); } }
@Test public void testPhantomDeleteOnDetecting() { if (!_shouldTest()) { return; } final AtomicInteger checkDeleteCount = new AtomicInteger(); final AtomicBoolean checkFlag = new AtomicBoolean(); SecurityManager securityManager = new SecurityManager() { @Override public void checkDelete(String file) { if (!checkFlag.get() && file.contains("temp-fifo-")) { checkFlag.set(true); if (checkDeleteCount.getAndIncrement() == 0) { Assert.assertTrue(new File(file).delete()); } checkFlag.set(false); } } @Override public void checkRead(String file) { if (!checkFlag.get() && file.contains("temp-fifo-")) { try { checkFlag.set(true); new File(file).createNewFile(); checkFlag.set(false); } catch (IOException ioe) { Assert.fail(ioe.getMessage()); } } } @Override public void checkPermission(Permission permission) {} }; System.setSecurityManager(securityManager); try { Assert.assertTrue(FIFOUtil.isFIFOSupported()); } finally { System.setSecurityManager(null); } Assert.assertEquals(2, checkDeleteCount.get()); }
/** verify Identity.toString() throws Exception is permission is denied */ public void testToString1() { MySecurityManager sm = new MySecurityManager(); sm.denied.add(new SecurityPermission("printIdentity")); System.setSecurityManager(sm); try { new IdentityStub("testToString").toString(); fail("SecurityException should be thrown"); } catch (SecurityException ok) { } finally { System.setSecurityManager(null); } }
/** verify Identity.setInfo() throws SecurityException if permission is denied */ public void testSetInfo() throws Exception { MySecurityManager sm = new MySecurityManager(); sm.denied.add(new SecurityPermission("setIdentityInfo")); System.setSecurityManager(sm); try { new IdentityStub("testSetInfo").setInfo("some info"); fail("SecurityException should be thrown"); } catch (SecurityException ok) { } finally { System.setSecurityManager(null); } }
/** * verify addCertificate(Certificate certificate) throws SecurityException is permission is denied */ public void testAddCertificate3() throws Exception { MySecurityManager sm = new MySecurityManager(); sm.denied.add(new SecurityPermission("addIdentityCertificate")); System.setSecurityManager(sm); try { new IdentityStub("iii").addCertificate(new CertificateStub("ccc", null, null, null)); fail("SecurityException should be thrown"); } catch (SecurityException ok) { } finally { System.setSecurityManager(null); } }
/** * verify removeCertificate(Certificate certificate) throws SecurityException if permission is * denied */ public void testRemoveCertificate2() throws Exception { MySecurityManager sm = new MySecurityManager(); sm.denied.add(new SecurityPermission("removeIdentityCertificate")); Identity i = new IdentityStub("iii"); i.addCertificate(new CertificateStub("ccc", null, null, null)); System.setSecurityManager(sm); try { i.removeCertificate(i.certificates()[0]); fail("SecurityException should be thrown"); } catch (SecurityException ok) { } finally { System.setSecurityManager(null); } }
/** * Write object fields to string * * @throws IllegalArgumentException if obj == null */ public static String objectFieldsToString(Object obj) throws IllegalArgumentException { if (obj == null) { throw new IllegalArgumentException("obj == null"); } // Temporarily disable the security manager SecurityManager oldsecurity = System.getSecurityManager(); System.setSecurityManager( new SecurityManager() { @Override public void checkPermission(Permission perm) {} }); Class<?> c = obj.getClass(); StringBuffer buf = new StringBuffer(FULLY_QUALIFIED_NAMES ? c.getName() : removePackageName(c.getName())); while (c != Object.class) { Field[] fields = c.getDeclaredFields(); if (fields.length > 0) buf = buf.append(" ("); for (int i = 0; i < fields.length; i++) { // Make this field accessible fields[i].setAccessible(true); try { Class<?> type = fields[i].getType(); String name = fields[i].getName(); Object value = fields[i].get(obj); // name=value : type buf = buf.append(name); buf = buf.append("="); buf = buf.append(value == null ? "null" : value.toString()); buf = buf.append(" : "); buf = buf.append( FULLY_QUALIFIED_NAMES ? type.getName() : removePackageName(type.getName())); } catch (IllegalAccessException e) { e.printStackTrace(); } buf = buf.append(i + 1 >= fields.length ? ")" : ","); } c = c.getSuperclass(); } // Reinstate the security manager System.setSecurityManager(oldsecurity); return buf.toString(); }
/** @param args */ public static void main(String[] args) { if (args.length < 1) { System.out.println("Uso echo <host>"); System.exit(1); } if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); } BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in)); PrintWriter stdOut = new PrintWriter(System.out); String input, output; try { EchoInt eo = (EchoInt) Naming.lookup("//" + args[0] + "/miEcho"); stdOut.print("> "); stdOut.flush(); while ((input = stdIn.readLine()) != null) { output = eo.echo(input); stdOut.println(output); stdOut.print("> "); stdOut.flush(); } } catch (Exception e) { System.err.println("RMI Echo Client error: " + e.getLocalizedMessage()); } }
/** Initializes SecurityManager for the environment Can only happen once! */ static void configure(Environment environment) throws Exception { // set properties for jar locations setCodebaseProperties(); // enable security policy: union of template and environment-based paths, and possibly plugin // permissions Policy.setPolicy( new ESPolicy(createPermissions(environment), getPluginPermissions(environment))); // enable security manager System.setSecurityManager( new SecurityManager() { // we disable this completely, because its granted otherwise: // 'Note: The "exitVM.*" permission is automatically granted to // all code loaded from the application class path, thus enabling // applications to terminate themselves.' @Override public void checkExit(int status) { throw new SecurityException("exit(" + status + ") not allowed by system policy"); } }); // do some basic tests selfTest(); }
/** * Proper execution of the maven project, but the coverage file was not found, can be test by * giving a random non existing output directory */ @Test public void testCoverageXMLNotFound() { System.setSecurityManager(new NoExitSecurityManager()); boolean exceptionThrown = false; cobertura = new Cobertura("src/test/resources/simpleMavenProject"); cobertura.setOutputDirectory("target/randomFolder"); try { cobertura.executeCobertura(); } catch (ExitException e) { exceptionThrown = true; assertEquals("Exit status invalid", OperiasStatus.COVERAGE_XML_NOT_FOUND.ordinal(), e.status); } System.setSecurityManager(null); assertTrue("No exception was thrown", exceptionThrown); }
public synchronized void run() { String programPath = epubcheck1_recursive_checker1 .class .getProtectionDomain() .getCodeSource() .getLocation() .getFile(); try { programPath = new File(programPath).getCanonicalPath() + File.separator; } catch (IOException ex) { ex.printStackTrace(); System.exit(-1); } System.setProperty("java.rmi.server.codebase", "file://" + programPath + File.separator); System.setProperty("java.security.policy", "file://" + programPath + "rmi.policy"); System.setSecurityManager(new SecurityManager()); try { LocateRegistry.createRegistry(Registry.REGISTRY_PORT); } catch (RemoteException ex) { StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); ex.printStackTrace(printWriter); this.messageException = stringWriter.toString(); } }
@Before public void setUp() throws Exception { System.setProperty("java.security.policy", "polis.policy"); if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); } try { Registry registry = LocateRegistry.getRegistry("localhost"); articoloFacade = (IArticoloMenuFacade) registry.lookup("ArticoloFacade"); userFacade = (IUserFacade) registry.lookup("UserFacade"); } catch (Exception e) { System.err.println("Exception to obtain the reference to the remote object: " + e); fail("Exception"); } user = userFacade.login(Ruolo.TEST, "test"); bevanda = new Bevanda(); bevanda.setCapacita(1000F); bevanda.setNome("BEVANDA TEST"); bevanda.setTipoArticolo("Bevanda"); bevanda.setTipoPietanza(TipoPietanza.BEVANDA.ordinal()); bevanda = articoloFacade.inserisciBevandaMenu(user, bevanda); articoloFacade.inserisciBevandaMagazzino(user, bevanda.getId(), 1L, 10000); }
public JParSolverImpl(String host, int port) throws RemoteException { if (System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager()); } String serverName = "JParServer"; try { Registry registry = LocateRegistry.getRegistry(host, port); this.server = (JParServer) registry.lookup(serverName); } catch (AccessException e) { System.err.println("Solver: Java RMI AccessException: " + e.getMessage()); return; } catch (RemoteException e) { System.err.println("Solver: Java RMI Exception: " + e.getMessage()); return; } catch (NotBoundException e) { System.err.println("Solver: " + serverName + " lookup failed:" + e.getMessage()); return; } catch (Exception e) { System.err.println("Solver: JParSolver Constructor:" + e.getMessage()); e.printStackTrace(); return; } this.taskSynchObj = new Object(); this.pendingJob = JOB_WAITING_FOR; if (this.register()) { initialized = true; } }
/** * This test will run both with and without a security manager. * * <p>The test starts a number of threads that will call LogManager.readConfiguration() * concurrently (ReadConf), then starts a number of threads that will create new loggers * concurrently (AddLogger), and then two additional threads: one (Stopper) that will stop the * test after 4secs (TIME ms), and one DeadlockDetector that will attempt to detect deadlocks. If * after 4secs no deadlock was detected and no exception was thrown then the test is considered a * success and passes. * * <p>This procedure is done twice: once without a security manager and once again with a security * manager - which means the test takes ~8secs to run. * * <p>Note that 8sec may not be enough to detect issues if there are some. This is a best effort * test. * * @param args the command line arguments * @throws java.lang.Exception if the test fails. */ public static void main(String[] args) throws Exception { File config = new File(System.getProperty("test.src", "."), "deadlockconf.properties"); if (!config.canRead()) { System.err.println("Can't read config file: test cannot execute."); System.err.println("Please check your test environment: "); System.err.println("\t -Dtest.src=" + System.getProperty("test.src", ".")); System.err.println("\t config file is: " + config.getAbsolutePath()); throw new RuntimeException("Can't read config file: " + config.getAbsolutePath()); } System.setProperty("java.util.logging.config.file", config.getAbsolutePath()); // test without security System.out.println("No security"); test(); // test with security System.out.println("\nWith security"); Policy.setPolicy( new Policy() { @Override public boolean implies(ProtectionDomain domain, Permission permission) { if (super.implies(domain, permission)) return true; // System.out.println("Granting " + permission); return true; // all permissions } }); System.setSecurityManager(new SecurityManager()); test(); }
public static void main(String[] args) throws Exception { System.setProperty( "java.security.policy", System.getProperty("user.home") + "/jini/policy.all"); if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); System.out.println("DynamicDownloadRmiClient.main() setting custom security manager"); } LookupLocator lookup = new LookupLocator("jini://localhost:4160"); ServiceRegistrar registrar = lookup.getRegistrar(); // give the poor guys some time to lookup Thread.sleep(10); UserService userService = (UserService) registrar.lookup( new ServiceTemplate( null, new Class[] {UserService.class}, new Entry[] {new Name(UserService.class.getSimpleName())})); System.out.println("Getting current users from remote: " + userService.getCurrentUsers()); BankAccountService bankAccountService = (BankAccountService) registrar.lookup( new ServiceTemplate( null, new Class[] {BankAccountService.class}, new Entry[] {new Name(BankAccountService.class.getSimpleName())})); System.out.println( "Creating bank account from remote, id: " + bankAccountService.createBankAccount("aaa")); }
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); } }
/** Main entry point. */ public static void main(String[] params) { // Load native library for IPC by Unix sockets: System.loadLibrary("mmjipc"); // Install a security manager that disallows System.exit: System.setSecurityManager(new JvmdRunSecurityManager()); // Run jvmd: int status = getSharedInstance().run(); // Uninstalls the security manager: System.setSecurityManager(null); // Exit: System.exit(status); }
/* ------------------------------------------------------------------------------------------------------ * Main Method for the application * ------------------------------------------------------------------------------------------------------ */ public static void main(String[] args) { // Check of the security manager is installed, if not se it. if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); } try { // Locate the RMI registry Registry registry = LocateRegistry.getRegistry(); // Create the Player object ref in the registry and bind it Players players = new Players(); PlayerInterface stubPlayer = (PlayerInterface) UnicastRemoteObject.exportObject(players, 3001); Naming.rebind("rmi://localhost/Players", players); // Similar process for shapes. Shapes Hello = new Shapes(); ShapeInterface stub = (ShapeInterface) UnicastRemoteObject.exportObject(Hello, 3001); Naming.rebind("rmi://localhost/Shapes", Hello); // Confirm to the console the server is ready System.out.println("2Draw Server is ready."); } catch (Exception e) { System.out.println("2Draw Server failed: " + e); e.printStackTrace(); } }
@Before public void setUp() throws Exception { System.setProperty("java.security.policy", "polis.policy"); if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); } try { Registry registry = LocateRegistry.getRegistry("localhost"); userFacade = (IUserFacade) registry.lookup("UserFacade"); ristoranteFacade = (IRistoranteFacade) registry.lookup("RistoranteFacade"); } catch (Exception e) { System.err.println("Exception to obtain the reference to the remote object: " + e); fail("Exception"); } user = userFacade.login(Ruolo.TEST, "test"); Indirizzo indirizzo = new Indirizzo(); indirizzo.setCap("83100"); indirizzo.setCitta("Avellino"); indirizzo.setCivico("23 A"); indirizzo.setId(1000000L); indirizzo.setProvincia("AV"); indirizzo.setVia("via Roma"); ristorante = new Ristorante(); ristorante.setIndirizzo(indirizzo); ristorante.setPartitaIva("01234567890"); ristorante.setRagioneSociale("Ristorante Test"); ristorante = ristoranteFacade.inserisciRistorante(user, ristorante); }
public static void main(String[] args) throws RemoteException, MalformedURLException { if (args.length <= 1) { System.out.println("Usage:\n./papp.sh {server name} {ps}\n"); // notice System.out.println( "Execute before launching: export CLASSPATH=$(pwd)/papp.jar:inters.jar:matrix.jar:queue.jar"); System.out.println("Then: rmiregistry&"); System.exit(0); } if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); } ProcessingAppInterface pa = new ProcessingApp(args[0], Integer.parseInt(args[1])); Registry registry = LocateRegistry.getRegistry(); registry.rebind(args[0], pa); // effacage d'affichage System.out.printf("\033[H\033[2J"); System.out.flush(); // affichage de l'etat de serveru System.out.println("Server: " + pa.getName() + ", ps = " + pa.getPs()); }
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(); } }
@SuppressWarnings("deprecation") @Before public void setUp() throws Exception { System.setProperty("java.security.policy", "polis.policy"); if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); } try { Registry registry = LocateRegistry.getRegistry("localhost"); articoloFacade = (IArticoloMenuFacade) registry.lookup("ArticoloFacade"); userFacade = (IUserFacade) registry.lookup("UserFacade"); } catch (Exception e) { System.err.println("Exception to obtain the reference to the remote object: " + e); fail("Exception"); } user = userFacade.login(Ruolo.TEST, "test"); ingrediente = new Ingrediente(); ingrediente.setNome("INGREDIENTE TEST"); ingrediente.setScadenza(new Date(109, 4, 31)); ingrediente.setVariante(true); ingrediente = articoloFacade.inserisciIngrediente(user, ingrediente); }
@SuppressWarnings("deprecation") @Before public void setUp() throws Exception { System.setProperty("java.security.policy", "polis.policy"); if (System.getSecurityManager() == null) { System.setSecurityManager(new SecurityManager()); } try { Registry registry = LocateRegistry.getRegistry("localhost"); articoloFacade = (IArticoloMenuFacade) registry.lookup("ArticoloFacade"); // CONTROLLARE userFacade = (IUserFacade) registry.lookup("UserFacade"); } catch (Exception e) { System.err.println("Exception to obtain the reference to the remote object: " + e); fail("Exception"); } user = userFacade.login(Ruolo.TEST, "test"); ingrediente = new Ingrediente(); ingrediente.setDescrizione("Ingrediente di test"); ingrediente.setId((long) 1000000L); ingrediente.setNome("Ingrediente di Test"); ingrediente.setTipoIngrediente("IngredienteLungaConservazione"); ingrediente.setScadenza(new Date(109, 1, 21)); ingrediente.setUnitaMisura("g"); ingrediente.setVariante(true); ingrediente = articoloFacade.inserisciIngrediente(user, ingrediente); }