mcconnell 2004/02/24 13:35:31
Modified: meta/api/src/java/org/apache/avalon/meta/info
PermissionDescriptor.java Type.java
meta/api/src/test/org/apache/avalon/meta/info/test
PermissionDescriptorTestCase.java TypeTestCase.java
Added: meta/api/src/java/org/apache/avalon/meta/info
SecurityDescriptor.java
Log:
Add a SecurityDescriptor to hold the PermissionDescriptor and update Type to expose
the SecurityDescriptor.
Revision Changes Path
1.2 +31 -4
avalon/meta/api/src/java/org/apache/avalon/meta/info/PermissionDescriptor.java
Index: PermissionDescriptor.java
===================================================================
RCS file:
/home/cvs/avalon/meta/api/src/java/org/apache/avalon/meta/info/PermissionDescriptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PermissionDescriptor.java 24 Feb 2004 15:25:00 -0000 1.1
+++ PermissionDescriptor.java 24 Feb 2004 21:35:31 -0000 1.2
@@ -37,6 +37,9 @@
implements Serializable
{
+ private static final String[] EMPTY_ACTIONS =
+ new String[0];
+
/**
* The permission classname.
*/
@@ -59,7 +62,7 @@
* @param actions the permission actions
*/
public PermissionDescriptor(
- final String classname, final String name, final String actions )
+ final String classname, final String name, final String[] actions )
{
if ( null == classname )
{
@@ -68,7 +71,14 @@
m_classname = classname;
m_name = name;
- m_actions = expandActions( actions );
+ if( null == actions )
+ {
+ m_actions = EMPTY_ACTIONS;
+ }
+ else
+ {
+ m_actions = actions;
+ }
}
/**
@@ -116,7 +126,6 @@
if ( isEqual )
{
PermissionDescriptor permission = (PermissionDescriptor) other;
-
isEqual = isEqual && m_classname.equals( permission.m_classname );
if ( null == m_name )
{
@@ -171,5 +180,23 @@
list.add( tokenizer.nextToken() );
}
return (String[]) list.toArray( new String[0] );
+ }
+
+ public String toString()
+ {
+ String list = "";
+ for( int i=0; i<m_actions.length; i++ )
+ {
+ list = list + m_actions[i];
+ if( i < (m_actions.length - 1 ))
+ {
+ list = list + ", ";
+ }
+ }
+ return "[permission class="
+ + getClassname()
+ + " name=" + getName()
+ + " actions=" + list
+ + "]";
}
}
1.4 +58 -1 avalon/meta/api/src/java/org/apache/avalon/meta/info/Type.java
Index: Type.java
===================================================================
RCS file: /home/cvs/avalon/meta/api/src/java/org/apache/avalon/meta/info/Type.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Type.java 24 Jan 2004 23:20:45 -0000 1.3
+++ Type.java 24 Feb 2004 21:35:31 -0000 1.4
@@ -44,6 +44,7 @@
public class Type implements Serializable
{
private final InfoDescriptor m_descriptor;
+ private final SecurityDescriptor m_security;
private final ContextDescriptor m_context;
private final Configuration m_configuration;
private final ServiceDescriptor[] m_services;
@@ -117,10 +118,52 @@
final Configuration defaults )
throws NullPointerException
{
+ this(
+ descriptor, new SecurityDescriptor( null, null ), loggers, context,
services, dependencies,
+ stages, extensions, defaults );
+ }
+
+ /**
+ * Creation of a new Type instance using a supplied component descriptor,
+ * logging, cotext, services, depedencies, stages and extension descriptors.
+ * @param descriptor a component descriptor that contains information about
+ * the component type
+ * @param security a component security descriptor
+ * @param loggers a set of logger descriptors the declare the logging channels
+ * required by the type
+ * @param context a component context descriptor that declares the context type
+ * and context entry key and value classnames
+ * @param services a set of service descriprors that detail the service that
+ * this component type is capable of supplying
+ * @param dependencies a set of depedency descriprors that detail the service
+ * that this component type is depedent on
+ * @param stages a set of stage descriprors that detail the extensiuon stage
+ * interfaces that this component requires a handler for
+ * @param extensions a set of lifecycle extension capabilities that this
+ * componet can provide to its container during the process of stage
+ * suppier resolution
+ * @exception NullPointerException if the descriptor, loggers, context,
services,
+ * dependencies, stages, or extensions argument is null
+ */
+ public Type( final InfoDescriptor descriptor,
+ final SecurityDescriptor security,
+ final CategoryDescriptor[] loggers,
+ final ContextDescriptor context,
+ final ServiceDescriptor[] services,
+ final DependencyDescriptor[] dependencies,
+ final StageDescriptor[] stages,
+ final ExtensionDescriptor[] extensions,
+ final Configuration defaults )
+ throws NullPointerException
+ {
if ( null == descriptor )
{
throw new NullPointerException( "descriptor" );
}
+ if ( null == security )
+ {
+ throw new NullPointerException( "security" );
+ }
if ( null == loggers )
{
throw new NullPointerException( "loggers" );
@@ -147,6 +190,7 @@
}
m_descriptor = descriptor;
+ m_security = security;
m_loggers = loggers;
m_context = context;
m_services = services;
@@ -167,6 +211,16 @@
}
/**
+ * Return the security descriptor
+ *
+ * @return the security descriptor.
+ */
+ public SecurityDescriptor getSecurity()
+ {
+ return m_security;
+ }
+
+ /**
* Return the set of Logger that this Component will use.
*
* @return the set of Logger that this Component will use.
@@ -362,6 +416,7 @@
{
boolean isEqual = other instanceof Type;
isEqual = isEqual && m_descriptor.equals(((Type)other).m_descriptor);
+ isEqual = isEqual && m_security.equals(((Type)other).m_security);
isEqual = isEqual && m_configuration.equals(((Type)other).m_configuration);
isEqual = isEqual && m_context.equals(((Type)other).m_context);
for( int i=0; i<m_loggers.length; i++ )
@@ -394,6 +449,8 @@
public int hashCode()
{
int hash = m_descriptor.hashCode();
+ hash >>>= 13;
+ hash ^= m_security.hashCode();
hash >>>= 13;
hash ^= m_context.hashCode();
hash >>>= 13;
1.1
avalon/meta/api/src/java/org/apache/avalon/meta/info/SecurityDescriptor.java
Index: SecurityDescriptor.java
===================================================================
/*
* Copyright 2004 Apache Software Foundation
* Licensed 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.avalon.meta.info;
import java.util.Properties;
import org.apache.avalon.framework.Version;
/**
* This class is used to provide security information to assembler
* and administrator about the component type.
*
* <p>The SecurityDescriptor also includes an arbitrary set
* of attributes about component. Usually these are container
* specific attributes that can store arbitrary information.
* The attributes should be stored with keys based on package
* name of container.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
* @version $Revision: 1.1 $ $Date: 2004/02/24 21:35:31 $
*/
public final class SecurityDescriptor extends Descriptor
{
//-------------------------------------------------------------------
// static
//-------------------------------------------------------------------
private static final PermissionDescriptor[] EMPTY_PERMISSIONS =
new PermissionDescriptor[0];
//-------------------------------------------------------------------
// immutable state
//-------------------------------------------------------------------
/**
* The set of permissions that this component type requires in order
* to execute.
*/
private final PermissionDescriptor[] m_permissions;
//-------------------------------------------------------------------
// constructor
//-------------------------------------------------------------------
/**
* Creation of a new info descriptor using a supplied name, key, version
* and attribute set.
*
* @param permissions the set of permissions
* @param supplimentary security attributes
* @since 1.4
*/
public SecurityDescriptor(
final PermissionDescriptor[] permissions,
final Properties attributes )
{
super( attributes );
if ( null == permissions )
{
m_permissions = EMPTY_PERMISSIONS;
}
else
{
m_permissions = permissions;
}
}
/**
* Return the set of permissions requested by the component type.
*
* @return the permissions
*/
public PermissionDescriptor[] getPermissions()
{
return m_permissions;
}
/**
* Test is the supplied object is equal to this object.
* @return true if the object are equivalent
*/
public boolean equals(Object other)
{
boolean isEqual = super.equals(other) && other instanceof SecurityDescriptor;
if (isEqual)
{
SecurityDescriptor security = (SecurityDescriptor) other;
PermissionDescriptor[] permissions = security.getPermissions();
if( m_permissions.length != permissions.length ) return false;
for( int i=0; i<permissions.length; i++ )
{
if( !permissions[i].equals( m_permissions[i] ) )return false;
}
}
return isEqual;
}
/**
* Return the hashcode for the object.
* @return the hashcode value
*/
public int hashCode()
{
int hash = super.hashCode();
hash >>>= 7;
for( int i=0; i<m_permissions.length; i++ )
{
hash ^= m_permissions[i].hashCode();
hash >>>= 13;
}
return hash;
}
public String toString()
{
StringBuffer buffer = new StringBuffer( "[security " );
for( int i=0; i<m_permissions.length; i++ )
{
buffer.append( m_permissions[i].toString() );
}
buffer.append( "]" );
return buffer.toString();
}
}
1.2 +2 -3
avalon/meta/api/src/test/org/apache/avalon/meta/info/test/PermissionDescriptorTestCase.java
Index: PermissionDescriptorTestCase.java
===================================================================
RCS file:
/home/cvs/avalon/meta/api/src/test/org/apache/avalon/meta/info/test/PermissionDescriptorTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PermissionDescriptorTestCase.java 24 Feb 2004 16:19:57 -0000 1.1
+++ PermissionDescriptorTestCase.java 24 Feb 2004 21:35:31 -0000 1.2
@@ -32,7 +32,6 @@
{
private static final String m_classname = FilePermission.class.getName();
private static final String m_name = "${avalon.dir}";
- private static final String m_actionsList = "read,write";
private static final String[] m_actions = new String[]{"read","write"};
public PermissionDescriptorTestCase( String name )
@@ -79,14 +78,14 @@
public void testPermission()
{
- PermissionDescriptor d = new PermissionDescriptor( m_classname, m_name,
m_actionsList );
+ PermissionDescriptor d = new PermissionDescriptor( m_classname, m_name,
m_actions );
check( d, m_classname, m_name, m_actions );
}
public void testSerialization() throws IOException, ClassNotFoundException
{
- PermissionDescriptor p = new PermissionDescriptor( m_classname, m_name,
m_actionsList );
+ PermissionDescriptor p = new PermissionDescriptor( m_classname, m_name,
m_actions );
File file = new File( "test.out" );
ObjectOutputStream oos = new ObjectOutputStream( new FileOutputStream( file
) );
1.4 +5 -2
avalon/meta/api/src/test/org/apache/avalon/meta/info/test/TypeTestCase.java
Index: TypeTestCase.java
===================================================================
RCS file:
/home/cvs/avalon/meta/api/src/test/org/apache/avalon/meta/info/test/TypeTestCase.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TypeTestCase.java 21 Feb 2004 13:27:03 -0000 1.3
+++ TypeTestCase.java 24 Feb 2004 21:35:31 -0000 1.4
@@ -34,6 +34,7 @@
public class TypeTestCase extends TestCase
{
private InfoDescriptor m_descriptor;
+ private SecurityDescriptor m_security;
private CategoryDescriptor[] m_loggers;
private ContextDescriptor m_context;
private ServiceDescriptor[] m_services;
@@ -54,6 +55,7 @@
m_reference = new ReferenceDescriptor(TypeTestCase.class.getName());
m_key = TypeTestCase.class.getName();
m_descriptor = createSimpleInfo(TypeTestCase.class.getName());
+ m_security = new SecurityDescriptor( null, null );
m_loggers = new CategoryDescriptor[] {
new CategoryDescriptor("name", new Properties())
};
@@ -78,6 +80,7 @@
{
assertNotNull(type);
checkArray(m_loggers, type.getCategories());
+ assertEquals( m_security, type.getSecurity() );
assertEquals( m_defaults, type.getConfiguration() );
assertEquals( m_context, type.getContext());
checkArray(m_dependencies, type.getDependencies());
@@ -106,7 +109,7 @@
{
Type type =
new Type(
- m_descriptor, m_loggers, m_context, m_services, m_dependencies,
+ m_descriptor, m_security, m_loggers, m_context, m_services,
m_dependencies,
m_stages, m_extensions, m_defaults);
checkType(type);
}
@@ -115,7 +118,7 @@
{
Type type =
new Type(
- m_descriptor, m_loggers, m_context, m_services, m_dependencies,
+ m_descriptor, m_security, m_loggers, m_context, m_services,
m_dependencies,
m_stages, m_extensions, m_defaults );
checkType( type );
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]