Skip to Content.
Sympa Menu

notify-dpml - svn commit: r1257 - in development/main/transit/handler/src: main/net/dpml/transit/artifact test/net/dpml/transit/artifact

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell AT netcompartner.com
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r1257 - in development/main/transit/handler/src: main/net/dpml/transit/artifact test/net/dpml/transit/artifact
  • Date: Wed, 22 Dec 2004 19:54:32 +0100

Author: mcconnell
Date: Wed Dec 22 19:54:32 2004
New Revision: 1257

Added:

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

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

development/main/transit/handler/src/test/net/dpml/transit/artifact/OnlineTestCase.java
Log:
add proxy handling to the SecureTransitContext

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
Wed Dec 22 19:54:32 2004
@@ -24,6 +24,7 @@

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

import java.util.Properties;

@@ -70,6 +71,11 @@
static final String PROXY_PORT_KEY = DOMAIN + ".proxy.port";

/**
+ * The exluded proxy host names.
+ */
+ static final String PROXY_EXCLUDES_KEY = DOMAIN +
".proxy.excludes";
+
+ /**
* The proxy username key.
*/
static final String PROXY_USERNAME_KEY = DOMAIN +
".proxy.username";
@@ -184,7 +190,7 @@
{
URL conf = new URL( authorative, TRANSIT_PROPERTIES_FILENAME );
Properties props = Util.readProps( conf );
- setupProxy( props );
+ setupAuthenticator( props, hosts );
}
catch( IOException e )
{
@@ -405,12 +411,12 @@
}

/**
- * Setup proxies.
- * @param props the proxy properties
+ * Setup the transit authenticator.
+ * @param props the transit properties
+ * @param hosts the transit remote hosts
*/
- private void setupProxy( Properties props )
+ private void setupAuthenticator( Properties props, ResourceHost[] hosts )
{
- // TODO: NH: IIRC, This is not the way to do it.
String proxy = Util.getProperty( props, PROXY_HOST_KEY, null );
if( null != proxy )
{
@@ -420,12 +426,35 @@
portText = "0";
}
int port = Integer.parseInt( portText );
-// String username = getProperty( props, PROXY_USERNAME_KEY );
-// String password = getProperty( props, PROXY_PASSWORD_KEY );
Properties system = System.getProperties();
- system.put( "proxySet", "true" );
- system.put( "proxyHost", proxy );
- system.put( "proxyPort", "" + port );
+ 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 );
+ }
+ }
+ Authenticator authenticator = createAuthenticator( props, hosts );
+ Authenticator.setDefault( authenticator );
+ }
+
+ /**
+ * Creation of a new transit authenticator.
+ * @param props the transit properties
+ * @param hosts the transit hosts
+ */
+ private Authenticator createAuthenticator( Properties props,
ResourceHost[] hosts )
+ {
+ 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
+ {
+ return new TransitAuthenticator( hosts );
}
}
}

Added:
development/main/transit/handler/src/main/net/dpml/transit/artifact/TransitAuthenticator.java
==============================================================================
--- (empty file)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/TransitAuthenticator.java
Wed Dec 22 19:54:32 2004
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2004 Stephen McConnell, 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 TransitAuthenticator extends Authenticator
+{
+ /**
+ * 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();
+ }
+ }
+}

Modified:
development/main/transit/handler/src/test/net/dpml/transit/artifact/OnlineTestCase.java
==============================================================================
---
development/main/transit/handler/src/test/net/dpml/transit/artifact/OnlineTestCase.java
(original)
+++
development/main/transit/handler/src/test/net/dpml/transit/artifact/OnlineTestCase.java
Wed Dec 22 19:54:32 2004
@@ -69,13 +69,15 @@
classloader.loadClass( "net.dpml.test.testb.B" );
}

- public void testResource() throws Exception
+ public void testInternalResource() throws Exception
{
URL url = new URL( "artifact:jar:dpml/test/dpml-test-testb" );
ClassLoader classloader = new URLClassLoader( new URL[]{ url } );
Class clazz = classloader.loadClass( "net.dpml.test.testb.B" );
URL resourceUrl = clazz.getResource( "TestB.xinfo" );
- System.out.println( "#URL: " + resourceUrl.toExternalForm() );
+ String external =
+
"artifact:jar:dpml/test/dpml-test-testb!/net/dpml/test/testb/TestB.xinfo";
+ assertEquals( "external", external, resourceUrl.toExternalForm() );
resourceUrl.openStream();
}




  • svn commit: r1257 - in development/main/transit/handler/src: main/net/dpml/transit/artifact test/net/dpml/transit/artifact, mcconnell, 12/22/2004

Archive powered by MHonArc 2.6.24.

Top of Page