You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juddi.apache.org by jf...@apache.org on 2008/11/01 00:54:23 UTC

svn commit: r709604 [1/2] - in /webservices/juddi/branches/v3_trunk/juddi-core/src/main: java/org/apache/juddi/api/impl/ java/org/apache/juddi/auth/ java/org/apache/juddi/config/ java/org/apache/juddi/cryptor/ java/org/apache/juddi/error/ java/org/apac...

Author: jfaath
Date: Fri Oct 31 16:54:22 2008
New Revision: 709604

URL: http://svn.apache.org/viewvc?rev=709604&view=rev
Log:
JUDDI-151: completed the security API.

Added:
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/Authenticator.java   (with props)
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/AuthenticatorFactory.java   (with props)
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/CryptedXMLDocAuthenticator.java   (with props)
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/DefaultAuthenticator.java   (with props)
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/XMLDocAuthenticator.java   (with props)
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/cryptor/
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/cryptor/Cryptor.java   (with props)
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/cryptor/CryptorFactory.java   (with props)
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/cryptor/DefaultCryptor.java   (with props)
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/error/AuthTokenExpiredException.java   (with props)
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/error/AuthTokenRequiredException.java   (with props)
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/error/UnknownUserException.java   (with props)
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/util/Loader.java   (with props)
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/DefaultUUIDGen.java   (with props)
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/NativeUUIDGen.java   (with props)
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/SecureUUIDGen.java   (with props)
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/UUIDGen.java   (with props)
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/UUIDGenFactory.java   (with props)
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/Win32UUIDGen.java   (with props)
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/validation/ValidateAuth.java   (with props)
Modified:
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/UDDISecurityImpl.java
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/config/Property.java
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/mapping/MappingModelToApi.java
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/resources/messages_en.properties

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/UDDISecurityImpl.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/UDDISecurityImpl.java?rev=709604&r1=709603&r2=709604&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/UDDISecurityImpl.java (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/UDDISecurityImpl.java Fri Oct 31 16:54:22 2008
@@ -17,7 +17,10 @@
 
 package org.apache.juddi.api.impl;
 
+import java.util.Date;
 import javax.jws.WebService;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
 
 import org.uddi.api_v3.AuthToken;
 import org.uddi.api_v3.DiscardAuthToken;
@@ -25,22 +28,90 @@
 import org.uddi.v3_service.DispositionReportFaultMessage;
 import org.uddi.v3_service.UDDISecurityPortType;
 
+import org.apache.juddi.auth.AuthenticatorFactory;
+import org.apache.juddi.auth.Authenticator;
+import org.apache.juddi.error.UnknownUserException;
+import org.apache.juddi.error.ErrorMessage;
+import org.apache.juddi.util.JPAUtil;
+import org.apache.juddi.uuidgen.UUIDGen;
+import org.apache.juddi.uuidgen.UUIDGenFactory;
+import org.apache.juddi.mapping.MappingModelToApi;
+import org.apache.juddi.validation.ValidateAuth;
+import org.apache.juddi.model.Publisher;
+
+/**
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
 @WebService(serviceName="UDDISecurityService", 
 			endpointInterface="org.uddi.v3_service.UDDISecurityPortType")
 public class UDDISecurityImpl implements UDDISecurityPortType {
 
+	public static final String AUTH_TOKEN_PREFIX = "authtoken:";
 
 	public void discardAuthToken(DiscardAuthToken body)
 			throws DispositionReportFaultMessage {
-		// TODO Auto-generated method stub
 
+		EntityManager em = JPAUtil.getEntityManager();
+		EntityTransaction tx = em.getTransaction();
+		tx.begin();
+		
+		ValidateAuth.getPublisher(em, body.getAuthInfo());
+		
+		org.apache.juddi.model.AuthToken modelAuthToken = em.find(org.apache.juddi.model.AuthToken.class, body.getAuthInfo());
+		if (modelAuthToken != null) {
+			modelAuthToken.setLastUsed(new Date());
+			modelAuthToken.setNumberOfUses(modelAuthToken.getNumberOfUses() + 1);
+			modelAuthToken.setTokenState(ValidateAuth.AUTHTOKEN_RETIRED);
+		}
+
+		tx.commit();
+		em.close();
 	}
 
 
 	public AuthToken getAuthToken(GetAuthToken body)
 			throws DispositionReportFaultMessage {
-		// TODO Auto-generated method stub
-		return null;
+
+		Authenticator authenticator = AuthenticatorFactory.getAuthenticator();
+		
+		String publisherId = authenticator.authenticate(body.getUserID(), body.getCred());
+		
+		if (publisherId == null || publisherId.length() == 0)
+			throw new UnknownUserException(new ErrorMessage("errors.auth.InvalidCredentials", publisherId));
+		
+		EntityManager em = JPAUtil.getEntityManager();
+		EntityTransaction tx = em.getTransaction();
+		tx.begin();
+
+		// Verify that that user has a publisher account and thus the authority to publish
+		Publisher publisher = em.find(org.apache.juddi.model.Publisher.class, publisherId);
+		if (publisher == null)
+			throw new UnknownUserException(new ErrorMessage("errors.auth.NoPublisher", publisherId));
+				
+		// Generate auth token and store it!
+		UUIDGen uuidgen = UUIDGenFactory.getUUIDGen();
+		String authInfo = AUTH_TOKEN_PREFIX + uuidgen.uuidgen();
+		org.apache.juddi.model.AuthToken modelAuthToken = new org.apache.juddi.model.AuthToken();
+		if (authInfo != null) {
+			modelAuthToken.setAuthToken(authInfo);
+			modelAuthToken.setCreated(new Date());
+			modelAuthToken.setLastUsed(new Date());
+			modelAuthToken.setPublisherId(publisherId);
+			modelAuthToken.setPublisherName(publisher.getPublisherName());
+			modelAuthToken.setNumberOfUses(0);
+			modelAuthToken.setTokenState(ValidateAuth.AUTHTOKEN_ACTIVE);
+			
+			em.persist(modelAuthToken);
+		}
+		
+		org.uddi.api_v3.AuthToken apiAuthToken = new org.uddi.api_v3.AuthToken();
+		
+		MappingModelToApi.mapAuthToken(modelAuthToken, apiAuthToken);
+		
+		tx.commit();
+		em.close();
+		
+		return apiAuthToken;
 	}
 
 }

Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/Authenticator.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/Authenticator.java?rev=709604&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/Authenticator.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/Authenticator.java Fri Oct 31 16:54:22 2008
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2001-2008 The Apache Software Foundation.
+ * 
+ * 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 org.apache.juddi.auth;
+
+/**
+ * @author Steve Viens (sviens@apache.org)
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+public interface Authenticator {
+
+	/**
+	*
+	* @param userID
+	* @param cred
+	* @return The publisherID for this user
+	* @throws RegistryException
+	*/
+	String authenticate(String userID,String cred) throws org.apache.juddi.error.RegistryException;
+}

Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/Authenticator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/AuthenticatorFactory.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/AuthenticatorFactory.java?rev=709604&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/AuthenticatorFactory.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/AuthenticatorFactory.java Fri Oct 31 16:54:22 2008
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2001-2008 The Apache Software Foundation.
+ * 
+ * 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 org.apache.juddi.auth;
+
+import org.apache.log4j.Logger;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.juddi.config.AppConfig;
+import org.apache.juddi.config.Property;
+import org.apache.juddi.util.Loader;
+
+/**
+ * @author Steve Viens (sviens@apache.org)
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+public class AuthenticatorFactory {
+	private static Logger log = Logger.getLogger(AuthenticatorFactory.class);
+
+	// Default authenticator implementation
+	private static final String DEFAULT_IMPL = "org.apache.juddi.auth.DefaultAuthenticator";
+
+	// the shared Authenticator instance
+	private static Authenticator auth = null;
+
+
+	/*
+	 * Returns a new instance of a AuthenticatorFactory.
+	 * 
+	 * @return Authenticator
+	 */
+	public static Authenticator getAuthenticator() {
+		if (auth == null)
+			auth = createAuthenticator();
+		return auth;
+	}
+
+	/*
+	 * Returns a new instance of a Authenticator.
+	 * 
+	 * @return Authenticator
+	 */
+	private static synchronized Authenticator createAuthenticator() {
+		if (auth != null)
+			return auth;
+	
+		String className = DEFAULT_IMPL;
+		try {
+			// grab class name of the Authenticator implementation to create
+			className = AppConfig.getConfiguration().getString(Property.JUDDI_AUTHENTICATOR, DEFAULT_IMPL);
+		}
+		catch(ConfigurationException ce) {
+			log.error("Configuration exception occurred retrieving: " + Property.JUDDI_AUTHENTICATOR);
+		}
+	
+		// write the Authenticator implementation name to the log
+		log.debug("Authenticator Implementation = " + className);
+	
+		Class<?> authClass = null;
+		try {
+			// Use Loader to locate & load the Authenticator implementation
+			authClass = Loader.getClassForName(className);
+		}
+		catch(ClassNotFoundException e) {
+			log.error("The specified Authenticator class '" + className + "' was not found in classpath.");
+			log.error(e);
+		}
+	
+		try {
+			// try to instantiate the Authenticator implementation
+			auth = (Authenticator)authClass.newInstance();
+		}
+		catch(Exception e) {
+			log.error("Exception while attempting to instantiate the implementation of Authenticator: " + authClass.getName() + "\n" + e.getMessage());
+			log.error(e);
+		}
+	
+		return auth;
+	}
+}

Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/AuthenticatorFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/CryptedXMLDocAuthenticator.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/CryptedXMLDocAuthenticator.java?rev=709604&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/CryptedXMLDocAuthenticator.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/CryptedXMLDocAuthenticator.java Fri Oct 31 16:54:22 2008
@@ -0,0 +1,196 @@
+/*
+ * Copyright 2001-2008 The Apache Software Foundation.
+ * 
+ * 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 org.apache.juddi.auth;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+
+import javax.crypto.BadPaddingException;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.juddi.cryptor.Cryptor;
+import org.apache.juddi.cryptor.CryptorFactory;
+import org.apache.juddi.error.RegistryException;
+import org.apache.juddi.error.FatalErrorException;
+import org.apache.juddi.error.ErrorMessage;
+import org.apache.juddi.error.UnknownUserException;
+
+/**
+ * @author Anou Manavalan
+ */
+public class CryptedXMLDocAuthenticator extends XMLDocAuthenticator
+{
+  // private reference to the jUDDI logger
+  private static Log log = LogFactory.getLog(CryptedXMLDocAuthenticator.class);
+
+  /**
+   *
+   */
+  public CryptedXMLDocAuthenticator()
+  {
+    super();
+  }
+
+  /**
+   *
+   */
+  public String authenticate(String userID,String credential)
+    throws RegistryException
+  {
+    preProcess(userID,credential);
+    String encryptedCredential = encrypt(credential);
+    return postProcess(userID, encryptedCredential);
+  }
+
+  /**
+   *
+   */
+  private String encrypt(String str) 
+    throws RegistryException
+  {
+    try
+    {
+      Cryptor cryptor = (Cryptor)CryptorFactory.getCryptor();
+  
+      return cryptor.encrypt(str);
+    }
+    catch (InvalidKeyException e)
+    {
+      log.error("Invalid Key Exception in crypting the password",e);
+      throw new FatalErrorException(new ErrorMessage("errors.auth.cryptor.InvalidKey", e.getMessage()));
+    }
+    catch (NoSuchPaddingException e)
+    {
+      log.error("Padding Exception in crypting the password",e);
+      throw new FatalErrorException(new ErrorMessage("errors.auth.cryptor.Padding", e.getMessage()));
+    }
+    catch (NoSuchAlgorithmException e)
+    {
+      log.error("Algorithm Exception in crypting the password",e);
+      throw new FatalErrorException(new ErrorMessage("errors.auth.cryptor.Algorithm", e.getMessage()));
+    }
+    catch (InvalidAlgorithmParameterException e)
+    {
+      log.error("Algorithm parameter Exception in crypting the password",e);
+      throw new FatalErrorException(new ErrorMessage("errors.auth.cryptor.AlgorithmParam", e.getMessage()));
+    }
+    catch (IllegalBlockSizeException e)
+    {
+      log.error("Block size Exception in crypting the password",e);
+      throw new FatalErrorException(new ErrorMessage("errors.auth.cryptor.BlockSize", e.getMessage()));
+    }
+    catch (BadPaddingException e)
+    {
+      log.error("Bad Padding Exception in crypting the password",e);
+      throw new FatalErrorException(new ErrorMessage("errors.auth.cryptor.BadPadding", e.getMessage()));
+    }
+  }
+
+  /**
+   * @param userID
+   * @param credential
+   * @throws RegistryException
+   */
+  private void preProcess(String userID, String credential) 
+    throws RegistryException
+  {
+    // a userID must be specified.
+    if (userID == null)
+      //throw new UnknownUserException("Invalid user ID: "+userID);
+      throw new UnknownUserException(new ErrorMessage("errors.auth.InvalidUserId", userID));
+
+    // credential (password) must be specified.
+    if (credential == null)
+      //throw new UnknownUserException("Invalid credentials");
+      throw new UnknownUserException(new ErrorMessage("errors.auth.InvalidCredentials"));
+  }
+
+  /**
+   * @param userID
+   * @param encryptedCredential
+   * @return
+   * @throws RegistryException
+   */
+  private String postProcess(String userID, String encryptedCredential) 
+    throws RegistryException
+  {
+    if (userTable.containsKey(userID))
+    {
+      UserInfo userInfo = (UserInfo)userTable.get(userID);
+      if ((userInfo.password == null) || (!encryptedCredential.equals(userInfo.password)))
+      throw new UnknownUserException(new ErrorMessage("errors.auth.InvalidCredentials", userID));
+    }
+    else
+      throw new UnknownUserException(new ErrorMessage("errors.auth.InvalidUserId", userID));
+
+    return userID;
+  }
+
+
+  /***************************************************************************/
+  /***************************** TEST DRIVER *********************************/
+  /***************************************************************************/
+
+
+  public static void main(String[] args)
+    throws Exception
+  {
+    Authenticator auth = new CryptedXMLDocAuthenticator();
+
+    try {
+      System.out.print("anou_mana/password: ");
+      auth.authenticate("anou_mana","password");
+      System.out.println("successfully authenticated");
+    }
+    catch(Exception ex) {
+      System.out.println(ex.getMessage());
+    }
+
+    try {
+      System.out.print("anou_mana/badpass: ");
+      auth.authenticate("anou_mana","badpass");
+      System.out.println("successfully authenticated");
+    }
+    catch(Exception ex) {
+      System.out.println(ex.getMessage());
+    }
+
+    try {
+      System.out.print("bozo/clown: ");
+      auth.authenticate("bozo","clown");
+      System.out.println("successfully authenticated");
+    }
+    catch(Exception ex) {
+      System.out.println(ex.getMessage());
+    }
+
+    try {
+      System.out.print("sviens/password: ");
+      auth.authenticate("sviens","password");
+      System.out.println("successfully authenticated");
+    }
+    catch(Exception ex) {
+      System.out.println(ex.getMessage());
+    }
+  }
+  
+}

Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/CryptedXMLDocAuthenticator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/DefaultAuthenticator.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/DefaultAuthenticator.java?rev=709604&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/DefaultAuthenticator.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/DefaultAuthenticator.java Fri Oct 31 16:54:22 2008
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2001-2008 The Apache Software Foundation.
+ * 
+ * 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 org.apache.juddi.auth;
+
+import org.apache.juddi.error.RegistryException;
+
+/**
+ * This is a simple implementation of jUDDI's Authenticator interface.
+ *
+ * @author Steve Viens (sviens@apache.org)
+ */
+public class DefaultAuthenticator implements Authenticator {
+
+	public DefaultAuthenticator() {
+	}
+
+	public String authenticate(String userID, String credential) throws RegistryException {
+		return userID;
+	}
+
+}
\ No newline at end of file

Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/DefaultAuthenticator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/XMLDocAuthenticator.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/XMLDocAuthenticator.java?rev=709604&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/XMLDocAuthenticator.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/XMLDocAuthenticator.java Fri Oct 31 16:54:22 2008
@@ -0,0 +1,364 @@
+/*
+ * Copyright 2001-2008 The Apache Software Foundation.
+ * 
+ * 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 org.apache.juddi.auth;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.juddi.error.ErrorMessage;
+import org.apache.juddi.error.RegistryException;
+import org.apache.juddi.error.UnknownUserException;
+import org.apache.juddi.config.AppConfig;
+import org.apache.juddi.config.Property;
+import org.apache.log4j.Logger;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.XMLReader;
+
+/**
+ * This is a simple implementation of jUDDI's Authenticator interface. The credential
+ * store is simply an unencrypted xml document called 'juddi.users' that can be
+ * found in jUDDI's config directory. Below is an example of what you might find
+ * in this document.
+ *
+ *     Example juddi.users document:
+ *     =============================
+ *     <?xml version="1.0" encoding="UTF-8"?>
+ *     <juddi-users>
+ *       <user userid="sviens" password="password" />
+ *       <user userid="griddell" password="password" />
+ *       <user userid="bhablutzel" password="password" />
+ *     </juddi-users>
+ *
+ * @author Steve Viens (sviens@apache.org)
+ */
+public class XMLDocAuthenticator implements ContentHandler, ErrorHandler, Authenticator
+{
+	private static Logger log = Logger.getLogger(AuthenticatorFactory.class);
+
+  // static default juddi users file name
+  private static final String FILE_NAME_KEY = "juddi.users";
+  private static final String DEFAULT_FILE_NAME = "juddi-users.xml";
+
+  // hashtable of UserInfo objects
+  Hashtable userTable;
+
+  class UserInfo
+  {
+    public String userid;
+    public String password;
+
+    public String toString()
+    {
+      StringBuffer buff = new StringBuffer(75);
+      buff.append(userid);
+      buff.append(" | ");
+      buff.append(password);
+      return buff.toString();
+    }
+  }
+
+  /**
+   *
+   */
+  public XMLDocAuthenticator()
+  {
+    init();
+  }
+
+  /**
+   * Perform auth initialization tasks
+   */
+  public synchronized void init()
+  {
+    // create and populate a Hashtable of UserInfo objects (one per user)
+    try {
+      userTable = new Hashtable();
+
+      String usersFileName = AppConfig.getConfiguration().getString(Property.JUDDI_USERSFILE);
+
+      log.info("Using jUDDI Users File: "+usersFileName);
+
+      build(new FileInputStream(usersFileName));
+    }
+    catch (ConfigurationException ce) {
+        ce.printStackTrace();
+    }
+    catch (IOException ioex) {
+      ioex.printStackTrace();
+    }
+    catch (SAXException saxex) {
+      saxex.printStackTrace();
+    }
+    catch (ParserConfigurationException pcex) {
+      pcex.printStackTrace();
+    }
+  }
+
+  /**
+   *
+   */
+  public String authenticate(String userID,String credential)
+    throws RegistryException
+  {
+    // a userID must be specified.
+    if (userID == null)
+      throw new UnknownUserException(new ErrorMessage("errors.auth.InvalidUserId", userID));
+
+    // credential (password) must be specified.
+    if (credential == null)
+      throw new UnknownUserException(new ErrorMessage("errors.auth.InvalidCredentials"));
+
+    if (userTable.containsKey(userID))
+    {
+      UserInfo userInfo = (UserInfo)userTable.get(userID);
+      if ((userInfo.password == null) || (!credential.equals(userInfo.password)))
+         throw new UnknownUserException(new ErrorMessage("errors.auth.InvalidCredentials"));
+    }
+    else
+      throw new UnknownUserException(new ErrorMessage("errors.auth.InvalidUserId", userID));
+
+    return userID;
+  }
+
+  /**
+   *
+   */
+  public String toString()
+  {
+    StringBuffer buff = new StringBuffer(100);
+
+    Enumeration e = userTable.keys();
+    while (e.hasMoreElements())
+    {
+      UserInfo userInfo = (UserInfo)userTable.get(e.nextElement());
+      buff.append(userInfo.toString()+"\n");
+    }
+
+    return buff.toString();
+  }
+
+  /**
+   *
+   */
+  Hashtable build(InputStream istream)
+    throws ParserConfigurationException,SAXException,IOException
+  {
+    SAXParserFactory spf = SAXParserFactory.newInstance();
+    spf.setNamespaceAware(true);
+
+    XMLReader xr = spf.newSAXParser().getXMLReader();
+    xr.setContentHandler(this);
+    xr.setErrorHandler(this);
+    xr.parse(new InputSource(istream));
+
+    return (Hashtable)this.getObject();
+  }
+
+  /**
+   * handle setDocumentLocator event
+   */
+  public void setDocumentLocator(org.xml.sax.Locator locator)
+  {
+  }
+
+  /**
+   * handle startDocument event
+   */
+  public void startDocument()
+    throws SAXException
+  {
+  }
+
+  /**
+   * handle endDocument event
+   */
+  public void endDocument()
+    throws SAXException
+  {
+  }
+
+  /**
+   * handle startElement event
+   */
+  public void startElement(String uri,String name,String qName,Attributes attributes)
+    throws SAXException
+  {
+    if (name.equalsIgnoreCase("user"))
+    {
+      UserInfo userInfo = new UserInfo();
+
+      for(int i=0; i<attributes.getLength(); i++)
+      {
+        if (attributes.getQName(i).equalsIgnoreCase("userid"))
+          userInfo.userid = attributes.getValue(i);
+        else if (attributes.getQName(i).equalsIgnoreCase("password"))
+          userInfo.password = attributes.getValue(i);
+      }
+
+      userTable.put(userInfo.userid,userInfo);
+    }
+  }
+
+  /**
+   * handle endElement event
+   */
+  public void endElement(String name,String string2,String string3)
+    throws SAXException
+  {
+  }
+
+  /**
+   * handle characters event
+   */
+  public void characters(char[] chars,int int1, int int2)
+    throws SAXException
+  {
+  }
+
+  /**
+   * handle ignorableWhitespace event
+   */
+  public void ignorableWhitespace(char[] chars,int int1, int int2)
+    throws SAXException
+  {
+  }
+
+  /**
+   * handle processingInstruction event
+   */
+  public void processingInstruction(String string1,String string2)
+    throws SAXException
+  {
+  }
+
+  /**
+   * handle startPrefixMapping event
+   */
+  public void startPrefixMapping(String string1,String string2)
+    throws SAXException
+  {
+  }
+
+  /**
+   * handle endPrefixMapping event
+   */
+  public void endPrefixMapping(String string)
+    throws SAXException
+  {
+  }
+
+  /**
+   * handle skippedEntity event
+   */
+  public void skippedEntity(String string)
+    throws SAXException
+  {
+  }
+
+  /**
+   * handle warning event
+   */
+  public void warning(SAXParseException spex)
+    throws SAXException
+  {
+  }
+
+  /**
+   * handle error event
+   */
+  public void error(SAXParseException spex)
+    throws SAXException
+  {
+  }
+
+  /**
+   * handle fatalError event
+   */
+  public void fatalError(SAXParseException spex)
+    throws SAXException
+  {
+  }
+
+  /**
+   * Retrieve the object built by the handling of SAX events.
+   */
+  Object getObject()
+  {
+    return this.userTable;
+  }
+
+
+  /***************************************************************************/
+  /***************************** TEST DRIVER *********************************/
+  /***************************************************************************/
+
+
+  public static void main(String[] args)
+    throws Exception
+  {
+    Authenticator auth = new XMLDocAuthenticator();
+
+    try {
+      System.out.print("anou_mana/password: ");
+      auth.authenticate("anou_mana","password");
+      System.out.println("successfully authenticated");
+    }
+    catch(Exception ex) {
+      System.out.println(ex.getMessage());
+    }
+
+    try {
+      System.out.print("anou_mana/badpass: ");
+      auth.authenticate("anou_mana","badpass");
+      System.out.println("successfully authenticated");
+    }
+    catch(Exception ex) {
+      System.out.println(ex.getMessage());
+    }
+
+    try {
+      System.out.print("bozo/clown: ");
+      auth.authenticate("bozo","clown");
+      System.out.println("successfully authenticated");
+    }
+    catch(Exception ex) {
+      System.out.println(ex.getMessage());
+    }
+
+    try {
+      System.out.print("sviens/password: ");
+      auth.authenticate("sviens","password");
+      System.out.println("successfully authenticated");
+    }
+    catch(Exception ex) {
+      System.out.println(ex.getMessage());
+    }
+  }
+}
\ No newline at end of file

Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/auth/XMLDocAuthenticator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/config/Property.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/config/Property.java?rev=709604&r1=709603&r2=709604&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/config/Property.java (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/config/Property.java Fri Oct 31 16:54:22 2008
@@ -13,6 +13,8 @@
 	public final static String JUDDI_MAX_TMODELS_PER_PUBLISHER   ="juddi.maxTModelsPerPublisher";
 	public final static String JUDDI_AUTHENTICATOR               ="juddi.authenticator";
 	public final static String JUDDI_UUID_GENERATOR              ="juddi.uuidgen";
+	public final static String JUDDI_UUID_COMMAND                ="juddi.uuidgenCommand";
 	public final static String JUDDI_CRYPTOR                     ="juddi.cryptor";
 	public final static String JUDDI_VALIDATOR                   ="juddi.validator";
+	public final static String JUDDI_USERSFILE                   ="juddi.usersfile";
 }

Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/cryptor/Cryptor.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/cryptor/Cryptor.java?rev=709604&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/cryptor/Cryptor.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/cryptor/Cryptor.java Fri Oct 31 16:54:22 2008
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2001-2008 The Apache Software Foundation.
+ * 
+ * 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 org.apache.juddi.cryptor;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+
+import javax.crypto.BadPaddingException;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
+
+/**
+ * @author Anou Manavalan
+ */
+public interface Cryptor
+{
+  /**
+   * Encrypt the string
+   */
+  byte[] encrypt(byte[] bytes)
+    throws  NoSuchPaddingException,
+            NoSuchAlgorithmException,
+            InvalidAlgorithmParameterException,
+            InvalidKeyException,
+            IllegalBlockSizeException,
+            BadPaddingException;
+
+  String encrypt(String str)
+    throws  NoSuchPaddingException,
+            NoSuchAlgorithmException,
+            InvalidAlgorithmParameterException,
+            InvalidKeyException,
+            IllegalBlockSizeException,
+            BadPaddingException;
+
+  /**
+   * Decrypt the string
+   */
+  byte[] decrypt(byte[] bytes)
+    throws  NoSuchPaddingException,
+            NoSuchAlgorithmException,
+            InvalidAlgorithmParameterException,
+            InvalidKeyException,
+            IllegalBlockSizeException,
+            BadPaddingException;
+
+  String decrypt(String str)
+    throws  NoSuchPaddingException,
+            NoSuchAlgorithmException,
+            InvalidAlgorithmParameterException,
+            InvalidKeyException,
+            IllegalBlockSizeException,
+            BadPaddingException;
+}
\ No newline at end of file

Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/cryptor/Cryptor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/cryptor/CryptorFactory.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/cryptor/CryptorFactory.java?rev=709604&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/cryptor/CryptorFactory.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/cryptor/CryptorFactory.java Fri Oct 31 16:54:22 2008
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2001-2008 The Apache Software Foundation.
+ * 
+ * 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 org.apache.juddi.cryptor;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.juddi.config.AppConfig;
+import org.apache.juddi.config.Property;
+import org.apache.juddi.util.Loader;
+import org.apache.log4j.Logger;
+
+/**
+ * Used to create the org.apache.juddi.cryptor.Cryptor implementation
+ * as specified by the 'juddi.cryptor' property. Defaults to
+ * org.apache.juddi.cryptor.DefaultCryptor if an implementation is not
+ * specified.
+ *
+ * @author Steve Viens (sviens@apache.org)
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+public abstract class CryptorFactory {
+	private static Logger log = Logger.getLogger(CryptorFactory.class);
+
+	// Cryptor default implementation
+	private static final String DEFAULT_IMPL = "org.apache.juddi.cryptor.DefaultCryptor";
+
+	// the shared Cryptor instance
+	private static Cryptor cryptor = null;
+
+	/*
+	 * Returns a new instance of a CryptorFactory.
+	 * 
+	 * @return Cryptor
+	 */
+	public static Cryptor getCryptor() {
+		if (cryptor == null)
+			cryptor = createCryptor();
+		return cryptor;
+	}
+
+	/*
+	 * Returns a new instance of a Cryptor.
+	 * 
+	 * @return Cryptor
+	 */
+	private static synchronized Cryptor createCryptor() {
+		if (cryptor != null)
+			return cryptor;
+	
+		// grab class name of the Cryptor implementation to create
+		String className = DEFAULT_IMPL;
+		try {
+			// grab class name of the Authenticator implementation to create
+			className = AppConfig.getConfiguration().getString(Property.JUDDI_CRYPTOR, DEFAULT_IMPL);
+		}
+		catch(ConfigurationException ce) {
+			log.error("Configuration exception occurred retrieving: " + Property.JUDDI_CRYPTOR);
+		}
+		
+		// write the Cryptor implementation name to the log
+		log.debug("Cryptor Implementation = " + className);
+	
+		Class<?> cryptorClass = null;
+		try {
+			// Use Loader to locate & load the Cryptor implementation
+			cryptorClass = Loader.getClassForName(className);
+		}
+		catch(ClassNotFoundException e) {
+			log.error("The specified Cryptor class '" + className + "' was not found in classpath.");
+			log.error(e);
+		}
+	
+		try {
+			// try to instantiate the Cryptor implementation
+			cryptor = (Cryptor)cryptorClass.newInstance();
+		}
+		catch(Exception e) {
+			log.error("Exception while attempting to instantiate the implementation of Cryptor: " + cryptorClass.getName() + "\n" + e.getMessage());
+			log.error(e);
+		}
+	
+		return cryptor;
+	}
+}
\ No newline at end of file

Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/cryptor/CryptorFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/cryptor/DefaultCryptor.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/cryptor/DefaultCryptor.java?rev=709604&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/cryptor/DefaultCryptor.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/cryptor/DefaultCryptor.java Fri Oct 31 16:54:22 2008
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2001-2008 The Apache Software Foundation.
+ * 
+ * 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 org.apache.juddi.cryptor;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.spec.InvalidKeySpecException;
+
+import javax.crypto.BadPaddingException;
+import javax.crypto.Cipher;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
+import javax.crypto.SecretKey;
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.PBEKeySpec;
+import javax.crypto.spec.PBEParameterSpec;
+
+/**
+ * @author Anou Manavalan
+ */
+public class DefaultCryptor implements Cryptor
+{
+  private PBEKeySpec pbeKeySpec = null;
+  private PBEParameterSpec pbeParamSpec = null;
+  private SecretKeyFactory keyFac = null;
+  private SecretKey pbeKey = null;
+
+  // Salt
+  private byte[] salt = {
+    (byte)0xc7, (byte)0x73, (byte)0x21, (byte)0x8c,
+    (byte)0x7e, (byte)0xc8, (byte)0xee, (byte)0x99
+  };
+
+  // Iteration count
+  private int count = 20;
+
+  /**
+   * Constructor for DefaultCryptor.
+   */
+  public DefaultCryptor()
+    throws NoSuchAlgorithmException,InvalidKeySpecException
+  {
+    // Create PBE parameter set
+    pbeParamSpec = new PBEParameterSpec(salt,count);
+    pbeKeySpec = new PBEKeySpec("saagar".toCharArray());
+    keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
+    pbeKey = keyFac.generateSecret(pbeKeySpec);
+  }
+
+  /**
+   * Encrypt the string
+   */
+  private byte[] crypt(int cipherMode,byte[] text)
+    throws  NoSuchPaddingException,
+            NoSuchAlgorithmException,
+            InvalidAlgorithmParameterException,
+            InvalidKeyException,
+            IllegalBlockSizeException,
+            BadPaddingException
+
+  {
+    // Create PBE Cipher
+    Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
+
+    // Initialize PBE Cipher with key and parameters
+    pbeCipher.init(cipherMode,pbeKey,pbeParamSpec);
+
+    //byte[] text = str.getBytes();
+
+    // Encrypt/Decrypt the string
+    byte[] cryptext = pbeCipher.doFinal(text);
+
+    return cryptext;
+  }
+
+  /**
+   * Encrypt the string
+   */
+  public String encrypt(String str)
+    throws  NoSuchPaddingException,
+            NoSuchAlgorithmException,
+            InvalidAlgorithmParameterException,
+            InvalidKeyException,
+            IllegalBlockSizeException,
+            BadPaddingException
+  {
+    byte[] encs = crypt(Cipher.ENCRYPT_MODE,str.getBytes());
+    return new String(encs);
+  }
+
+  public byte[] encrypt(byte[] bytes)
+    throws  NoSuchPaddingException,
+            NoSuchAlgorithmException,
+            InvalidAlgorithmParameterException,
+            InvalidKeyException,
+            IllegalBlockSizeException,
+            BadPaddingException
+  {
+    return crypt(Cipher.ENCRYPT_MODE, bytes);
+  }
+
+  /**
+   * Decrypt the string
+   */
+  public String decrypt(String str)
+    throws  NoSuchPaddingException,
+            NoSuchAlgorithmException,
+            InvalidAlgorithmParameterException,
+            InvalidKeyException,
+            IllegalBlockSizeException,
+            BadPaddingException
+  {
+    byte[] decs = crypt(Cipher.DECRYPT_MODE,str.getBytes());
+    return new String(decs);
+  }
+
+
+  public byte[] decrypt(byte[] bytes)
+    throws  NoSuchPaddingException,
+            NoSuchAlgorithmException,
+            InvalidAlgorithmParameterException,
+            InvalidKeyException,
+            IllegalBlockSizeException,
+            BadPaddingException
+  {
+    return crypt(Cipher.DECRYPT_MODE,bytes);
+  }
+
+}
\ No newline at end of file

Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/cryptor/DefaultCryptor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/error/AuthTokenExpiredException.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/error/AuthTokenExpiredException.java?rev=709604&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/error/AuthTokenExpiredException.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/error/AuthTokenExpiredException.java Fri Oct 31 16:54:22 2008
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2001-2008 The Apache Software Foundation.
+ * 
+ * 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 org.apache.juddi.error;
+
+/**
+ *   E_authTokenExpired: (10110) Signifies that the authentication token information has timed out.
+ * 
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+public class AuthTokenExpiredException extends RegistryException {
+
+	private static final long serialVersionUID = 1L;
+
+	public AuthTokenExpiredException(ErrorMessage message) {
+		super(message, UDDIErrorHelper.buildDispositionReport(UDDIErrorHelper.E_AUTH_TOKEN_EXPIRED));
+	}
+}

Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/error/AuthTokenExpiredException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/error/AuthTokenRequiredException.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/error/AuthTokenRequiredException.java?rev=709604&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/error/AuthTokenRequiredException.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/error/AuthTokenRequiredException.java Fri Oct 31 16:54:22 2008
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2001-2008 The Apache Software Foundation.
+ * 
+ * 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 org.apache.juddi.error;
+
+/**
+ *   E_authTokenRequired: (10120) Signifies that an authentication token is missing or is invalid for an API call that requires authentication.
+ * 
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+public class AuthTokenRequiredException extends RegistryException {
+
+	private static final long serialVersionUID = 1L;
+
+	public AuthTokenRequiredException(ErrorMessage message) {
+		super(message, UDDIErrorHelper.buildDispositionReport(UDDIErrorHelper.E_AUTH_TOKEN_REQUIRED));
+	}
+}

Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/error/AuthTokenRequiredException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/error/UnknownUserException.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/error/UnknownUserException.java?rev=709604&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/error/UnknownUserException.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/error/UnknownUserException.java Fri Oct 31 16:54:22 2008
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2001-2008 The Apache Software Foundation.
+ * 
+ * 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 org.apache.juddi.error;
+
+/**
+ *   E_unknownUser: (10150) Signifies that the user ID and password pair passed in a get_authToken API is not known to the UDDI node or is not valid.
+ * 
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+public class UnknownUserException extends RegistryException {
+
+	private static final long serialVersionUID = 1L;
+
+	public UnknownUserException(ErrorMessage message) {
+		super(message, UDDIErrorHelper.buildDispositionReport(UDDIErrorHelper.E_UNKNOWN_USER));
+	}
+}

Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/error/UnknownUserException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/mapping/MappingModelToApi.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/mapping/MappingModelToApi.java?rev=709604&r1=709603&r2=709604&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/mapping/MappingModelToApi.java (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/mapping/MappingModelToApi.java Fri Oct 31 16:54:22 2008
@@ -584,4 +584,12 @@
 
 	}
 	
+	public static void mapAuthToken(org.apache.juddi.model.AuthToken modelAuthToken, 
+									org.uddi.api_v3.AuthToken apiAuthToken) 
+				   throws DispositionReportFaultMessage {
+		apiAuthToken.setAuthInfo(modelAuthToken.getAuthToken());
+	
+	}
+
+	
 }

Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/util/Loader.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/util/Loader.java?rev=709604&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/util/Loader.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/util/Loader.java Fri Oct 31 16:54:22 2008
@@ -0,0 +1,202 @@
+/*
+ * Copyright 2001-2008 The Apache Software Foundation.
+ * 
+ * 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 org.apache.juddi.util;
+
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URL;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * The idea for most of this code was taken from the Apache
+ * (Jakarta) Log4j project: http://jakarta.apache.org/log4j
+ *
+ *  - Steve
+ *
+ * @author Ceki G&uuml;lc&uuml;
+ * @author anou_mana;
+*/
+public class Loader
+{
+  // private reference to the jUDDI logger
+  private static Log log = LogFactory.getLog(Loader.class);
+  /**
+   * Added for unittesting with maven
+   * 
+   * @param resource
+   * @return
+   */
+  public InputStream getResourceAsStreamFromClass(String resource) {
+      InputStream stream = getClass().getClassLoader().getResourceAsStream(resource);
+      return stream;
+  }
+  /**
+   * @param resource
+   * @return InputStream to the named resource
+   */
+  public static InputStream getResourceAsStream(String resource)
+  {
+    ClassLoader classLoader = null;
+    InputStream stream = null;
+
+    // Get the Thread Context Class Loader which is
+    // only available in JDK 1.2 and later.
+    try
+    {
+      classLoader = getContextClassLoader();
+      if (classLoader != null)
+      {
+        log.debug("Trying to find ["+resource+"] using context classloader "+classLoader+".");
+        stream = classLoader.getResourceAsStream(resource);
+        if(stream != null) {
+          return stream;
+        }
+      }
+
+      // We could not find resource. Ler us now try
+      // with the class loader that loaded this class.
+      classLoader = Loader.class.getClassLoader();
+      if (classLoader != null)
+      {
+        log.debug("Trying to find ["+resource+"] using "+classLoader+" class loader.");
+        stream = classLoader.getResourceAsStream(resource);
+        if(stream != null) {
+          return stream;
+        }
+      }
+    }
+    catch(Throwable th) {
+      log.warn("Exception thrown from Loader.getResource(\""+resource+"\").",th);
+    }
+
+    // Last ditch attempt: get the resource from the class path. It
+    // may be the case that class was loaded by the Extentsion class
+    // loader which the parent of the system class loader.
+    log.debug("Trying to find ["+resource+"] using ClassLoader.getSystemResource().");
+
+    return ClassLoader.getSystemResourceAsStream(resource);
+  }
+
+  /**
+   * @param resource name
+   * @return URL to the named resource
+   */
+  public static URL getResource(String resource)
+  {
+    ClassLoader classLoader = null;
+    URL url = null;
+
+    // Get the Thread Context Class Loader which is
+    // only available in JDK 1.2 and later.
+    try
+    {
+      classLoader = getContextClassLoader();
+      if (classLoader != null)
+      {
+        log.debug("Trying to find ["+resource+"] using context classloader "+classLoader+".");
+        url = classLoader.getResource(resource);
+        if(url != null) {
+          return url;
+        }
+      }
+
+      // We could not find resource. Ler us now try
+      // with the class loader that loaded this class.
+      classLoader = Loader.class.getClassLoader();
+      if (classLoader != null)
+      {
+        log.debug("Trying to find ["+resource+"] using "+classLoader+" class loader.");
+        url = classLoader.getResource(resource);
+        if(url != null) {
+          return url;
+        }
+      }
+    }
+    catch(Throwable th) {
+      log.warn("Exception thrown from Loader.getResource(\""+resource+"\").",th);
+    }
+
+    // Last ditch attempt: get the resource from the class path. It
+    // may be the case that class was loaded by the Extentsion class
+    // loader which the parent of the system class loader.
+    log.debug("Trying to find ["+resource+"] using ClassLoader.getSystemResource().");
+
+    return ClassLoader.getSystemResource(resource);
+  }
+
+  /**
+   * Get the Thread Context Class Loader which is only available
+   * in JDK 1.2 and later.
+   * @return null if running under a JDK that's earlier than 1.2
+   **/
+  private static ClassLoader getContextClassLoader()
+    throws IllegalAccessException, InvocationTargetException
+  {
+    Method method = null;
+    try {
+      method = Thread.class.getMethod("getContextClassLoader",(Class[])null);
+    }
+    catch (NoSuchMethodException e) {
+      return null; // Using JDK 1.1 or earlier
+    }
+
+    return (ClassLoader)method.invoke(Thread.currentThread(),(Object[])null);
+  }
+
+  /**
+   * 
+   * @param name
+   * @return The class object for the name given
+   * @throws ClassNotFoundException
+   * @throws NoClassDefFoundError
+   */
+  public static Class getClassForName(String name)
+    throws ClassNotFoundException, NoClassDefFoundError
+  {
+    Class clazz = null;
+
+    try
+    {
+      log.info("Using the Context ClassLoader");
+      ClassLoader ccl = Thread.currentThread().getContextClassLoader();
+      clazz = Class.forName(name, true, ccl);
+    }
+    catch (Exception e)
+    {
+      log.warn("Failed to load the class " + name + " with context class loader " + e);
+    }
+
+    if (null == clazz)
+    {
+      ClassLoader scl = ClassLoader.getSystemClassLoader();
+      try
+      {
+        log.info("Using the System ClassLoader");
+        clazz = Class.forName(name, true, scl);
+      }
+      catch (Exception e)
+      {
+        log.warn("Failed to load the class " + name + " with system class loader " + e);
+      }
+    }
+
+    return clazz;
+  }
+}
\ No newline at end of file

Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/util/Loader.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/DefaultUUIDGen.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/DefaultUUIDGen.java?rev=709604&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/DefaultUUIDGen.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/DefaultUUIDGen.java Fri Oct 31 16:54:22 2008
@@ -0,0 +1,292 @@
+/*
+ * Copyright 2001-2008 The Apache Software Foundation.
+ * 
+ * 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 org.apache.juddi.uuidgen;
+
+import java.math.BigInteger;
+import java.util.Random;
+
+/**
+ * Used to create new universally unique identifiers or UUID's (sometimes called
+ * GUID's).  UDDI UUID's are allways formmated according to DCE UUID conventions.
+ *
+ * @author Maarten Coene
+ * @author Steve Viens (sviens@apache.org)
+ */
+public class DefaultUUIDGen implements UUIDGen
+{
+  private static final BigInteger COUNT_START = new BigInteger("-12219292800000");  // 15 October 1582
+  private static final int CLOCK_SEQUENCE = (new Random()).nextInt(16384);
+  
+  private Random random;
+
+  /**
+   *
+   */
+  public DefaultUUIDGen()
+  {
+    try {
+      random = new Random();
+      random.setSeed(System.currentTimeMillis());
+    } catch (Exception e) {
+      random = new Random();
+    }
+  }
+
+  /**
+   *
+   */
+  public String uuidgen()
+  {
+    return nextUUID();
+  }
+
+  /**
+   *
+   */
+  public String[] uuidgen(int nmbr)
+  {
+    String[] uuids = new String[nmbr];
+
+    for (int i=0; i<uuids.length; i++)
+      uuids[i] = nextUUID();
+
+    return uuids;
+  }
+
+  /**
+   * Creates a new UUID. The algorithm used is described by The Open Group.
+   * See <a href="http://www.opengroup.org/onlinepubs/009629399/apdxa.htm">
+   * Universal Unique Identifier</a> for more details.
+   *
+   * Due to a lack of functionality in Java, a part of the UUID is a secure
+   * random. This results in a long processing time when this method is called
+   * for the first time.
+   */
+  private String nextUUID()
+  {
+    // the number of milliseconds since 1 January 1970
+    BigInteger current = BigInteger.valueOf(System.currentTimeMillis());
+
+    // the number of milliseconds since 15 October 1582
+    BigInteger countMillis = current.subtract(COUNT_START);
+
+    // the count of 100-nanosecond intervals since 00:00:00.00 15 October 1582
+    BigInteger count = countMillis.multiply(BigInteger.valueOf(10000));
+
+    String bitString = count.toString(2);
+    if (bitString.length() < 60)
+    {
+      int nbExtraZeros  = 60 - bitString.length();
+      String extraZeros = new String();
+      for (int i=0; i<nbExtraZeros; i++)
+        extraZeros = extraZeros.concat("0");
+
+      bitString = extraZeros.concat(bitString);
+    }
+
+    byte[] bits = bitString.getBytes();
+
+    // the time_low field
+    byte[] time_low = new byte[32];
+    for (int i=0; i<32; i++)
+      time_low[i] = bits[bits.length - i - 1];
+
+    // the time_mid field
+    byte[] time_mid = new byte[16];
+    for (int i=0; i<16; i++)
+      time_mid[i] = bits[bits.length - 32 - i - 1];
+
+    // the time_hi_and_version field
+    byte[] time_hi_and_version = new byte[16];
+    for (int i=0; i<12; i++)
+      time_hi_and_version[i] = bits[bits.length - 48 - i - 1];
+
+    time_hi_and_version[12] = ((new String("1")).getBytes())[0];
+    time_hi_and_version[13] = ((new String("0")).getBytes())[0];
+    time_hi_and_version[14] = ((new String("0")).getBytes())[0];
+    time_hi_and_version[15] = ((new String("0")).getBytes())[0];
+
+    // the clock_seq_low field
+    BigInteger clockSequence = BigInteger.valueOf(CLOCK_SEQUENCE);
+    String clockString = clockSequence.toString(2);
+    if (clockString.length() < 14)
+    {
+      int nbExtraZeros  = 14 - bitString.length();
+      String extraZeros = new String();
+      for (int i=0; i<nbExtraZeros; i++)
+        extraZeros = extraZeros.concat("0");
+
+      clockString = extraZeros.concat(bitString);
+    }
+
+    byte[] clock_bits = clockString.getBytes();
+    byte[] clock_seq_low = new byte[8];
+    for (int i=0; i<8; i++)
+      clock_seq_low[i] = clock_bits[clock_bits.length - i - 1];
+
+    // the clock_seq_hi_and_reserved
+    byte[] clock_seq_hi_and_reserved = new byte[8];
+    for (int i=0; i<6; i++)
+      clock_seq_hi_and_reserved[i] = clock_bits[clock_bits.length - 8 - i - 1];
+
+    clock_seq_hi_and_reserved[6] = ((new String("0")).getBytes())[0];
+    clock_seq_hi_and_reserved[7] = ((new String("1")).getBytes())[0];
+
+    String timeLow = Long.toHexString((new BigInteger(new String(reverseArray(time_low)), 2)).longValue());
+    if (timeLow.length() < 8)
+    {
+      int nbExtraZeros = 8 - timeLow.length();
+      String extraZeros = new String();
+      for (int i=0; i<nbExtraZeros; i++)
+        extraZeros = extraZeros.concat("0");
+
+      timeLow = extraZeros.concat(timeLow);
+    }
+
+    String timeMid = Long.toHexString((new BigInteger(new String(reverseArray(time_mid)), 2)).longValue());
+    if (timeMid.length() < 4)
+    {
+      int nbExtraZeros = 4 - timeMid.length();
+      String extraZeros = new String();
+      for (int i=0; i<nbExtraZeros; i++)
+        extraZeros = extraZeros.concat("0");
+
+      timeMid = extraZeros.concat(timeMid);
+    }
+
+    String timeHiAndVersion = Long.toHexString((new BigInteger(new String(reverseArray(time_hi_and_version)), 2)).longValue());
+    if (timeHiAndVersion.length() < 4)
+    {
+      int nbExtraZeros = 4 - timeHiAndVersion.length();
+      String extraZeros = new String();
+      for (int i=0; i<nbExtraZeros; i++)
+        extraZeros = extraZeros.concat("0");
+
+      timeHiAndVersion = extraZeros.concat(timeHiAndVersion);
+    }
+
+    String clockSeqHiAndReserved = Long.toHexString((new BigInteger(new String(reverseArray(clock_seq_hi_and_reserved)), 2)).longValue());
+    if (clockSeqHiAndReserved.length() < 2)
+    {
+      int nbExtraZeros = 2 - clockSeqHiAndReserved.length();
+      String extraZeros = new String();
+      for (int i=0; i<nbExtraZeros; i++)
+        extraZeros = extraZeros.concat("0");
+
+      clockSeqHiAndReserved = extraZeros.concat(clockSeqHiAndReserved);
+    }
+
+    String clockSeqLow = Long.toHexString((new BigInteger(new String(reverseArray(clock_seq_low)), 2)).longValue());
+    if (clockSeqLow.length() < 2)
+    {
+      int nbExtraZeros = 2 - clockSeqLow.length();
+      String extraZeros = new String();
+      for (int i=0; i<nbExtraZeros; i++)
+        extraZeros = extraZeros.concat("0");
+
+      clockSeqLow = extraZeros.concat(clockSeqLow);
+    }
+
+    // problem: the node should be the IEEE 802 ethernet address, but can not
+    // be retrieved in Java yet.
+    // see bug ID 4173528
+    // workaround (also suggested in bug ID 4173528)
+    // If a system wants to generate UUIDs but has no IEE 802 compliant
+    // network card or other source of IEEE 802 addresses, then this section
+    // describes how to generate one.
+    // The ideal solution is to obtain a 47 bit cryptographic quality random
+    // number, and use it as the low 47 bits of the node ID, with the most
+    // significant bit of the first octet of the node ID set to 1. This bit
+    // is the unicast/multicast bit, which will never be set in IEEE 802
+    // addresses obtained from network cards; hence, there can never be a
+    // conflict between UUIDs generated by machines with and without network
+    // cards.
+
+    long nodeValue = random.nextLong();
+    nodeValue = Math.abs(nodeValue);
+    while (nodeValue > 140737488355328L)
+    {
+      nodeValue = random.nextLong();
+      nodeValue = Math.abs(nodeValue);
+    }
+
+    BigInteger nodeInt = BigInteger.valueOf(nodeValue);
+    String nodeString = nodeInt.toString(2);
+    if (nodeString.length() < 47)
+    {
+      int nbExtraZeros = 47 - nodeString.length();
+      String extraZeros = new String();
+      for (int i=0; i<nbExtraZeros; i++)
+        extraZeros = extraZeros.concat("0");
+
+      nodeString = extraZeros.concat(nodeString);
+    }
+
+    byte[] node_bits = nodeString.getBytes();
+    byte[] node = new byte[48];
+    for (int i=0; i<47; i++)
+      node[i] = node_bits[node_bits.length - i - 1];
+
+    node[47] = ((new String("1")).getBytes())[0];
+    String theNode = Long.toHexString((new BigInteger(new String(reverseArray(node)), 2)).longValue());
+    if (theNode.length() < 12)
+    {
+      int nbExtraZeros = 12 - theNode.length();
+      String extraZeros = new String();
+      for (int i=0; i<nbExtraZeros; i++)
+        extraZeros = extraZeros.concat("0");
+      theNode = extraZeros.concat(theNode);
+    }
+
+    String result = timeLow + "-" + timeMid +"-" + timeHiAndVersion + "-" + clockSeqHiAndReserved + clockSeqLow + "-" + theNode;
+
+    return result.toUpperCase();
+  }
+
+  /**
+   *
+   */
+  private static byte[] reverseArray(byte[] bits)
+  {
+    byte[] result = new byte[bits.length];
+    for (int i=0; i<result.length; i++)
+      result[i] = bits[result.length - 1 - i];
+
+    return result;
+  }
+
+
+  /***************************************************************************/
+  /***************************** TEST DRIVER *********************************/
+  /***************************************************************************/
+
+
+  public static void main(String args[])
+  {
+    DefaultUUIDGen generator = new DefaultUUIDGen();
+
+    long start = System.currentTimeMillis();
+
+    for (int i = 1; i <= 100; ++i)
+      generator.uuidgen();
+
+    long end = System.currentTimeMillis();
+
+    System.out.println("DefaultUUIDGen: Generation of 100 UUID's took "+(end-start)+" milliseconds.");
+  }
+}
\ No newline at end of file

Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/DefaultUUIDGen.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/NativeUUIDGen.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/NativeUUIDGen.java?rev=709604&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/NativeUUIDGen.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/NativeUUIDGen.java Fri Oct 31 16:54:22 2008
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * 
+ * 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 org.apache.juddi.uuidgen;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+import org.apache.juddi.config.AppConfig;
+import org.apache.juddi.config.Property;
+
+/**
+ * Used to create new universally unique identifiers or UUID's
+ * (sometimes called GUID's).  UDDI UUID's are allways formmated
+ * according to DCE UUID conventions.
+ * 
+ * @author Steve Viens (sviens@apache.org)
+ */
+public final class NativeUUIDGen implements UUIDGen
+{
+  private static final String DEFAULT_COMMAND = "uuidgen";
+  private String command = null;
+  
+  /**
+   *
+   */
+  public NativeUUIDGen()
+  {     
+      this.command = DEFAULT_COMMAND;  
+	  try { this.command = AppConfig.getConfiguration().getString(Property.JUDDI_UUID_COMMAND, DEFAULT_COMMAND); }
+	  catch(Exception e) {}
+  }
+  
+  /**
+   *
+   */
+  public String uuidgen()
+  {
+    try
+    {
+      Runtime r = Runtime.getRuntime();
+      Process p = r.exec(command);
+      BufferedReader x = new BufferedReader(
+                new InputStreamReader(p.getInputStream()));
+      
+      return x.readLine();
+    }    
+    catch (IOException e)
+    {      
+        e.printStackTrace();
+    }    
+    
+    return null;
+  }  
+  
+  /**
+   *
+   */
+  public String[] uuidgen(int nmbr) 
+  {    
+        String[] uuids = new String[nmbr];
+    for (int i=0; i<uuids.length; i++)
+      uuids[i] = uuidgen();    
+  
+    return uuids; 
+  }  
+        
+                
+  /***************************************************************************/
+  /***************************** TEST DRIVER *********************************/
+  /***************************************************************************/
+  
+        
+  public static void main(String args[])
+  {
+    UUIDGen generator = new NativeUUIDGen();
+    long start = System.currentTimeMillis();
+
+    for (int i = 1; i <= 100; ++i)
+        generator.uuidgen();
+
+    long end = System.currentTimeMillis();
+
+    System.out.println("\nNativeUUIDGen: Generation of 100 UUID's took " +
+                (end-start)+" milliseconds.");  
+  }
+}
\ No newline at end of file

Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/NativeUUIDGen.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/SecureUUIDGen.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/SecureUUIDGen.java?rev=709604&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/SecureUUIDGen.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/SecureUUIDGen.java Fri Oct 31 16:54:22 2008
@@ -0,0 +1,271 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * 
+ * 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 org.apache.juddi.uuidgen;
+
+import java.math.BigInteger;
+import java.security.SecureRandom;
+import java.util.Random;
+
+/**
+ * Used to create new universally unique identifiers or UUID's (sometimes called
+ * GUID's).  UDDI UUID's are allways formmated according to DCE UUID conventions.
+ *
+ * @author Maarten Coene
+ * @author Steve Viens (sviens@apache.org)
+ */
+public class SecureUUIDGen implements UUIDGen
+{
+  private static final BigInteger COUNT_START = new BigInteger("-12219292800000");  // 15 October 1582
+  private static final int CLOCK_SEQUENCE = (new Random()).nextInt(16384);
+
+  /**
+   *
+   */
+  public String uuidgen()
+  {
+    return nextUUID();
+  }
+
+  /**
+   *
+   */
+  public String[] uuidgen(int nmbr)
+  {
+    String[] uuids = new String[nmbr];
+
+    for (int i=0; i<uuids.length; i++)
+      uuids[i] = nextUUID();
+
+    return uuids;
+  }
+
+  /**
+   * Creates a new UUID. The algorithm used is described by The Open Group.
+   * See <a href="http://www.opengroup.org/onlinepubs/009629399/apdxa.htm">
+   * Universal Unique Identifier</a> for more details.
+   * <p>
+   * Due to a lack of functionality in Java, a part of the UUID is a secure
+   * random. This results in a long processing time when this method is called
+   * for the first time.
+   */
+  protected String nextUUID()
+  {
+      // the count of 100-nanosecond intervals since 00:00:00.00 15 October 1582
+      BigInteger count;
+
+      // the number of milliseconds since 1 January 1970
+      BigInteger current = BigInteger.valueOf(System.currentTimeMillis());
+
+      // the number of milliseconds since 15 October 1582
+      BigInteger countMillis = current.subtract(COUNT_START);
+
+      // the result
+      count = countMillis.multiply(BigInteger.valueOf(10000));
+
+      String bitString = count.toString(2);
+      if (bitString.length() < 60) {
+          int nbExtraZeros = 60 - bitString.length();
+          String extraZeros = new String();
+          for (int i = 0; i < nbExtraZeros; i++)
+              extraZeros = extraZeros.concat("0");
+
+          bitString = extraZeros.concat(bitString);
+      }
+
+      byte[] bits = bitString.getBytes();
+
+      // the time_low field
+      byte[] time_low = new byte[32];
+      for (int i = 0; i < 32; i++)
+          time_low[i] = bits[bits.length - i - 1];
+
+      // the time_mid field
+      byte[] time_mid = new byte[16];
+      for (int i = 0; i < 16; i++)
+          time_mid[i] = bits[bits.length - 32 - i - 1];
+
+      // the time_hi_and_version field
+      byte[] time_hi_and_version = new byte[16];
+      for (int i = 0; i < 12; i++)
+          time_hi_and_version[i] = bits[bits.length - 48 - i - 1];
+
+      time_hi_and_version[12] = ((new String("1")).getBytes())[0];
+      time_hi_and_version[13] = ((new String("0")).getBytes())[0];
+      time_hi_and_version[14] = ((new String("0")).getBytes())[0];
+      time_hi_and_version[15] = ((new String("0")).getBytes())[0];
+
+      // the clock_seq_low field
+      BigInteger clockSequence = BigInteger.valueOf(CLOCK_SEQUENCE);
+      String clockString = clockSequence.toString(2);
+      if (clockString.length() < 14) {
+          int nbExtraZeros = 14 - bitString.length();
+          String extraZeros = new String();
+          for (int i = 0; i < nbExtraZeros; i++)
+              extraZeros = extraZeros.concat("0");
+
+          clockString = extraZeros.concat(bitString);
+      }
+
+      byte[] clock_bits = clockString.getBytes();
+      byte[] clock_seq_low = new byte[8];
+      for (int i = 0; i < 8; i++)
+          clock_seq_low[i] = clock_bits[clock_bits.length - i - 1];
+
+      // the clock_seq_hi_and_reserved
+      byte[] clock_seq_hi_and_reserved = new byte[8];
+      for (int i = 0; i < 6; i++)
+          clock_seq_hi_and_reserved[i] = clock_bits[clock_bits.length - 8 - i - 1];
+
+      clock_seq_hi_and_reserved[6] = ((new String("0")).getBytes())[0];
+      clock_seq_hi_and_reserved[7] = ((new String("1")).getBytes())[0];
+
+      String timeLow = Long.toHexString((new BigInteger(new String(reverseArray(time_low)), 2)).longValue());
+      if (timeLow.length() < 8) {
+          int nbExtraZeros = 8 - timeLow.length();
+          String extraZeros = new String();
+          for (int i = 0; i < nbExtraZeros; i++)
+              extraZeros = extraZeros.concat("0");
+
+          timeLow = extraZeros.concat(timeLow);
+      }
+
+      String timeMid = Long.toHexString((new BigInteger(new String(reverseArray(time_mid)), 2)).longValue());
+      if (timeMid.length() < 4) {
+          int nbExtraZeros = 4 - timeMid.length();
+          String extraZeros = new String();
+          for (int i = 0; i < nbExtraZeros; i++)
+              extraZeros = extraZeros.concat("0");
+          timeMid = extraZeros.concat(timeMid);
+      }
+
+      String timeHiAndVersion = Long.toHexString((new BigInteger(new String(reverseArray(time_hi_and_version)), 2)).longValue());
+      if (timeHiAndVersion.length() < 4) {
+          int nbExtraZeros = 4 - timeHiAndVersion.length();
+          String extraZeros = new String();
+          for (int i = 0; i < nbExtraZeros; i++)
+              extraZeros = extraZeros.concat("0");
+
+          timeHiAndVersion = extraZeros.concat(timeHiAndVersion);
+      }
+
+      String clockSeqHiAndReserved = Long.toHexString((new BigInteger(new String(reverseArray(clock_seq_hi_and_reserved)), 2)).longValue());
+      if (clockSeqHiAndReserved.length() < 2) {
+          int nbExtraZeros = 2 - clockSeqHiAndReserved.length();
+          String extraZeros = new String();
+          for (int i = 0; i < nbExtraZeros; i++)
+              extraZeros = extraZeros.concat("0");
+
+          clockSeqHiAndReserved = extraZeros.concat(clockSeqHiAndReserved);
+      }
+
+      String clockSeqLow = Long.toHexString((new BigInteger(new String(reverseArray(clock_seq_low)), 2)).longValue());
+      if (clockSeqLow.length() < 2) {
+          int nbExtraZeros = 2 - clockSeqLow.length();
+          String extraZeros = new String();
+          for (int i = 0; i < nbExtraZeros; i++)
+              extraZeros = extraZeros.concat("0");
+
+          clockSeqLow = extraZeros.concat(clockSeqLow);
+      }
+
+      // problem: the node should be the IEEE 802 ethernet address, but can not
+      // be retrieved in Java yet.
+      // see bug ID 4173528
+      // workaround (also suggested in bug ID 4173528)
+      // If a system wants to generate UUIDs but has no IEE 802 compliant
+      // network card or other source of IEEE 802 addresses, then this section
+      // describes how to generate one.
+      // The ideal solution is to obtain a 47 bit cryptographic quality random
+      // number, and use it as the low 47 bits of the node ID, with the most
+      // significant bit of the first octet of the node ID set to 1. This bit
+      // is the unicast/multicast bit, which will never be set in IEEE 802
+      // addresses obtained from network cards; hence, there can never be a
+      // conflict between UUIDs generated by machines with and without network
+      // cards.
+      Random secureRandom = null;
+      try {
+          secureRandom = SecureRandom.getInstance("SHA1PRNG", "SUN");
+      } catch (Exception e) {
+          secureRandom = new Random();
+      }
+
+      long nodeValue = secureRandom.nextLong();
+      nodeValue = Math.abs(nodeValue);
+      while (nodeValue > 140737488355328L) {
+          nodeValue = secureRandom.nextLong();
+          nodeValue = Math.abs(nodeValue);
+      }
+
+      BigInteger nodeInt = BigInteger.valueOf(nodeValue);
+      String nodeString = nodeInt.toString(2);
+      if (nodeString.length() < 47) {
+          int nbExtraZeros = 47 - nodeString.length();
+          String extraZeros = new String();
+          for (int i = 0; i < nbExtraZeros; i++)
+              extraZeros = extraZeros.concat("0");
+
+          nodeString = extraZeros.concat(nodeString);
+      }
+
+      byte[] node_bits = nodeString.getBytes();
+      byte[] node = new byte[48];
+      for (int i = 0; i < 47; i++)
+          node[i] = node_bits[node_bits.length - i - 1];
+
+      node[47] = ((new String("1")).getBytes())[0];
+      String theNode = Long.toHexString((new BigInteger(new String(reverseArray(node)), 2)).longValue());
+      if (theNode.length() < 12) {
+          int nbExtraZeros = 12 - theNode.length();
+          String extraZeros = new String();
+          for (int i = 0; i < nbExtraZeros; i++)
+              extraZeros = extraZeros.concat("0");
+          theNode = extraZeros.concat(theNode);
+      }
+
+      String result = timeLow + "-" + timeMid + "-" + timeHiAndVersion + "-" + clockSeqHiAndReserved + clockSeqLow + "-" + theNode;
+
+      return result.toUpperCase();
+  }
+
+  private static byte[] reverseArray(byte[] bits)
+  {
+    byte[] result = new byte[bits.length];
+    for (int i = 0; i < result.length; i++)
+      result[i] = bits[result.length - 1 - i];
+
+    return result;
+  }
+
+
+  /***************************************************************************/
+  /***************************** TEST DRIVER *********************************/
+  /***************************************************************************/
+
+
+  public static void main(String args[])
+  {
+    SecureUUIDGen generator = new SecureUUIDGen();
+
+    long start = System.currentTimeMillis();
+
+    for (int i = 1; i <= 100; ++i)
+      generator.uuidgen();
+
+    long end = System.currentTimeMillis();
+
+    System.out.println("SecureUUIDGen: Generation of 100 UUID's took "+(end-start)+" milliseconds.");
+  }
+}

Propchange: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/SecureUUIDGen.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/UUIDGen.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/UUIDGen.java?rev=709604&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/UUIDGen.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/uuidgen/UUIDGen.java Fri Oct 31 16:54:22 2008
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ * 
+ * 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 org.apache.juddi.uuidgen;
+
+/**
+ * A Universally Unique Identifier (UUID) is a 128 bit number generated
+ * according to an algorithm that is garanteed to be unique in time and space 
+ * from all other UUIDs. It consists of an IEEE 802 Internet Address and 
+ * various time stamps to ensure uniqueness. For a complete specification, 
+ * see ftp://ietf.org/internet-drafts/draft-leach-uuids-guids-01.txt [leach].
+ *  
+ * @author Steve Viens (sviens@apache.org) 
+ */
+public interface UUIDGen
+{  
+  /**
+   * Generates a UUID and returns it's value as a String
+   * @return The new UUID value as a String
+   */
+  String uuidgen(); 
+  
+  /**
+   * Generates a collection of UUID's and returns thier 
+   * values as an array of Strings 
+   * @param nmbr The number of UUID's to generate
+   * @return An array of UUID's as String objects
+   */
+  String[] uuidgen(int nmbr);
+}
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: juddi-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: juddi-cvs-help@ws.apache.org