notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
svn commit: r2447 - development/main/transit/core/handler/src/main/net/dpml/transit/link
- From: niclas AT hedhman.org
- To: notify-dpml AT lists.ibiblio.org
- Subject: svn commit: r2447 - development/main/transit/core/handler/src/main/net/dpml/transit/link
- Date: Thu, 28 Apr 2005 21:10:01 -0400
Author: niclas AT hedhman.org
Date: Thu Apr 28 21:09:58 2005
New Revision: 2447
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/link/ArtifactLinkManager.java
development/main/transit/core/handler/src/main/net/dpml/transit/link/FileLinkManager.java
development/main/transit/core/handler/src/main/net/dpml/transit/link/Handler.java
development/main/transit/core/handler/src/main/net/dpml/transit/link/LinkURLConnection.java
Log:
Starting to secure Transit.
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/link/ArtifactLinkManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/link/ArtifactLinkManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/link/ArtifactLinkManager.java
Thu Apr 28 21:09:58 2005
@@ -17,21 +17,18 @@
package net.dpml.transit.link;
+import net.dpml.transit.util.StreamUtils;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
-
import java.net.URI;
import java.net.URL;
-
-import java.util.Properties;
-
-import net.dpml.transit.SecuredTransitContext;
-import net.dpml.transit.Transit;
-
-import net.dpml.transit.util.StreamUtils;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
/** The LinkManager is responsible for storing the mapping between a Link
* instance and a URI.
@@ -61,15 +58,30 @@
* network topologies.
* @exception IOException if the mapping could not be updated.
*/
- public void setTargetURI( URI linkUri, URI targetUri )
+ public void setTargetURI( final URI linkUri, final URI targetUri )
throws IOException
{
- String artifact = "artifact:" + linkUri.toString();
- URL store = new URL( artifact );
- OutputStream out = store.openConnection().getOutputStream();
- byte[] array = targetUri.toString().getBytes( "ISO8859-1" );
- ByteArrayInputStream in = new ByteArrayInputStream( array );
- StreamUtils.copyStream( in, out, true );
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+
+ public Object run()
+ throws IOException
+ {
+ String artifact = "artifact:" + linkUri.toString();
+ URL store = new URL( artifact );
+ OutputStream out =
store.openConnection().getOutputStream();
+ byte[] array = targetUri.toString().getBytes(
"ISO8859-1" );
+ ByteArrayInputStream in = new ByteArrayInputStream(
array );
+ StreamUtils.copyStream( in, out, true );
+ return null; // nothing to return
+ }
+ });
+ } catch( PrivilegedActionException e )
+ {
+ throw (IOException) e.getException();
+ }
}
/** Returns the URI that the provided link: URI instance is pointing to.
@@ -78,15 +90,30 @@
* @return target URI that the link points to, or null if it could not
* be found.
*/
- public URI getTargetURI( URI linkUri )
+ public URI getTargetURI( final URI linkUri )
throws IOException
{
- String artifact = "artifact:" + linkUri.toString();
- URL store = new URL( artifact );
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- InputStream in = store.openConnection().getInputStream();
- StreamUtils.copyStream( in, out, true );
- String target = out.toString( "ISO8859-1" );
- return URI.create( target );
+ try
+ {
+ URI result = (URI) AccessController.doPrivileged( new
PrivilegedExceptionAction()
+ {
+
+ public Object run()
+ throws IOException
+ {
+ String artifact = "artifact:" + linkUri.toString();
+ URL store = new URL( artifact );
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ InputStream in = store.openConnection().getInputStream();
+ StreamUtils.copyStream( in, out, true );
+ String target = out.toString( "ISO8859-1" );
+ return URI.create( target );
+ }
+ });
+ return result;
+ } catch( PrivilegedActionException e )
+ {
+ throw (IOException) e.getException();
+ }
}
}
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/link/FileLinkManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/link/FileLinkManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/link/FileLinkManager.java
Thu Apr 28 21:09:58 2005
@@ -17,17 +17,18 @@
package net.dpml.transit.link;
+import net.dpml.transit.Transit;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
-
import java.net.URI;
-
import java.util.Properties;
-
-import net.dpml.transit.SecuredTransitContext;
-import net.dpml.transit.Transit;
+import java.security.AccessController;
+import java.security.PrivilegedExceptionAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedAction;
/** The LinkManager is responsible for storing the mapping between a Link
* instance and a URI.
@@ -55,9 +56,15 @@
public FileLinkManager()
{
- m_linksDir = new File( Transit.DPML_PREFS, "transit/links" );
- m_linksDir.mkdirs();
-
+ AccessController.doPrivileged( new PrivilegedAction()
+ {
+ public Object run()
+ {
+ m_linksDir = new File( Transit.DPML_PREFS, "transit/links" );
+ m_linksDir.mkdirs();
+ return null;
+ }
+ });
}
/** Sets the URI for the provided Link.
@@ -68,17 +75,32 @@
* network topologies.
* @exception IOException if the mapping could not be updated.
*/
- public void setTargetURI( URI linkUri, URI targetUri )
+ public void setTargetURI( final URI linkUri, final URI targetUri )
throws IOException
{
- File linkFile = getLinkFile( linkUri );
- lockWrite( linkFile );
try
{
- setTargetURI( linkFile, linkUri, targetUri );
- } finally
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+
+ public Object run()
+ throws IOException
+ {
+ File linkFile = getLinkFile( linkUri );
+ lockWrite( linkFile );
+ try
+ {
+ setTargetURI( linkFile, linkUri, targetUri );
+ } finally
+ {
+ unlock( linkFile );
+ }
+ return null;
+ }
+ });
+ } catch( PrivilegedActionException e )
{
- unlock( linkFile );
+ throw (IOException) e.getException();
}
}
@@ -88,17 +110,32 @@
* @return target URI that the link points to, or null if it could not
* be found.
*/
- public URI getTargetURI( URI linkUri )
+ public URI getTargetURI( final URI linkUri )
throws IOException
{
- File linkFile = getLinkFile( linkUri );
- lockRead( linkFile );
try
{
- return getTargetURI( linkFile, linkUri );
- } finally
+ URI result = (URI) AccessController.doPrivileged( new
PrivilegedExceptionAction()
+ {
+
+ public Object run()
+ throws IOException
+ {
+ File linkFile = getLinkFile( linkUri );
+ lockRead( linkFile );
+ try
+ {
+ return getTargetURI( linkFile, linkUri );
+ } finally
+ {
+ unlock( linkFile );
+ }
+ }
+ });
+ return result;
+ } catch( PrivilegedActionException e )
{
- unlock( linkFile );
+ throw (IOException) e.getException();
}
}
@@ -109,7 +146,7 @@
return f;
}
- private void setTargetURI( File linkFile, URI linkUri, URI targetUri )
+ private void setTargetURI( final File linkFile, final URI linkUri, final
URI targetUri )
throws IOException
{
Properties props = new Properties();
@@ -139,7 +176,7 @@
}
}
- private URI getTargetURI( File linkFile, URI linkUri )
+ private URI getTargetURI( final File linkFile, final URI linkUri )
throws IOException
{
if( linkFile.exists() == false )
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/link/Handler.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/link/Handler.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/link/Handler.java
Thu Apr 28 21:09:58 2005
@@ -35,7 +35,6 @@
{
/**
* Creation of a new transit link: protocol handler.
- * @exception TransitException if a transit system error occurs
*/
public Handler()
{
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/link/LinkURLConnection.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/link/LinkURLConnection.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/link/LinkURLConnection.java
Thu Apr 28 21:09:58 2005
@@ -17,18 +17,20 @@
package net.dpml.transit.link;
-import java.io.InputStream;
+import net.dpml.transit.SecuredTransitContext;
+import net.dpml.transit.util.MimeTypeHandler;
+
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
-
-import java.net.UnknownServiceException;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
-
-import net.dpml.transit.Transit;
-import net.dpml.transit.SecuredTransitContext;
-import net.dpml.transit.util.MimeTypeHandler;
+import java.net.UnknownServiceException;
+import java.security.AccessController;
+import java.security.PrivilegedExceptionAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedAction;
/**
* link: URL protocol connection processor.
@@ -41,14 +43,10 @@
/**
* Creation of a new handler.
* @param url the url to establish a connection with
- * @param context the transit context
* @exception NullPointerException if the url argument is null
- * @exception IOException if the url argument is not a valid,
- * i.e. the path must contain a group and an artifactId
- * separated by a slash.
*/
LinkURLConnection( URL url )
- throws NullPointerException, IOException
+ throws NullPointerException
{
super( url );
m_connected = false;
@@ -66,13 +64,29 @@
if( m_connected )
return;
m_connected = true;
- LinkManager linkManager =
SecuredTransitContext.create().getLinkManager();
- URI linkUri = URI.create( url.toExternalForm() );
- URI targetUri = linkManager.getTargetURI( linkUri );
- if( targetUri != null )
- m_targetURL = new URL( targetUri.toString() );
- else
- m_targetURL = null;
+ final SecuredTransitContext securedTransitContext =
SecuredTransitContext.create();
+ final LinkManager linkManager =
securedTransitContext.getLinkManager();
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+
+ public Object run()
+ throws IOException
+ {
+ URI linkUri = URI.create( url.toExternalForm() );
+ URI targetUri = linkManager.getTargetURI( linkUri );
+ if( targetUri != null )
+ m_targetURL = new URL( targetUri.toString() );
+ else
+ m_targetURL = null;
+ return null; // nothing to return
+ }
+ });
+ } catch( PrivilegedActionException e )
+ {
+ throw (IOException) e.getException();
+ }
}
/**
@@ -123,7 +137,7 @@
* @return the content object (possibly null)
* @exception IOException is an error occurs
*/
- public Object getContent( Class[] classes )
+ public Object getContent( final Class[] classes )
throws IOException
{
try
@@ -143,24 +157,32 @@
// attempt to resolve this locally
//
- for( int i=0; i < classes.length; i++ )
+ Object result = AccessController.doPrivileged( new PrivilegedAction()
{
- Class c = classes[i];
- if( c.equals( Link.class ) )
- {
- LinkManager linkManager =
SecuredTransitContext.getInstance().getLinkManager();
- String extUri = getURL().toString();
- URI uri = URI.create( extUri );
- Link link = new Link( uri, linkManager );
- return link;
- }
- if( c.equals( URI.class ) )
+
+ public Object run()
{
- String extUri = getURL().toString();
- URI uri = URI.create( extUri );
- return uri;
+ for( int i=0; i < classes.length; i++ )
+ {
+ Class c = classes[i];
+ if( c.equals( Link.class ) )
+ {
+ LinkManager linkManager =
SecuredTransitContext.getInstance().getLinkManager();
+ String extUri = getURL().toString();
+ URI uri = URI.create( extUri );
+ Link link = new Link( uri, linkManager );
+ return link;
+ }
+ if( c.equals( URI.class ) )
+ {
+ String extUri = getURL().toString();
+ URI uri = URI.create( extUri );
+ return uri;
+ }
+ }
+ return null;
}
- }
- return null;
+ });
+ return result;
}
}
- svn commit: r2447 - development/main/transit/core/handler/src/main/net/dpml/transit/link, niclas, 04/28/2005
Archive powered by MHonArc 2.6.24.