Skip to Content.
Sympa Menu

notify-dpml - svn commit: r1336 - 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: r1336 - development/main/transit/handler/src/main/net/dpml/transit/artifact
  • Date: Sat, 01 Jan 2005 12:37:04 +0100

Author: niclas
Date: Sat Jan 1 12:37:04 2005
New Revision: 1336

Added:

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

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

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

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

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

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

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

development/main/transit/handler/src/main/net/dpml/transit/artifact/XMLHostsBuilder.java
Log:
I think that both HTTPS and ResourceHost Authentication has been implemented.

Added:
development/main/transit/handler/src/main/net/dpml/transit/artifact/AllowSelfCertTrustManager.java
==============================================================================
--- (empty file)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/AllowSelfCertTrustManager.java
Sat Jan 1 12:37:04 2005
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ * 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.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+import javax.net.ssl.X509TrustManager;
+
+class AllowSelfCertTrustManager
+ implements X509TrustManager
+{
+ public void checkServerTrusted( X509Certificate[] certs, String authType
)
+ throws CertificateException
+ {
+ }
+
+ public void checkClientTrusted( X509Certificate[] certs, String authType
)
+ throws java.security.cert.CertificateException
+ {
+ }
+
+ public X509Certificate[] getAcceptedIssuers()
+ {
+ return null;
+ }
+}
+

Modified:
development/main/transit/handler/src/main/net/dpml/transit/artifact/DelegatingAuthenticator.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/artifact/DelegatingAuthenticator.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/DelegatingAuthenticator.java
Sat Jan 1 12:37:04 2005
@@ -98,10 +98,14 @@
if( addr == null )
addr = InetAddress.getByName( host );

- RequestIdentifier id = new RequestIdentifier( addr, port,
protocol, prompt, scheme );
+ RequestIdentifier id = new RequestIdentifier( addr, port,
protocol, scheme, prompt );
synchronized( m_Authenticators )
{
TransitAuthenticator auth = (TransitAuthenticator)
m_Authenticators.get( id );
+ if( auth == null )
+ {
+ return null;
+ }
return auth.resolvePasswordAuthentication( this );
}
} catch( UnknownHostException e )

Modified:
development/main/transit/handler/src/main/net/dpml/transit/artifact/FileCacheHandler.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/artifact/FileCacheHandler.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/FileCacheHandler.java
Sat Jan 1 12:37:04 2005
@@ -209,7 +209,6 @@
private boolean download( ResourceHost host, Artifact artifact, File
destination )
throws IOException, TransitException
{
- // TODO: Should we throw exception or return null ??
if( host == null )
{
return false;

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 12:37:04 2005
@@ -24,15 +24,22 @@
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.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+
import java.util.HashMap;
import java.util.HashSet;
import java.util.WeakHashMap;

+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+
/** This class represents a single host where resources are stored at.
* <p>
* <strong>NOTE:</strong> This ResourceHost does NOT currently support
@@ -64,11 +71,6 @@
private int m_priority;

/**
- * Authenticaction params.
- */
- private PasswordAuthentication m_authentication;
-
- /**
* Enabled state.
*/
private boolean m_enabled;
@@ -102,17 +104,19 @@
* @param trusted the trusted state
* @param username an authentication username
* @param password the authentication password
+ * @param scheme the authentication scheme
+ * @param prompt the authentication prompt/realm
*/
- public MavenResourceHost( URL base,
- String[] knownGroups,
- int priority,
- Policy downloadPolicy,
- boolean enabled,
- boolean trusted,
- String username,
- String password,
- String scheme,
- String prompt )
+ public MavenResourceHost( URL base,
+ String[] knownGroups,
+ int priority,
+ Policy downloadPolicy,
+ boolean enabled,
+ boolean trusted,
+ String username,
+ String password,
+ String scheme,
+ String prompt )
throws UnknownHostException
{
m_locks = new HashMap();
@@ -120,7 +124,6 @@
m_baseUrl = base;
m_priority = priority;
m_knownGroups = new HashSet();
- m_authentication = new PasswordAuthentication( username,
password.toCharArray() );
m_policy = downloadPolicy;
m_trusted = trusted;
m_enabled = enabled;
@@ -149,22 +152,6 @@
da.addTransitAuthenticator( ta, id );
}

- /**
- * Returns the authentication when connecting to this host.
- *
- * <p>
- * <strong>NOTE:</strong> This ResourceHost does NOT currently support
- * realm/domain authentication. It may be introduced in the future.
- * </p>
- *
- * @param prompt The path requested to be authenticated.
- * @return the password authentication instance
- */
- public PasswordAuthentication getAuthentication( String prompt )
- {
- return m_authentication;
- }
-
/**
* Return the host name.
* @return the hostname
@@ -325,6 +312,14 @@
{
return false;
}
+ catch( NoSuchAlgorithmException e )
+ {
+ return false;
+ }
+ catch( KeyManagementException e )
+ {
+ return false;
+ }
}

/**
@@ -352,10 +347,22 @@
* @exception IOException if an IO error occurs
*/
private void openRemoteConnection( Artifact artifact )
- throws IOException
+ throws IOException, KeyManagementException, NoSuchAlgorithmException
{
URL remote = createRemoteUrl( artifact );
URLConnection conn = remote.openConnection();
+ if( conn instanceof HttpsURLConnection )
+ {
+ if( m_trusted )
+ {
+ HttpsURLConnection ssl = (HttpsURLConnection) conn;
+ TrustManager tm = new AllowSelfCertTrustManager();
+ SSLContext ctx = SSLContext.getInstance( "SSLv3" );
+ ctx.init( null, new TrustManager[] { tm }, null );
+ SSLSocketFactory factory = ctx.getSocketFactory();
+ ssl.setSSLSocketFactory( factory );
+ }
+ }
conn.connect();
if( conn instanceof HttpURLConnection )
{

Modified:
development/main/transit/handler/src/main/net/dpml/transit/artifact/RequestIdentifier.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/artifact/RequestIdentifier.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/RequestIdentifier.java
Sat Jan 1 12:37:04 2005
@@ -75,5 +75,22 @@
hash = hash ^ m_scheme.hashCode();
return hash;
}
+
+ public String toString()
+ {
+ StringBuffer b = new StringBuffer();
+ b.append( "ID[ " );
+ b.append( m_protocol );
+ b.append( ", " );
+ b.append( m_address );
+ b.append( ", " );
+ b.append( m_port );
+ b.append( ", " );
+ b.append( m_scheme );
+ b.append( ", " );
+ b.append( m_prompt );
+ b.append( " ]" );
+ return b.toString();
+ }
}


Modified:
development/main/transit/handler/src/main/net/dpml/transit/artifact/ResourceHost.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/artifact/ResourceHost.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/ResourceHost.java
Sat Jan 1 12:37:04 2005
@@ -66,15 +66,6 @@
*/
boolean checkPresence( Artifact artifact, File dest, boolean knownOnly );

- /** Returns the authentication when connecting to this host.
- *
- * @param prompt The realm/domain requested to be authenticated.
- * Implementations are free to not support realm/domain
authentication,
- * but then must clearly state so in the documentation.
- * @return the password authentifaction instance
- */
- PasswordAuthentication getAuthentication( String prompt );
-
/** Returns the hostname of the resource host.
*
* <p>

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 12:37:04 2005
@@ -101,12 +101,14 @@
ResourceHost[] createResourceHosts()
throws IOException, TransitException
{
+ ArrayList result = new ArrayList();
+
URL hosts = new URL( m_authorative, "hosts.xml" );
InputStream input = null;
try
{
input = hosts.openStream();
- return new XMLHostsBuilder( this ).buildResourceHosts( input );
+ new XMLHostsBuilder( this ).buildResourceHosts( result, input );
}
catch( IOException ioe )
{
@@ -126,23 +128,25 @@
}

File base = new File( authorative );
- if( !base.exists() )
+ if( ! base.exists() )
{
- final String error =
- "Authority base directory does not exist: " + base;
+ final String error = "Authority base directory does not
exist: " + base;
throw new FileNotFoundException( error );
}
- return createResourceHostsFromDirectory( base );
+ createResourceHostsFromDirectory( result, base );
}
else
{
URL index = new URL( m_authorative, REMOTE_LIST_FILENAME );
String[] files = Util.readListFile( index );
- return createResourceHosts( files );
+ createResourceHosts( result, files );
}
+ ResourceHost[] hostArray = new ResourceHost[ result.size() ];
+ result.toArray( hostArray );
+ return hostArray;
}

- /** Creates the ResourceHosts defined in the properties.
+ /** Creates the ResourceHosts defined in the properties for the
ResourceHost.
*
* <pre>
* dpml.transit.resourcehost.class=[classname]
@@ -151,15 +155,16 @@
* dpml.transit.resourcehost.priority=[priority]
* dpml.transit.resourcehost.username=[username]
* dpml.transit.resourcehost.password=[password]
+ * dpml.transit.resourcehost.scheme=[scheme]
+ * dpml.transit.resourcehost.prompt=[prompt/realm]
* </pre>
* @param files the set of filesname to scan
* @return the resource hosts resolved from the supplied files
* @exception TransitException if an error occurs in resource host
construction
*/
- private ResourceHost[] createResourceHosts( String[] files )
+ private void createResourceHosts( ArrayList result, String[] files )
throws TransitException
{
- ArrayList hosts = new ArrayList();
for( int i=0; i < files.length; i++ )
{
URL file;
@@ -169,7 +174,7 @@
ResourceHost host = createResourceHostFromDescriptor( file );
if( host != null )
{
- hosts.add( host );
+ result.add( host );
}
}
catch( MalformedURLException e )
@@ -183,9 +188,6 @@
throw new TransitException( "Unable to read : " +
m_authorative + ", " + files[i], e );
}
}
- ResourceHost[] result = new ResourceHost[ hosts.size() ];
- hosts.toArray( result );
- return result;
}


@@ -203,18 +205,14 @@
* @return the set of host defintions
* @exception TransitException if an error occurs while reading host
descriptors
*/
- private ResourceHost[] createResourceHostsFromDirectory( File base )
+ private void createResourceHostsFromDirectory( ArrayList result, File
base )
throws TransitException
{
File hosts = new File( base, "hosts" );
- if( !hosts.exists() )
- {
- return new ResourceHost[0];
- }
- else
+ if( hosts.exists() )
{
File[] files = hosts.listFiles();
- return createResourceHostsFromFiles( files );
+ createResourceHostsFromFiles( result, files );
}
}

@@ -232,7 +230,7 @@
* @return the set of host defintions
* @exception TransitException if an error occurs while reading host
descriptors
*/
- private ResourceHost[] createResourceHostsFromFiles( File[] files )
+ private void createResourceHostsFromFiles( ArrayList result, File[]
files )
throws TransitException
{
if( null == files )
@@ -240,7 +238,6 @@
throw new NullPointerException( "files" );
}

- ArrayList hosts = new ArrayList();
for( int i=0; i < files.length; i++ )
{
try
@@ -249,7 +246,7 @@
ResourceHost host = createResourceHostFromDescriptor( url );
if( host != null )
{
- hosts.add( host );
+ result.add( host );
}
}
catch( MalformedURLException e )
@@ -261,10 +258,6 @@
throw new TransitException( "Unable to read : " + files[i],
e );
}
}
-
- ResourceHost[] result = new ResourceHost[ hosts.size() ];
- hosts.toArray( result );
- return result;
}

/**

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 12:37:04 2005
@@ -25,6 +25,8 @@

import java.net.URL;

+import java.util.List;
+
import net.dpml.transit.Transit;
import net.dpml.transit.TransitException;
import net.dpml.transit.util.ElementHelper;
@@ -58,20 +60,19 @@
* @exception TransitException if an error occurs in constructing the
* host defintions
*/
- public ResourceHost[] buildResourceHosts( InputStream input )
+ void buildResourceHosts( List result, InputStream input )
throws IOException, TransitException
{
try
{
Element root = ElementHelper.getRootElement( input );
Element[] elements = ElementHelper.getChildren( root, "host" );
- ResourceHost[] hosts = new ResourceHost[ elements.length ];
for( int i=0; i < elements.length; i++ )
{
Element element = elements[i];
- hosts[i] = buildResourceHost( element );
+ ResourceHost host = buildResourceHost( element );
+ result.add( host );
}
- return hosts;
}
catch( Exception e )
{
@@ -89,7 +90,7 @@
* @exception TransitException if an error occurs in constructing the
* host defintions
*/
- public ResourceHost buildResourceHost( Element element )
+ private ResourceHost buildResourceHost( Element element )
throws IOException, TransitException
{
String classname = getClassname( element );



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

Archive powered by MHonArc 2.6.24.

Top of Page