You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by ni...@apache.org on 2008/12/10 06:12:29 UTC
svn commit: r724976 [4/6] - in
/incubator/river/jtsk/skunk/niclas1/services/phoenix: ./ src/ src/main/
src/main/java/ src/main/java/com/ src/main/java/com/sun/
src/main/java/com/sun/jini/ src/main/java/com/sun/jini/phoenix/
src/main/java/com/sun/jini/p...
Added: incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/ExecOptionPermission.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/ExecOptionPermission.java?rev=724976&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/ExecOptionPermission.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/ExecOptionPermission.java Tue Dec 9 21:12:27 2008
@@ -0,0 +1,235 @@
+/*
+ * 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 com.sun.jini.phoenix;
+
+import java.io.FilePermission;
+import java.io.IOException;
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.security.Permission;
+
+/**
+ * Represents permission to use a specific option or options in the command
+ * for creating an activation group. An instance of this class 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 target name can be any of the
+ * following forms:
+ * <pre>
+ * "<i>literal</i>"
+ * <i>literal</i>*
+ * <i>literal</i>{<i>fpname</i>}
+ * <i>string</i>
+ * </pre>
+ * A target name is parsed according to the first form (in the order given
+ * above) that it matches. A <i>literal</i> is zero or more arbitrary
+ * characters. An <i>fpname</i> is zero or more characters, none of which
+ * are '{'. A <i>string</i> is zero or more arbitrary characters that do
+ * not match any of the previous forms.
+ * <p>
+ * An option <i>option</i> matches a target name of the form
+ * "<i>literal</i>" if <i>option</i> is equal to <i>literal</i>.
+ * <p>
+ * An option <i>option</i> matches a target name of the form
+ * <i>literal</i>* if <i>option</i> starts with <i>literal</i>.
+ * <p>
+ * An option <i>option</i> matches a target name of the form
+ * <i>literal</i>{<i>fpname</i>} if <i>option</i> starts with
+ * <i>literal</i> and the remainder of <i>option</i> matches <i>fpname</i>
+ * according to the matching semantics defined by {@link FilePermission};
+ * that is, if a <code>FilePermission</code> created with target name
+ * <i>fpname</i> (and some actions) implies a <code>FilePermission</code>
+ * created with the remainder of <i>option</i> (and the same actions).
+ * <p>
+ * An option <i>option</i> matches a target name of the form
+ * <i>string</i> if <i>option</i> is equal to <i>string</i>.
+ *
+ * @author Sun Microsystems, Inc.
+ * @since 2.0
+ */
+public final class ExecOptionPermission extends Permission
+{
+ private static final long serialVersionUID = 5842294756823092756L;
+
+ /**
+ * the name without any wildcard or fpname on the end
+ */
+ private transient String prefix;
+ /**
+ * true if the name ended with a wildcard or fpname, false otherwise
+ */
+ private transient boolean plain;
+ /*
+ * FilePermission containing fpname, if any
+ */
+ private transient Permission fp;
+
+ /**
+ * Constructs an instance with the specified name.
+ *
+ * @param name the target name
+ * @throws NullPointerException if the name is <code>null</code>
+ */
+ public ExecOptionPermission( String name )
+ {
+ super( name );
+ if( name == null )
+ {
+ throw new NullPointerException( "name cannot be null" );
+ }
+ init( name );
+ }
+
+ /**
+ * Parses the target name and initializes the transient fields.
+ */
+ private void init( String name )
+ {
+ prefix = name;
+ plain = true;
+ int last = name.length() - 1;
+ if( last >= 0 )
+ {
+ char c = name.charAt( last );
+ if( c == '"' && last > 0 && name.charAt( 0 ) == '"' )
+ {
+ prefix = name.substring( 1, last );
+ }
+ else if( c == '*' )
+ {
+ prefix = name.substring( 0, last );
+ plain = false;
+ }
+ else if( c == '}' )
+ {
+ int mid = name.lastIndexOf( '{' );
+ if( mid >= 0 )
+ {
+ prefix = name.substring( 0, mid );
+ String fpname = name.substring( mid + 1, last );
+ if( !fpname.equals( "<<ALL FILES>>" ) )
+ {
+ fp = new FilePermission( fpname, "read" );
+ }
+ plain = false;
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns <code>true</code> if the specified permission is an instance
+ * of <code>ExecOptionPermission</code> and every option that matches
+ * the name of specified permission also matches the name of this
+ * permission; returns <code>false</code> otherwise.
+ *
+ * @param p the permission to check
+ * @return <code>true</code> if the specified permission is an instance
+ * of <code>ExecOptionPermission</code> and every option that matches
+ * the name of specified permission also matches the name of this
+ * permission; <code>false</code> otherwise
+ */
+ public boolean implies( Permission p )
+ {
+ if( !( p instanceof ExecOptionPermission ) )
+ {
+ return false;
+ }
+ ExecOptionPermission ep = (ExecOptionPermission) p;
+ if( plain )
+ {
+ return ep.plain && prefix.equals( ep.prefix );
+ }
+ else if( fp == null )
+ {
+ return ep.prefix.startsWith( prefix );
+ }
+ else if( ep.plain )
+ {
+ return ( ep.prefix.startsWith( prefix ) &&
+ fp.implies( new FilePermission(
+ ep.prefix.substring( prefix.length() ),
+ "read" ) ) );
+ }
+ else
+ {
+ return prefix.equals( ep.prefix ) && fp.implies( ep.fp );
+ }
+ }
+
+ /**
+ * Two instances of this class are equal if each implies the other;
+ * that is, every option that matches the name of one instance matches
+ * the name of the other instance.
+ */
+ public boolean equals( Object obj )
+ {
+ if( !( obj instanceof ExecOptionPermission ) )
+ {
+ return false;
+ }
+ ExecOptionPermission p = (ExecOptionPermission) obj;
+ return ( prefix.equals( p.prefix ) &&
+ plain == p.plain &&
+ ( fp == null ? p.fp == null : fp.equals( p.fp ) ) );
+ }
+
+ /**
+ * Returns a hash code value for this object.
+ */
+ public int hashCode()
+ {
+ int h = prefix.hashCode();
+ if( !plain )
+ {
+ if( fp != null )
+ {
+ h += fp.hashCode();
+ }
+ else
+ {
+ h++;
+ }
+ }
+ return h;
+ }
+
+ /**
+ * Returns the empty string.
+ */
+ public String getActions()
+ {
+ return "";
+ }
+
+ /**
+ * Recreates any transient state.
+ *
+ * @throws InvalidObjectException if the target name is <code>null</code>
+ */
+ private void readObject( ObjectInputStream s )
+ throws IOException, ClassNotFoundException
+ {
+ s.defaultReadObject();
+ if( getName() == null )
+ {
+ throw new InvalidObjectException( "name cannot be null" );
+ }
+ init( getName() );
+ }
+}
Added: incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/ExecPermission.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/ExecPermission.java?rev=724976&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/ExecPermission.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/ExecPermission.java Tue Dec 9 21:12:27 2008
@@ -0,0 +1,119 @@
+/*
+ * 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 com.sun.jini.phoenix;
+
+import java.io.FilePermission;
+import java.io.IOException;
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.security.Permission;
+
+/**
+ * Represents permission to execute a command to create an activation group.
+ * An instance of this class 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 target name is any name accepted by {@link FilePermission},
+ * with the same matching semantics.
+ *
+ * @author Sun Microsystems, Inc.
+ * @since 2.0
+ */
+public final class ExecPermission extends Permission
+{
+ private static final long serialVersionUID = -6208470287358147919L;
+
+ /*
+ * FilePermission containing the name.
+ */
+ private transient Permission fp;
+
+ /**
+ * Constructs an instance with the specified name.
+ *
+ * @param name the target name
+ * @throws NullPointerException if the name is <code>null</code>
+ */
+ public ExecPermission( String name )
+ {
+ super( name );
+ fp = new FilePermission( name, "execute" );
+ }
+
+ /**
+ * Returns <code>true</code> if the specified permission is an instance
+ * of <code>ExecPermission</code> and a <code>FilePermission</code>
+ * constructed with the name of this permission implies a
+ * <code>FilePermission</code> constructed with the name of the specified
+ * permission; returns <code>false</code> otherwise.
+ *
+ * @param p the permission to check
+ * @return <code>true</code> if the specified permission is an instance
+ * of <code>ExecPermission</code> and a <code>FilePermission</code>
+ * constructed with the name of this permission implies a
+ * <code>FilePermission</code> constructed with the name of the specified
+ * permission; returns <code>false</code> otherwise.
+ */
+ public boolean implies( Permission p )
+ {
+ return ( p instanceof ExecPermission &&
+ fp.implies( ( (ExecPermission) p ).fp ) );
+ }
+
+ /**
+ * Two instances of this class are equal if <code>FilePermission</code>
+ * instances created with their names are equal.
+ */
+ public boolean equals( Object obj )
+ {
+ return ( obj instanceof ExecPermission &&
+ fp.equals( ( (ExecPermission) obj ).fp ) );
+ }
+
+ /**
+ * Returns a hash code value for this object.
+ */
+ public int hashCode()
+ {
+ return fp.hashCode();
+ }
+
+ /**
+ * Returns the empty string.
+ */
+ public String getActions()
+ {
+ return "";
+ }
+
+ /**
+ * Recreates any transient state.
+ *
+ * @throws InvalidObjectException if the target name is <code>null</code>
+ */
+ private void readObject( ObjectInputStream s )
+ throws IOException, ClassNotFoundException
+ {
+ s.defaultReadObject();
+ if( getName() == null )
+ {
+ throw new InvalidObjectException( "name cannot be null" );
+ }
+ fp = new FilePermission( getName(), "execute" );
+ }
+}
Added: incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/GroupOutputHandler.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/GroupOutputHandler.java?rev=724976&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/GroupOutputHandler.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/GroupOutputHandler.java Tue Dec 9 21:12:27 2008
@@ -0,0 +1,52 @@
+/*
+ * 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 com.sun.jini.phoenix;
+
+import java.io.InputStream;
+import java.rmi.activation.ActivationGroupDesc;
+import java.rmi.activation.ActivationGroupID;
+
+/**
+ * Defines the interface for handlers of the output of activation group
+ * processes.
+ *
+ * @author Sun Microsystems, Inc.
+ * @since 2.0
+ */
+public interface GroupOutputHandler
+{
+ /**
+ * Handles the output from an activation group process. The data
+ * from each of the specified streams must be read (asynchronously after
+ * this method returns) until EOF is reached, and processed in whatever
+ * manner is deemed appropriate by the handler.
+ *
+ * @param id the activation group identifier of the group
+ * @param desc the activation group descriptor of the group
+ * @param incarnation the current incarnation number of the group
+ * @param name the name of the group, in the form "Group-<i>n</i>"
+ * @param out a stream that produces the standard output of the group
+ * @param err a stream that produces the error output of the group
+ */
+ void handleOutput( ActivationGroupID id,
+ ActivationGroupDesc desc,
+ long incarnation,
+ String name,
+ InputStream out,
+ InputStream err );
+}
Added: incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/GroupPolicy.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/GroupPolicy.java?rev=724976&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/GroupPolicy.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/GroupPolicy.java Tue Dec 9 21:12:27 2008
@@ -0,0 +1,41 @@
+/*
+ * 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 com.sun.jini.phoenix;
+
+import java.rmi.activation.ActivationGroupDesc;
+
+/**
+ * Interface for policy objects to control what {@link ActivationGroupDesc}
+ * instances can be used.
+ *
+ * @author Sun Microsystems, Inc.
+ * @since 2.0
+ */
+public interface GroupPolicy
+{
+ /**
+ * Checks if the caller is permitted to use the specified group descriptor.
+ *
+ * @param desc group descriptor
+ * @throws java.security.AccessControlException
+ * if the caller is not
+ * permitted to use the specified group descriptor
+ */
+ void checkGroup( ActivationGroupDesc desc );
+}
Added: incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/InactiveGroupException.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/InactiveGroupException.java?rev=724976&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/InactiveGroupException.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/InactiveGroupException.java Tue Dec 9 21:12:27 2008
@@ -0,0 +1,43 @@
+/*
+ * 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 com.sun.jini.phoenix;
+
+import java.rmi.activation.ActivationException;
+
+/**
+ * Thrown if a local or remote call is made on a group implementation
+ * instance that is inactive.
+ *
+ * @author Sun Microsystems, Inc.
+ * @since 2.0
+ */
+public class InactiveGroupException extends ActivationException
+{
+ private static final long serialVersionUID = -4596896675720356592L;
+
+ /**
+ * Constructs an instance with the specified detail message.
+ *
+ * @param s the detail message
+ */
+ public InactiveGroupException( String s )
+ {
+ super( s );
+ }
+}
Added: incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/InstantiatorAccessExporter.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/InstantiatorAccessExporter.java?rev=724976&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/InstantiatorAccessExporter.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/InstantiatorAccessExporter.java Tue Dec 9 21:12:27 2008
@@ -0,0 +1,122 @@
+/*
+ * 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 com.sun.jini.phoenix;
+
+import java.rmi.MarshalledObject;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.rmi.activation.ActivationDesc;
+import java.rmi.activation.ActivationException;
+import java.rmi.activation.ActivationID;
+import java.rmi.activation.ActivationInstantiator;
+import java.rmi.server.ExportException;
+import net.jini.export.Exporter;
+import net.jini.jrmp.JrmpExporter;
+
+/**
+ * Exporter that wraps an <code>ActivationInstantiator</code> instance so that
+ * it only accepts calls from the local host.
+ *
+ * @author Sun Microsystems, Inc.
+ * @since 2.0
+ */
+public class InstantiatorAccessExporter implements Exporter
+{
+ /**
+ * The underlying exporter.
+ */
+ private final Exporter exporter;
+ /**
+ * The wrapped impl.
+ */
+ private Remote wrapped;
+
+ /**
+ * Creates an exporter with an underlying {@link JrmpExporter} that
+ * exports on an anonymous port.
+ */
+ public InstantiatorAccessExporter()
+ {
+ this.exporter = new JrmpExporter();
+ }
+
+ /**
+ * Creates an exporter with the specified underlying exporter.
+ *
+ * @param exporter the underlying exporter
+ */
+ public InstantiatorAccessExporter( Exporter exporter )
+ {
+ this.exporter = exporter;
+ }
+
+ /**
+ * Wraps the specified remote object in an
+ * <code>ActivationInstantiator</code> implementation that only accepts
+ * calls from the local host before delegating to the specified remote
+ * object, exports the wrapper with the underlying exporter, and returns
+ * the resulting proxy. The wrapper is strongly referenced by this
+ * exporter. For the <code>newInstance</code> method, the wrapper throws an
+ * <code>AccessControlException</code> if the client is not calling from
+ * the local host.
+ *
+ * @throws IllegalArgumentException if <code>impl</code> does not
+ * implement <code>ActivationInstantiator</code>
+ * @throws NullPointerException {@inheritDoc}
+ * @throws IllegalStateException {@inheritDoc}
+ */
+ public Remote export( Remote impl ) throws ExportException
+ {
+ if( !( impl instanceof ActivationInstantiator ) )
+ {
+ throw new IllegalArgumentException(
+ "not an ActivationInstantiator" );
+ }
+ Remote wrapped = new InstantiatorImpl( (ActivationInstantiator) impl );
+ Remote proxy = exporter.export( wrapped );
+ this.wrapped = wrapped;
+ return proxy;
+ }
+
+ /**
+ * @throws IllegalStateException {@inheritDoc}
+ */
+ public boolean unexport( boolean force )
+ {
+ return exporter.unexport( force );
+ }
+
+ private static class InstantiatorImpl extends AbstractInstantiator
+ {
+ private final ActivationInstantiator impl;
+
+ InstantiatorImpl( ActivationInstantiator impl )
+ {
+ this.impl = impl;
+ }
+
+ public MarshalledObject newInstance( ActivationID id,
+ ActivationDesc desc )
+ throws ActivationException, RemoteException
+ {
+ LocalAccess.check();
+ return impl.newInstance( id, desc );
+ }
+ }
+}
Added: incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/InstantiatorPermission.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/InstantiatorPermission.java?rev=724976&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/InstantiatorPermission.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/InstantiatorPermission.java Tue Dec 9 21:12:27 2008
@@ -0,0 +1,70 @@
+/*
+ * 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 com.sun.jini.phoenix;
+
+import net.jini.security.AccessPermission;
+
+/**
+ * Represents permissions that can be used to express the access control
+ * policy for the {@link java.rmi.activation.ActivationInstantiator} remote
+ * object exported with
+ * {@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 fully 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 the activation instantiator are:
+ * <table border=1 cellpadding=5>
+ * <tr>
+ * <th>Permission Target Name</th>
+ * <th>What the Permission Allows</th>
+ * <th>Risks of Allowing this Permission</th>
+ * </tr>
+ * <tr>
+ * <td>java.rmi.activation.ActivationInstantiator.newInstance</td>
+ * <td>invoking {@link java.rmi.activation.ActivationInstantiator#newInstance
+ * ActivationInstantiator.newInstance}</td>
+ * <td>The caller can inject a new object into the activation group if it
+ * knows the activation group identifier.</td>
+ * </tr>
+ * </table>
+ *
+ * @author Sun Microsystems, Inc.
+ * @since 2.0
+ */
+public final class InstantiatorPermission extends AccessPermission
+{
+ private static final long serialVersionUID = 6532912902541268520L;
+
+ /**
+ * Creates an instance with the specified name.
+ *
+ * @param name the target name
+ */
+ public InstantiatorPermission( String name )
+ {
+ super( name );
+ }
+}
Added: incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/LocalAccess.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/LocalAccess.java?rev=724976&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/LocalAccess.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/LocalAccess.java Tue Dec 9 21:12:27 2008
@@ -0,0 +1,79 @@
+/*
+ * 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 com.sun.jini.phoenix;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.rmi.server.ServerNotActiveException;
+import java.security.AccessControlException;
+import java.util.HashMap;
+import java.util.Map;
+import net.jini.export.ServerContext;
+import net.jini.io.context.ClientHost;
+
+/**
+ * @author Sun Microsystems, Inc.
+ * @since 2.0
+ */
+class LocalAccess
+{
+ private static Map cache = new HashMap( 3 );
+
+ private LocalAccess()
+ {
+ }
+
+ public static synchronized void check()
+ {
+ ClientHost host = null;
+ try
+ {
+ host = (ClientHost)
+ ServerContext.getServerContextElement( ClientHost.class );
+ }
+ catch( ServerNotActiveException e )
+ {
+ return;
+ }
+ if( host == null )
+ {
+ return;
+ }
+ InetAddress addr = host.getClientHost();
+ Boolean ok = (Boolean) cache.get( addr );
+ if( ok == null )
+ {
+ try
+ {
+ ok = Boolean.valueOf( NetworkInterface.getByInetAddress(
+ addr ) != null );
+ }
+ catch( IOException e )
+ {
+ ok = Boolean.FALSE;
+ }
+ cache.put( addr, ok );
+ }
+ if( !ok.booleanValue() )
+ {
+ throw new AccessControlException( "origin is non-local host" );
+ }
+ }
+}
Added: incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/MonitorAccessExporter.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/MonitorAccessExporter.java?rev=724976&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/MonitorAccessExporter.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/MonitorAccessExporter.java Tue Dec 9 21:12:27 2008
@@ -0,0 +1,149 @@
+/*
+ * 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 com.sun.jini.phoenix;
+
+import java.rmi.MarshalledObject;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.rmi.activation.ActivationGroupID;
+import java.rmi.activation.ActivationID;
+import java.rmi.activation.ActivationMonitor;
+import java.rmi.activation.ActivationSystem;
+import java.rmi.activation.UnknownGroupException;
+import java.rmi.activation.UnknownObjectException;
+import java.rmi.server.ExportException;
+import net.jini.export.Exporter;
+import net.jini.jrmp.JrmpExporter;
+
+/**
+ * Exporter that wraps an <code>ActivationMonitor</code> instance so that it
+ * only accepts calls from the local host.
+ *
+ * @author Sun Microsystems, Inc.
+ * @since 2.0
+ */
+public class MonitorAccessExporter implements Exporter
+{
+ /**
+ * The underlying exporter.
+ */
+ private final Exporter exporter;
+ /**
+ * The wrapped impl.
+ */
+ private Remote wrapped;
+
+ /**
+ * Creates an exporter with an underlying {@link JrmpExporter} that
+ * exports on the standard activation port (1098).
+ */
+ public MonitorAccessExporter()
+ {
+ this.exporter = new JrmpExporter( ActivationSystem.SYSTEM_PORT );
+ }
+
+ /**
+ * Creates an exporter with an underlying {@link JrmpExporter} that
+ * exports on the specified port.
+ *
+ * @param port the port on which to receive calls (if zero, an anonymous
+ * port will be chosen)
+ */
+ public MonitorAccessExporter( int port )
+ {
+ this.exporter = new JrmpExporter( port );
+ }
+
+ /**
+ * Creates an exporter with the specified underlying exporter.
+ *
+ * @param exporter the underlying exporter
+ */
+ public MonitorAccessExporter( Exporter exporter )
+ {
+ this.exporter = exporter;
+ }
+
+ /**
+ * Wraps the specified remote object in an <code>ActivationMonitor</code>
+ * implementation that only accepts calls from the local host before
+ * delegating to the specified remote object, exports the wrapper with
+ * the underlying exporter, and returns the resulting proxy. The wrapper
+ * is strongly referenced by this exporter. For all
+ * <code>ActivationMonitor</code> methods, the wrapper throws an
+ * <code>AccessControlException</code> if the client is not calling from
+ * the local host.
+ *
+ * @throws IllegalArgumentException if <code>impl</code> does not
+ * implement <code>ActivationMonitor</code>
+ * @throws NullPointerException {@inheritDoc}
+ * @throws IllegalStateException {@inheritDoc}
+ */
+ public Remote export( Remote impl ) throws ExportException
+ {
+ if( !( impl instanceof ActivationMonitor ) )
+ {
+ throw new IllegalArgumentException( "not an ActivationMonitor" );
+ }
+ Remote wrapped = new MonitorImpl( (ActivationMonitor) impl );
+ Remote proxy = exporter.export( wrapped );
+ this.wrapped = wrapped;
+ return proxy;
+ }
+
+ /**
+ * @throws IllegalStateException {@inheritDoc}
+ */
+ public boolean unexport( boolean force )
+ {
+ return exporter.unexport( force );
+ }
+
+ private static class MonitorImpl extends AbstractMonitor
+ {
+ private final ActivationMonitor impl;
+
+ MonitorImpl( ActivationMonitor impl )
+ {
+ this.impl = impl;
+ }
+
+ public void inactiveObject( ActivationID id )
+ throws UnknownObjectException, RemoteException
+ {
+ LocalAccess.check();
+ impl.inactiveObject( id );
+ }
+
+ public void activeObject( ActivationID id, MarshalledObject mobj )
+ throws UnknownObjectException, RemoteException
+ {
+ LocalAccess.check();
+ impl.activeObject( id, mobj );
+ }
+
+ public void inactiveGroup( ActivationGroupID id,
+ long incarnation )
+ throws UnknownGroupException, RemoteException
+ {
+ LocalAccess.check();
+ impl.inactiveGroup( id, incarnation );
+ }
+ }
+}
Added: incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/MonitorPermission.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/MonitorPermission.java?rev=724976&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/MonitorPermission.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/MonitorPermission.java Tue Dec 9 21:12:27 2008
@@ -0,0 +1,92 @@
+/*
+ * 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 com.sun.jini.phoenix;
+
+import java.rmi.activation.ActivationMonitor;
+import net.jini.security.AccessPermission;
+
+/**
+ * Represents permissions that can be used to express the access control
+ * policy for the {@link ActivationMonitor} remote object exported with
+ * {@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>This permission class can also be used to grant permission to invoke
+ * the method {@link java.rmi.activation.ActivationGroup#activeObject
+ * ActivationGroup.activeObject}, {@link
+ * java.rmi.activation.ActivationGroup#inactiveObject
+ * ActivationGroup.inactiveObject }, or {@link
+ * net.jini.activation.ActivationGroup#inactive ActivationGroup.inactive}.
+ *
+ * <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 fully 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 the activation monitor are:
+ * <table border=1 cellpadding=5>
+ * <tr>
+ * <th>Permission Target Name</th>
+ * <th>What the Permission Allows</th>
+ * <th>Risks of Allowing this Permission</th>
+ * </tr>
+ * <tr>
+ * <td>ActivationMonitor.activeObject</td>
+ * <td>invoking {@link ActivationMonitor#activeObject
+ * ActivationMonitor.activeObject}</td>
+ * <td>The caller can cause an object to be treated as active by the
+ * activation system and can inject the proxy for that object that will be
+ * returned by the activator, if it knows the activation identifier.</td>
+ * </tr>
+ * <tr>
+ * <td>ActivationMonitor.inactiveGroup</td>
+ * <td>invoking {@link ActivationMonitor#inactiveGroup
+ * ActivationMonitor.inactiveGroup}</td>
+ * <td>The caller can cause an activation group to be treated as inactive by
+ * the activation system if it knows the activation group identifier and
+ * the incarnation.</td>
+ * </tr>
+ * <tr>
+ * <td>ActivationMonitor.inactiveObject</td>
+ * <td>invoking {@link ActivationMonitor#inactiveObject
+ * ActivationMonitor.inactiveObject}</td>
+ * <td>The caller can cause an active object to be treated as inactive by
+ * the activation system if it knows the activation identifier.</td>
+ * </tr>
+ * </table>
+ *
+ * @author Sun Microsystems, Inc.
+ * @since 2.0
+ */
+public final class MonitorPermission extends AccessPermission
+{
+ private static final long serialVersionUID = 2475659022830374738L;
+
+ /**
+ * Creates an instance with the specified name.
+ *
+ * @param name the target name
+ */
+ public MonitorPermission( String name )
+ {
+ super( name );
+ }
+}
Added: incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/PhoenixConstants.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/PhoenixConstants.java?rev=724976&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/PhoenixConstants.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/PhoenixConstants.java Tue Dec 9 21:12:27 2008
@@ -0,0 +1,52 @@
+/*
+ * 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 com.sun.jini.phoenix;
+
+import net.jini.id.Uuid;
+import net.jini.id.UuidFactory;
+
+/**
+ * Provides constants for Phoenix.
+ *
+ * @author Sun Microsystems, Inc.
+ * @since 2.0
+ */
+public final class PhoenixConstants
+{
+
+ /**
+ * An object identifier for exporting the activator.
+ */
+ public static final Uuid ACTIVATOR_UUID =
+ UuidFactory.create( "d710347c-273c-11b2-bee3-080020c9e4a1" );
+
+ /**
+ * An object identifier for exporting the activation system.
+ */
+ public static final Uuid ACTIVATION_SYSTEM_UUID =
+ UuidFactory.create( "d7115186-273c-11b2-8836-080020c9e4a1" );
+
+ /**
+ * Prevents instantiation.
+ */
+ private PhoenixConstants()
+ {
+ throw new AssertionError();
+ }
+}
Added: incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/PhoenixStarter.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/PhoenixStarter.java?rev=724976&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/PhoenixStarter.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/PhoenixStarter.java Tue Dec 9 21:12:27 2008
@@ -0,0 +1,70 @@
+/*
+ * 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 com.sun.jini.phoenix;
+
+import com.sun.jini.start.LifeCycle;
+import com.sun.jini.start.ServiceProxyAccessor;
+
+/**
+ * Used to start phoenix from the {@link
+ * com.sun.jini.start.ServiceStarter}.
+ */
+class PhoenixStarter implements ServiceProxyAccessor
+{
+
+ /**
+ * reference to recovered Activation instance
+ */
+ private final Activation phoenixImpl;
+ /**
+ * the ActivationSystem proxy
+ */
+ private final Object serviceProxy;
+ /**
+ * the LifeCycle callback object
+ */
+ private final LifeCycle lifeCycle;
+
+ /**
+ * Constructs a <code>PhoenixStarter</code> instance. This
+ * constructor is defined such that it can be called from the
+ * {@link com.sun.jini.start.NonActivatableServiceDescriptor#create
+ * NonActivatableServiceDescriptor.create} method which allows
+ * phoenix to be started from the {@link
+ * com.sun.jini.start.ServiceStarter}.
+ */
+ PhoenixStarter( String[] configOptions, LifeCycle lifeCycle )
+ throws Exception
+ {
+ this.lifeCycle = lifeCycle;
+ this.phoenixImpl = Activation.main( configOptions, false, this );
+ this.serviceProxy = phoenixImpl.getActivationSystemProxy();
+ }
+
+ public Object getServiceProxy()
+ {
+ return serviceProxy;
+ }
+
+ void unregister()
+ {
+ lifeCycle.unregister( phoenixImpl );
+ }
+}
+
Added: incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/PipeWriter.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/PipeWriter.java?rev=724976&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/PipeWriter.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/PipeWriter.java Tue Dec 9 21:12:27 2008
@@ -0,0 +1,238 @@
+/*
+ * 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 com.sun.jini.phoenix;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.text.MessageFormat;
+import java.util.Date;
+
+/**
+ * PipeWriter plugs together two pairs of input and output streams by
+ * providing readers for input streams and writing through to
+ * appropriate output streams. Both output streams are annotated on a
+ * per-line basis.
+ *
+ * @author Sun Microsystems, Inc.
+ * @since 2.0
+ */
+class PipeWriter implements Runnable
+{
+
+ /**
+ * stream used for buffering lines
+ */
+ private final ByteArrayOutputStream bufOut;
+
+ /**
+ * count since last separator
+ */
+ private int cLast;
+
+ /**
+ * current chunk of input being compared to lineSeparator.
+ */
+ private final byte[] currSep;
+
+ private final PrintWriter out;
+ private final InputStream in;
+
+ private final String execString;
+ private final Object[] date = new Object[]{ new Date() };
+
+ private static final String lineSeparator =
+ System.getProperty( "line.separator" );
+ private static final int lineSeparatorLength = lineSeparator.length();
+ private static final String format = "{0,date} {0,time}";
+ private static final MessageFormat formatter = new MessageFormat( format );
+
+ /**
+ * Create a new PipeWriter object. All methods of PipeWriter,
+ * except plugTogetherPair, are only accessible to PipeWriter
+ * itself. Synchronization is unnecessary on functions that will
+ * only be used internally in PipeWriter.
+ *
+ * @param in input stream from which pipe input flows
+ * @param out output stream to which log messages will be sent
+ * @param name name of the process
+ * @param tag name of the stream (out or err)
+ */
+ private PipeWriter( InputStream in,
+ OutputStream out,
+ String name,
+ String tag )
+ {
+
+ this.in = in;
+ this.out = new PrintWriter( out );
+
+ bufOut = new ByteArrayOutputStream();
+ currSep = new byte[lineSeparatorLength];
+
+ /* set unique pipe/pair annotations */
+ execString = ":" + name + ':' + tag + ':';
+ }
+
+ /**
+ * Create a thread to listen and read from input stream, in. buffer
+ * the data that is read until a marker which equals lineSeparator
+ * is read. Once such a string has been discovered; write out an
+ * annotation string followed by the buffered data and a line
+ * separator.
+ */
+ public void run()
+ {
+ byte[] buf = new byte[256];
+ int count;
+
+ try
+ {
+ /* read bytes till there are no more. */
+ while( ( count = in.read( buf ) ) != -1 )
+ {
+ write( buf, 0, count );
+ }
+
+ /* flush internal buffer... may not have ended on a line
+ * separator, we also need a last annotation if
+ * something was left.
+ */
+ String lastInBuffer = bufOut.toString();
+ bufOut.reset();
+ if( lastInBuffer.length() > 0 )
+ {
+ out.println( createAnnotation() + lastInBuffer );
+ out.flush(); // add a line separator
+ // to make output nicer
+ }
+
+ }
+ catch( IOException e )
+ {
+ }
+ }
+
+ /**
+ * Write a subarray of bytes. Pass each through write byte method.
+ */
+ private void write( byte b[], int off, int len ) throws IOException
+ {
+
+ if( len < 0 )
+ {
+ throw new ArrayIndexOutOfBoundsException( len );
+ }
+ for( int i = 0; i < len; ++i )
+ {
+ write( b[ off + i ] );
+ }
+ }
+
+ /**
+ * Write a byte of data to the stream. If we have not matched a
+ * line separator string, then the byte is appended to the internal
+ * buffer. If we have matched a line separator, then the currently
+ * buffered line is sent to the output writer with a prepended
+ * annotation string.
+ */
+ private void write( byte b ) throws IOException
+ {
+ int i = 0;
+
+ /* shift current to the left */
+ for( i = 1; i < ( currSep.length ); i++ )
+ {
+ currSep[ i - 1 ] = currSep[ i ];
+ }
+ currSep[ i - 1 ] = b;
+ bufOut.write( b );
+
+ /* enough characters for a separator? */
+ if( ( cLast >= ( lineSeparatorLength - 1 ) ) &&
+ ( lineSeparator.equals( new String( currSep ) ) ) )
+ {
+
+ cLast = 0;
+
+ /* write prefix through to underlying byte stream */
+ out.print( createAnnotation() + bufOut.toString() );
+ out.flush();
+ bufOut.reset();
+
+ if( out.checkError() )
+ {
+ throw new IOException
+ ( "PipeWriter: IO Exception when" +
+ " writing to output stream." );
+ }
+
+ }
+ else
+ {
+ cLast++;
+ }
+ }
+
+ /**
+ * Create an annotation string to be printed out after
+ * a new line and end of stream.
+ */
+ private String createAnnotation()
+ {
+
+ /* construct prefix for log messages:
+ * date/time stamp...
+ */
+ StringBuffer text = new StringBuffer();
+ ( (Date) date[ 0 ] ).setTime( System.currentTimeMillis() );
+ formatter.format( date, text, null );
+ text.append( execString );
+ return text.toString();
+ }
+
+ /**
+ * Allow plugging together two pipes at a time, to associate
+ * output from an exec'ed process.
+ *
+ * @param name name of the process
+ * @param in input stream from which pipe input comes
+ * @param out output stream to which log messages will be sent
+ * @param in1 input stream from which pipe input comes
+ * @param out1 output stream to which log messages will be sent
+ */
+ static void plugTogetherPair( String name,
+ InputStream in,
+ OutputStream out,
+ InputStream in1,
+ OutputStream out1 )
+ {
+ /* start threads to read output from child process */
+ Thread outThread = new Thread( new PipeWriter( in, out, name, "out" ),
+ name + "-out" );
+ outThread.setDaemon( true );
+ outThread.start();
+ Thread errThread = new Thread( new PipeWriter( in1, out1, name, "err" ),
+ name + "-err" );
+ errThread.setDaemon( true );
+ errThread.start();
+ }
+}
Added: incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/RegistrySunExporter.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/RegistrySunExporter.java?rev=724976&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/RegistrySunExporter.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/RegistrySunExporter.java Tue Dec 9 21:12:27 2008
@@ -0,0 +1,121 @@
+/*
+ * 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 com.sun.jini.phoenix;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.rmi.Remote;
+import java.rmi.activation.ActivationSystem;
+import java.rmi.server.ObjID;
+import java.rmi.server.RemoteCall;
+import sun.rmi.server.MarshalInputStream;
+import sun.rmi.server.UnicastServerRef;
+import sun.rmi.transport.LiveRef;
+
+/**
+ * JRMP exporter to export a <code>Registry</code> using the well-known
+ * registry object identifier, and preventing remote code downloading for
+ * incoming remote calls. This exporter implementation is only designed to
+ * work with Java(TM) 2 Standard Edition implementations from Sun
+ * Microsystems(TM), Inc.
+ *
+ * @author Sun Microsystems, Inc.
+ * @since 2.0
+ */
+public class RegistrySunExporter extends SunJrmpExporter
+{
+ /**
+ * Creates a JRMP exporter that exports on the standard activation port
+ * (1098).
+ */
+ public RegistrySunExporter()
+ {
+ super( ObjID.REGISTRY_ID, ActivationSystem.SYSTEM_PORT );
+ }
+
+ /**
+ * Creates a JRMP exporter that exports on the specified port.
+ *
+ * @param port the port (if zero, an anonymous port will be chosen)
+ */
+ public RegistrySunExporter( int port )
+ {
+ super( ObjID.REGISTRY_ID, port );
+ }
+
+ UnicastServerRef getServerRef( LiveRef lref )
+ {
+ return new BootstrapServerRef( lref );
+ }
+
+ /**
+ * Server-side ref to prevent remote code downloading when unmarshalling
+ * arguments.
+ */
+ static class BootstrapServerRef extends UnicastServerRef
+ {
+ private static final long serialVersionUID = 3007040253722540025L;
+ private static Method useCodebaseOnly;
+
+ static
+ {
+ try
+ {
+ useCodebaseOnly =
+ MarshalInputStream.class.getDeclaredMethod(
+ "useCodebaseOnly", null );
+ }
+ catch( NoSuchMethodException e )
+ {
+ throw new InternalError( "XXX" );
+ }
+ useCodebaseOnly.setAccessible( true );
+ }
+
+ /**
+ * Construct an instance with the given live ref.
+ */
+ public BootstrapServerRef( LiveRef lref )
+ {
+ super( lref );
+ }
+
+ /**
+ * Disable remote code downloading on the input stream and then
+ * continue normal dispatching.
+ */
+ public void dispatch( Remote obj, RemoteCall call ) throws IOException
+ {
+ try
+ {
+ useCodebaseOnly.invoke( call.getInputStream(), new Object[0] );
+ }
+ catch( IllegalAccessException e )
+ {
+ throw new InternalError( "XXX" );
+ }
+ catch( InvocationTargetException e )
+ {
+ throw (Error) e.getTargetException();
+ }
+ super.dispatch( obj, call );
+ }
+ }
+}
Added: incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/SunJrmpExporter.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/SunJrmpExporter.java?rev=724976&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/SunJrmpExporter.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/SunJrmpExporter.java Tue Dec 9 21:12:27 2008
@@ -0,0 +1,167 @@
+/*
+ * 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 com.sun.jini.phoenix;
+
+import java.lang.ref.WeakReference;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.rmi.NoSuchObjectException;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.rmi.server.ExportException;
+import java.rmi.server.ObjID;
+import java.rmi.server.UnicastRemoteObject;
+import net.jini.export.Exporter;
+import sun.rmi.server.UnicastServerRef;
+import sun.rmi.transport.LiveRef;
+
+/**
+ * JRMP exporter to export an object using a well-known object identifier.
+ * This exporter implementation is only designed to work with
+ * Java(TM) 2 Standard Edition implementations from Sun Microsystems(TM), Inc.
+ *
+ * @author Sun Microsystems, Inc.
+ * @since 2.0
+ */
+public class SunJrmpExporter implements Exporter
+{
+ /**
+ * The object identifier.
+ */
+ private final int id;
+ /**
+ * The port.
+ */
+ private final int port;
+ /**
+ * Weak reference to the impl.
+ */
+ private WeakReference ref;
+
+ private static final Method exportMethod;
+
+ static
+ {
+ try
+ {
+ Class[] paramTypes =
+ new Class[]{ Remote.class, Object.class, boolean.class };
+ exportMethod = UnicastServerRef.class.getMethod( "exportObject",
+ paramTypes );
+ }
+ catch( NoSuchMethodException nsme )
+ {
+ throw (Error) new NoSuchMethodError().initCause( nsme );
+ }
+ }
+
+ /**
+ * Creates a JRMP exporter that exports using the specified well-known
+ * object identifier and the specified port.
+ *
+ * @param id the object identifier
+ * @param port the port (if zero, an anonymous port will be chosen)
+ */
+ public SunJrmpExporter( int id, int port )
+ {
+ this.id = id;
+ this.port = port;
+ }
+
+ /**
+ * @throws NullPointerException {@inheritDoc}
+ * @throws IllegalStateException {@inheritDoc}
+ */
+ public Remote export( Remote impl ) throws ExportException
+ {
+ if( ref != null )
+ {
+ throw new IllegalStateException( "already used for export" );
+ }
+ else if( impl == null )
+ {
+ throw new NullPointerException();
+ }
+ ref = new WeakReference( impl );
+ UnicastServerRef uref = getServerRef( new LiveRef( new ObjID( id ), port ) );
+ try
+ {
+ Object[] args = new Object[]{ impl, null, Boolean.TRUE };
+ return (Remote) exportMethod.invoke( uref, args );
+ }
+ catch( InvocationTargetException e )
+ {
+ Throwable t = e.getTargetException();
+ if( t instanceof ExportException )
+ {
+ throw (ExportException) t;
+ }
+ else if( t instanceof RemoteException )
+ {
+ throw new ExportException( "export failed", (Exception) t );
+ }
+ else if( t instanceof RuntimeException )
+ {
+ throw (RuntimeException) t;
+ }
+ else if( t instanceof Error )
+ {
+ throw (Error) t;
+ }
+ else
+ {
+ throw new AssertionError( t );
+ }
+ }
+ catch( IllegalAccessException e )
+ {
+ throw (Error) new IllegalAccessError().initCause( e );
+ }
+ }
+
+ UnicastServerRef getServerRef( LiveRef lref )
+ {
+ return new UnicastServerRef( lref );
+ }
+
+ /**
+ * @throws IllegalStateException {@inheritDoc}
+ */
+ public boolean unexport( boolean force )
+ {
+ if( ref == null )
+ {
+ throw new IllegalStateException(
+ "no object exported through this exporter" );
+ }
+ Remote impl = (Remote) ref.get();
+ if( impl == null )
+ {
+ return true;
+ }
+ try
+ {
+ return UnicastRemoteObject.unexportObject( impl, force );
+ }
+ catch( NoSuchObjectException ex )
+ {
+ return true;
+ }
+ }
+}
Added: incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/SystemAccessExporter.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/SystemAccessExporter.java?rev=724976&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/SystemAccessExporter.java (added)
+++ incubator/river/jtsk/skunk/niclas1/services/phoenix/src/main/java/com/sun/jini/phoenix/SystemAccessExporter.java Tue Dec 9 21:12:27 2008
@@ -0,0 +1,282 @@
+/*
+ * 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 com.sun.jini.phoenix;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.rmi.activation.ActivationDesc;
+import java.rmi.activation.ActivationException;
+import java.rmi.activation.ActivationGroupDesc;
+import java.rmi.activation.ActivationGroupID;
+import java.rmi.activation.ActivationID;
+import java.rmi.activation.ActivationInstantiator;
+import java.rmi.activation.ActivationMonitor;
+import java.rmi.activation.ActivationSystem;
+import java.rmi.activation.UnknownGroupException;
+import java.rmi.server.ExportException;
+import java.util.Map;
+import net.jini.export.Exporter;
+
+/**
+ * Exporter that wraps an <code>ActivationSystem</code> instance so that it
+ * only accepts calls from the local host and optionally enforces a
+ * {@link GroupPolicy} on calls to <code>registerGroup</code> and
+ * <code>setActivationGroupDesc</code>.
+ *
+ * @author Sun Microsystems, Inc.
+ * @since 2.0
+ */
+public class SystemAccessExporter implements Exporter
+{
+ /**
+ * The underlying exporter.
+ */
+ private final Exporter exporter;
+ /**
+ * The group policy, if any.
+ */
+ private final GroupPolicy policy;
+ /**
+ * The wrapped impl.
+ */
+ private Remote wrapped;
+
+ /**
+ * Creates an exporter with an underlying {@link SunJrmpExporter} that
+ * exports using a well-known object identifier (4) on the standard
+ * activation port (1098), and a {@link DefaultGroupPolicy} instance.
+ */
+ public SystemAccessExporter()
+ {
+ this( ActivationSystem.SYSTEM_PORT );
+ }
+
+ /**
+ * Creates an exporter with an underlying {@link SunJrmpExporter} that
+ * exports using a well-known object identifier (4) on the standard
+ * activation port (1098), and the specified group policy, if any.
+ *
+ * @param policy the group policy, or <code>null</code>
+ */
+ public SystemAccessExporter( GroupPolicy policy )
+ {
+ this( ActivationSystem.SYSTEM_PORT, policy );
+ }
+
+ /**
+ * Creates an exporter with an underlying {@link SunJrmpExporter} that
+ * exports using a well-known object identifier (4) on the specified port,
+ * and a {@link DefaultGroupPolicy} instance.
+ *
+ * @param port the port on which to receive calls (if zero, an anonymous
+ * port will be chosen)
+ */
+ public SystemAccessExporter( int port )
+ {
+ this( port, new DefaultGroupPolicy() );
+ }
+
+ /**
+ * Creates an exporter with an underlying {@link SunJrmpExporter} that
+ * exports using a well-known object identifier (4) on the specified port,
+ * and the specified group policy, if any.
+ *
+ * @param port the port on which to receive calls (if zero, an anonymous
+ * port will be chosen)
+ * @param policy the group policy, or <code>null</code>
+ */
+ public SystemAccessExporter( int port, GroupPolicy policy )
+ {
+ this( new SunJrmpExporter( 4, port ), policy );
+ }
+
+ /**
+ * Creates an exporter with the specified underlying exporter and a
+ * {@link DefaultGroupPolicy} instance.
+ *
+ * @param exporter the underlying exporter
+ */
+ public SystemAccessExporter( Exporter exporter )
+ {
+ this( exporter, new DefaultGroupPolicy() );
+ }
+
+ /**
+ * Creates an exporter with the specified underlying exporter and the
+ * specified group policy, if any.
+ *
+ * @param exporter the underlying exporter
+ * @param policy the group policy, or <code>null</code>
+ */
+ public SystemAccessExporter( Exporter exporter, GroupPolicy policy )
+ {
+ this.exporter = exporter;
+ this.policy = policy;
+ }
+
+ /**
+ * Wraps the specified remote object in an <code>ActivationSystem</code>
+ * implementation that only accepts calls from the local host and
+ * enforces the group policy (if any) before delegating to the specified
+ * remote object, exports the wrapper with the underlying exporter, and
+ * returns the resulting proxy. The wrapper is strongly referenced by
+ * this exporter. For all <code>ActivationSystem</code> and
+ * <code>ActivationAdmin</code> methods, the wrapper throws an
+ * <code>AccessControlException</code> if the client is not calling from
+ * the local host. For the <code>registerGroup</code> and
+ * <code>setActivationGroupDesc</code> methods, the policy (if any)
+ * is checked by calling its {@link GroupPolicy#checkGroup checkGroup}
+ * method with the <code>ActivationGroupDesc</code> argument.
+ *
+ * @throws IllegalArgumentException if <code>impl</code> does not
+ * implement <code>ActivationSystem</code> or <code>ActivationAdmin</code>
+ * @throws NullPointerException {@inheritDoc}
+ * @throws IllegalStateException {@inheritDoc}
+ */
+ public Remote export( Remote impl ) throws ExportException
+ {
+ if( !( impl instanceof ActivationSystem ) )
+ {
+ throw new IllegalArgumentException( "not an ActivationSystem" );
+ }
+ if( !( impl instanceof ActivationAdmin ) )
+ {
+ throw new IllegalArgumentException( "not an ActivationAdmin" );
+ }
+ Remote wrapped = new SystemImpl( (ActivationSystem) impl, policy );
+ Remote proxy = exporter.export( wrapped );
+ this.wrapped = wrapped;
+ return proxy;
+ }
+
+ /**
+ * @throws IllegalStateException {@inheritDoc}
+ */
+ public boolean unexport( boolean force )
+ {
+ return exporter.unexport( force );
+ }
+
+ private static class SystemImpl extends AbstractSystem
+ {
+ private final ActivationSystem impl;
+ private final GroupPolicy policy;
+
+ SystemImpl( ActivationSystem impl, GroupPolicy policy )
+ {
+ this.impl = impl;
+ this.policy = policy;
+ }
+
+ public ActivationID registerObject( ActivationDesc desc )
+ throws ActivationException, RemoteException
+ {
+ LocalAccess.check();
+ return impl.registerObject( desc );
+ }
+
+ public void unregisterObject( ActivationID id )
+ throws ActivationException, RemoteException
+ {
+ LocalAccess.check();
+ impl.unregisterObject( id );
+ }
+
+ public ActivationGroupID registerGroup( ActivationGroupDesc desc )
+ throws ActivationException, RemoteException
+ {
+ LocalAccess.check();
+ if( policy != null )
+ {
+ policy.checkGroup( desc );
+ }
+ return impl.registerGroup( desc );
+ }
+
+ public ActivationMonitor activeGroup( ActivationGroupID id,
+ ActivationInstantiator group,
+ long incarnation )
+ throws ActivationException, RemoteException
+ {
+ LocalAccess.check();
+ return impl.activeGroup( id, group, incarnation );
+ }
+
+ public void unregisterGroup( ActivationGroupID id )
+ throws ActivationException, RemoteException
+ {
+ LocalAccess.check();
+ impl.unregisterGroup( id );
+ }
+
+ public ActivationDesc setActivationDesc( ActivationID id,
+ ActivationDesc desc )
+ throws ActivationException, RemoteException
+ {
+ LocalAccess.check();
+ return impl.setActivationDesc( id, desc );
+ }
+
+ public ActivationGroupDesc setActivationGroupDesc(
+ ActivationGroupID id,
+ ActivationGroupDesc desc )
+ throws ActivationException, RemoteException
+ {
+ LocalAccess.check();
+ if( policy != null )
+ {
+ policy.checkGroup( desc );
+ }
+ return impl.setActivationGroupDesc( id, desc );
+ }
+
+ public ActivationDesc getActivationDesc( ActivationID id )
+ throws ActivationException, RemoteException
+ {
+ LocalAccess.check();
+ return impl.getActivationDesc( id );
+ }
+
+ public ActivationGroupDesc getActivationGroupDesc( ActivationGroupID id )
+ throws ActivationException, RemoteException
+ {
+ LocalAccess.check();
+ return impl.getActivationGroupDesc( id );
+ }
+
+ public void shutdown() throws RemoteException
+ {
+ LocalAccess.check();
+ impl.shutdown();
+ }
+
+ public Map getActivationGroups() throws RemoteException
+ {
+ LocalAccess.check();
+ return ( (ActivationAdmin) impl ).getActivationGroups();
+ }
+
+ public Map getActivatableObjects( ActivationGroupID id )
+ throws UnknownGroupException, RemoteException
+ {
+ LocalAccess.check();
+ return ( (ActivationAdmin) impl ).getActivatableObjects( id );
+ }
+ }
+}