Skip to Content.
Sympa Menu

notify-dpml - svn commit: r1335 - development/main/transit/handler/src/main/net/dpml/transit/artifact

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: niclas AT netcompartner.com
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r1335 - development/main/transit/handler/src/main/net/dpml/transit/artifact
  • Date: Sat, 01 Jan 2005 07:35:55 +0100

Author: niclas
Date: Sat Jan 1 07:35:55 2005
New Revision: 1335

Added:

development/main/transit/handler/src/main/net/dpml/transit/artifact/DelegatingAuthenticator.java
(contents, props changed)

development/main/transit/handler/src/main/net/dpml/transit/artifact/RequestIdentifier.java
(contents, props changed)

development/main/transit/handler/src/main/net/dpml/transit/artifact/TransitAuthenticatorImpl.java
(contents, props changed)
Removed:

development/main/transit/handler/src/main/net/dpml/transit/artifact/ResourceHostAuthenticator.java
Modified:

development/main/transit/handler/src/main/net/dpml/transit/artifact/Handler.java

development/main/transit/handler/src/main/net/dpml/transit/artifact/MavenResourceHost.java

development/main/transit/handler/src/main/net/dpml/transit/artifact/ResourceHostFactory.java

development/main/transit/handler/src/main/net/dpml/transit/artifact/SecuredTransitContext.java

development/main/transit/handler/src/main/net/dpml/transit/artifact/TransitAuthenticator.java

development/main/transit/handler/src/main/net/dpml/transit/artifact/XMLHostsBuilder.java
Log:
Beginning of full ResourceHost authentication.

Added:
development/main/transit/handler/src/main/net/dpml/transit/artifact/DelegatingAuthenticator.java
==============================================================================
--- (empty file)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/DelegatingAuthenticator.java
Sat Jan 1 07:35:55 2005
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2004 Niclas Hedhman, DPML
+ *
+ * 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 net.dpml.transit.artifact;
+
+import java.net.Authenticator;
+import java.net.InetAddress;
+import java.net.PasswordAuthentication;
+import java.net.UnknownHostException;
+
+import java.util.HashMap;
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:dev AT avalon.apache.org";>Avalon Development Team</a>
+ * @version $Id: DefaultAuthenticator.java 30977 2004-07-30 08:57:54Z niclas
$
+ */
+final class DelegatingAuthenticator extends Authenticator
+{
+ private static DelegatingAuthenticator m_instance;
+
+ private HashMap m_Authenticators;
+
+ static DelegatingAuthenticator getInstance()
+ {
+ synchronized( DelegatingAuthenticator.class )
+ {
+ if( m_instance == null )
+ {
+ m_instance = new DelegatingAuthenticator();
+ Authenticator.setDefault( m_instance );
+ }
+ return m_instance;
+ }
+ }
+
+ /**
+ * Creation of a new delegating authenticator.
+ */
+ DelegatingAuthenticator()
+ {
+ m_Authenticators = new HashMap();
+ }
+
+ void addTransitAuthenticator( TransitAuthenticator auth,
RequestIdentifier id )
+ {
+ synchronized( m_Authenticators )
+ {
+ m_Authenticators.put( id, auth );
+ }
+ }
+
+ void removeTransitAuthenticator( TransitAuthenticator auth )
+ {
+ synchronized( m_Authenticators )
+ {
+ Iterator list = m_Authenticators.values().iterator();
+ while( list.hasNext() )
+ {
+ Authenticator item = (Authenticator) list.next();
+ if( item.equals( auth ) )
+ {
+ list.remove();
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns the password authenticator.
+ * @return the password authenticator
+ */
+ protected PasswordAuthentication getPasswordAuthentication()
+ {
+ try
+ {
+ String host = getRequestingHost();
+ String protocol = getRequestingProtocol();
+ String prompt = getRequestingPrompt();
+ String scheme = getRequestingScheme();
+ int port = getRequestingPort();
+ InetAddress addr = getRequestingSite();
+ if( addr == null )
+ addr = InetAddress.getByName( host );
+
+ RequestIdentifier id = new RequestIdentifier( addr, port,
protocol, prompt, scheme );
+ synchronized( m_Authenticators )
+ {
+ TransitAuthenticator auth = (TransitAuthenticator)
m_Authenticators.get( id );
+ return auth.resolvePasswordAuthentication( this );
+ }
+ } catch( UnknownHostException e )
+ {
+ return null;
+ }
+ }
+}

Modified:
development/main/transit/handler/src/main/net/dpml/transit/artifact/Handler.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/artifact/Handler.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/Handler.java
Sat Jan 1 07:35:55 2005
@@ -53,10 +53,12 @@
}
catch( TransitException e )
{
+ e.printStackTrace();
throw e;
}
catch( RuntimeException e )
{
+ e.printStackTrace();
throw e;
}
}

Modified:
development/main/transit/handler/src/main/net/dpml/transit/artifact/MavenResourceHost.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/artifact/MavenResourceHost.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/MavenResourceHost.java
Sat Jan 1 07:35:55 2005
@@ -22,10 +22,12 @@
import java.io.IOException;

import java.net.HttpURLConnection;
+import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.net.URLConnection;
+import java.net.UnknownHostException;

import java.util.HashMap;
import java.util.HashSet;
@@ -108,7 +110,10 @@
boolean enabled,
boolean trusted,
String username,
- String password )
+ String password,
+ String scheme,
+ String prompt )
+ throws UnknownHostException
{
m_locks = new HashMap();
m_connections = new WeakHashMap();
@@ -125,6 +130,23 @@
String group = knownGroups[ i ];
m_knownGroups.add( group );
}
+
+ String protocol = base.getProtocol();
+ InetAddress host = InetAddress.getByName( base.getHost() );
+ int port = base.getPort();
+ if( port == 0 )
+ {
+ if( protocol.equals( "http" ) )
+ port = 80;
+ if( protocol.equals( "ftp" ) )
+ port = 21;
+ if( protocol.equals( "https" ) )
+ port = 443;
+ }
+ RequestIdentifier id = new RequestIdentifier( host, port, protocol,
scheme, prompt );
+ TransitAuthenticator ta = new TransitAuthenticatorImpl( username,
password );
+ DelegatingAuthenticator da = DelegatingAuthenticator.getInstance();
+ da.addTransitAuthenticator( ta, id );
}

/**

Added:
development/main/transit/handler/src/main/net/dpml/transit/artifact/RequestIdentifier.java
==============================================================================
--- (empty file)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/RequestIdentifier.java
Sat Jan 1 07:35:55 2005
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2004 Niclas Hedhman, DPML
+ *
+ * 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 net.dpml.transit.artifact;
+
+import java.net.InetAddress;
+
+final class RequestIdentifier
+{
+ private InetAddress m_address;
+ private int m_port;
+ private String m_prompt;
+ private String m_protocol;
+ private String m_scheme;
+
+ RequestIdentifier( InetAddress addr, int port,
+ String protocol, String scheme, String prompt )
+ {
+ if( addr == null )
+ throw new IllegalArgumentException( "Null argument: addr" );
+ if( protocol == null )
+ throw new IllegalArgumentException( "Null argument: protocol" );
+ if( scheme == null )
+ throw new IllegalArgumentException( "Null argument: scheme" );
+ if( prompt == null )
+ throw new IllegalArgumentException( "Null argument: prompt" );
+ m_address = addr;
+ m_port = port;
+ m_protocol = protocol;
+ m_prompt = prompt;
+ m_scheme = scheme;
+ }
+
+ public boolean equals( Object obj )
+ {
+ if( ! ( obj instanceof RequestIdentifier ) )
+ return false;
+ RequestIdentifier other = (RequestIdentifier) obj;
+
+ if( m_port != other.m_port )
+ return false;
+
+ if( ! m_address.equals( other.m_address ) )
+ return false;
+ if( ! m_protocol.equals( other.m_protocol ) )
+ return false;
+ if( ! m_prompt.equals( other.m_prompt ) )
+ return false;
+ if( ! m_scheme.equals( other.m_scheme ) )
+ return false;
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int hash = 72349724 >>> m_port;
+ hash = hash ^ m_address.hashCode();
+ hash = hash ^ m_protocol.hashCode();
+ hash = hash ^ m_prompt.hashCode();
+ hash = hash ^ m_scheme.hashCode();
+ return hash;
+ }
+}
+

Modified:
development/main/transit/handler/src/main/net/dpml/transit/artifact/ResourceHostFactory.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/artifact/ResourceHostFactory.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/ResourceHostFactory.java
Sat Jan 1 07:35:55 2005
@@ -26,7 +26,6 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

-import java.net.Authenticator;
import java.net.URL;
import java.net.MalformedURLException;

@@ -107,7 +106,7 @@
try
{
input = hosts.openStream();
- return XMLHostsBuilder.buildResourceHosts( input );
+ return new XMLHostsBuilder( this ).buildResourceHosts( input );
}
catch( IOException ioe )
{
@@ -186,8 +185,6 @@
}
ResourceHost[] result = new ResourceHost[ hosts.size() ];
hosts.toArray( result );
- Authenticator authenticator = new ResourceHostAuthenticator( result
);
- Authenticator.setDefault( authenticator );
return result;
}

@@ -267,8 +264,6 @@

ResourceHost[] result = new ResourceHost[ hosts.size() ];
hosts.toArray( result );
- Authenticator authenticator = new ResourceHostAuthenticator( result
);
- Authenticator.setDefault( authenticator );
return result;
}

@@ -353,6 +348,8 @@
int priority = Integer.parseInt( priorityText );
String username = Util.getProperty( props,
"dpml.transit.resourcehost.username", "" );
String password = Util.getProperty( props,
"dpml.transit.resourcehost.password", "" );
+ String prompt = Util.getProperty( props,
"dpml.transit.resourcehost.prompt", "" );
+ String scheme = Util.getProperty( props,
"dpml.transit.resourcehost.scheme", "" );
boolean enabled =
Util.getProperty(
props, "dpml.transit.resourcehost.enabled", TRUE_VALUE
).equalsIgnoreCase( TRUE_VALUE );
@@ -371,7 +368,7 @@
try
{
return createResourceHost(
- classname, baseUrl, groupFile, priority, policy, enabled,
trusted, username, password );
+ classname, baseUrl, groupFile, priority, policy, enabled,
trusted, username, password, scheme, prompt );
}
catch( Throwable e )
{
@@ -411,7 +408,7 @@
* @return the class
* @exception ClassNotFoundException if the class cannot be found
*/
- private static Class getHostClass( String classname ) throws
ClassNotFoundException
+ private Class getHostClass( String classname ) throws
ClassNotFoundException
{
return ResourceHostFactory.class.getClassLoader().loadClass(
classname );
}
@@ -423,7 +420,7 @@
* @exception TransitException if an error occurs while attempting to
read the
* remote address
*/
- private static String[] getKnownGroups( URL href ) throws
TransitException
+ private String[] getKnownGroups( URL href ) throws TransitException
{
if( href != null )
{
@@ -455,13 +452,16 @@
* @param trusted if the host is trusted
* @param username the authentication username
* @param password the authentication password
+ * @param scheme the authentication request scheme
+ * @param prompt the authentication prompt (should be HTTP realm)
* @return the resource host
* @exception TransitException if a construction error occurs
* @exception IOException if an IO related error occurs
*/
- public static ResourceHost createResourceHost(
+ ResourceHost createResourceHost(
String classname, URL base, URL index, int priority, Policy policy,
- boolean enabled, boolean trusted, String username, String password )
+ boolean enabled, boolean trusted, String username, String password,
+ String scheme, String prompt )
throws TransitException, IOException
{
String[] groups = getKnownGroups( index );
@@ -474,6 +474,8 @@
Boolean.TYPE,
Boolean.TYPE,
String.class,
+ String.class,
+ String.class,
String.class
};

@@ -486,7 +488,9 @@
enabled ? Boolean.TRUE : Boolean.FALSE,
trusted ? Boolean.TRUE : Boolean.FALSE,
username,
- password
+ password,
+ scheme,
+ prompt
};

try

Modified:
development/main/transit/handler/src/main/net/dpml/transit/artifact/SecuredTransitContext.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/artifact/SecuredTransitContext.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/SecuredTransitContext.java
Sat Jan 1 07:35:55 2005
@@ -22,9 +22,11 @@
import java.io.FileInputStream;
import java.io.IOException;

-import java.net.URL;
-import java.net.MalformedURLException;
import java.net.Authenticator;
+import java.net.InetAddress;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.UnknownHostException;

import java.util.Properties;

@@ -86,6 +88,21 @@
static final String PROXY_PASSWORD_KEY = DOMAIN +
".proxy.password";

/**
+ * The proxy protocol key.
+ */
+ static final String PROXY_PROTOCOL_KEY = DOMAIN +
".proxy.protocol";
+
+ /**
+ * The proxy scheme key.
+ */
+ static final String PROXY_SCHEME_KEY = DOMAIN + ".proxy.scheme";
+
+ /**
+ * The proxy prompt/realm key.
+ */
+ static final String PROXY_PROMPT_KEY = DOMAIN + ".proxy.prompt";
+
+ /**
* The transit properties filename.
*/
static final String TRANSIT_PROPERTIES_FILENAME = "transit.properties";
@@ -93,7 +110,7 @@
/**
* The singleton transit context.
*/
- private static SecuredTransitContext secureTransitContext;
+ private static SecuredTransitContext m_secureTransitContext;

//------------------------------------------------------------------
// state
@@ -114,6 +131,11 @@
*/
private ResourceHost[] m_resourceHosts;

+ public static SecuredTransitContext getInstance()
+ {
+ return m_secureTransitContext;
+ }
+
//------------------------------------------------------------------
// implementation
//------------------------------------------------------------------
@@ -144,9 +166,9 @@
public static SecuredTransitContext create( final Monitor monitor )
throws TransitException
{
- if( secureTransitContext != null )
+ if( m_secureTransitContext != null )
{
- return secureTransitContext;
+ return m_secureTransitContext;
}
if( null == monitor )
{
@@ -163,8 +185,8 @@
ResourceHost[] hosts = rhFactory.createResourceHosts();
CacheHandlerFactory chFactory = new CacheHandlerFactory(
authorative );
CacheHandler ch = chFactory.createCacheHandler( hosts );
- secureTransitContext = new SecuredTransitContext( authorative,
hosts, ch );
- return secureTransitContext;
+ m_secureTransitContext = new SecuredTransitContext( authorative,
hosts, ch );
+ return m_secureTransitContext;
}
catch( IOException e )
{
@@ -180,7 +202,7 @@
* @param ch the cache handler
* @exception TransitException if a context creation error occurs
*/
- SecuredTransitContext( URL authorative, ResourceHost[] hosts,
CacheHandler ch )
+ private SecuredTransitContext( URL authorative, ResourceHost[] hosts,
CacheHandler ch )
throws TransitException
{
m_authorativeHost = authorative;
@@ -190,7 +212,7 @@
{
URL conf = new URL( authorative, TRANSIT_PROPERTIES_FILENAME );
Properties props = Util.readProps( conf );
- setupAuthenticator( props, hosts );
+ setupAuthenticator( props );
}
catch( IOException e )
{
@@ -415,28 +437,16 @@
* @param props the transit properties
* @param hosts the transit remote hosts
*/
- private void setupAuthenticator( Properties props, ResourceHost[] hosts )
+ private void setupAuthenticator( Properties props )
+ throws UnknownHostException
{
- String proxy = Util.getProperty( props, PROXY_HOST_KEY, null );
- if( null != proxy )
+ TransitAuthenticator ta = createProxyAuthenticator( props );
+ if( ta != null )
{
- String portText = Util.getProperty( props, PROXY_PORT_KEY, "0" );
- if( "".equals( portText ) )
- {
- portText = "0";
- }
- int port = Integer.parseInt( portText );
- Properties system = System.getProperties();
- system.put( "http.proxyHost", proxy );
- system.put( "http.proxyPort", "" + port );
- String excludes = Util.getProperty( props, PROXY_EXCLUDES_KEY,
null );
- if( null != excludes )
- {
- system.put( "http.nonProxyHosts", excludes );
- }
+ RequestIdentifier id = createProxyRequestIdentifier( props );
+ DelegatingAuthenticator da =
DelegatingAuthenticator.getInstance();
+ da.addTransitAuthenticator( ta, id );
}
- Authenticator authenticator = createAuthenticator( props, hosts );
- Authenticator.setDefault( authenticator );
}

/**
@@ -444,17 +454,43 @@
* @param props the transit properties
* @param hosts the transit hosts
*/
- private Authenticator createAuthenticator( Properties props,
ResourceHost[] hosts )
+ private TransitAuthenticator createProxyAuthenticator( Properties props )
{
String username = Util.getProperty( props, PROXY_USERNAME_KEY, null
);
String password = Util.getProperty( props, PROXY_PASSWORD_KEY, null
);
- if( null != username )
- {
- return new TransitAuthenticator( username, password, hosts );
- }
- else
+ if( null == username )
+ return null;
+
+ return new TransitAuthenticatorImpl( username, password );
+ }
+
+ private RequestIdentifier createProxyRequestIdentifier( Properties props
)
+ throws UnknownHostException, IllegalArgumentException
+ {
+ String proxy = Util.getProperty( props, PROXY_HOST_KEY, null );
+ if( null == proxy )
+ return null;
+
+ String protocol = Util.getProperty( props, PROXY_PROTOCOL_KEY,
"http" );
+ String scheme = Util.getProperty( props, PROXY_SCHEME_KEY, null );
+ if( scheme == null )
+ throw new IllegalArgumentException( "Missing " +
PROXY_SCHEME_KEY + " in properties." );
+ String prompt = Util.getProperty( props, PROXY_PROMPT_KEY, null );
+ if( prompt == null )
+ throw new IllegalArgumentException( "Missing " +
PROXY_PROMPT_KEY + " in properties." );
+
+ InetAddress host = InetAddress.getByName( proxy );
+ String portText = Util.getProperty( props, PROXY_PORT_KEY, "0" );
+ int port = Integer.parseInt( portText );
+ Properties system = System.getProperties();
+ system.put( "http.proxyHost", proxy );
+ system.put( "http.proxyPort", "" + port );
+ String excludes = Util.getProperty( props, PROXY_EXCLUDES_KEY, null
);
+ if( null != excludes )
{
- return new TransitAuthenticator( hosts );
+ system.put( "http.nonProxyHosts", excludes );
}
+ RequestIdentifier id = new RequestIdentifier( host, port, protocol,
scheme, prompt );
+ return id;
}
}

Modified:
development/main/transit/handler/src/main/net/dpml/transit/artifact/TransitAuthenticator.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/artifact/TransitAuthenticator.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/TransitAuthenticator.java
Sat Jan 1 07:35:55 2005
@@ -22,86 +22,14 @@
import java.net.PasswordAuthentication;

/**
- * Default authenticator that provides support for username password
- * based authentication in conjunction with the repository proxy settings.
- * TODO: setup implementation of password authentication relative to
- * supplied hosts.
- *
* @author <a href="mailto:dev AT avalon.apache.org";>Avalon Development Team</a>
* @version $Id: DefaultAuthenticator.java 30977 2004-07-30 08:57:54Z niclas
$
*/
-final class TransitAuthenticator extends Authenticator
+public interface TransitAuthenticator
{
/**
- * Proxy username.
- */
- private String m_username;
-
- /**
- * Proxy password.
- */
- private char[] m_password;
-
- /**
- * Hosts sequence.
- */
- private ResourceHost[] m_hosts;
-
- /**
- * Creation of a new simple authenticator.
- * @param hosts the registered hosts
- * @exception NullPointerException if the hosts argument is null
- */
- public TransitAuthenticator( ResourceHost[] hosts ) throws
NullPointerException
- {
- if( hosts == null )
- {
- throw new NullPointerException( "hosts" );
- }
- m_hosts = hosts;
- m_username = null;
- m_password = null;
- }
-
- /**
- * Creation of a new simple authenticator.
- * @param username the username
- * @param password a passsword
- * @exception NullPointerException if the supplied username or password
is null
- */
- public TransitAuthenticator( String username, String password,
ResourceHost[] hosts )
- throws NullPointerException
- {
- if( username == null )
- {
- throw new NullPointerException( "username" );
- }
- if( password == null )
- {
- throw new NullPointerException( "password" );
- }
- if( hosts == null )
- {
- throw new NullPointerException( "hosts" );
- }
- m_username = username;
- m_password = password.toCharArray();
- m_hosts = hosts;
- }
-
- /**
* Returns the password authenticator.
* @return the password authenticator
*/
- protected PasswordAuthentication getPasswordAuthentication()
- {
- if( m_username != null )
- {
- return new PasswordAuthentication( m_username, m_password );
- }
- else
- {
- return super.getPasswordAuthentication();
- }
- }
+ PasswordAuthentication resolvePasswordAuthentication( Authenticator auth
);
}

Added:
development/main/transit/handler/src/main/net/dpml/transit/artifact/TransitAuthenticatorImpl.java
==============================================================================
--- (empty file)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/TransitAuthenticatorImpl.java
Sat Jan 1 07:35:55 2005
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2004 Stephen McConnell, DPML
+ * Copyright 2004 Niclas Hedhman, DPML
+ *
+ * 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 net.dpml.transit.artifact;
+
+import java.net.Authenticator;
+import java.net.PasswordAuthentication;
+
+/**
+ * Default authenticator that provides support for username password
+ * based authentication in conjunction with the repository proxy settings.
+ * TODO: setup implementation of password authentication relative to
+ * supplied hosts.
+ *
+ * @author <a href="mailto:dev AT avalon.apache.org";>Avalon Development Team</a>
+ * @version $Id: DefaultAuthenticator.java 30977 2004-07-30 08:57:54Z niclas
$
+ */
+final class TransitAuthenticatorImpl
+ implements TransitAuthenticator
+{
+ /**
+ * Proxy username.
+ */
+ private PasswordAuthentication m_authentication;
+
+ /**
+ * Creation of a new simple authenticator.
+ * @param hosts the registered hosts
+ * @exception IllegalArgumentException if either the username or passwd
argument is null
+ */
+ public TransitAuthenticatorImpl( String username, String passwd )
+ throws IllegalArgumentException
+ {
+ if( username == null )
+ throw new IllegalArgumentException( "Null argument: username" );
+ if( passwd == null )
+ throw new IllegalArgumentException( "Null argument: passwd" );
+ m_authentication = new PasswordAuthentication( username,
passwd.toCharArray() );
+ }
+
+ /**
+ * Returns the password authenticator.
+ * @return the password authenticator
+ */
+ public PasswordAuthentication resolvePasswordAuthentication(
Authenticator auth )
+ {
+ return m_authentication;
+ }
+}

Modified:
development/main/transit/handler/src/main/net/dpml/transit/artifact/XMLHostsBuilder.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/artifact/XMLHostsBuilder.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/XMLHostsBuilder.java
Sat Jan 1 07:35:55 2005
@@ -1,5 +1,6 @@
/*
* Copyright 2004 Stephen McConnell
+ * Copyright 2004 Niclas Hedhman
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,11 +40,14 @@
*/
final class XMLHostsBuilder
{
+ private ResourceHostFactory m_ResourceHostFactory;
+
/**
* Constructor (disabled).
*/
- private XMLHostsBuilder()
+ XMLHostsBuilder( ResourceHostFactory rf )
{
+ m_ResourceHostFactory = rf;
}

/**
@@ -54,8 +58,8 @@
* @exception TransitException if an error occurs in constructing the
* host defintions
*/
- public static ResourceHost[] buildResourceHosts( InputStream input )
- throws IOException, TransitException
+ public ResourceHost[] buildResourceHosts( InputStream input )
+ throws IOException, TransitException
{
try
{
@@ -85,7 +89,8 @@
* @exception TransitException if an error occurs in constructing the
* host defintions
*/
- public static ResourceHost buildResourceHost( Element element ) throws
IOException, TransitException
+ public ResourceHost buildResourceHost( Element element )
+ throws IOException, TransitException
{
String classname = getClassname( element );
URL base = getBaseURL( element );
@@ -96,9 +101,12 @@
boolean trusted = getTrusted( element );
String username = getUsername( element );
String password = getPassword( element );
-
- return ResourceHostFactory.createResourceHost(
- classname, base, index, priority, policy, enabled, trusted,
username, password );
+ String scheme = getScheme( element );
+ String prompt = getPrompt( element );
+
+ return m_ResourceHostFactory.createResourceHost(
+ classname, base, index, priority, policy, enabled, trusted,
+ username, password, scheme, prompt );
}

/**
@@ -107,7 +115,7 @@
* @return the resource host base url
* @exception IOException if an IO related error occurs
*/
- private static URL getBaseURL( Element root )
+ private URL getBaseURL( Element root )
throws IOException
{
String base = ElementHelper.getAttribute( root, "href", null );
@@ -142,7 +150,8 @@
* @return the repository url
* @exception IOException if an IO related error occurs
*/
- private static URL resolveLocalRepositoryURL( String path ) throws
IOException
+ private URL resolveLocalRepositoryURL( String path )
+ throws IOException
{
File base = new File( path );
if( base.isAbsolute() )
@@ -165,7 +174,7 @@
* @return the index url (possibly null)
* @exception IOException if an IO related error occurs
*/
- private static URL getKnownGroupsURL( Element root )
+ private URL getKnownGroupsURL( Element root )
throws IOException
{
Element element = ElementHelper.getChild( root, "index" );
@@ -191,7 +200,7 @@
* @return the host classname
* @exception IOException if an IO related error occurs
*/
- private static String getClassname( Element root )
+ private String getClassname( Element root )
throws IOException
{
Element element = ElementHelper.getChild( root, "class" );
@@ -218,7 +227,7 @@
* @return the priority
* @exception IOException if an IO related error occurs
*/
- private static int getPriority( Element root )
+ private int getPriority( Element root )
throws IOException
{
Element element = ElementHelper.getChild( root, "priority" );
@@ -241,7 +250,7 @@
* @return the enabled status
* @exception IOException if an IO related error occurs
*/
- private static boolean getEnabled( Element root )
+ private boolean getEnabled( Element root )
throws IOException
{
String enabled = ElementHelper.getAttribute( root, "enabled", "true"
);
@@ -255,7 +264,7 @@
* @return the trusted status
* @exception IOException if an IO related error occurs
*/
- private static boolean getTrusted( Element root )
+ private boolean getTrusted( Element root )
throws IOException
{
Element element = ElementHelper.getChild( root, "trusted" );
@@ -274,7 +283,7 @@
* @return the timestamp policy
* @exception IOException if an IO related error occurs
*/
- private static Policy getPolicy( Element root )
+ private Policy getPolicy( Element root )
throws IOException
{
Element element = ElementHelper.getChild( root, "policy" );
@@ -292,7 +301,7 @@
* @return the username
* @exception IOException if an IO related error occurs
*/
- private static String getUsername( Element root )
+ private String getUsername( Element root )
throws IOException
{
Element credentials = ElementHelper.getChild( root, "credentials" );
@@ -319,7 +328,7 @@
* @return the password
* @exception IOException if an IO related error occurs
*/
- private static String getPassword( Element root )
+ private String getPassword( Element root )
throws IOException
{
Element credentials = ElementHelper.getChild( root, "credentials" );
@@ -338,4 +347,46 @@
return ElementHelper.getValue( element );
}
}
+
+ /**
+ * Get the scheme from the supplied host element using the
+ * value of a child element named 'scheme'.
+ * @param root the XML host element
+ * @return the scheme
+ * @exception IOException if an IO related error occurs
+ */
+ private String getScheme( Element root )
+ throws IOException
+ {
+ Element element = ElementHelper.getChild( root, "scheme" );
+ if( null == element )
+ {
+ return "";
+ }
+ else
+ {
+ return ElementHelper.getValue( element );
+ }
+ }
+
+ /**
+ * Get the prompt/realm from the supplied host element using the
+ * value of a child element named 'prompt'.
+ * @param root the XML host element
+ * @return the prompt/realm
+ * @exception IOException if an IO related error occurs
+ */
+ private String getPrompt( Element root )
+ throws IOException
+ {
+ Element element = ElementHelper.getChild( root, "prompt" );
+ if( null == element )
+ {
+ return "";
+ }
+ else
+ {
+ return ElementHelper.getValue( element );
+ }
+ }
}



  • svn commit: r1335 - development/main/transit/handler/src/main/net/dpml/transit/artifact, niclas, 01/01/2005

Archive powered by MHonArc 2.6.24.

Top of Page