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/05 23:46:39 UTC

svn commit: r711730 - in /webservices/juddi/branches/v3_trunk/juddi-core/src: main/java/org/apache/juddi/api/impl/ main/java/org/apache/juddi/error/ main/java/org/apache/juddi/model/ main/java/org/apache/juddi/validation/ main/resources/ test/java/org/...

Author: jfaath
Date: Wed Nov  5 14:46:39 2008
New Revision: 711730

URL: http://svn.apache.org/viewvc?rev=711730&view=rev
Log:
Added authentication and ownership checks to the necessary api calls.

Added:
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/AuthenticatedService.java   (with props)
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/UddiEntityPublisher.java   (with props)
    webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/publisher1.xml
Removed:
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/validation/ValidateAuth.java
Modified:
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/UDDIInquiryImpl.java
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/UDDIPublicationImpl.java
    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/error/ErrorMessage.java
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/BindingTemplate.java
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/BusinessEntity.java
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/BusinessService.java
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/Publisher.java
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/Tmodel.java
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/UddiEntity.java
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/validation/ValidatePublish.java
    webservices/juddi/branches/v3_trunk/juddi-core/src/main/resources/messages_en.properties
    webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/BusinessEntityTest.java
    webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/BusinessServiceTest.java
    webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/PublisherTest.java
    webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/UDDIApiTestHelper.java
    webservices/juddi/branches/v3_trunk/juddi-core/src/test/resources/suite-one.xml

Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/AuthenticatedService.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/AuthenticatedService.java?rev=711730&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/AuthenticatedService.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/AuthenticatedService.java Wed Nov  5 14:46:39 2008
@@ -0,0 +1,62 @@
+/*
+ * 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.api.impl;
+
+import java.util.Date;
+
+import javax.persistence.EntityManager;
+
+import org.apache.juddi.error.AuthTokenRequiredException;
+import org.apache.juddi.error.ErrorMessage;
+import org.apache.juddi.model.Publisher;
+import org.apache.juddi.model.UddiEntityPublisher;
+import org.uddi.v3_service.DispositionReportFaultMessage;
+
+/**
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+public abstract class AuthenticatedService {
+	public static final int AUTHTOKEN_ACTIVE = 1;
+	public static final int AUTHTOKEN_RETIRED = 0;
+	
+	public UddiEntityPublisher getEntityPublisher(EntityManager em, String authInfo) throws DispositionReportFaultMessage {
+		
+		if (authInfo == null || authInfo.length() == 0)
+			throw new AuthTokenRequiredException(new ErrorMessage("errors.auth.AuthRequired"));
+		
+		org.apache.juddi.model.AuthToken modelAuthToken = em.find(org.apache.juddi.model.AuthToken.class, authInfo);
+		if (modelAuthToken == null)
+			throw new AuthTokenRequiredException(new ErrorMessage("errors.auth.AuthInvalid"));
+		
+		if (modelAuthToken.getTokenState() == AUTHTOKEN_RETIRED)
+			throw new AuthTokenRequiredException(new ErrorMessage("errors.auth.AuthInvalid"));
+		
+		UddiEntityPublisher entityPublisher = em.find(Publisher.class, modelAuthToken.getPublisherId());
+		if (entityPublisher == null)
+			throw new AuthTokenRequiredException(new ErrorMessage("errors.auth.AuthInvalid"));
+		
+		// Auth token is being used.  Adjust appropriate values so that it's internal 'expiration clock' is reset.
+		modelAuthToken.setLastUsed(new Date());
+		modelAuthToken.setNumberOfUses(modelAuthToken.getNumberOfUses() + 1);
+		
+		return entityPublisher;
+			
+				   
+	}
+
+}

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

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/UDDIInquiryImpl.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/UDDIInquiryImpl.java?rev=711730&r1=711729&r2=711730&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/UDDIInquiryImpl.java (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/UDDIInquiryImpl.java Wed Nov  5 14:46:39 2008
@@ -395,6 +395,10 @@
 		return result;
 	}
 
+	/*-------------------------------------------------------------------
+	 Publisher functions are specific to jUDDI.
+	 --------------------------------------------------------------------*/
+	
 	/*
 	 * Retrieves publisher(s) from the persistence layer.  This method is specific to jUDDI.
 	 */

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/UDDIPublicationImpl.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/UDDIPublicationImpl.java?rev=711730&r1=711729&r2=711730&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/UDDIPublicationImpl.java (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/api/impl/UDDIPublicationImpl.java Wed Nov  5 14:46:39 2008
@@ -51,7 +51,9 @@
 import org.apache.juddi.util.JPAUtil;
 import org.apache.juddi.validation.ValidatePublish;
 import org.apache.juddi.query.PersistenceManager;
+import org.apache.juddi.model.UddiEntityPublisher;
 
+import org.apache.juddi.model.Publisher;
 import org.apache.juddi.api.datatype.PublisherDetail;
 import org.apache.juddi.api.datatype.SavePublisher;
 import org.apache.juddi.api.datatype.DeletePublisher;
@@ -61,7 +63,7 @@
  */
 @WebService(serviceName="UDDIPublicationService", 
 			endpointInterface="org.uddi.v3_service.UDDIPublicationPortType")
-public class UDDIPublicationImpl implements UDDIPublicationPortType {
+public class UDDIPublicationImpl extends AuthenticatedService implements UDDIPublicationPortType {
 
 	
 	public void addPublisherAssertions(AddPublisherAssertions body)
@@ -92,10 +94,9 @@
 		EntityTransaction tx = em.getTransaction();
 		tx.begin();
 
-		ValidatePublish.validateDeleteBinding(em, body);
-
-		// TODO: Perform necessary authentication logic
-		String authInfo = body.getAuthInfo();
+		UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo());
+		
+		ValidatePublish.validateDeleteBinding(em, publisher, body);
 		
 		List<String> entityKeyList = body.getBindingKey();
 		for (String entityKey : entityKeyList) {
@@ -114,11 +115,10 @@
 		EntityTransaction tx = em.getTransaction();
 		tx.begin();
 
-		ValidatePublish.validateDeleteBusiness(em, body);
-		
-		// TODO: Perform necessary authentication logic
-		String authInfo = body.getAuthInfo();
+		UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo());
 
+		ValidatePublish.validateDeleteBusiness(em, publisher, body);
+		
 		List<String> entityKeyList = body.getBusinessKey();
 		for (String entityKey : entityKeyList) {
 			Object obj = em.find(org.apache.juddi.model.BusinessEntity.class, entityKey);
@@ -136,11 +136,10 @@
 		EntityTransaction tx = em.getTransaction();
 		tx.begin();
 
+		UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo());
+
 		ValidatePublish.validateDeletePublisherAssertions(em, body);
 		
-		// TODO: Perform necessary authentication logic
-		String authInfo = body.getAuthInfo();
-
 		List<org.uddi.api_v3.PublisherAssertion> entityList = body.getPublisherAssertion();
 		for (org.uddi.api_v3.PublisherAssertion entity : entityList) {
 			org.apache.juddi.model.PublisherAssertionId pubAssertionId = new org.apache.juddi.model.PublisherAssertionId(entity.getFromKey(), entity.getToKey());
@@ -159,11 +158,10 @@
 		EntityTransaction tx = em.getTransaction();
 		tx.begin();
 
-		ValidatePublish.validateDeleteService(em, body);
+		UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo());
+		
+		ValidatePublish.validateDeleteService(em, publisher, body);
 		
-		// TODO: Perform necessary authentication logic
-		String authInfo = body.getAuthInfo();
-
 		List<String> entityKeyList = body.getServiceKey();
 		for (String entityKey : entityKeyList) {
 			Object obj = em.find(org.apache.juddi.model.BusinessService.class, entityKey);
@@ -182,10 +180,9 @@
 		EntityTransaction tx = em.getTransaction();
 		tx.begin();
 
-		ValidatePublish.validateDeleteTModel(em, body);
-		
-		// TODO: Perform necessary authentication logic
-		String authInfo = body.getAuthInfo();
+		UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo());
+
+		ValidatePublish.validateDeleteTModel(em, publisher, body);
 
 		// tModels are only lazily deleted!
 		List<String> entityKeyList = body.getTModelKey();
@@ -228,11 +225,10 @@
 		EntityTransaction tx = em.getTransaction();
 		tx.begin();
 		
-		ValidatePublish.validateSaveBinding(em, body);
-
-		// TODO: Perform necessary authentication logic
-		String authInfo = body.getAuthInfo();
+		UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo());
 		
+		ValidatePublish.validateSaveBinding(em, publisher, body);
+
 		BindingDetail result = new BindingDetail();
 		
 		List<org.uddi.api_v3.BindingTemplate> apiBindingTemplateList = body.getBindingTemplate();
@@ -248,6 +244,7 @@
 			if (existingUddiEntity != null)
 				em.remove(existingUddiEntity);
 			
+			modelBindingTemplate.assignPublisherId(publisher.getPublisherId());
 			em.persist(modelBindingTemplate);
 			
 			result.getBindingTemplate().add(apiBindingTemplate);
@@ -267,11 +264,10 @@
 		EntityTransaction tx = em.getTransaction();
 		tx.begin();
 		
-		ValidatePublish.validateSaveBusiness(em, body);
-		
-		// TODO: Perform necessary authentication logic
-		String authInfo = body.getAuthInfo();
+		UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo());
 		
+		ValidatePublish.validateSaveBusiness(em, publisher, body);
+
 		BusinessDetail result = new BusinessDetail();
 		
 		List<org.uddi.api_v3.BusinessEntity> apiBusinessEntityList = body.getBusinessEntity();
@@ -285,6 +281,7 @@
 			if (existingUddiEntity != null)
 				em.remove(existingUddiEntity);
 			
+			modelBusinessEntity.assignPublisherId(publisher.getPublisherId());
 			em.persist(modelBusinessEntity);
 
 			result.getBusinessEntity().add(apiBusinessEntity);
@@ -303,12 +300,11 @@
 		EntityManager em = PersistenceManager.getEntityManager();
 		EntityTransaction tx = em.getTransaction();
 		tx.begin();
+
+		UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo());
 		
-		ValidatePublish.validateSaveService(em, body);
+		ValidatePublish.validateSaveService(em, publisher, body);
 		
-		// TODO: Perform necessary authentication logic
-		String authInfo = body.getAuthInfo();
-
 		ServiceDetail result = new ServiceDetail();
 
 		List<org.uddi.api_v3.BusinessService> apiBusinessServiceList = body.getBusinessService();
@@ -324,6 +320,7 @@
 			if (existingUddiEntity != null)
 				em.remove(existingUddiEntity);
 			
+			modelBusinessService.assignPublisherId(publisher.getPublisherId());
 			em.persist(modelBusinessService);
 			
 			result.getBusinessService().add(apiBusinessService);
@@ -343,10 +340,9 @@
 		EntityTransaction tx = em.getTransaction();
 		tx.begin();
 
-		ValidatePublish.validateSaveTModel(em, body);
-		
-		// TODO: Perform necessary authentication logic
-		String authInfo = body.getAuthInfo();
+		UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo());
+
+		ValidatePublish.validateSaveTModel(em, publisher, body);
 
 		TModelDetail result = new TModelDetail();
 
@@ -361,6 +357,7 @@
 			if (existingUddiEntity != null)
 				em.remove(existingUddiEntity);
 			
+			modelTModel.assignPublisherId(publisher.getPublisherId());
 			em.persist(modelTModel);
 			
 			result.getTModel().add(apiTModel);
@@ -381,6 +378,10 @@
 	}
 
 	
+	/*-------------------------------------------------------------------
+	 Publisher functions are specific to jUDDI.
+	 --------------------------------------------------------------------*/
+	
 	/*
 	 * Saves publisher(s) to the persistence layer.  This method is specific to jUDDI.
 	 */
@@ -391,11 +392,10 @@
 		EntityTransaction tx = em.getTransaction();
 		tx.begin();
 
-		ValidatePublish.validateSavePublisher(em, body);
+		UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo());
+		
+		ValidatePublish.validateSavePublisher(em, (Publisher)publisher, body);
 		
-		// TODO: Perform necessary authentication logic
-		String authInfo = body.getAuthInfo();
-
 		PublisherDetail result = new PublisherDetail();
 
 		List<org.apache.juddi.api.datatype.Publisher> apiPublisherList = body.getPublisher();
@@ -430,11 +430,10 @@
 		EntityTransaction tx = em.getTransaction();
 		tx.begin();
 
-		ValidatePublish.validateDeletePublisher(em, body);
-
-		// TODO: Perform necessary authentication logic
-		String authInfo = body.getAuthInfo();
+		UddiEntityPublisher publisher = this.getEntityPublisher(em, body.getAuthInfo());
 		
+		ValidatePublish.validateDeletePublisher(em, (Publisher)publisher, body);
+
 		List<String> entityKeyList = body.getPublisherId();
 		for (String entityKey : entityKeyList) {
 			Object obj = em.find(org.apache.juddi.model.Publisher.class, entityKey);

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=711730&r1=711729&r2=711730&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 Wed Nov  5 14:46:39 2008
@@ -32,11 +32,9 @@
 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;
 import org.apache.juddi.query.PersistenceManager;
 
@@ -45,7 +43,7 @@
  */
 @WebService(serviceName="UDDISecurityService", 
 			endpointInterface="org.uddi.v3_service.UDDISecurityPortType")
-public class UDDISecurityImpl implements UDDISecurityPortType {
+public class UDDISecurityImpl extends AuthenticatedService implements UDDISecurityPortType {
 
 	public static final String AUTH_TOKEN_PREFIX = "authtoken:";
 
@@ -56,13 +54,13 @@
 		EntityTransaction tx = em.getTransaction();
 		tx.begin();
 		
-		ValidateAuth.getPublisher(em, body.getAuthInfo());
+		this.getEntityPublisher(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);
+			modelAuthToken.setTokenState(AUTHTOKEN_RETIRED);
 		}
 
 		tx.commit();
@@ -100,7 +98,7 @@
 			modelAuthToken.setPublisherId(publisherId);
 			modelAuthToken.setPublisherName(publisher.getPublisherName());
 			modelAuthToken.setNumberOfUses(0);
-			modelAuthToken.setTokenState(ValidateAuth.AUTHTOKEN_ACTIVE);
+			modelAuthToken.setTokenState(AUTHTOKEN_ACTIVE);
 			
 			em.persist(modelAuthToken);
 		}

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/error/ErrorMessage.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/error/ErrorMessage.java?rev=711730&r1=711729&r2=711730&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/error/ErrorMessage.java (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/error/ErrorMessage.java Wed Nov  5 14:46:39 2008
@@ -52,6 +52,10 @@
 	}
 	
 	public String toString() {
-		return message + ":  " + value;
+		if (value == null || value.length() == 0)
+			return message;
+		else
+			return message + ":  " + value;
+			
 	}
 }

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/BindingTemplate.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/BindingTemplate.java?rev=711730&r1=711729&r2=711730&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/BindingTemplate.java (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/BindingTemplate.java Wed Nov  5 14:46:39 2008
@@ -31,6 +31,7 @@
 
 /**
  * @author <a href="mailto:kurt@apache.org">Kurt T Stam</a>
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
  */
 @Entity
 @Table(name = "binding_template")
@@ -137,4 +138,11 @@
 		this.bindingDescrs = bindingDescrs;
 	}
 
+	public String retrievePublisherId() {
+		return this.getBusinessService().getBusinessEntity().getPublisherId();
+	}
+	public void assignPublisherId(String id) {
+		// Do nothing, the publisher id is set in the parent.
+	}
+
 }

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/BusinessEntity.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/BusinessEntity.java?rev=711730&r1=711729&r2=711730&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/BusinessEntity.java (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/BusinessEntity.java Wed Nov  5 14:46:39 2008
@@ -30,6 +30,7 @@
 
 /**
  * @author <a href="mailto:kurt@apache.org">Kurt T Stam</a>
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
  */
 @Entity
 @Table(name = "business_entity")
@@ -200,4 +201,12 @@
 		this.businessDescrs = businessDescrs;
 	}
 
+	public String retrievePublisherId() {
+		return this.publisherId;
+	}
+	public void assignPublisherId(String id) {
+		if (id != null)
+			this.publisherId = id;
+	}
+	
 }

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/BusinessService.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/BusinessService.java?rev=711730&r1=711729&r2=711730&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/BusinessService.java (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/BusinessService.java Wed Nov  5 14:46:39 2008
@@ -31,6 +31,7 @@
 
 /**
  * @author <a href="mailto:kurt@apache.org">Kurt T Stam</a>
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
  */
 @Entity
 @Table(name = "business_service")
@@ -115,4 +116,11 @@
 		this.serviceCategories = serviceCategories;
 	}
 
+	public String retrievePublisherId() {
+		return this.getBusinessEntity().getPublisherId();
+	}
+	public void assignPublisherId(String id) {
+		// Do nothing, the publisher id is set in the parent.
+	}
+
 }

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/Publisher.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/Publisher.java?rev=711730&r1=711729&r2=711730&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/Publisher.java (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/Publisher.java Wed Nov  5 14:46:39 2008
@@ -17,19 +17,18 @@
 
 import javax.persistence.Column;
 import javax.persistence.Entity;
-import javax.persistence.Id;
 import javax.persistence.Table;
 import javax.persistence.Transient;
 
 /**
  * @author <a href="mailto:kurt@apache.org">Kurt T Stam</a>
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
  */
 @Entity
 @Table(name = "publisher")
-public class Publisher implements java.io.Serializable {
+public class Publisher extends UddiEntityPublisher implements java.io.Serializable {
 
 	private static final long serialVersionUID = 1L;
-	private String publisherId;
 	private String publisherName;
 	private String emailAddress;
 	private String isAdmin;
@@ -61,15 +60,6 @@
 		this.maxTmodels = maxTmodels;
 	}
 
-	@Id
-	@Column(name = "publisher_id", nullable = false, length = 20)
-	public String getPublisherId() {
-		return this.publisherId;
-	}
-
-	public void setPublisherId(String publisherId) {
-		this.publisherId = publisherId;
-	}
 
 	@Column(name = "publisher_name", nullable = false)
 

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/Tmodel.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/Tmodel.java?rev=711730&r1=711729&r2=711730&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/Tmodel.java (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/Tmodel.java Wed Nov  5 14:46:39 2008
@@ -29,6 +29,7 @@
 
 /**
  * @author <a href="mailto:kurt@apache.org">Kurt T Stam</a>
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
  */
 @Entity
 @Table(name = "tmodel")
@@ -165,4 +166,12 @@
 		this.tmodelCategories = tmodelCategories;
 	}
 
+	public String retrievePublisherId() {
+		return this.publisherId;
+	}
+	public void assignPublisherId(String id) {
+		if (id != null)
+			this.publisherId = id;
+	}
+
 }

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/UddiEntity.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/UddiEntity.java?rev=711730&r1=711729&r2=711730&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/UddiEntity.java (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/UddiEntity.java Wed Nov  5 14:46:39 2008
@@ -39,5 +39,7 @@
 		this.lastUpdate = lastUpdate;
 	}
 
+	public abstract String retrievePublisherId();
+	public abstract void assignPublisherId(String id);
 
 }

Added: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/UddiEntityPublisher.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/UddiEntityPublisher.java?rev=711730&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/UddiEntityPublisher.java (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/model/UddiEntityPublisher.java Wed Nov  5 14:46:39 2008
@@ -0,0 +1,51 @@
+/*
+ * 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.model;
+
+import javax.persistence.Column;
+import javax.persistence.Id;
+import javax.persistence.MappedSuperclass;
+
+/**
+ * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
+ */
+@MappedSuperclass
+public abstract class UddiEntityPublisher {
+
+	protected String publisherId;
+
+	@Id
+	@Column(name = "publisher_id", nullable = false, length = 20)
+	public String getPublisherId() {
+		return this.publisherId;
+	}
+
+	public void setPublisherId(String publisherId) {
+		this.publisherId = publisherId;
+	}
+	
+	
+	public boolean isOwner(UddiEntity entity){
+		boolean ret = false;
+		if (entity != null) {
+			if (entity.retrievePublisherId().equals(this.publisherId))
+				ret = true;
+		}
+		return ret;
+	}
+}

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

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/validation/ValidatePublish.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/validation/ValidatePublish.java?rev=711730&r1=711729&r2=711730&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/validation/ValidatePublish.java (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/java/org/apache/juddi/validation/ValidatePublish.java Wed Nov  5 14:46:39 2008
@@ -36,6 +36,9 @@
 import org.apache.juddi.api.datatype.SavePublisher;
 import org.apache.juddi.api.datatype.DeletePublisher;
 
+import org.apache.juddi.model.UddiEntityPublisher;
+import org.apache.juddi.model.Publisher;
+import org.apache.juddi.model.UddiEntity;
 import org.apache.juddi.error.ErrorMessage;
 import org.apache.juddi.error.FatalErrorException;
 import org.apache.juddi.error.InvalidKeyPassedException;
@@ -43,6 +46,7 @@
 import org.apache.juddi.error.KeyUnavailableException;
 import org.apache.juddi.error.ValueNotAllowedException;
 import org.apache.juddi.error.InvalidProjectionException;
+import org.apache.juddi.error.UserMismatchException;
 
 
 /**
@@ -50,31 +54,7 @@
  */
 public class ValidatePublish {
 
-	public static void validateDeletePublisher(EntityManager em, DeletePublisher body) throws DispositionReportFaultMessage {
-
-		// No null input
-		if (body == null)
-			throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
-		
-		// No null or empty list
-		List<String> entityKeyList = body.getPublisherId();
-		if (entityKeyList == null || entityKeyList.size() == 0)
-			throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.NoKeys"));
-
-		HashSet<String> dupCheck = new HashSet<String>();
-		for (String entityKey : entityKeyList) {
-			boolean inserted = dupCheck.add(entityKey);
-			if (!inserted)
-				throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.DuplicateKey", entityKey));
-			
-			Object obj = em.find(org.apache.juddi.model.Publisher.class, entityKey);
-			if (obj == null)
-				throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.PublisherNotFound", entityKey));
-			
-		}
-	}
-
-	public static void validateDeleteBusiness(EntityManager em, DeleteBusiness body) throws DispositionReportFaultMessage {
+	public static void validateDeleteBusiness(EntityManager em, UddiEntityPublisher publisher, DeleteBusiness body) throws DispositionReportFaultMessage {
 
 		// No null input
 		if (body == null)
@@ -95,10 +75,13 @@
 			if (obj == null)
 				throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.BusinessNotFound", entityKey));
 			
+			if (!publisher.isOwner((UddiEntity)obj))
+				throw new UserMismatchException(new ErrorMessage("errors.usermismatch.InvalidOwner", entityKey));
+			
 		}
 	}
 
-	public static void validateDeleteService(EntityManager em, DeleteService body) throws DispositionReportFaultMessage {
+	public static void validateDeleteService(EntityManager em, UddiEntityPublisher publisher, DeleteService body) throws DispositionReportFaultMessage {
 
 		// No null input
 		if (body == null)
@@ -119,10 +102,13 @@
 			if (obj == null)
 				throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.ServiceNotFound", entityKey));
 			
+			if (!publisher.isOwner((UddiEntity)obj))
+				throw new UserMismatchException(new ErrorMessage("errors.usermismatch.InvalidOwner", entityKey));
+			
 		}
 	}
 
-	public static void validateDeleteBinding(EntityManager em, DeleteBinding body) throws DispositionReportFaultMessage {
+	public static void validateDeleteBinding(EntityManager em, UddiEntityPublisher publisher, DeleteBinding body) throws DispositionReportFaultMessage {
 
 		// No null input
 		if (body == null)
@@ -144,10 +130,13 @@
 			if (obj == null)
 				throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.BindingNotFound", entityKey));
 			
+			if (!publisher.isOwner((UddiEntity)obj))
+				throw new UserMismatchException(new ErrorMessage("errors.usermismatch.InvalidOwner", entityKey));
+
 		}
 	}
 	
-	public static void validateDeleteTModel(EntityManager em, DeleteTModel body) throws DispositionReportFaultMessage {
+	public static void validateDeleteTModel(EntityManager em, UddiEntityPublisher publisher, DeleteTModel body) throws DispositionReportFaultMessage {
 
 		// No null input
 		if (body == null)
@@ -168,6 +157,8 @@
 			if (obj == null)
 				throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.TModelNotFound", entityKey));
 			
+			if (!publisher.isOwner((UddiEntity)obj))
+				throw new UserMismatchException(new ErrorMessage("errors.usermismatch.InvalidOwner", entityKey));
 		}
 	}
 
@@ -193,26 +184,8 @@
 		}
 	}
 
-	public static void validateSavePublisher(EntityManager em, SavePublisher body) throws DispositionReportFaultMessage {
-
-		// No null input
-		if (body == null)
-			throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
-		
-		// No null or empty list
-		List<org.apache.juddi.api.datatype.Publisher> entityList = body.getPublisher();
-		if (entityList == null || entityList.size() == 0)
-			throw new ValueNotAllowedException(new ErrorMessage("errors.savepublisher.NoInput"));
-		
-		// TODO: only an admin can save a publisher
-		
-		for (org.apache.juddi.api.datatype.Publisher entity : entityList) {
-			validatePublisher(em, entity);
-		}
-	}
-	
 	
-	public static void validateSaveBusiness(EntityManager em, SaveBusiness body) throws DispositionReportFaultMessage {
+	public static void validateSaveBusiness(EntityManager em, UddiEntityPublisher publisher, SaveBusiness body) throws DispositionReportFaultMessage {
 
 		// No null input
 		if (body == null)
@@ -224,11 +197,11 @@
 			throw new ValueNotAllowedException(new ErrorMessage("errors.savebusiness.NoInput"));
 		
 		for (org.uddi.api_v3.BusinessEntity entity : entityList) {
-			validateBusinessEntity(em, entity);
+			validateBusinessEntity(em, publisher, entity);
 		}
 	}
 	
-	public static void validateSaveService(EntityManager em, SaveService body) throws DispositionReportFaultMessage {
+	public static void validateSaveService(EntityManager em, UddiEntityPublisher publisher, SaveService body) throws DispositionReportFaultMessage {
 
 		// No null input
 		if (body == null)
@@ -241,11 +214,11 @@
 		
 		for (org.uddi.api_v3.BusinessService entity : entityList) {
 			// Entity specific data validation
-			validateBusinessService(em, entity, null);
+			validateBusinessService(em, publisher, entity, null);
 		}
 	}
 	
-	public static void validateSaveBinding(EntityManager em, SaveBinding body) throws DispositionReportFaultMessage {
+	public static void validateSaveBinding(EntityManager em, UddiEntityPublisher publisher, SaveBinding body) throws DispositionReportFaultMessage {
 
 		// No null input
 		if (body == null)
@@ -257,11 +230,11 @@
 			throw new ValueNotAllowedException(new ErrorMessage("errors.savebinding.NoInput"));
 		
 		for (org.uddi.api_v3.BindingTemplate entity : entityList) {
-			validateBindingTemplate(em, entity, null);
+			validateBindingTemplate(em, publisher, entity, null);
 		}
 	}
 
-	public static void validateSaveTModel(EntityManager em, SaveTModel body) throws DispositionReportFaultMessage {
+	public static void validateSaveTModel(EntityManager em, UddiEntityPublisher publisher, SaveTModel body) throws DispositionReportFaultMessage {
 
 		// No null input
 		if (body == null)
@@ -273,24 +246,12 @@
 			throw new ValueNotAllowedException(new ErrorMessage("errors.savetmodel.NoInput"));
 		
 		for (org.uddi.api_v3.TModel entity : entityList) {
-			validateTModel(em, entity);
+			validateTModel(em, publisher, entity);
 		}
 	}
 
-	public static void validatePublisher(EntityManager em, org.apache.juddi.api.datatype.Publisher publisher) throws DispositionReportFaultMessage {
-
-		// No null input
-		if (publisher == null)
-			throw new ValueNotAllowedException(new ErrorMessage("errors.publisher.NullInput"));
-		
-		String publisherId = publisher.getPublisherId();
-		if (publisherId == null || publisherId.length() == 0)
-			throw new ValueNotAllowedException(new ErrorMessage("errors.publisher.NoPublisherId"));
-	
-	}
-
 	
-	public static void validateBusinessEntity(EntityManager em, org.uddi.api_v3.BusinessEntity businessEntity) throws DispositionReportFaultMessage {
+	public static void validateBusinessEntity(EntityManager em, UddiEntityPublisher publisher, org.uddi.api_v3.BusinessEntity businessEntity) throws DispositionReportFaultMessage {
 		
 		// A supplied businessService can't be null
 		if (businessEntity == null)
@@ -308,8 +269,13 @@
 			//throw new KeyUnavailableException(new ErrorMessage("errors.keyunavailable.BadPartition", entityKey));
 
 			Object obj = em.find(org.apache.juddi.model.BusinessEntity.class, entityKey);
-			if (obj != null)
+			if (obj != null) {
 				entityExists = true;
+
+				// Make sure publisher owns this entity.
+				if (!publisher.isOwner((UddiEntity)obj))
+					throw new UserMismatchException(new ErrorMessage("errors.usermismatch.InvalidOwner", entityKey));
+			}
 		}
 
 		if (!entityExists) {
@@ -326,11 +292,11 @@
 		validateCategoryBag(businessEntity.getCategoryBag());
 		validateIdentifierBag(businessEntity.getIdentifierBag());
 
-		validateBusinessServices(em, businessEntity.getBusinessServices(), businessEntity);
+		validateBusinessServices(em, publisher, businessEntity.getBusinessServices(), businessEntity);
 		
 	}
 
-	public static void validateBusinessServices(EntityManager em, org.uddi.api_v3.BusinessServices businessServices, org.uddi.api_v3.BusinessEntity parent) 
+	public static void validateBusinessServices(EntityManager em, UddiEntityPublisher publisher, org.uddi.api_v3.BusinessServices businessServices, org.uddi.api_v3.BusinessEntity parent) 
 					throws DispositionReportFaultMessage {
 		// Business services is optional
 		if (businessServices == null)
@@ -341,12 +307,12 @@
 			throw new ValueNotAllowedException(new ErrorMessage("errors.businessservices.NoInput"));
 		
 		for (org.uddi.api_v3.BusinessService businessService : businessServiceList) {
-			validateBusinessService(em, businessService, parent);
+			validateBusinessService(em, publisher, businessService, parent);
 		}
 			
 	}
 
-	public static void validateBusinessService(EntityManager em, org.uddi.api_v3.BusinessService businessService, org.uddi.api_v3.BusinessEntity parent) 
+	public static void validateBusinessService(EntityManager em, UddiEntityPublisher publisher, org.uddi.api_v3.BusinessService businessService, org.uddi.api_v3.BusinessEntity parent) 
 					throws DispositionReportFaultMessage {
 
 		// A supplied businessService can't be null
@@ -408,6 +374,11 @@
 					org.apache.juddi.model.BusinessService bs = (org.apache.juddi.model.BusinessService)obj;
 					if (!parentKey.equals(bs.getBusinessEntity().getBusinessKey()))
 						throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.businessservice.ParentMismatch", parentKey + ", " + bs.getBusinessEntity().getBusinessKey()));
+					
+					// Make sure publisher owns this entity.
+					if (!publisher.isOwner((UddiEntity)obj))
+						throw new UserMismatchException(new ErrorMessage("errors.usermismatch.InvalidOwner", entityKey));
+					
 				}
 				
 			}
@@ -426,8 +397,9 @@
 					if (parentTemp == null)
 						throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.ParentBusinessNotFound", parentKey));
 
-					// TODO: Test that publisher is owner of parent: UserMismatchException 
-
+					// Make sure publisher owns this parent entity.
+					if (!publisher.isOwner((UddiEntity)parentTemp))
+						throw new UserMismatchException(new ErrorMessage("errors.usermismatch.InvalidOwnerParent", parentKey));
 				}
 			}
 
@@ -442,12 +414,12 @@
 			validateNames(businessService.getName());
 			validateCategoryBag(businessService.getCategoryBag());
 			
-			validateBindingTemplates(em, businessService.getBindingTemplates(), businessService);
+			validateBindingTemplates(em, publisher, businessService.getBindingTemplates(), businessService);
 		}
 		
 	}
 
-	public static void validateBindingTemplates(EntityManager em, org.uddi.api_v3.BindingTemplates bindingTemplates, org.uddi.api_v3.BusinessService parent) 
+	public static void validateBindingTemplates(EntityManager em, UddiEntityPublisher publisher, org.uddi.api_v3.BindingTemplates bindingTemplates, org.uddi.api_v3.BusinessService parent) 
 					throws DispositionReportFaultMessage {
 		// Binding templates is optional
 		if (bindingTemplates == null)
@@ -458,12 +430,12 @@
 			throw new ValueNotAllowedException(new ErrorMessage("errors.bindingtemplates.NoInput"));
 	
 		for (org.uddi.api_v3.BindingTemplate bindingTemplate : bindingTemplateList) {
-			validateBindingTemplate(em, bindingTemplate, parent);
+			validateBindingTemplate(em, publisher, bindingTemplate, parent);
 		}
 	
 	}
 	
-	public static void validateBindingTemplate(EntityManager em, org.uddi.api_v3.BindingTemplate bindingTemplate, org.uddi.api_v3.BusinessService parent) 
+	public static void validateBindingTemplate(EntityManager em, UddiEntityPublisher publisher, org.uddi.api_v3.BindingTemplate bindingTemplate, org.uddi.api_v3.BusinessService parent) 
 					throws DispositionReportFaultMessage {
 
 		// A supplied bindingTemplate can't be null
@@ -502,6 +474,11 @@
 				org.apache.juddi.model.BindingTemplate bt = (org.apache.juddi.model.BindingTemplate)obj;
 				if (!parentKey.equals(bt.getBusinessService().getServiceKey()))
 					throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.bindingtemplate.ParentMismatch", parentKey + ", " + bt.getBusinessService().getServiceKey()));
+				
+				// Make sure publisher owns this entity.
+				if (!publisher.isOwner((UddiEntity)obj))
+					throw new UserMismatchException(new ErrorMessage("errors.usermismatch.InvalidOwner", entityKey));
+
 			}
 			
 		}
@@ -520,7 +497,9 @@
 				if (parentTemp == null)
 					throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.ParentBusinessNotFound", parentKey));
 
-				// TODO: Test that publisher is owner of parent: UserMismatchException 
+				// Make sure publisher owns this parent entity.
+				if (!publisher.isOwner((UddiEntity)parentTemp))
+					throw new UserMismatchException(new ErrorMessage("errors.usermismatch.InvalidOwnerParent", parentKey));
 
 			}
 		}
@@ -543,7 +522,7 @@
 		
 	}
 
-	public static void validateTModel(EntityManager em, org.uddi.api_v3.TModel tModel) throws DispositionReportFaultMessage {
+	public static void validateTModel(EntityManager em, UddiEntityPublisher publisher, org.uddi.api_v3.TModel tModel) throws DispositionReportFaultMessage {
 		// A supplied tModel can't be null
 		if (tModel == null)
 			throw new ValueNotAllowedException(new ErrorMessage("errors.tmodel.NullInput"));
@@ -560,8 +539,13 @@
 			//throw new KeyUnavailableException(new ErrorMessage("errors.keyunavailable.BadPartition", entityKey));
 
 			Object obj = em.find(org.apache.juddi.model.BusinessEntity.class, entityKey);
-			if (obj != null)
+			if (obj != null) {
 				entityExists = true;
+
+				// Make sure publisher owns this entity.
+				if (!publisher.isOwner((UddiEntity)obj))
+					throw new UserMismatchException(new ErrorMessage("errors.usermismatch.InvalidOwner", entityKey));
+			}
 		}
 
 		if (!entityExists) {
@@ -763,4 +747,70 @@
 			throw new ValueNotAllowedException(new ErrorMessage("errors.overviewdoc.NoDescOrUrl"));
 	}
 
+	/*-------------------------------------------------------------------
+	 Publisher functions are specific to jUDDI.
+	 --------------------------------------------------------------------*/
+	
+	public static void validateDeletePublisher(EntityManager em, Publisher publisher, DeletePublisher body) throws DispositionReportFaultMessage {
+
+		// No null input
+		if (body == null)
+			throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
+		
+		// No null or empty list
+		List<String> entityKeyList = body.getPublisherId();
+		if (entityKeyList == null || entityKeyList.size() == 0)
+			throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.NoKeys"));
+		
+		if (!publisher.isAdmin())
+			throw new UserMismatchException(new ErrorMessage("errors.deletepublisher.AdminReqd"));
+
+		HashSet<String> dupCheck = new HashSet<String>();
+		for (String entityKey : entityKeyList) {
+			boolean inserted = dupCheck.add(entityKey);
+			if (!inserted)
+				throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.DuplicateKey", entityKey));
+			
+			Object obj = em.find(org.apache.juddi.model.Publisher.class, entityKey);
+			if (obj == null)
+				throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.PublisherNotFound", entityKey));
+			
+		}
+	}
+
+	public static void validateSavePublisher(EntityManager em, Publisher publisher, SavePublisher body) throws DispositionReportFaultMessage {
+
+		// No null input
+		if (body == null)
+			throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
+		
+		// No null or empty list
+		List<org.apache.juddi.api.datatype.Publisher> entityList = body.getPublisher();
+		if (entityList == null || entityList.size() == 0)
+			throw new ValueNotAllowedException(new ErrorMessage("errors.savepublisher.NoInput"));
+		
+		if (!publisher.isAdmin())
+			throw new UserMismatchException(new ErrorMessage("errors.savepublisher.AdminReqd"));
+		
+		for (org.apache.juddi.api.datatype.Publisher entity : entityList) {
+			validatePublisher(em, entity);
+		}
+	}
+
+	public static void validatePublisher(EntityManager em, org.apache.juddi.api.datatype.Publisher publisher) throws DispositionReportFaultMessage {
+
+		// No null input
+		if (publisher == null)
+			throw new ValueNotAllowedException(new ErrorMessage("errors.publisher.NullInput"));
+		
+		String publisherId = publisher.getPublisherId();
+		if (publisherId == null || publisherId.length() == 0)
+			throw new ValueNotAllowedException(new ErrorMessage("errors.publisher.NoPublisherId"));
+	
+		String publisherName = publisher.getPublisherName();
+		if (publisherName == null || publisherName.length() == 0)
+			throw new ValueNotAllowedException(new ErrorMessage("errors.publisher.NoPublisherName"));
+
+	}
+	
 }

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/main/resources/messages_en.properties
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/main/resources/messages_en.properties?rev=711730&r1=711729&r2=711730&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/main/resources/messages_en.properties (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/main/resources/messages_en.properties Wed Nov  5 14:46:39 2008
@@ -73,15 +73,14 @@
 errors.invalidprojection.ParentMismatch=The supplied business key doesn't match the actual business key of the service being projected
 errors.assertion.NoPubAssertions=No publisher assertions were passed.  At least one assertion must be passed
 errors.assertion.AssertionNotFound=The publisher assertion was not found for the given key
+errors.usermismatch.InvalidOwner=The user is not authorized to access the given entity
+errors.usermismatch.InvalidOwnerParent=The user is not authorized to access the given parent entity
 
 #-- Error messages related to entities and other data structures
-errors.savepublisher.NoInput=At least one Publisher must be provided
 errors.savebusiness.NoInput=At least one BusinessEntity must be provided
 errors.saveservice.NoInput=At least one BusinessService must be provided
 errors.savebinding.NoInput=At least one BindingTemplate must be provided
 errors.savetmodel.NoInput=At least one tModel must be provided
-errors.publisher.NullInput=The Publisher structure cannot be blank
-errors.publisher.NoPublisherId=A valid publisher Id was not specified
 errors.businessentity.NullInput=The businessEntity structure cannot be blank
 errors.businessservice.NullInput=The businessService structure cannot be blank
 errors.bindingtemplate.NullInput=The bindingTemplate structure cannot be blank
@@ -116,6 +115,14 @@
 errors.findtmodel.NoInput=At least one categoryBag, identifierBag or name must be supplied
 errors.tmodelbag.NoInput=At tModel key must be supplied in the tModelBag
 
+#-- jUDDI-specific publisher messages
+errors.savepublisher.NoInput=At least one Publisher must be provided
+errors.savepublisher.AdminReqd=An account must have adminstrative privileges to save publishers
+errors.deletepublisher.AdminReqd=An account must have adminstrative privileges to delete publishers
+errors.publisher.NullInput=The Publisher structure cannot be blank
+errors.publisher.NoPublisherId=A valid publisher Id was not specified
+errors.publisher.NoPublisherName=A valid publisher name was not specified
+
 #-- Authentication error messages
 errors.auth.AuthRequired=Authentication is required for this API call
 errors.auth.AuthInvalid=Invalid authentication information

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/BusinessEntityTest.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/BusinessEntityTest.java?rev=711730&r1=711729&r2=711730&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/BusinessEntityTest.java (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/BusinessEntityTest.java Wed Nov  5 14:46:39 2008
@@ -16,11 +16,15 @@
 	private UDDIPublicationImpl publish = new UDDIPublicationImpl();
 	private UDDIInquiryImpl inquiry = new UDDIInquiryImpl();
 	
-	@Parameters({ "businessFile", "businessKey" })
+	@Parameters({ "businessFile", "businessKey", "publisherId" })
 	@Test
-	public void saveBusiness(String businessFile, String businessKey) {
+	public void saveBusiness(String businessFile, String businessKey, String publisherId) {
 		try {
+			String authInfo = UDDIApiTestHelper.getAuthToken(publisherId);
+			
 			SaveBusiness sb = new SaveBusiness();
+			sb.setAuthInfo(authInfo);
+
 			BusinessEntity beIn = (BusinessEntity)UDDIApiTestHelper.buildEntityFromDoc(businessFile, "org.uddi.api_v3");
 			sb.getBusinessEntity().add(beIn);
 			publish.saveBusiness(sb);
@@ -49,12 +53,16 @@
 
 	}
 
-	@Parameters({ "businessKey" })
+	@Parameters({ "businessKey", "publisherId" })
 	@Test
-	public void deleteBusiness(String businessKey) {
+	public void deleteBusiness(String businessKey, String publisherId) {
 		try {
+			String authInfo = UDDIApiTestHelper.getAuthToken(publisherId);
+			
 			// Delete the entity and make sure it is removed
 			DeleteBusiness db = new DeleteBusiness();
+			db.setAuthInfo(authInfo);
+			
 			db.getBusinessKey().add(businessKey);
 			publish.deleteBusiness(db);
 		}

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/BusinessServiceTest.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/BusinessServiceTest.java?rev=711730&r1=711729&r2=711730&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/BusinessServiceTest.java (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/BusinessServiceTest.java Wed Nov  5 14:46:39 2008
@@ -20,12 +20,16 @@
 	private UDDIPublicationImpl publish = new UDDIPublicationImpl();
 	private UDDIInquiryImpl inquiry = new UDDIInquiryImpl();
 
-	@Parameters({ "serviceFile", "serviceKey" })
+	@Parameters({ "serviceFile", "serviceKey", "publisherId" })
 	@Test
-	public void saveService(String serviceFile, String serviceKey) {
+	public void saveService(String serviceFile, String serviceKey, String publisherId) {
 		try {
+			String authInfo = UDDIApiTestHelper.getAuthToken(publisherId);
+
 			// First save the entity
 			SaveService ss = new SaveService();
+			ss.setAuthInfo(authInfo);
+			
 			org.uddi.api_v3.BusinessService bsIn = (org.uddi.api_v3.BusinessService)UDDIApiTestHelper.buildEntityFromDoc(serviceFile, "org.uddi.api_v3");
 			ss.getBusinessService().add(bsIn);
 			publish.saveService(ss);
@@ -52,12 +56,16 @@
 		
 	}
 	
-	@Parameters({ "serviceKey" })
+	@Parameters({ "serviceKey", "publisherId" })
 	@Test
-	public void deleteService(String serviceKey) {
+	public void deleteService(String serviceKey, String publisherId) {
 		try {
+			String authInfo = UDDIApiTestHelper.getAuthToken(publisherId);
+	
 			// Delete the entity and make sure it is removed
 			DeleteService ds = new DeleteService();
+			ds.setAuthInfo(authInfo);
+			
 			ds.getServiceKey().add(serviceKey);
 			publish.deleteService(ds);
 		}

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/PublisherTest.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/PublisherTest.java?rev=711730&r1=711729&r2=711730&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/PublisherTest.java (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/PublisherTest.java Wed Nov  5 14:46:39 2008
@@ -1,6 +1,7 @@
 package org.apache.juddi.test;
 
 import java.util.List;
+
 import javax.xml.bind.JAXBException;
 
 import org.apache.juddi.api.impl.UDDIPublicationImpl;
@@ -13,6 +14,8 @@
 import org.uddi.v3_service.DispositionReportFaultMessage;
 
 public class PublisherTest {
+	private static final String ADMIN_PUBID = "admin";
+	
 	private UDDIPublicationImpl publish = new UDDIPublicationImpl();
 	private UDDIInquiryImpl inquiry = new UDDIInquiryImpl();
 	
@@ -20,7 +23,13 @@
 	@Test
 	public void savePublisher(String publisherFile, String publisherId) {
 		try {
+			// An admin publisher must exist to add publisher accounts
+			UDDIApiTestHelper.addAdminPublisher(ADMIN_PUBID);
+
+			String authInfo = UDDIApiTestHelper.getAuthToken(ADMIN_PUBID);
+			
 			SavePublisher sp = new SavePublisher();
+			sp.setAuthInfo(authInfo);
 			Publisher pubIn = (Publisher)UDDIApiTestHelper.buildEntityFromDoc(publisherFile, "org.apache.juddi.api.datatype");
 			sp.getPublisher().add(pubIn);
 			publish.savePublisher(sp);
@@ -56,10 +65,17 @@
 	@Test
 	public void deletePublisher(String publisherId) {
 		try {
+			String authInfo = UDDIApiTestHelper.getAuthToken(ADMIN_PUBID);
+			
 			// Delete the entity and make sure it is removed
 			DeletePublisher dp = new DeletePublisher();
+			dp.setAuthInfo(authInfo);
+			
 			dp.getPublisherId().add(publisherId);
 			publish.deletePublisher(dp);
+			
+			UDDIApiTestHelper.removeAdminPublisher(ADMIN_PUBID);
+			UDDIApiTestHelper.removeAuthTokens();
 		}
 		catch(DispositionReportFaultMessage dr) {
 			Assert.fail("No exception should be thrown", dr);
@@ -67,4 +83,6 @@
 		
 	}
 
+	
+	
 }

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/UDDIApiTestHelper.java
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/UDDIApiTestHelper.java?rev=711730&r1=711729&r2=711730&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/UDDIApiTestHelper.java (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/UDDIApiTestHelper.java Wed Nov  5 14:46:39 2008
@@ -6,13 +6,19 @@
 import java.util.List;
 import java.util.Iterator;
 
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Query;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.Marshaller;
 
+import org.apache.juddi.api.impl.UDDISecurityImpl;
+import org.apache.juddi.query.PersistenceManager;
 import org.uddi.api_v3.*;
+import org.uddi.v3_service.DispositionReportFaultMessage;
 
 public class UDDIApiTestHelper {
 
@@ -31,6 +37,64 @@
 		
 	}
 
+	public static void addAdminPublisher(String pubId) {
+		org.apache.juddi.model.Publisher pub = new org.apache.juddi.model.Publisher();
+		pub.setPublisherId(pubId);
+		pub.setPublisherName("Administrator");
+		pub.setIsAdmin("true");
+		
+		EntityManager em = PersistenceManager.getEntityManager();
+		EntityTransaction tx = em.getTransaction();
+		tx.begin();
+
+		em.persist(pub);
+		
+		tx.commit();
+		em.close();
+
+	}
+	
+	public static void removeAdminPublisher(String pubId) {
+		
+		EntityManager em = PersistenceManager.getEntityManager();
+		EntityTransaction tx = em.getTransaction();
+		tx.begin();
+
+		Object obj = em.find(org.apache.juddi.model.Publisher.class, pubId);
+		em.remove(obj);
+		
+		tx.commit();
+		em.close();
+
+	}
+	
+	public static void removeAuthTokens() {
+		
+		EntityManager em = PersistenceManager.getEntityManager();
+		EntityTransaction tx = em.getTransaction();
+		tx.begin();
+
+		Query qry = em.createQuery("delete from AuthToken");
+		qry.executeUpdate();
+		
+		tx.commit();
+		em.close();
+
+	}
+
+	
+	public static String getAuthToken(String pubId) throws DispositionReportFaultMessage {
+		UDDISecurityImpl securityService = new UDDISecurityImpl();
+
+		org.uddi.api_v3.GetAuthToken ga = new org.uddi.api_v3.GetAuthToken();
+		ga.setUserID(pubId);
+		ga.setCred("");
+
+		org.uddi.api_v3.AuthToken token = securityService.getAuthToken(ga);
+		
+		return token.getAuthInfo();
+	}
+
 
 	public static void checkNames(List<Name> names1, List<Name> names2) {
 		if (names1 == null || names2 == null) {

Added: webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/publisher1.xml
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/publisher1.xml?rev=711730&view=auto
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/publisher1.xml (added)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/test/java/org/apache/juddi/test/publisher1.xml Wed Nov  5 14:46:39 2008
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<publisher xmlns="urn:apache-org:juddi_v3" publisherId="jpublisher">
+  <publisherName>Joe Publisher</publisherName>
+  <emailAddress>jpublisher@business.com</emailAddress>
+  <isAdmin>false</isAdmin>
+  <isEnabled>TrUe</isEnabled>
+  <maxBindingsPerService>199</maxBindingsPerService>
+  <maxBusinesses>100</maxBusinesses>
+  <maxServicePerBusiness>100</maxServicePerBusiness>
+  <maxTModels>100</maxTModels>
+</publisher>

Modified: webservices/juddi/branches/v3_trunk/juddi-core/src/test/resources/suite-one.xml
URL: http://svn.apache.org/viewvc/webservices/juddi/branches/v3_trunk/juddi-core/src/test/resources/suite-one.xml?rev=711730&r1=711729&r2=711730&view=diff
==============================================================================
--- webservices/juddi/branches/v3_trunk/juddi-core/src/test/resources/suite-one.xml (original)
+++ webservices/juddi/branches/v3_trunk/juddi-core/src/test/resources/suite-one.xml Wed Nov  5 14:46:39 2008
@@ -3,7 +3,7 @@
   <parameter name="publisherFile" value="./src/test/java/org/apache/juddi/test/publisher1.xml" />
   <parameter name="businessFile" value="./src/test/java/org/apache/juddi/test/businessEntity1.xml" />
   <parameter name="serviceFile" value="./src/test/java/org/apache/juddi/test/businessService1.xml" />
-  <parameter name="publisherId" value="admin" />
+  <parameter name="publisherId" value="jpublisher" />
   <parameter name="businessKey" value="uddi:businessone.com" />
   <parameter name="serviceKey" value="uddi:businessone.com:services:serviceone" />
   <test name="savePublisher">



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