Exemplo n.º 1
2
  /**
   * 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());
    }
  }
Exemplo n.º 2
0
  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 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();
    }
  }