notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
r1048 - in trunk/main/planet/web/server: . src/main/net/dpml/web/server
- From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
- To: notify-dpml AT lists.ibiblio.org
- Subject: r1048 - in trunk/main/planet/web/server: . src/main/net/dpml/web/server
- Date: Mon, 6 Feb 2006 20:59:00 +0100
Author: mcconnell
Date: 2006-02-06 20:58:50 +0100 (Mon, 06 Feb 2006)
New Revision: 1048
Modified:
trunk/main/planet/web/server/build.xml
trunk/main/planet/web/server/src/main/net/dpml/web/server/HashUserRealm.java
trunk/main/planet/web/server/src/main/net/dpml/web/server/Server.java
Log:
Add user realm component and server-based unfolding of realms.
Modified: trunk/main/planet/web/server/build.xml
===================================================================
--- trunk/main/planet/web/server/build.xml 2006-02-06 19:25:51 UTC (rev
1047)
+++ trunk/main/planet/web/server/build.xml 2006-02-06 19:58:50 UTC (rev
1048)
@@ -24,33 +24,33 @@
<target name="build" depends="standard.build">
<depot:plugin uri="link:plugin:dpml/metro/dpml-metro-tools" urn="metro"/>
- <type xmlns="metro" class="net.dpml.web.server.NCSARequestLog"
threadsafe="true" name="ncsa">
+ <type xmlns="metro" name="static"
class="net.dpml.web.server.ResourceContextHandler" threadsafe="true" >
<services>
- <service class="org.mortbay.jetty.RequestLog"/>
+ <service class="net.dpml.web.server.ResourceContextHandler"/>
</services>
</type>
- <type xmlns="metro" name="context"
class="net.dpml.web.server.ContextHandler" threadsafe="true" >
+ <type xmlns="metro" name="servlets"
class="net.dpml.web.server.ServletContextHandler" threadsafe="true" >
<services>
- <service class="org.mortbay.jetty.handler.ContextHandler"/>
+ <service class="net.dpml.web.server.ServletContextHandler"/>
</services>
</type>
- <type xmlns="metro" name="static"
class="net.dpml.web.server.ResourceContextHandler" threadsafe="true" >
+ <type xmlns="metro" name="apps"
class="net.dpml.web.server.WebAppContextHandler" threadsafe="true" >
<services>
- <service class="net.dpml.web.server.ResourceContextHandler"/>
+ <service class="net.dpml.web.server.WebAppContextHandler"/>
</services>
</type>
- <type xmlns="metro" name="servlets"
class="net.dpml.web.server.ServletContextHandler" threadsafe="true" >
+ <type xmlns="metro" class="net.dpml.web.server.NCSARequestLog"
threadsafe="true" name="ncsa">
<services>
- <service class="net.dpml.web.server.ServletContextHandler"/>
+ <service class="org.mortbay.jetty.RequestLog"/>
</services>
</type>
- <type xmlns="metro" name="apps"
class="net.dpml.web.server.WebAppContextHandler" threadsafe="true" >
+ <type xmlns="metro" class="net.dpml.web.server.HashUserRealm"
threadsafe="true" name="realm">
<services>
- <service class="net.dpml.web.server.WebAppContextHandler"/>
+ <service class="org.mortbay.jetty.security.UserRealm"/>
</services>
</type>
@@ -93,6 +93,15 @@
<component xmlns="metro" type="net.dpml.web.server.Server"
lifestyle="singleton">
<parts>
<!--
+ Add a user realm.
+ -->
+ <component key="realm" type="net.dpml.web.server.HashUserRealm">
+ <context>
+ <entry key="name" value="Test Realm"/>
+ <entry key="URI" value="local:properties:dpml/planet/web/realm"/>
+ </context>
+ </component>
+ <!--
Add an experimental web app.
-->
<component key="apps"
type="net.dpml.web.server.WebAppContextHandler">
Modified:
trunk/main/planet/web/server/src/main/net/dpml/web/server/HashUserRealm.java
===================================================================
---
trunk/main/planet/web/server/src/main/net/dpml/web/server/HashUserRealm.java
2006-02-06 19:25:51 UTC (rev 1047)
+++
trunk/main/planet/web/server/src/main/net/dpml/web/server/HashUserRealm.java
2006-02-06 19:58:50 UTC (rev 1048)
@@ -19,46 +19,37 @@
import java.io.IOException;
import java.net.URI;
-import net.dpml.transit.util.PropertyResolver;
-
/**
* Hash user realm with enhanced keystore resolution semantics.
*/
public class HashUserRealm extends org.mortbay.jetty.security.HashUserRealm
{
- /**
- * Load realm users from properties file.
- * The property file maps usernames to password specs followed by
- * an optional comma separated list of role names. The implementation
- * provides support for Transit local protocol resoution and system
- * property symbolic expansion.
- *
- * @param config Filename or url of user properties file.
- * @exception IOException is an IO error occurs
- */
- public void setConfig( String config ) throws IOException
+ /**
+ * HTTP Context handler context defintion.
+ */
+ public interface Context
{
- String resolved = PropertyResolver.resolve( config );
- if( resolved.startsWith( "local:" ) )
- {
- try
- {
- URI uri = new URI( resolved );
- File file = (File) uri.toURL().getContent( new
Class[]{File.class} );
- super.setConfig( file.getCanonicalPath() );
- }
- catch( Exception e )
- {
- final String error =
- "Invalid local resource specification: " + resolved;
- IOException ioe = new IOException( error );
- ioe.initCause( e );
- throw ioe;
- }
- }
- else
- {
- super.setConfig( resolved );
- }
+ /**
+ * Get the user realm name.
+ *
+ * @return the realm name
+ */
+ String getName();
+
+ /**
+ * Return a uri of the real configuration properties file.
+ *
+ * @return the realm configuration uri
+ */
+ URI getURI();
+
}
+
+ public HashUserRealm( Context context ) throws Exception
+ {
+ String name = context.getName();
+ super.setName( name );
+ URI config = context.getURI();
+ setConfig( config.toASCIIString() );
+ }
}
Modified:
trunk/main/planet/web/server/src/main/net/dpml/web/server/Server.java
===================================================================
--- trunk/main/planet/web/server/src/main/net/dpml/web/server/Server.java
2006-02-06 19:25:51 UTC (rev 1047)
+++ trunk/main/planet/web/server/src/main/net/dpml/web/server/Server.java
2006-02-06 19:58:50 UTC (rev 1048)
@@ -18,6 +18,7 @@
import java.net.URI;
import java.net.URL;
import java.util.Arrays;
+import java.util.ArrayList;
import net.dpml.logging.Logger;
@@ -31,6 +32,7 @@
import org.mortbay.jetty.RequestLog;
import org.mortbay.xml.XmlConfiguration;
import org.mortbay.util.LazyList;
+import org.mortbay.jetty.security.UserRealm;
/**
* HTTP server implementation.
@@ -108,10 +110,15 @@
super.setRequestLog( parts.getRequestLog() );
}
- //
- // check for any internal parts that are context handlers
- //
+ // add realms and context handlers
+ addUserRealms( parts );
+ addContextHandlers( parts );
+ getLogger().debug( "server established" );
+ }
+
+ private void addContextHandlers( PartsManager parts ) throws Exception
+ {
getLogger().debug( "commencing context handler addition" );
ComponentHandler[] handlers = parts.getComponentHandlers(
org.mortbay.jetty.handler.ContextHandler.class );
for( int i=0; i<handlers.length; i++ )
@@ -132,9 +139,35 @@
throw new Exception( error, e );
}
}
- getLogger().debug( "server established" );
}
+ private void addUserRealms( PartsManager parts ) throws Exception
+ {
+ getLogger().debug( "commencing realm addition" );
+ ArrayList list = new ArrayList();
+ ComponentHandler[] handlers = parts.getComponentHandlers(
org.mortbay.jetty.security.UserRealm.class );
+ for( int i=0; i<handlers.length; i++ )
+ {
+ ComponentHandler handler = handlers[i];
+ getLogger().debug( "adding realm: " + handler );
+ try
+ {
+ Provider provider = handler.getProvider();
+ org.mortbay.jetty.security.UserRealm ch =
+ (org.mortbay.jetty.security.UserRealm) provider.getValue(
false );
+ list.add( ch );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Failed to deploy user realm: " + handler;
+ throw new Exception( error, e );
+ }
+ }
+ UserRealm[] realms = (UserRealm[]) list.toArray( new UserRealm[0] );
+ setUserRealms( realms );
+ }
+
/*
public void addHandler( Handler handler )
throws Exception
- r1048 - in trunk/main/planet/web/server: . src/main/net/dpml/web/server, mcconnell at BerliOS, 02/06/2006
Archive powered by MHonArc 2.6.24.