Example usage for java.rmi RMISecurityManager RMISecurityManager

List of usage examples for java.rmi RMISecurityManager RMISecurityManager

Introduction

In this page you can find the example usage for java.rmi RMISecurityManager RMISecurityManager.

Prototype

public RMISecurityManager() 

Source Link

Document

Constructs a new RMISecurityManager .

Usage

From source file:org.apache.jcs.auxiliary.remote.RemoteUtils.java

/**
 * Creates and exports a registry on the specified port of the local host.
 * <p>//from w  w w. j  a v  a 2s.co m
 * @param port
 * @return the port the registry was started on
 * @throws RemoteException
 */
public static int createRegistry(int port) throws RemoteException {
    if (log.isInfoEnabled()) {
        log.info("createRegistry> setting security manager");
    }
    System.setSecurityManager(new RMISecurityManager());

    if (port < 1024) {
        if (log.isInfoEnabled()) {
            log.info("Port chosen was less than 1024, will use default [" + Registry.REGISTRY_PORT
                    + "] instead.");
        }
        port = Registry.REGISTRY_PORT;
    }

    if (log.isInfoEnabled()) {
        log.info("createRegistry> creating registry on port [" + port + "]");
    }
    LocateRegistry.createRegistry(port);
    return port;
}

From source file:org.lnicholls.galleon.server.Server.java

public static void setup(ArrayList errors) {
    System.setProperty("os.user.home", System.getProperty("user.home"));

    System.setProperty("http.agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");

    try {/*from www. j  av  a  2  s . c  om*/
        File file = new File(".");
        String root = file.getAbsolutePath() + "/..";

        if (System.getProperty("root") == null)
            System.setProperty("root", root);
        else
            root = System.getProperty("root");

        File check = new File(System.getProperty("root"));
        if (!check.exists() || !check.isDirectory())
            errors.add("Invalid system propery: root=" + System.getProperty("root"));

        System.setProperty("user.home", System.getProperty("root"));

        if (System.getProperty("bin") == null)
            System.setProperty("bin", root + "/bin");

        check = new File(System.getProperty("bin"));
        if (!check.exists() || !check.isDirectory())
            errors.add("Invalid system propery: bin=" + System.getProperty("bin"));

        if (System.getProperty("conf") == null)
            System.setProperty("conf", root + "/conf");

        check = new File(System.getProperty("conf"));
        if (!check.exists() || !check.isDirectory())
            errors.add("Invalid system propery: conf=" + System.getProperty("conf"));

        if (System.getProperty("cache") == null)
            System.setProperty("cache", root + "/data");

        check = new File(System.getProperty("cache"));
        if (!check.exists() || !check.isDirectory())
            errors.add("Invalid system propery: cache=" + System.getProperty("cache"));

        if (System.getProperty("data") == null)
            System.setProperty("data", root + "/data");

        check = new File(System.getProperty("data"));
        if (!check.exists() || !check.isDirectory())
            errors.add("Invalid system propery: data=" + System.getProperty("data"));

        if (System.getProperty("apps") == null)
            System.setProperty("apps", root + "/apps");

        check = new File(System.getProperty("apps"));
        if (!check.exists() || !check.isDirectory())
            errors.add("Invalid system propery: apps=" + System.getProperty("apps"));

        if (System.getProperty("hme") == null)
            System.setProperty("hme", root + "/hme");

        check = new File(System.getProperty("hme"));
        if (!check.exists() || !check.isDirectory())
            errors.add("Invalid system propery: hme=" + System.getProperty("hme"));

        if (System.getProperty("skins") == null)
            System.setProperty("skins", root + "/skins");

        check = new File(System.getProperty("skins"));
        if (!check.exists() || !check.isDirectory())
            errors.add("Invalid system propery: skins=" + System.getProperty("skins"));

        if (System.getProperty("logs") == null)
            System.setProperty("logs", root + "/logs");

        check = new File(System.getProperty("logs"));
        if (!check.exists() || !check.isDirectory())
            errors.add("Invalid system propery: logs=" + System.getProperty("logs"));

        if (System.getProperty("demo") != null)
            mDemoMode = Boolean.valueOf(System.getProperty("demo")).booleanValue();

        if (System.getProperty("remoteHost") != null) {
            System.setSecurityManager(new RMISecurityManager() {
                public void checkConnect(String host, int port) {
                    if (host != null && host.equals(System.getProperty("remoteHost")))
                        return;
                    throw new SecurityException("Invalid remote host: " + host);
                }

                public void checkConnect(String host, int port, Object context) {
                    if (host != null && host.equals(System.getProperty("remoteHost")))
                        return;
                    throw new SecurityException("Invalid remote host: " + host);
                }
            });
        }
    } catch (Exception ex) {
        Tools.logException(Server.class, ex);
    }
}

From source file:org.mule.transport.rmi.RmiMessageReceiver.java

@SuppressWarnings("unchecked")
@Override/* w  w  w . j a v a2  s. co m*/
protected void doConnect() throws Exception {
    System.setProperty("java.security.policy", connector.getSecurityPolicy());

    // Set security manager
    if (System.getSecurityManager() == null) {
        System.setSecurityManager(new RMISecurityManager());
    }

    // Get methodName
    String methodName = MapUtils.getString(endpoint.getEndpointURI().getParams(),
            MuleProperties.MULE_METHOD_PROPERTY, null);
    if (null == methodName) {
        methodName = (String) endpoint.getProperty(MuleProperties.MULE_METHOD_PROPERTY);

        if (null == methodName) {
            throw new ConnectException(RmiMessages.messageParamServiceMethodNotSet(), this);
        }
    }

    // Get remoteObject
    remoteObject = connector.getRemoteObject(getEndpoint());

    // Set methodArguments
    List<Object> args = (List<Object>) endpoint.getProperty(RmiConnector.PROPERTY_SERVICE_METHOD_PARAMS_LIST);
    Class[] argTypes = new Class[] {};
    if (args == null) {
        logger.info(RmiConnector.PROPERTY_SERVICE_METHOD_PARAMS_LIST
                + " not set on endpoint, assuming method call has no arguments");
        methodArguments = ClassUtils.NO_ARGS;
    } else {
        argTypes = connector.getArgTypes(endpoint.getProperty(RmiConnector.PROPERTY_SERVICE_METHOD_PARAM_TYPES),
                RequestContext.getEvent());
        methodArguments = new Object[args.size()];
        methodArguments = args.toArray(methodArguments);
    }

    // Set invokeMethod
    invokeMethod = remoteObject.getClass().getMethod(methodName, argTypes);
}

From source file:org.ublog.benchmark.social.SocialBenchmark.java

private GraphInterface getRemoteGraphServer(String serverName, int serverPort) {
    if (System.getSecurityManager() == null) {
        System.setSecurityManager(new RMISecurityManager());
    }/*from   ww w .  jav  a 2  s  .c  o m*/
    try {
        if (logger.isInfoEnabled()) {
            logger.info("Trying to connect to graph server");
        }
        Registry reg = LocateRegistry.getRegistry(serverName, serverPort);
        System.out.println("reg " + reg.list().toString());
        return (GraphInterface) reg.lookup("Graph");

    } catch (NotBoundException ex) {
        Logger.getLogger("global").log(null, ex);
        return null;
    } catch (RemoteException ex) {
        ex.printStackTrace();
        Logger.getLogger("global").log(null, ex);
        return null;
    }
}