src/share/classes/sun/rmi/server/Activation.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 72,91 **** --- 72,93 ---- import java.rmi.server.RMIClassLoader; import java.rmi.server.RMIClientSocketFactory; import java.rmi.server.RMIServerSocketFactory; import java.rmi.server.RemoteObject; import java.rmi.server.RemoteServer; + import java.rmi.server.ServerNotActiveException; import java.rmi.server.UnicastRemoteObject; import java.security.AccessControlException; import java.security.AccessController; import java.security.AllPermission; import java.security.CodeSource; import java.security.Permission; import java.security.PermissionCollection; import java.security.Permissions; import java.security.Policy; import java.security.PrivilegedAction; + import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; import java.security.cert.Certificate; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays;
*** 105,114 **** --- 107,117 ---- import sun.rmi.log.ReliableLog; import sun.rmi.registry.RegistryImpl; import sun.rmi.runtime.NewThreadAction; import sun.rmi.server.UnicastServerRef; import sun.rmi.transport.LiveRef; + import sun.rmi.transport.tcp.TCPTransport; import sun.security.action.GetBooleanAction; import sun.security.action.GetIntegerAction; import sun.security.action.GetPropertyAction; import sun.security.provider.PolicyFile; import com.sun.rmi.rmid.ExecPermission;
*** 180,189 **** --- 183,217 ---- getInt("sun.rmi.activation.execTimeout", 30000); private static final Object initLock = new Object(); private static boolean initDone = false; + private static final InetAddress remoteClientAddress; + static { + remoteClientAddress = java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction<InetAddress>() { + public InetAddress run() { + String remoteClientProp = + System.getProperty("sun.rmi.activation.remoteClient", + null); + + if (remoteClientProp == null) { + return null; + } + + try { + return InetAddress.getByName(remoteClientProp); + } catch (Throwable t) { + System.err.println("Activation: Cannot get the IP " + + "address of the remote client: " + + remoteClientProp); + } + + return null; + }}); + } + // this should be a *private* method since it is privileged private static int getInt(String name, int def) { return AccessController.doPrivileged(new GetIntegerAction(name, def)); }
*** 205,214 **** --- 233,294 ---- * snapshot is taken during the first incarnation of rmid. */ private Activation() {} /** + * Check that the caller has access to this interface. + * <p> + * Use the default policy as implemented in RegistryImpl.checkAccess, + * unless the sun.rmi.activation.remoteClient property is set, and in + * that case only allow access from that host. + * + * @param op name of operation used to create a meaningful exception + * message, the parameter is not used to determine access + */ + static void checkAccess(String op) throws AccessException { + if (remoteClientAddress == null) { + /* + * Note, the op arg to checkAccess is only used to build an + * access exception message if needed. + */ + RegistryImpl.checkAccess(op); + return; + } + + InetAddress clientHost; + + try { + // Get client host that this operation was made from. + final String clientHostName = TCPTransport.getClientHost(); + + try { + clientHost = java.security.AccessController.doPrivileged( + new java.security.PrivilegedExceptionAction<InetAddress>() { + public InetAddress run() + throws java.net.UnknownHostException + { + return InetAddress.getByName(clientHostName); + } + }); + } catch (PrivilegedActionException pae) { + throw new AccessException("RMI " + op + " disallowed; " + + clientHostName + " is an unknown client"); + } + } catch (ServerNotActiveException ex) { + throw new AccessException("RMI " + op + + " is not allowed from the local host"); + } + + if (remoteClientAddress.equals(clientHost)) { + return; + } + + throw new AccessException("RMI " + op + " is not allowed from " + + clientHost); + } + + /** * Recover activation state from the reliable log and initialize * activation services. */ private static void startActivation(int port, RMIServerSocketFactory ssf,
*** 424,434 **** try { checkShutdown(); } catch (ActivationException e) { return; } ! RegistryImpl.checkAccess("Activator.inactiveObject"); getGroupEntry(id).inactiveObject(id); } public void activeObject(ActivationID id, MarshalledObject<? extends Remote> mobj) --- 504,514 ---- try { checkShutdown(); } catch (ActivationException e) { return; } ! Activation.checkAccess("Activator.inactiveObject"); getGroupEntry(id).inactiveObject(id); } public void activeObject(ActivationID id, MarshalledObject<? extends Remote> mobj)
*** 437,447 **** try { checkShutdown(); } catch (ActivationException e) { return; } ! RegistryImpl.checkAccess("ActivationSystem.activeObject"); getGroupEntry(id).activeObject(id, mobj); } public void inactiveGroup(ActivationGroupID id, long incarnation) --- 517,527 ---- try { checkShutdown(); } catch (ActivationException e) { return; } ! Activation.checkAccess("ActivationSystem.activeObject"); getGroupEntry(id).activeObject(id, mobj); } public void inactiveGroup(ActivationGroupID id, long incarnation)
*** 450,460 **** try { checkShutdown(); } catch (ActivationException e) { return; } ! RegistryImpl.checkAccess("ActivationMonitor.inactiveGroup"); getGroupEntry(id).inactiveGroup(incarnation, false); } } --- 530,540 ---- try { checkShutdown(); } catch (ActivationException e) { return; } ! Activation.checkAccess("ActivationMonitor.inactiveGroup"); getGroupEntry(id).inactiveGroup(incarnation, false); } }
*** 482,492 **** public ActivationID registerObject(ActivationDesc desc) throws ActivationException, UnknownGroupException, RemoteException { checkShutdown(); ! RegistryImpl.checkAccess("ActivationSystem.registerObject"); ActivationGroupID groupID = desc.getGroupID(); ActivationID id = new ActivationID(activatorStub); getGroupEntry(groupID).registerObject(id, desc, true); return id; --- 562,572 ---- public ActivationID registerObject(ActivationDesc desc) throws ActivationException, UnknownGroupException, RemoteException { checkShutdown(); ! Activation.checkAccess("ActivationSystem.registerObject"); ActivationGroupID groupID = desc.getGroupID(); ActivationID id = new ActivationID(activatorStub); getGroupEntry(groupID).registerObject(id, desc, true); return id;
*** 494,512 **** public void unregisterObject(ActivationID id) throws ActivationException, UnknownObjectException, RemoteException { checkShutdown(); ! RegistryImpl.checkAccess("ActivationSystem.unregisterObject"); getGroupEntry(id).unregisterObject(id, true); } public ActivationGroupID registerGroup(ActivationGroupDesc desc) throws ActivationException, RemoteException { checkShutdown(); ! RegistryImpl.checkAccess("ActivationSystem.registerGroup"); checkArgs(desc, null); ActivationGroupID id = new ActivationGroupID(systemStub); GroupEntry entry = new GroupEntry(id, desc); // table insertion must take place before log update --- 574,592 ---- public void unregisterObject(ActivationID id) throws ActivationException, UnknownObjectException, RemoteException { checkShutdown(); ! Activation.checkAccess("ActivationSystem.unregisterObject"); getGroupEntry(id).unregisterObject(id, true); } public ActivationGroupID registerGroup(ActivationGroupDesc desc) throws ActivationException, RemoteException { checkShutdown(); ! Activation.checkAccess("ActivationSystem.registerGroup"); checkArgs(desc, null); ActivationGroupID id = new ActivationGroupID(systemStub); GroupEntry entry = new GroupEntry(id, desc); // table insertion must take place before log update
*** 519,539 **** ActivationInstantiator group, long incarnation) throws ActivationException, UnknownGroupException, RemoteException { checkShutdown(); ! RegistryImpl.checkAccess("ActivationSystem.activeGroup"); getGroupEntry(id).activeGroup(group, incarnation); return monitor; } public void unregisterGroup(ActivationGroupID id) throws ActivationException, UnknownGroupException, RemoteException { checkShutdown(); ! RegistryImpl.checkAccess("ActivationSystem.unregisterGroup"); // remove entry before unregister so state is updated before // logged removeGroupEntry(id).unregisterGroup(true); } --- 599,619 ---- ActivationInstantiator group, long incarnation) throws ActivationException, UnknownGroupException, RemoteException { checkShutdown(); ! Activation.checkAccess("ActivationSystem.activeGroup"); getGroupEntry(id).activeGroup(group, incarnation); return monitor; } public void unregisterGroup(ActivationGroupID id) throws ActivationException, UnknownGroupException, RemoteException { checkShutdown(); ! Activation.checkAccess("ActivationSystem.unregisterGroup"); // remove entry before unregister so state is updated before // logged removeGroupEntry(id).unregisterGroup(true); }
*** 541,551 **** public ActivationDesc setActivationDesc(ActivationID id, ActivationDesc desc) throws ActivationException, UnknownObjectException, RemoteException { checkShutdown(); ! RegistryImpl.checkAccess("ActivationSystem.setActivationDesc"); if (!getGroupID(id).equals(desc.getGroupID())) { throw new ActivationException( "ActivationDesc contains wrong group"); } --- 621,631 ---- public ActivationDesc setActivationDesc(ActivationID id, ActivationDesc desc) throws ActivationException, UnknownObjectException, RemoteException { checkShutdown(); ! Activation.checkAccess("ActivationSystem.setActivationDesc"); if (!getGroupID(id).equals(desc.getGroupID())) { throw new ActivationException( "ActivationDesc contains wrong group"); }
*** 555,596 **** public ActivationGroupDesc setActivationGroupDesc(ActivationGroupID id, ActivationGroupDesc desc) throws ActivationException, UnknownGroupException, RemoteException { checkShutdown(); ! RegistryImpl.checkAccess( "ActivationSystem.setActivationGroupDesc"); checkArgs(desc, null); return getGroupEntry(id).setActivationGroupDesc(id, desc, true); } public ActivationDesc getActivationDesc(ActivationID id) throws ActivationException, UnknownObjectException, RemoteException { checkShutdown(); ! RegistryImpl.checkAccess("ActivationSystem.getActivationDesc"); return getGroupEntry(id).getActivationDesc(id); } public ActivationGroupDesc getActivationGroupDesc(ActivationGroupID id) throws ActivationException, UnknownGroupException, RemoteException { checkShutdown(); ! RegistryImpl.checkAccess ("ActivationSystem.getActivationGroupDesc"); return getGroupEntry(id).desc; } /** * Shutdown the activation system. Destroys all groups spawned by * the activation daemon and exits the activation daemon. */ public void shutdown() throws AccessException { ! RegistryImpl.checkAccess("ActivationSystem.shutdown"); Object lock = startupLock; if (lock != null) { synchronized (lock) { // nothing --- 635,676 ---- public ActivationGroupDesc setActivationGroupDesc(ActivationGroupID id, ActivationGroupDesc desc) throws ActivationException, UnknownGroupException, RemoteException { checkShutdown(); ! Activation.checkAccess( "ActivationSystem.setActivationGroupDesc"); checkArgs(desc, null); return getGroupEntry(id).setActivationGroupDesc(id, desc, true); } public ActivationDesc getActivationDesc(ActivationID id) throws ActivationException, UnknownObjectException, RemoteException { checkShutdown(); ! Activation.checkAccess("ActivationSystem.getActivationDesc"); return getGroupEntry(id).getActivationDesc(id); } public ActivationGroupDesc getActivationGroupDesc(ActivationGroupID id) throws ActivationException, UnknownGroupException, RemoteException { checkShutdown(); ! Activation.checkAccess ("ActivationSystem.getActivationGroupDesc"); return getGroupEntry(id).desc; } /** * Shutdown the activation system. Destroys all groups spawned by * the activation daemon and exits the activation daemon. */ public void shutdown() throws AccessException { ! Activation.checkAccess("ActivationSystem.shutdown"); Object lock = startupLock; if (lock != null) { synchronized (lock) { // nothing