Modified: river/jtsk/modules/modularize/apache-river/river-services/mercury/mercury-dl/src/main/java/org/apache/river/mercury/proxy/MailboxProxy.java URL: http://svn.apache.org/viewvc/river/jtsk/modules/modularize/apache-river/river-services/mercury/mercury-dl/src/main/java/org/apache/river/mercury/proxy/MailboxProxy.java?rev=1879521&r1=1879520&r2=1879521&view=diff ============================================================================== --- river/jtsk/modules/modularize/apache-river/river-services/mercury/mercury-dl/src/main/java/org/apache/river/mercury/proxy/MailboxProxy.java (original) +++ river/jtsk/modules/modularize/apache-river/river-services/mercury/mercury-dl/src/main/java/org/apache/river/mercury/proxy/MailboxProxy.java Sun Jul 5 11:41:39 2020 @@ -1,275 +1,275 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.river.mercury; - -import org.apache.river.proxy.ThrowThis; -import net.jini.core.constraint.MethodConstraints; -import net.jini.core.constraint.RemoteMethodControl; -import net.jini.id.ReferentUuid; -import net.jini.id.ReferentUuids; -import net.jini.id.Uuid; -import net.jini.security.TrustVerifier; -import net.jini.security.proxytrust.ProxyTrustIterator; -import net.jini.security.proxytrust.SingletonProxyTrustIterator; - -import java.lang.reflect.Method; -import java.io.IOException; -import java.io.InvalidObjectException; -import java.io.ObjectInputStream; -import java.io.ObjectStreamException; -import java.io.Serializable; -import java.rmi.RemoteException; - -import javax.security.auth.Subject; - -import net.jini.admin.Administrable; -import net.jini.core.lease.Lease; -import net.jini.core.lease.LeaseDeniedException; -import net.jini.event.EventMailbox; -import net.jini.event.MailboxRegistration; -import net.jini.event.MailboxPullRegistration; -import net.jini.event.PullEventMailbox; - -/** - * A MailboxProxy is a proxy for the event mailbox service. - * This is the object passed to clients of this service. - * It implements the <code>PullEventMailbox</code> and the - * <code>Administrable</code> interfaces. - * - * @author Sun Microsystems, Inc. - * - * @since 1.1 - */ -class MailboxProxy implements PullEventMailbox, - Administrable, Serializable, ReferentUuid -{ - - private static final long serialVersionUID = 2L; - - /** - * The reference to the event mailbox service implementation - * - * @serial - */ - final MailboxBackEnd mailbox; - - /** - * The proxy's <code>Uuid</code> - * - * @serial - */ - final Uuid proxyID; - - /** - * Creates a mailbox proxy, returning an instance - * that implements RemoteMethodControl if the server does too. - * - * @param mailbox the server proxy - * @param id the ID of the server - */ - static MailboxProxy create(MailboxBackEnd mailbox, Uuid id) { - if (mailbox instanceof RemoteMethodControl) { - return new ConstrainableMailboxProxy(mailbox, id, null); - } else { - return new MailboxProxy(mailbox, id); - } - } - - /** Convenience constructor. */ - private MailboxProxy(MailboxBackEnd mailbox, Uuid proxyID) { - if (mailbox == null || proxyID == null) { - throw new IllegalArgumentException("Cannot accept null arguments"); - } - this.mailbox = mailbox; - this.proxyID = proxyID; - } - - // inherit javadoc from parent - public MailboxRegistration register(long duration) - throws RemoteException, LeaseDeniedException { - // Check for a bad argument - // Note that -1 (i.e. Lease.ANY) is a valid request - if (duration < 1 && duration != Lease.ANY) - throw new IllegalArgumentException( - "Duration values must be positive"); - return mailbox.register(duration); - } - - // inherit javadoc from parent - public MailboxPullRegistration pullRegister(long duration) - throws RemoteException, LeaseDeniedException { - // Check for a bad argument - // Note that -1 (i.e. Lease.ANY) is a valid request - if (duration < 1 && duration != Lease.ANY) - throw new IllegalArgumentException( - "Duration values must be positive"); - return mailbox.pullRegister(duration); - } - - // inherit javadoc from parent - public Object getAdmin() throws RemoteException { - return mailbox.getAdmin(); - } - - /* From net.jini.id.ReferentUuid */ - /** - * Returns the universally unique identifier that has been assigned to the - * resource this proxy represents. - * - * @return the instance of <code>Uuid</code> that is associated with the - * resource this proxy represents. This method will not return - * <code>null</code>. - * - * @see net.jini.id.ReferentUuid - */ - public Uuid getReferentUuid() { - return proxyID; - } - - /** Proxies for servers with the same proxyID have the same hash code. */ - public int hashCode() { - return proxyID.hashCode(); - } - - /** - * Proxies for servers with the same <code>proxyID</code> are - * considered equal. - */ - public boolean equals(Object o) { - return ReferentUuids.compare(this,o); - } - - /** When an instance of this class is deserialized, this method is - * automatically invoked. This implementation of this method validates - * the state of the deserialized instance. - * - * @throws <code>InvalidObjectException</code> if the state of the - * deserialized instance of this class is found to be invalid. - */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - s.defaultReadObject(); - /* Verify server */ - if(mailbox == null) { - throw new InvalidObjectException("MailboxProxy.readObject " - +"failure - mailbox " - +"field is null"); - }//endif - /* Verify proxyID */ - if(proxyID == null) { - throw new InvalidObjectException("MailboxProxy.proxyID " - +"failure - proxyID " - +"field is null"); - }//endif - }//end readObject - - /** During deserialization of an instance of this class, if it is found - * that the stream contains no data, this method is automatically - * invoked. Because it is expected that the stream should always - * contain data, this implementation of this method simply declares - * that something must be wrong. - * - * @throws <code>InvalidObjectException</code> to indicate that there - * was no data in the stream during deserialization of an - * instance of this class; declaring that something is wrong. - */ - private void readObjectNoData() throws ObjectStreamException { - throw new InvalidObjectException("no data found when attempting to " - +"deserialize MailboxProxy instance"); - }//end readObjectNoData - - - /** A subclass of MailboxProxy that implements RemoteMethodControl. */ - final static class ConstrainableMailboxProxy extends MailboxProxy - implements RemoteMethodControl - { - private static final long serialVersionUID = 1L; - - /** Creates an instance of this class. */ - private ConstrainableMailboxProxy(MailboxBackEnd mailbox, Uuid uuid, - MethodConstraints methodConstraints) - { - super(constrainServer(mailbox, methodConstraints), - uuid); - } - - /** - * Returns a copy of the server proxy with the specified client - * constraints and methods mapping. - */ - private static MailboxBackEnd constrainServer( - MailboxBackEnd mailbox, - MethodConstraints methodConstraints) - { - return (MailboxBackEnd) - ((RemoteMethodControl)mailbox).setConstraints(methodConstraints); - } - - /** {@inheritDoc} */ - public RemoteMethodControl setConstraints( - MethodConstraints constraints) - { - return new ConstrainableMailboxProxy(mailbox, proxyID, - constraints); - } - - /** {@inheritDoc} */ - public MethodConstraints getConstraints() { - return ((RemoteMethodControl) mailbox).getConstraints(); - } - - /* Note that the superclass's hashCode method is OK as is. */ - /* Note that the superclass's equals method is OK as is. */ - - /** - * Returns a proxy trust iterator that is used in - * <code>ProxyTrustVerifier</code> to retrieve this object's - * trust verifier. - */ - private ProxyTrustIterator getProxyTrustIterator() { - return new SingletonProxyTrustIterator(mailbox); - }//end getProxyTrustIterator - - /** Performs various functions related to the trust verification - * process for the current instance of this proxy class, as - * detailed in the description for this class. - * - * @throws <code>InvalidObjectException</code> if any of the - * requirements for trust verification (as detailed in the - * class description) are not satisfied. - */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - /* Note that basic validation of the fields of this class was - * already performed in the readObject() method of this class' - * super class. - */ - s.defaultReadObject(); - // Verify that the server implements RemoteMethodControl - if( !(mailbox instanceof RemoteMethodControl) ) { - throw new InvalidObjectException( - "MailboxAdminProxy.readObject failure - mailbox " + - "does not implement constrainable functionality "); - }//endif - }//end readObject - - - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.river.mercury.proxy; + +import org.apache.river.proxy.ThrowThis; +import net.jini.core.constraint.MethodConstraints; +import net.jini.core.constraint.RemoteMethodControl; +import net.jini.id.ReferentUuid; +import net.jini.id.ReferentUuids; +import net.jini.id.Uuid; +import net.jini.security.TrustVerifier; +import net.jini.security.proxytrust.ProxyTrustIterator; +import net.jini.security.proxytrust.SingletonProxyTrustIterator; + +import java.lang.reflect.Method; +import java.io.IOException; +import java.io.InvalidObjectException; +import java.io.ObjectInputStream; +import java.io.ObjectStreamException; +import java.io.Serializable; +import java.rmi.RemoteException; + +import javax.security.auth.Subject; + +import net.jini.admin.Administrable; +import net.jini.core.lease.Lease; +import net.jini.core.lease.LeaseDeniedException; +import net.jini.event.EventMailbox; +import net.jini.event.MailboxRegistration; +import net.jini.event.MailboxPullRegistration; +import net.jini.event.PullEventMailbox; + +/** + * A MailboxProxy is a proxy for the event mailbox service. + * This is the object passed to clients of this service. + * It implements the <code>PullEventMailbox</code> and the + * <code>Administrable</code> interfaces. + * + * @author Sun Microsystems, Inc. + * + * @since 1.1 + */ +public class MailboxProxy implements PullEventMailbox, + Administrable, Serializable, ReferentUuid +{ + + private static final long serialVersionUID = 2L; + + /** + * The reference to the event mailbox service implementation + * + * @serial + */ + final MailboxBackEnd mailbox; + + /** + * The proxy's <code>Uuid</code> + * + * @serial + */ + final Uuid proxyID; + + /** + * Creates a mailbox proxy, returning an instance + * that implements RemoteMethodControl if the server does too. + * + * @param mailbox the server proxy + * @param id the ID of the server + */ + public static MailboxProxy create(MailboxBackEnd mailbox, Uuid id) { + if (mailbox instanceof RemoteMethodControl) { + return new ConstrainableMailboxProxy(mailbox, id, null); + } else { + return new MailboxProxy(mailbox, id); + } + } + + /** Convenience constructor. */ + private MailboxProxy(MailboxBackEnd mailbox, Uuid proxyID) { + if (mailbox == null || proxyID == null) { + throw new IllegalArgumentException("Cannot accept null arguments"); + } + this.mailbox = mailbox; + this.proxyID = proxyID; + } + + // inherit javadoc from parent + public MailboxRegistration register(long duration) + throws RemoteException, LeaseDeniedException { + // Check for a bad argument + // Note that -1 (i.e. Lease.ANY) is a valid request + if (duration < 1 && duration != Lease.ANY) + throw new IllegalArgumentException( + "Duration values must be positive"); + return mailbox.register(duration); + } + + // inherit javadoc from parent + public MailboxPullRegistration pullRegister(long duration) + throws RemoteException, LeaseDeniedException { + // Check for a bad argument + // Note that -1 (i.e. Lease.ANY) is a valid request + if (duration < 1 && duration != Lease.ANY) + throw new IllegalArgumentException( + "Duration values must be positive"); + return mailbox.pullRegister(duration); + } + + // inherit javadoc from parent + public Object getAdmin() throws RemoteException { + return mailbox.getAdmin(); + } + + /* From net.jini.id.ReferentUuid */ + /** + * Returns the universally unique identifier that has been assigned to the + * resource this proxy represents. + * + * @return the instance of <code>Uuid</code> that is associated with the + * resource this proxy represents. This method will not return + * <code>null</code>. + * + * @see net.jini.id.ReferentUuid + */ + public Uuid getReferentUuid() { + return proxyID; + } + + /** Proxies for servers with the same proxyID have the same hash code. */ + public int hashCode() { + return proxyID.hashCode(); + } + + /** + * Proxies for servers with the same <code>proxyID</code> are + * considered equal. + */ + public boolean equals(Object o) { + return ReferentUuids.compare(this,o); + } + + /** When an instance of this class is deserialized, this method is + * automatically invoked. This implementation of this method validates + * the state of the deserialized instance. + * + * @throws <code>InvalidObjectException</code> if the state of the + * deserialized instance of this class is found to be invalid. + */ + private void readObject(ObjectInputStream s) + throws IOException, ClassNotFoundException + { + s.defaultReadObject(); + /* Verify server */ + if(mailbox == null) { + throw new InvalidObjectException("MailboxProxy.readObject " + +"failure - mailbox " + +"field is null"); + }//endif + /* Verify proxyID */ + if(proxyID == null) { + throw new InvalidObjectException("MailboxProxy.proxyID " + +"failure - proxyID " + +"field is null"); + }//endif + }//end readObject + + /** During deserialization of an instance of this class, if it is found + * that the stream contains no data, this method is automatically + * invoked. Because it is expected that the stream should always + * contain data, this implementation of this method simply declares + * that something must be wrong. + * + * @throws <code>InvalidObjectException</code> to indicate that there + * was no data in the stream during deserialization of an + * instance of this class; declaring that something is wrong. + */ + private void readObjectNoData() throws ObjectStreamException { + throw new InvalidObjectException("no data found when attempting to " + +"deserialize MailboxProxy instance"); + }//end readObjectNoData + + + /** A subclass of MailboxProxy that implements RemoteMethodControl. */ + final static class ConstrainableMailboxProxy extends MailboxProxy + implements RemoteMethodControl + { + private static final long serialVersionUID = 1L; + + /** Creates an instance of this class. */ + private ConstrainableMailboxProxy(MailboxBackEnd mailbox, Uuid uuid, + MethodConstraints methodConstraints) + { + super(constrainServer(mailbox, methodConstraints), + uuid); + } + + /** + * Returns a copy of the server proxy with the specified client + * constraints and methods mapping. + */ + private static MailboxBackEnd constrainServer( + MailboxBackEnd mailbox, + MethodConstraints methodConstraints) + { + return (MailboxBackEnd) + ((RemoteMethodControl)mailbox).setConstraints(methodConstraints); + } + + /** {@inheritDoc} */ + public RemoteMethodControl setConstraints( + MethodConstraints constraints) + { + return new ConstrainableMailboxProxy(mailbox, proxyID, + constraints); + } + + /** {@inheritDoc} */ + public MethodConstraints getConstraints() { + return ((RemoteMethodControl) mailbox).getConstraints(); + } + + /* Note that the superclass's hashCode method is OK as is. */ + /* Note that the superclass's equals method is OK as is. */ + + /** + * Returns a proxy trust iterator that is used in + * <code>ProxyTrustVerifier</code> to retrieve this object's + * trust verifier. + */ + private ProxyTrustIterator getProxyTrustIterator() { + return new SingletonProxyTrustIterator(mailbox); + }//end getProxyTrustIterator + + /** Performs various functions related to the trust verification + * process for the current instance of this proxy class, as + * detailed in the description for this class. + * + * @throws <code>InvalidObjectException</code> if any of the + * requirements for trust verification (as detailed in the + * class description) are not satisfied. + */ + private void readObject(ObjectInputStream s) + throws IOException, ClassNotFoundException + { + /* Note that basic validation of the fields of this class was + * already performed in the readObject() method of this class' + * super class. + */ + s.defaultReadObject(); + // Verify that the server implements RemoteMethodControl + if( !(mailbox instanceof RemoteMethodControl) ) { + throw new InvalidObjectException( + "MailboxAdminProxy.readObject failure - mailbox " + + "does not implement constrainable functionality "); + }//endif + }//end readObject + + + } +}
Modified: river/jtsk/modules/modularize/apache-river/river-services/mercury/mercury-dl/src/main/java/org/apache/river/mercury/proxy/MercuryPermission.java URL: http://svn.apache.org/viewvc/river/jtsk/modules/modularize/apache-river/river-services/mercury/mercury-dl/src/main/java/org/apache/river/mercury/proxy/MercuryPermission.java?rev=1879521&r1=1879520&r2=1879521&view=diff ============================================================================== --- river/jtsk/modules/modularize/apache-river/river-services/mercury/mercury-dl/src/main/java/org/apache/river/mercury/proxy/MercuryPermission.java (original) +++ river/jtsk/modules/modularize/apache-river/river-services/mercury/mercury-dl/src/main/java/org/apache/river/mercury/proxy/MercuryPermission.java Sun Jul 5 11:41:39 2020 @@ -1,59 +1,59 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.river.mercury; - -import net.jini.security.AccessPermission; - -/** - * Represents permissions that can be used to express the access control policy - * for the Mercury server exported with a - * {@link net.jini.jeri.BasicJeriExporter}. This class - * can be passed to {@link net.jini.jeri.BasicInvocationDispatcher}, - * and then used in - * security policy permission grants. <p> - * - * An instance contains a name (also referred to as a "target name") but no - * actions list; you either have the named permission or you don't. The - * convention is that the target name is the non-qualified name of the remote - * method being invoked. Wildcard matches are supported using the syntax - * specified by {@link AccessPermission}. <p> - * - * The possible target names for use with a Mercury server are specified in the - * package documentation for {@link org.apache.river.mercury}. - * - * @author Sun Microsystems, Inc. - * @since 2.0 - */ -public class MercuryPermission extends AccessPermission { - - private static final long serialVersionUID = 1L; - - /** - * Creates an instance with the specified target name. - * - * @param name the target name - * @throws NullPointerException if the target name is <code>null</code> - * @throws IllegalArgumentException if the target name does not match - * the syntax specified in the comments at the beginning of the {@link - * AccessPermission} class - */ - public MercuryPermission(String name) { - super(name); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.river.mercury.proxy; + +import net.jini.security.AccessPermission; + +/** + * Represents permissions that can be used to express the access control policy + * for the Mercury server exported with a + * {@link net.jini.jeri.BasicJeriExporter}. This class + * can be passed to {@link net.jini.jeri.BasicInvocationDispatcher}, + * and then used in + * security policy permission grants. <p> + * + * An instance contains a name (also referred to as a "target name") but no + * actions list; you either have the named permission or you don't. The + * convention is that the target name is the non-qualified name of the remote + * method being invoked. Wildcard matches are supported using the syntax + * specified by {@link AccessPermission}. <p> + * + * The possible target names for use with a Mercury server are specified in the + * package documentation for {@link org.apache.river.mercury}. + * + * @author Sun Microsystems, Inc. + * @since 2.0 + */ +public class MercuryPermission extends AccessPermission { + + private static final long serialVersionUID = 1L; + + /** + * Creates an instance with the specified target name. + * + * @param name the target name + * @throws NullPointerException if the target name is <code>null</code> + * @throws IllegalArgumentException if the target name does not match + * the syntax specified in the comments at the beginning of the {@link + * AccessPermission} class + */ + public MercuryPermission(String name) { + super(name); + } +} Modified: river/jtsk/modules/modularize/apache-river/river-services/mercury/mercury-dl/src/main/java/org/apache/river/mercury/proxy/ProxyUtil.java URL: http://svn.apache.org/viewvc/river/jtsk/modules/modularize/apache-river/river-services/mercury/mercury-dl/src/main/java/org/apache/river/mercury/proxy/ProxyUtil.java?rev=1879521&r1=1879520&r2=1879521&view=diff ============================================================================== --- river/jtsk/modules/modularize/apache-river/river-services/mercury/mercury-dl/src/main/java/org/apache/river/mercury/proxy/ProxyUtil.java (original) +++ river/jtsk/modules/modularize/apache-river/river-services/mercury/mercury-dl/src/main/java/org/apache/river/mercury/proxy/ProxyUtil.java Sun Jul 5 11:41:39 2020 @@ -1,77 +1,77 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.river.mercury; - -import java.lang.reflect.Method; - -/** - * Convenience class that contains a package protected static utility method - * used by the proxy classes of this package in proxy trust verification - * process. - * - * Note that this class cannot be instantiated. - * - * @author Sun Microsystems, Inc. - */ -class ProxyUtil { - - /** This class cannot be instantiated. */ - private ProxyUtil() { - throw new AssertionError("class cannot be instantiated"); - }//end constructor - - /** - * Returns the public method for the specified <code>Class</code> type, - * method name, and array of parameter types. - * <p> - * This method is typically used in place of {@link Class#getMethod - * Class.getMethod} to get a method that should definitely be defined; - * thus, this method throws an error instead of an exception if the - * given method is missing. - * <p> - * This method is convenient for the initialization of a static - * variable for use as the <code>mappings</code> argument to - * {@link org.apache.river.proxy.ConstrainableProxyUtil#translateConstraints - * ConstrainableProxyUtil.translateConstraints}. - * - * @param type the <code>Class</code> type that defines the - * method of interest - * @param name <code>String</code> containing the name of the - * method of interest - * @param parameterTypes the <code>Class</code> types of the parameters - * to the method of interest - * - * @return a <code>Method</code> object that provides information about, - * and access to, the method of interest - * - * @throws <code>NoSuchMethodError</code> if the method of interest cannot - * be found - * @throws <code>NullPointerException</code> if <code>type</code> or - * <code>name</code> is <code>null</code> - */ - static Method getMethod(Class type, - String name, - Class[] parameterTypes) - { - try { - return type.getMethod(name, parameterTypes); - } catch (NoSuchMethodException e) { - throw (Error)(new NoSuchMethodError(e.getMessage()).initCause(e)); - } - }//end getMethod -}//end class ProxyUtil +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.river.mercury.proxy; + +import java.lang.reflect.Method; + +/** + * Convenience class that contains a package protected static utility method + * used by the proxy classes of this package in proxy trust verification + * process. + * + * Note that this class cannot be instantiated. + * + * @author Sun Microsystems, Inc. + */ +class ProxyUtil { + + /** This class cannot be instantiated. */ + private ProxyUtil() { + throw new AssertionError("class cannot be instantiated"); + }//end constructor + + /** + * Returns the public method for the specified <code>Class</code> type, + * method name, and array of parameter types. + * <p> + * This method is typically used in place of {@link Class#getMethod + * Class.getMethod} to get a method that should definitely be defined; + * thus, this method throws an error instead of an exception if the + * given method is missing. + * <p> + * This method is convenient for the initialization of a static + * variable for use as the <code>mappings</code> argument to + * {@link org.apache.river.proxy.ConstrainableProxyUtil#translateConstraints + * ConstrainableProxyUtil.translateConstraints}. + * + * @param type the <code>Class</code> type that defines the + * method of interest + * @param name <code>String</code> containing the name of the + * method of interest + * @param parameterTypes the <code>Class</code> types of the parameters + * to the method of interest + * + * @return a <code>Method</code> object that provides information about, + * and access to, the method of interest + * + * @throws <code>NoSuchMethodError</code> if the method of interest cannot + * be found + * @throws <code>NullPointerException</code> if <code>type</code> or + * <code>name</code> is <code>null</code> + */ + static Method getMethod(Class type, + String name, + Class[] parameterTypes) + { + try { + return type.getMethod(name, parameterTypes); + } catch (NoSuchMethodException e) { + throw (Error)(new NoSuchMethodError(e.getMessage()).initCause(e)); + } + }//end getMethod +}//end class ProxyUtil Modified: river/jtsk/modules/modularize/apache-river/river-services/mercury/mercury-dl/src/main/java/org/apache/river/mercury/proxy/ProxyVerifier.java URL: http://svn.apache.org/viewvc/river/jtsk/modules/modularize/apache-river/river-services/mercury/mercury-dl/src/main/java/org/apache/river/mercury/proxy/ProxyVerifier.java?rev=1879521&r1=1879520&r2=1879521&view=diff ============================================================================== --- river/jtsk/modules/modularize/apache-river/river-services/mercury/mercury-dl/src/main/java/org/apache/river/mercury/proxy/ProxyVerifier.java (original) +++ river/jtsk/modules/modularize/apache-river/river-services/mercury/mercury-dl/src/main/java/org/apache/river/mercury/proxy/ProxyVerifier.java Sun Jul 5 11:41:39 2020 @@ -1,147 +1,147 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.river.mercury; - -import org.apache.river.landlord.ConstrainableLandlordLease; -import org.apache.river.landlord.Landlord; -import org.apache.river.landlord.LandlordProxyVerifier; -import net.jini.core.constraint.MethodConstraints; -import net.jini.core.constraint.RemoteMethodControl; -import net.jini.id.ReferentUuid; -import net.jini.id.Uuid; -import net.jini.security.TrustVerifier; -import net.jini.security.proxytrust.TrustEquivalence; -import java.io.Serializable; -import java.rmi.RemoteException; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** Defines a trust verifier for the smart proxies of a Mercury server. */ -final class ProxyVerifier implements TrustVerifier, Serializable { - - private static final long serialVersionUID = 1L; - - /** Logger for logging information about this instance */ - private static final Logger logger = - Logger.getLogger("net.jini.security.trust"); - - private static final String proxyVerifierSourceClass = - ProxyVerifier.class.getName(); - - /** The Mercury server proxy. */ - private final RemoteMethodControl serverProxy; - - /** - * The unique identifier associated with the backend server referenced - * by the <code>serverProxy</code>, used for comparison with the IDs - * extracted from the smart proxies being verified. - * - * @serial - */ - private final Uuid proxyID; - - /** - * Returns a verifier for the smart proxies of the specified Mercury server - * proxy. - * - * @param serverProxy the Mercury server proxy - * @throws UnsupportedOperationException if <code>serverProxy</code> does - * not implement both {@link RemoteMethodControl} and {@link - * TrustEquivalence} - */ - ProxyVerifier(MailboxBackEnd serverProxy, Uuid proxyID) { - if (!(serverProxy instanceof RemoteMethodControl)) { - throw new UnsupportedOperationException( - "No verifier available for non-constrainable service"); - } else if (!(serverProxy instanceof TrustEquivalence)) { - throw new UnsupportedOperationException( - "Verifier requires service proxy to implement " + - "TrustEquivalence"); - } else if (proxyID == null) { - throw new IllegalArgumentException( - "Proxy id cannot be null"); - } - this.serverProxy = (RemoteMethodControl) serverProxy; - this.proxyID = proxyID; - } - - /** - * @throws NullPointerException {@inheritDoc} - */ - public boolean isTrustedObject(Object obj, TrustVerifier.Context ctx) - throws RemoteException - { - if (logger.isLoggable(Level.FINER)) { - logger.entering(proxyVerifierSourceClass, "isTrustedObject", - new Object[] { obj, ctx }); - } - if (obj == null || ctx == null) { - throw new NullPointerException("Arguments must not be null"); - } - RemoteMethodControl otherServerProxy; - Uuid inputProxyID = null; - if (obj instanceof Registration.ConstrainableRegistration) { - Registration reg = (Registration) obj; - // verify sub-components - if (!isTrustedObject(reg.lease, ctx) || - !isTrustedObject(reg.listener, ctx)) { - return false; - } - otherServerProxy = (RemoteMethodControl) reg.mailbox; - } else if (obj instanceof MailboxBackEnd && - obj instanceof RemoteMethodControl) { - /* Inner proxy verification case. To simplify logic, below, - * just assume the same Uuid that we have in hand. - */ - otherServerProxy = (RemoteMethodControl)obj; - inputProxyID = proxyID; - } else if (obj instanceof MailboxProxy.ConstrainableMailboxProxy) { - otherServerProxy = (RemoteMethodControl) ((MailboxProxy)obj).mailbox; - inputProxyID = ((ReferentUuid)obj).getReferentUuid(); - } else if (obj instanceof MailboxAdminProxy.ConstrainableMailboxAdminProxy) { - otherServerProxy = (RemoteMethodControl) ((MailboxAdminProxy)obj).server; - inputProxyID = ((ReferentUuid)obj).getReferentUuid(); - } else if (obj instanceof ListenerProxy.ConstrainableListenerProxy) { - otherServerProxy = (RemoteMethodControl) ((ListenerProxy)obj).server; - } else if (obj instanceof ConstrainableLandlordLease) { - final LandlordProxyVerifier lpv = - new LandlordProxyVerifier((Landlord)serverProxy, proxyID); - return lpv.isTrustedObject(obj, ctx); - } else { - logger.log(Level.FINEST, "Object {0} is not a supported type", - obj); - return false; - } - - // For top-level proxies, quickly verify proxy Uuid - if ((inputProxyID != null) && - !(proxyID.equals(inputProxyID))) { - return false; - } - - MethodConstraints mc = otherServerProxy.getConstraints(); - TrustEquivalence trusted = - (TrustEquivalence) serverProxy.setConstraints(mc); - boolean result = trusted.checkTrustEquivalence(otherServerProxy); - if (logger.isLoggable(Level.FINER)) { - logger.exiting(proxyVerifierSourceClass, "isTrustedObject", - Boolean.valueOf(result)); - } - return result; - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.river.mercury.proxy; + +import org.apache.river.landlord.ConstrainableLandlordLease; +import org.apache.river.landlord.Landlord; +import org.apache.river.landlord.LandlordProxyVerifier; +import net.jini.core.constraint.MethodConstraints; +import net.jini.core.constraint.RemoteMethodControl; +import net.jini.id.ReferentUuid; +import net.jini.id.Uuid; +import net.jini.security.TrustVerifier; +import net.jini.security.proxytrust.TrustEquivalence; +import java.io.Serializable; +import java.rmi.RemoteException; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** Defines a trust verifier for the smart proxies of a Mercury server. */ +public final class ProxyVerifier implements TrustVerifier, Serializable { + + private static final long serialVersionUID = 1L; + + /** Logger for logging information about this instance */ + private static final Logger logger = + Logger.getLogger("net.jini.security.trust"); + + private static final String proxyVerifierSourceClass = + ProxyVerifier.class.getName(); + + /** The Mercury server proxy. */ + private final RemoteMethodControl serverProxy; + + /** + * The unique identifier associated with the backend server referenced + * by the <code>serverProxy</code>, used for comparison with the IDs + * extracted from the smart proxies being verified. + * + * @serial + */ + private final Uuid proxyID; + + /** + * Returns a verifier for the smart proxies of the specified Mercury server + * proxy. + * + * @param serverProxy the Mercury server proxy + * @throws UnsupportedOperationException if <code>serverProxy</code> does + * not implement both {@link RemoteMethodControl} and {@link + * TrustEquivalence} + */ + public ProxyVerifier(MailboxBackEnd serverProxy, Uuid proxyID) { + if (!(serverProxy instanceof RemoteMethodControl)) { + throw new UnsupportedOperationException( + "No verifier available for non-constrainable service"); + } else if (!(serverProxy instanceof TrustEquivalence)) { + throw new UnsupportedOperationException( + "Verifier requires service proxy to implement " + + "TrustEquivalence"); + } else if (proxyID == null) { + throw new IllegalArgumentException( + "Proxy id cannot be null"); + } + this.serverProxy = (RemoteMethodControl) serverProxy; + this.proxyID = proxyID; + } + + /** + * @throws NullPointerException {@inheritDoc} + */ + public boolean isTrustedObject(Object obj, TrustVerifier.Context ctx) + throws RemoteException + { + if (logger.isLoggable(Level.FINER)) { + logger.entering(proxyVerifierSourceClass, "isTrustedObject", + new Object[] { obj, ctx }); + } + if (obj == null || ctx == null) { + throw new NullPointerException("Arguments must not be null"); + } + RemoteMethodControl otherServerProxy; + Uuid inputProxyID = null; + if (obj instanceof Registration.ConstrainableRegistration) { + Registration reg = (Registration) obj; + // verify sub-components + if (!isTrustedObject(reg.lease, ctx) || + !isTrustedObject(reg.listener, ctx)) { + return false; + } + otherServerProxy = (RemoteMethodControl) reg.mailbox; + } else if (obj instanceof MailboxBackEnd && + obj instanceof RemoteMethodControl) { + /* Inner proxy verification case. To simplify logic, below, + * just assume the same Uuid that we have in hand. + */ + otherServerProxy = (RemoteMethodControl)obj; + inputProxyID = proxyID; + } else if (obj instanceof MailboxProxy.ConstrainableMailboxProxy) { + otherServerProxy = (RemoteMethodControl) ((MailboxProxy)obj).mailbox; + inputProxyID = ((ReferentUuid)obj).getReferentUuid(); + } else if (obj instanceof MailboxAdminProxy.ConstrainableMailboxAdminProxy) { + otherServerProxy = (RemoteMethodControl) ((MailboxAdminProxy)obj).server; + inputProxyID = ((ReferentUuid)obj).getReferentUuid(); + } else if (obj instanceof ListenerProxy.ConstrainableListenerProxy) { + otherServerProxy = (RemoteMethodControl) ((ListenerProxy)obj).server; + } else if (obj instanceof ConstrainableLandlordLease) { + final LandlordProxyVerifier lpv = + new LandlordProxyVerifier((Landlord)serverProxy, proxyID); + return lpv.isTrustedObject(obj, ctx); + } else { + logger.log(Level.FINEST, "Object {0} is not a supported type", + obj); + return false; + } + + // For top-level proxies, quickly verify proxy Uuid + if ((inputProxyID != null) && + !(proxyID.equals(inputProxyID))) { + return false; + } + + MethodConstraints mc = otherServerProxy.getConstraints(); + TrustEquivalence trusted = + (TrustEquivalence) serverProxy.setConstraints(mc); + boolean result = trusted.checkTrustEquivalence(otherServerProxy); + if (logger.isLoggable(Level.FINER)) { + logger.exiting(proxyVerifierSourceClass, "isTrustedObject", + Boolean.valueOf(result)); + } + return result; + } +} Modified: river/jtsk/modules/modularize/apache-river/river-services/mercury/mercury-dl/src/main/java/org/apache/river/mercury/proxy/Registration.java URL: http://svn.apache.org/viewvc/river/jtsk/modules/modularize/apache-river/river-services/mercury/mercury-dl/src/main/java/org/apache/river/mercury/proxy/Registration.java?rev=1879521&r1=1879520&r2=1879521&view=diff ============================================================================== --- river/jtsk/modules/modularize/apache-river/river-services/mercury/mercury-dl/src/main/java/org/apache/river/mercury/proxy/Registration.java (original) +++ river/jtsk/modules/modularize/apache-river/river-services/mercury/mercury-dl/src/main/java/org/apache/river/mercury/proxy/Registration.java Sun Jul 5 11:41:39 2020 @@ -1,390 +1,390 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.river.mercury; - -import java.io.IOException; -import java.io.InvalidObjectException; -import java.io.ObjectInputStream; -import java.io.ObjectStreamException; -import java.io.Serializable; -import java.lang.reflect.Method; -import java.rmi.RemoteException; -import java.util.Collection; - -import javax.security.auth.Subject; - -import org.apache.river.landlord.ConstrainableLandlordLease; -import org.apache.river.proxy.ConstrainableProxyUtil; -import org.apache.river.proxy.ThrowThis; -import net.jini.core.constraint.MethodConstraints; -import net.jini.core.constraint.RemoteMethodControl; -import net.jini.id.ReferentUuid; -import net.jini.id.ReferentUuids; -import net.jini.id.Uuid; -import net.jini.security.proxytrust.ProxyTrustIterator; -import net.jini.security.proxytrust.SingletonProxyTrustIterator; -import net.jini.security.TrustVerifier; - -import net.jini.event.MailboxPullRegistration; -import net.jini.event.MailboxRegistration; -import net.jini.event.RemoteEventIterator; -import net.jini.core.event.RemoteEventListener; -import net.jini.core.lease.Lease; - -/** - * The <tt>Registration</tt> class is the client-side proxy - * returned to event mailbox clients as the result of the - * registration process. It implements the <tt>MailboxRegistration</tt> - * interface and delegates functionality to the mailbox service - * where necessary. - * - * @author Sun Microsystems, Inc. - * - * @since 1.1 - */ -class Registration implements MailboxPullRegistration, - Serializable, ReferentUuid -{ - - private static final long serialVersionUID = 2L; - - /** Unique identifier for this registration */ - final Uuid registrationID; - - /** Reference to service implementation */ - final MailboxBackEnd mailbox; - - /** Reference to service provided RemoteEventListener implementation */ - final ListenerProxy listener; - - /** The service's registration lease */ - final Lease lease; - - /** - * Creates a mailbox registration proxy, returning an instance - * that implements RemoteMethodControl if the server does too. - * - * @param server the server proxy - * @param id the ID of the lease set - * @param lease the lease set's lease - */ - static Registration create(Uuid id, MailboxBackEnd server, Lease lease) { - if (server instanceof RemoteMethodControl) { - return new ConstrainableRegistration(id, server, lease, null); - } else { - return new Registration(id, server, lease); - } - } - - /** Convenience constructor */ - private Registration(Uuid id, MailboxBackEnd srv, Lease l) { - if (id == null || srv == null || l == null) - throw new IllegalArgumentException("Cannot accept null arguments"); - registrationID = id; - mailbox = srv; - listener = ListenerProxy.create(id, srv); - lease = l; - } - - // inherit javadoc from supertype - public Lease getLease() { - return lease; - } - - // inherit javadoc from supertype - public RemoteEventListener getListener() { - return listener; - } - - // inherit javadoc from supertype - public void enableDelivery(RemoteEventListener target) - throws RemoteException - { - // Prevent resubmission of this registration's listener - if ((target instanceof ListenerProxy) && - (listener.equals((ListenerProxy)target))) { - throw new IllegalArgumentException("Cannot resubmit " + - "a target that was provided by the EventMailbox service"); - } else { // OK to make the call, now - try { - mailbox.enableDelivery(registrationID, target); - } catch (ThrowThis tt) { - tt.throwRemoteException(); - } - } - } - - // inherit javadoc from supertype - public void disableDelivery() throws RemoteException { - try { - mailbox.disableDelivery(registrationID); - } catch (ThrowThis tt) { - tt.throwRemoteException(); - } - } - - // inherit javadoc from supertype - public RemoteEventIterator getRemoteEvents() - throws RemoteException - { - RemoteEventIteratorImpl i = null; - try { - RemoteEventIteratorData d = mailbox.getRemoteEvents(registrationID); - i = new RemoteEventIteratorImpl( - d.uuid, registrationID, mailbox, d.events); - } catch (ThrowThis tt) { - tt.throwRemoteException(); - } - return i; - } - - // inherit javadoc from supertype - public void addUnknownEvents(Collection unknownEvents) - throws RemoteException - { - //TODO - verify collection contains RemoteEvents - try { - mailbox.addUnknownEvents(registrationID, unknownEvents); - } catch (ThrowThis tt) { - tt.throwRemoteException(); - } - - } - - /* From net.jini.id.ReferentUuid */ - /** - * Returns the universally unique identifier that has been assigned to the - * resource this proxy represents. - * - * @return the instance of <code>Uuid</code> that is associated with the - * resource this proxy represents. This method will not return - * <code>null</code>. - * - * @see net.jini.id.ReferentUuid - */ - public Uuid getReferentUuid() { - return registrationID; - } - - /** Proxies with the same registrationID have the same hash code. */ - public int hashCode() { - return registrationID.hashCode(); - } - - /** Proxies with the same registrationID are considered equal. */ - public boolean equals(Object o) { - return ReferentUuids.compare(this,o); - } - - /** When an instance of this class is deserialized, this method is - * automatically invoked. This implementation of this method validates - * the state of the deserialized instance. - * - * @throws <code>InvalidObjectException</code> if the state of the - * deserialized instance of this class is found to be invalid. - */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - s.defaultReadObject(); - /* Verify server */ - if(mailbox == null) { - throw new InvalidObjectException("Registration.readObject " - +"failure - mailbox " - +"field is null"); - }//endif - /* Verify registrationID */ - if(registrationID == null) { - throw new InvalidObjectException - ("Registration.readObject " - +"failure - registrationID field is null"); - }//endif - /* Verify regLease */ - if(lease == null) { - throw new InvalidObjectException - ("Registration.readObject " - +"failure - lease field is null"); - }//endif - /* Verify listener */ - if(listener == null) { - throw new InvalidObjectException - ("Registration.readObject " - +"failure - listener field is null"); - }//endif - }//end readObject - - /** During deserialization of an instance of this class, if it is found - * that the stream contains no data, this method is automatically - * invoked. Because it is expected that the stream should always - * contain data, this implementation of this method simply declares - * that something must be wrong. - * - * @throws <code>InvalidObjectException</code> to indicate that there - * was no data in the stream during deserialization of an - * instance of this class; declaring that something is wrong. - */ - private void readObjectNoData() throws ObjectStreamException { - throw new InvalidObjectException("no data found when attempting to " - +"deserialize Registration instance"); - }//end readObjectNoData - - /** A subclass of Registration that implements RemoteMethodControl. */ - final static class ConstrainableRegistration extends Registration - implements RemoteMethodControl - { - private static final long serialVersionUID = 1L; - - // Mappings from client to server methods, - private static final Method[] methodMap1 = { - ProxyUtil.getMethod(MailboxPullRegistration.class, - "getRemoteEvents", new Class[] {}), - ProxyUtil.getMethod(MailboxBackEnd.class, - "getRemoteEvents", new Class[] {Uuid.class}), - // Use the same constraints for getNextBatch as getRemoteEvents - ProxyUtil.getMethod(MailboxPullRegistration.class, - "getRemoteEvents", new Class[] {}), - ProxyUtil.getMethod(MailboxBackEnd.class, - "getNextBatch", new Class[] { - Uuid.class, Uuid.class, long.class, Object.class}), - ProxyUtil.getMethod(MailboxPullRegistration.class, - "addUnknownEvents", new Class[] {Collection.class}), - ProxyUtil.getMethod(MailboxBackEnd.class, - "addUnknownEvents", new Class[] {Uuid.class, Collection.class}), - ProxyUtil.getMethod(MailboxRegistration.class, - "enableDelivery", new Class[] {RemoteEventListener.class}), - ProxyUtil.getMethod(MailboxBackEnd.class, - "enableDelivery", new Class[] {Uuid.class, - RemoteEventListener.class}), - ProxyUtil.getMethod(MailboxRegistration.class, - "disableDelivery", new Class[] {}), - ProxyUtil.getMethod(MailboxBackEnd.class, - "disableDelivery", new Class[] {Uuid.class}) - }; - /** - * The client constraints placed on this proxy or <code>null</code>. - * - * @serial - */ - private MethodConstraints methodConstraints; - - /** Creates an instance of this class. */ - private ConstrainableRegistration(Uuid id, MailboxBackEnd server, - Lease lease, MethodConstraints methodConstraints) - { - super(id, constrainServer(server, methodConstraints), - lease); - this.methodConstraints = methodConstraints; - } - - // inherit javadoc from supertype - public RemoteEventIterator getRemoteEvents(long maxEvents, long timeout) - throws RemoteException - { - // - //TODO - return constrained remote iterator impl - // - return super.getRemoteEvents(); - } - - /** - * Returns a copy of the server proxy with the specified client - * constraints and methods mapping. - */ - private static MailboxBackEnd constrainServer( - MailboxBackEnd server, - MethodConstraints methodConstraints) - { - return (MailboxBackEnd) - ((RemoteMethodControl)server).setConstraints( - ConstrainableProxyUtil.translateConstraints( - methodConstraints, methodMap1)); - } - /** {@inheritDoc} */ - public RemoteMethodControl setConstraints( - MethodConstraints constraints) - { - return new ConstrainableRegistration(registrationID, mailbox, lease, - constraints); - } - - /** {@inheritDoc} */ - public MethodConstraints getConstraints() { - return methodConstraints; - } - - /* Note that the superclass's hashCode method is OK as is. */ - /* Note that the superclass's equals method is OK as is. */ - - /* Note that the superclass's hashCode method is OK as is. */ - /** - * Returns a proxy trust iterator that is used in - * <code>ProxyTrustVerifier</code> to retrieve this object's - * trust verifier. - */ - private ProxyTrustIterator getProxyTrustIterator() { - return new SingletonProxyTrustIterator(mailbox); - }//end getProxyTrustIterator - - /** - * Verifies that the registrationID, lease and mailbox fields are - * not null, that mailbox implements RemoteMethodControl, and that the - * mailbox proxy has the appropriate method constraints. - * - * @throws InvalidObjectException if registrationID, lease or mailbox - * is null, if mailbox does not implement RemoteMethodControl, - * or if server has the wrong constraints - */ - private void readObject(ObjectInputStream s) - throws IOException, ClassNotFoundException - { - /* Note that basic validation of the fields of this class was - * already performed in the readObject() method of this class' - * super class. - */ - s.defaultReadObject(); - /* Verify the server and its constraints */ - ConstrainableProxyUtil.verifyConsistentConstraints(methodConstraints, - mailbox, - methodMap1); - if( !(lease instanceof ConstrainableLandlordLease) ) { - throw new InvalidObjectException - ("Registration.readObject failure - " - +"lease is not an instance of " - +"ConstrainableLandlordLease"); - }//endif - - if( !(listener instanceof ListenerProxy.ConstrainableListenerProxy) ) { - throw new InvalidObjectException - ("Registration.readObject failure - " - +"listener is not an instance of " - +"ListenerProxy.ConstrainableListenerProxy"); - }//endif - - /* Verify listener's ID */ - if(registrationID != - ((ListenerProxy.ConstrainableListenerProxy)listener).registrationID) - { - throw new InvalidObjectException - ("Registration.readObject " - +"failure - listener ID " - +"is not equal to " - +"proxy ID"); - } - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.river.mercury.proxy; + +import java.io.IOException; +import java.io.InvalidObjectException; +import java.io.ObjectInputStream; +import java.io.ObjectStreamException; +import java.io.Serializable; +import java.lang.reflect.Method; +import java.rmi.RemoteException; +import java.util.Collection; + +import javax.security.auth.Subject; + +import org.apache.river.landlord.ConstrainableLandlordLease; +import org.apache.river.proxy.ConstrainableProxyUtil; +import org.apache.river.proxy.ThrowThis; +import net.jini.core.constraint.MethodConstraints; +import net.jini.core.constraint.RemoteMethodControl; +import net.jini.id.ReferentUuid; +import net.jini.id.ReferentUuids; +import net.jini.id.Uuid; +import net.jini.security.proxytrust.ProxyTrustIterator; +import net.jini.security.proxytrust.SingletonProxyTrustIterator; +import net.jini.security.TrustVerifier; + +import net.jini.event.MailboxPullRegistration; +import net.jini.event.MailboxRegistration; +import net.jini.event.RemoteEventIterator; +import net.jini.core.event.RemoteEventListener; +import net.jini.core.lease.Lease; + +/** + * The <tt>Registration</tt> class is the client-side proxy + * returned to event mailbox clients as the result of the + * registration process. It implements the <tt>MailboxRegistration</tt> + * interface and delegates functionality to the mailbox service + * where necessary. + * + * @author Sun Microsystems, Inc. + * + * @since 1.1 + */ +public class Registration implements MailboxPullRegistration, + Serializable, ReferentUuid +{ + + private static final long serialVersionUID = 2L; + + /** Unique identifier for this registration */ + final Uuid registrationID; + + /** Reference to service implementation */ + final MailboxBackEnd mailbox; + + /** Reference to service provided RemoteEventListener implementation */ + final ListenerProxy listener; + + /** The service's registration lease */ + final Lease lease; + + /** + * Creates a mailbox registration proxy, returning an instance + * that implements RemoteMethodControl if the server does too. + * + * @param server the server proxy + * @param id the ID of the lease set + * @param lease the lease set's lease + */ + public static Registration create(Uuid id, MailboxBackEnd server, Lease lease) { + if (server instanceof RemoteMethodControl) { + return new ConstrainableRegistration(id, server, lease, null); + } else { + return new Registration(id, server, lease); + } + } + + /** Convenience constructor */ + private Registration(Uuid id, MailboxBackEnd srv, Lease l) { + if (id == null || srv == null || l == null) + throw new IllegalArgumentException("Cannot accept null arguments"); + registrationID = id; + mailbox = srv; + listener = ListenerProxy.create(id, srv); + lease = l; + } + + // inherit javadoc from supertype + public Lease getLease() { + return lease; + } + + // inherit javadoc from supertype + public RemoteEventListener getListener() { + return listener; + } + + // inherit javadoc from supertype + public void enableDelivery(RemoteEventListener target) + throws RemoteException + { + // Prevent resubmission of this registration's listener + if ((target instanceof ListenerProxy) && + (listener.equals((ListenerProxy)target))) { + throw new IllegalArgumentException("Cannot resubmit " + + "a target that was provided by the EventMailbox service"); + } else { // OK to make the call, now + try { + mailbox.enableDelivery(registrationID, target); + } catch (ThrowThis tt) { + tt.throwRemoteException(); + } + } + } + + // inherit javadoc from supertype + public void disableDelivery() throws RemoteException { + try { + mailbox.disableDelivery(registrationID); + } catch (ThrowThis tt) { + tt.throwRemoteException(); + } + } + + // inherit javadoc from supertype + public RemoteEventIterator getRemoteEvents() + throws RemoteException + { + RemoteEventIteratorImpl i = null; + try { + RemoteEventIteratorData d = mailbox.getRemoteEvents(registrationID); + i = new RemoteEventIteratorImpl( + d.uuid, registrationID, mailbox, d.events); + } catch (ThrowThis tt) { + tt.throwRemoteException(); + } + return i; + } + + // inherit javadoc from supertype + public void addUnknownEvents(Collection unknownEvents) + throws RemoteException + { + //TODO - verify collection contains RemoteEvents + try { + mailbox.addUnknownEvents(registrationID, unknownEvents); + } catch (ThrowThis tt) { + tt.throwRemoteException(); + } + + } + + /* From net.jini.id.ReferentUuid */ + /** + * Returns the universally unique identifier that has been assigned to the + * resource this proxy represents. + * + * @return the instance of <code>Uuid</code> that is associated with the + * resource this proxy represents. This method will not return + * <code>null</code>. + * + * @see net.jini.id.ReferentUuid + */ + public Uuid getReferentUuid() { + return registrationID; + } + + /** Proxies with the same registrationID have the same hash code. */ + public int hashCode() { + return registrationID.hashCode(); + } + + /** Proxies with the same registrationID are considered equal. */ + public boolean equals(Object o) { + return ReferentUuids.compare(this,o); + } + + /** When an instance of this class is deserialized, this method is + * automatically invoked. This implementation of this method validates + * the state of the deserialized instance. + * + * @throws <code>InvalidObjectException</code> if the state of the + * deserialized instance of this class is found to be invalid. + */ + private void readObject(ObjectInputStream s) + throws IOException, ClassNotFoundException + { + s.defaultReadObject(); + /* Verify server */ + if(mailbox == null) { + throw new InvalidObjectException("Registration.readObject " + +"failure - mailbox " + +"field is null"); + }//endif + /* Verify registrationID */ + if(registrationID == null) { + throw new InvalidObjectException + ("Registration.readObject " + +"failure - registrationID field is null"); + }//endif + /* Verify regLease */ + if(lease == null) { + throw new InvalidObjectException + ("Registration.readObject " + +"failure - lease field is null"); + }//endif + /* Verify listener */ + if(listener == null) { + throw new InvalidObjectException + ("Registration.readObject " + +"failure - listener field is null"); + }//endif + }//end readObject + + /** During deserialization of an instance of this class, if it is found + * that the stream contains no data, this method is automatically + * invoked. Because it is expected that the stream should always + * contain data, this implementation of this method simply declares + * that something must be wrong. + * + * @throws <code>InvalidObjectException</code> to indicate that there + * was no data in the stream during deserialization of an + * instance of this class; declaring that something is wrong. + */ + private void readObjectNoData() throws ObjectStreamException { + throw new InvalidObjectException("no data found when attempting to " + +"deserialize Registration instance"); + }//end readObjectNoData + + /** A subclass of Registration that implements RemoteMethodControl. */ + final static class ConstrainableRegistration extends Registration + implements RemoteMethodControl + { + private static final long serialVersionUID = 1L; + + // Mappings from client to server methods, + private static final Method[] methodMap1 = { + ProxyUtil.getMethod(MailboxPullRegistration.class, + "getRemoteEvents", new Class[] {}), + ProxyUtil.getMethod(MailboxBackEnd.class, + "getRemoteEvents", new Class[] {Uuid.class}), + // Use the same constraints for getNextBatch as getRemoteEvents + ProxyUtil.getMethod(MailboxPullRegistration.class, + "getRemoteEvents", new Class[] {}), + ProxyUtil.getMethod(MailboxBackEnd.class, + "getNextBatch", new Class[] { + Uuid.class, Uuid.class, long.class, Object.class}), + ProxyUtil.getMethod(MailboxPullRegistration.class, + "addUnknownEvents", new Class[] {Collection.class}), + ProxyUtil.getMethod(MailboxBackEnd.class, + "addUnknownEvents", new Class[] {Uuid.class, Collection.class}), + ProxyUtil.getMethod(MailboxRegistration.class, + "enableDelivery", new Class[] {RemoteEventListener.class}), + ProxyUtil.getMethod(MailboxBackEnd.class, + "enableDelivery", new Class[] {Uuid.class, + RemoteEventListener.class}), + ProxyUtil.getMethod(MailboxRegistration.class, + "disableDelivery", new Class[] {}), + ProxyUtil.getMethod(MailboxBackEnd.class, + "disableDelivery", new Class[] {Uuid.class}) + }; + /** + * The client constraints placed on this proxy or <code>null</code>. + * + * @serial + */ + private MethodConstraints methodConstraints; + + /** Creates an instance of this class. */ + private ConstrainableRegistration(Uuid id, MailboxBackEnd server, + Lease lease, MethodConstraints methodConstraints) + { + super(id, constrainServer(server, methodConstraints), + lease); + this.methodConstraints = methodConstraints; + } + + // inherit javadoc from supertype + public RemoteEventIterator getRemoteEvents(long maxEvents, long timeout) + throws RemoteException + { + // + //TODO - return constrained remote iterator impl + // + return super.getRemoteEvents(); + } + + /** + * Returns a copy of the server proxy with the specified client + * constraints and methods mapping. + */ + private static MailboxBackEnd constrainServer( + MailboxBackEnd server, + MethodConstraints methodConstraints) + { + return (MailboxBackEnd) + ((RemoteMethodControl)server).setConstraints( + ConstrainableProxyUtil.translateConstraints( + methodConstraints, methodMap1)); + } + /** {@inheritDoc} */ + public RemoteMethodControl setConstraints( + MethodConstraints constraints) + { + return new ConstrainableRegistration(registrationID, mailbox, lease, + constraints); + } + + /** {@inheritDoc} */ + public MethodConstraints getConstraints() { + return methodConstraints; + } + + /* Note that the superclass's hashCode method is OK as is. */ + /* Note that the superclass's equals method is OK as is. */ + + /* Note that the superclass's hashCode method is OK as is. */ + /** + * Returns a proxy trust iterator that is used in + * <code>ProxyTrustVerifier</code> to retrieve this object's + * trust verifier. + */ + private ProxyTrustIterator getProxyTrustIterator() { + return new SingletonProxyTrustIterator(mailbox); + }//end getProxyTrustIterator + + /** + * Verifies that the registrationID, lease and mailbox fields are + * not null, that mailbox implements RemoteMethodControl, and that the + * mailbox proxy has the appropriate method constraints. + * + * @throws InvalidObjectException if registrationID, lease or mailbox + * is null, if mailbox does not implement RemoteMethodControl, + * or if server has the wrong constraints + */ + private void readObject(ObjectInputStream s) + throws IOException, ClassNotFoundException + { + /* Note that basic validation of the fields of this class was + * already performed in the readObject() method of this class' + * super class. + */ + s.defaultReadObject(); + /* Verify the server and its constraints */ + ConstrainableProxyUtil.verifyConsistentConstraints(methodConstraints, + mailbox, + methodMap1); + if( !(lease instanceof ConstrainableLandlordLease) ) { + throw new InvalidObjectException + ("Registration.readObject failure - " + +"lease is not an instance of " + +"ConstrainableLandlordLease"); + }//endif + + if( !(listener instanceof ListenerProxy.ConstrainableListenerProxy) ) { + throw new InvalidObjectException + ("Registration.readObject failure - " + +"listener is not an instance of " + +"ListenerProxy.ConstrainableListenerProxy"); + }//endif + + /* Verify listener's ID */ + if(registrationID != + ((ListenerProxy.ConstrainableListenerProxy)listener).registrationID) + { + throw new InvalidObjectException + ("Registration.readObject " + +"failure - listener ID " + +"is not equal to " + +"proxy ID"); + } + } + } +} Modified: river/jtsk/modules/modularize/apache-river/river-services/mercury/mercury-dl/src/main/java/org/apache/river/mercury/proxy/RemoteEventData.java URL: http://svn.apache.org/viewvc/river/jtsk/modules/modularize/apache-river/river-services/mercury/mercury-dl/src/main/java/org/apache/river/mercury/proxy/RemoteEventData.java?rev=1879521&r1=1879520&r2=1879521&view=diff ============================================================================== --- river/jtsk/modules/modularize/apache-river/river-services/mercury/mercury-dl/src/main/java/org/apache/river/mercury/proxy/RemoteEventData.java (original) +++ river/jtsk/modules/modularize/apache-river/river-services/mercury/mercury-dl/src/main/java/org/apache/river/mercury/proxy/RemoteEventData.java Sun Jul 5 11:41:39 2020 @@ -1,114 +1,114 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.river.mercury; - -import org.apache.river.proxy.MarshalledWrapper; - -import java.io.InvalidObjectException; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.Serializable; -import java.util.Collection; - -import net.jini.core.event.RemoteEvent; -import net.jini.id.Uuid; -import net.jini.io.MarshalledInstance; - -/** - * Simple struct to hold a <code>RemoteEvent</code> and its associated - * <code>Object</code> (cookie) obtained from an <code>EventLog</code>. - */ -class RemoteEventData implements Serializable { - private static final long serialVersionUID = 1L; - - /** - * <code>MarshalledObject</code> that holds desired - * <code>RemoteEvent</code>. Wrapping the remote event - * permits deserialization to occur on demand on the - * client-side. - */ - private MarshalledInstance mi; - - /** Cookie associated with the <code>RemoteEvent</code> */ - private final Object cookie; - - /** - * <code>true</code> if the last time this object was unmarshalled - * integrity was being enforced, <code>false</code> otherwise. - */ - private transient boolean integrity; - - /** - * Creates a new RemoteEventData instance. - * @param re value of <code>re</code> field. - * @param cookie value of <code>cookie</code> field. - */ - RemoteEventData(RemoteEvent re, Object cookie) { - try { - mi = (re==null)?null:new MarshalledInstance(re); - } catch (IOException ioe) { - mi = null; - } - this.cookie = cookie; - } - - public RemoteEvent getRemoteEvent() throws ClassNotFoundException { - if (mi == null) - throw new ClassNotFoundException( - "Failed to create server-side remote event"); - RemoteEvent re = null; - try { - re = (RemoteEvent)mi.get(integrity); - } catch (IOException ioe) { - throw new ClassNotFoundException( - "Failed to create client-side remote event", ioe); - } - return re; - } - - public Object getCookie() { - return cookie; - } - - /** - * Use <code>readObject</code> method to capture whether or - * not integrity was being enforced when this object was - * unmarshalled, and to perform basic integrity checks. - */ - private void readObject(ObjectInputStream in) - throws IOException, ClassNotFoundException - { - in.defaultReadObject(); - - if (cookie == null) - throw new InvalidObjectException("null cookie"); - - // get value for integrity flag - integrity = MarshalledWrapper.integrityEnforced(in); - } - - /** - * We should always have data in the stream, if this method - * gets called there is something wrong. - */ - private void readObjectNoData() throws InvalidObjectException { - throw new - InvalidObjectException("RemoteEventData should always have data"); - } - -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.river.mercury.proxy; + +import org.apache.river.proxy.MarshalledWrapper; + +import java.io.InvalidObjectException; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.Serializable; +import java.util.Collection; + +import net.jini.core.event.RemoteEvent; +import net.jini.id.Uuid; +import net.jini.io.MarshalledInstance; + +/** + * Simple struct to hold a <code>RemoteEvent</code> and its associated + * <code>Object</code> (cookie) obtained from an <code>EventLog</code>. + */ +public class RemoteEventData implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * <code>MarshalledObject</code> that holds desired + * <code>RemoteEvent</code>. Wrapping the remote event + * permits deserialization to occur on demand on the + * client-side. + */ + private MarshalledInstance mi; + + /** Cookie associated with the <code>RemoteEvent</code> */ + private final Object cookie; + + /** + * <code>true</code> if the last time this object was unmarshalled + * integrity was being enforced, <code>false</code> otherwise. + */ + private transient boolean integrity; + + /** + * Creates a new RemoteEventData instance. + * @param re value of <code>re</code> field. + * @param cookie value of <code>cookie</code> field. + */ + public RemoteEventData(RemoteEvent re, Object cookie) { + try { + mi = (re==null)?null:new MarshalledInstance(re); + } catch (IOException ioe) { + mi = null; + } + this.cookie = cookie; + } + + public RemoteEvent getRemoteEvent() throws ClassNotFoundException { + if (mi == null) + throw new ClassNotFoundException( + "Failed to create server-side remote event"); + RemoteEvent re = null; + try { + re = (RemoteEvent)mi.get(integrity); + } catch (IOException ioe) { + throw new ClassNotFoundException( + "Failed to create client-side remote event", ioe); + } + return re; + } + + public Object getCookie() { + return cookie; + } + + /** + * Use <code>readObject</code> method to capture whether or + * not integrity was being enforced when this object was + * unmarshalled, and to perform basic integrity checks. + */ + private void readObject(ObjectInputStream in) + throws IOException, ClassNotFoundException + { + in.defaultReadObject(); + + if (cookie == null) + throw new InvalidObjectException("null cookie"); + + // get value for integrity flag + integrity = MarshalledWrapper.integrityEnforced(in); + } + + /** + * We should always have data in the stream, if this method + * gets called there is something wrong. + */ + private void readObjectNoData() throws InvalidObjectException { + throw new + InvalidObjectException("RemoteEventData should always have data"); + } + +}
