View Javadoc
1   /*
2    * Copyright 2001-2008 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   */
17  package org.apache.juddi.validation;
18  
19  import java.net.MalformedURLException;
20  import java.net.URL;
21  import java.security.cert.CertificateException;
22  import java.util.ArrayList;
23  import java.util.HashMap;
24  import java.util.HashSet;
25  import java.util.List;
26  import java.util.Map;
27  import java.util.Properties;
28  import java.util.concurrent.atomic.AtomicReference;
29  
30  import javax.persistence.EntityManager;
31  import javax.persistence.EntityTransaction;
32  import javax.xml.ws.Holder;
33  
34  import org.apache.commons.configuration.Configuration;
35  import org.apache.commons.configuration.ConfigurationException;
36  import org.apache.commons.logging.Log;
37  import org.apache.commons.logging.LogFactory;
38  import org.apache.juddi.api_v3.AccessPointType;
39  import org.apache.juddi.api_v3.DeleteClerk;
40  import org.apache.juddi.api_v3.DeleteNode;
41  import org.apache.juddi.api_v3.DeletePublisher;
42  import org.apache.juddi.api_v3.SavePublisher;
43  import org.apache.juddi.config.AppConfig;
44  import org.apache.juddi.config.Constants;
45  import org.apache.juddi.config.Install;
46  import org.apache.juddi.config.PersistenceManager;
47  import org.apache.juddi.config.Property;
48  import org.apache.juddi.keygen.KeyGenerator;
49  import org.apache.juddi.keygen.KeyGeneratorFactory;
50  import org.apache.juddi.mapping.MappingModelToApi;
51  import org.apache.juddi.model.Publisher;
52  import org.apache.juddi.model.Tmodel;
53  import org.apache.juddi.model.UddiEntity;
54  import org.apache.juddi.model.UddiEntityPublisher;
55  import org.apache.juddi.query.FindBusinessByPublisherQuery;
56  import org.apache.juddi.query.FindTModelByPublisherQuery;
57  import org.apache.juddi.v3.client.UDDIConstants;
58  import org.apache.juddi.v3.client.UDDIConstantsV2;
59  import org.apache.juddi.v3.client.config.TokenResolver;
60  import org.apache.juddi.v3.client.cryptor.CryptorFactory;
61  import org.apache.juddi.v3.client.cryptor.DigSigUtil;
62  import org.apache.juddi.v3.error.AssertionNotFoundException;
63  import org.apache.juddi.v3.error.ErrorMessage;
64  import org.apache.juddi.v3.error.FatalErrorException;
65  import org.apache.juddi.v3.error.InvalidKeyPassedException;
66  import org.apache.juddi.v3.error.InvalidProjectionException;
67  import org.apache.juddi.v3.error.KeyUnavailableException;
68  import org.apache.juddi.v3.error.MaxEntitiesExceededException;
69  import org.apache.juddi.v3.error.UserMismatchException;
70  import org.apache.juddi.v3.error.ValueNotAllowedException;
71  import org.uddi.api_v3.AccessPoint;
72  import org.uddi.api_v3.AddPublisherAssertions;
73  import org.uddi.api_v3.AddressLine;
74  import org.uddi.api_v3.BindingTemplate;
75  import org.uddi.api_v3.BusinessEntity;
76  import org.uddi.api_v3.BusinessService;
77  import org.uddi.api_v3.DeleteBinding;
78  import org.uddi.api_v3.DeleteBusiness;
79  import org.uddi.api_v3.DeletePublisherAssertions;
80  import org.uddi.api_v3.DeleteService;
81  import org.uddi.api_v3.DeleteTModel;
82  import org.uddi.api_v3.Description;
83  import org.uddi.api_v3.DiscoveryURL;
84  import org.uddi.api_v3.Email;
85  import org.uddi.api_v3.HostingRedirector;
86  import org.uddi.api_v3.KeyedReference;
87  import org.uddi.api_v3.KeyedReferenceGroup;
88  import org.uddi.api_v3.Name;
89  import org.uddi.api_v3.OverviewDoc;
90  import org.uddi.api_v3.OverviewURL;
91  import org.uddi.api_v3.Phone;
92  import org.uddi.api_v3.SaveBinding;
93  import org.uddi.api_v3.SaveBusiness;
94  import org.uddi.api_v3.SaveService;
95  import org.uddi.api_v3.SaveTModel;
96  import org.uddi.api_v3.TModel;
97  import org.uddi.repl_v3.ReplicationConfiguration;
98  import org.uddi.sub_v3.Subscription;
99  import org.uddi.v3_service.DispositionReportFaultMessage;
100 
101 /**
102  * Provides validation of publish requests to Juddi
103  *
104  * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
105  * @author <a href="mailto:tcunning@apache.org">Tom Cunningham</a>
106  * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a> Modified March
107  * 2013 to validate string length and ref integrity
108  *
109  * Advisory, be careful calling AppConfig.getConfiguration() from within
110  * validation functions, it may inadvertently cause infinite loops during the
111  * Install phase
112  * @see Install
113  */
114 public class ValidatePublish extends ValidateUDDIApi {
115 
116         private static final Log log = LogFactory.getLog(ValidatePublish.class);
117 
118         /**
119          * used from Install class
120          *
121          * @param publisher
122          * @param nodeid
123          * @see Install
124          */
125         public ValidatePublish(UddiEntityPublisher publisher, String nodeid) {
126                 super(publisher, nodeid);
127         }
128 
129         public ValidatePublish(UddiEntityPublisher publisher) {
130                 super(publisher);
131         }
132 
133         public void validateDeleteBusiness(EntityManager em, DeleteBusiness body) throws DispositionReportFaultMessage {
134 
135                 // No null input
136                 if (body == null) {
137                         throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
138                 }
139 
140                 // No null or empty list
141                 List<String> entityKeyList = body.getBusinessKey();
142                 if (entityKeyList == null || entityKeyList.size() == 0) {
143                         throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.NoKeys"));
144                 }
145 
146                 HashSet<String> dupCheck = new HashSet<String>();
147                 int i = 0;
148                 for (String entityKey : entityKeyList) {
149 
150                         // Per section 4.4: keys must be case-folded
151                         entityKey = entityKey.toLowerCase();
152                         entityKeyList.set(i, entityKey);
153 
154                         boolean inserted = dupCheck.add(entityKey);
155                         if (!inserted) {
156                                 throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.DuplicateKey", entityKey));
157                         }
158 
159                         Object obj = em.find(org.apache.juddi.model.BusinessEntity.class, entityKey);
160                         if (obj == null) {
161                                 throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.BusinessNotFound", entityKey));
162                         }
163 
164                         if (!publisher.isOwner((UddiEntity) obj) && !((Publisher) publisher).isAdmin()) {
165                                 throw new UserMismatchException(new ErrorMessage("errors.usermismatch.InvalidOwner", entityKey));
166                         }
167 
168                         i++;
169                 }
170         }
171 
172         public void validateDeleteService(EntityManager em, DeleteService body) throws DispositionReportFaultMessage {
173 
174                 // No null input
175                 if (body == null) {
176                         throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
177                 }
178 
179                 // No null or empty list
180                 List<String> entityKeyList = body.getServiceKey();
181                 if (entityKeyList == null || entityKeyList.size() == 0) {
182                         throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.NoKeys"));
183                 }
184 
185                 HashSet<String> dupCheck = new HashSet<String>();
186                 int i = 0;
187                 for (String entityKey : entityKeyList) {
188 
189                         // Per section 4.4: keys must be case-folded
190                         entityKey = entityKey.toLowerCase();
191                         entityKeyList.set(i, entityKey);
192 
193                         boolean inserted = dupCheck.add(entityKey);
194                         if (!inserted) {
195                                 throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.DuplicateKey", entityKey));
196                         }
197 
198                         Object obj = em.find(org.apache.juddi.model.BusinessService.class, entityKey);
199                         if (obj == null) {
200                                 throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.ServiceNotFound", entityKey));
201                         }
202 
203                         //if you're are the owner, access granted
204                         //if you are an admin && this item belongs to this node, access granted
205                         //else denied
206                         AccessCheck(obj, entityKey);
207                         i++;
208                 }
209         }
210 
211         public void validateDeleteBinding(EntityManager em, DeleteBinding body) throws DispositionReportFaultMessage {
212 
213                 // No null input
214                 if (body == null) {
215                         throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
216                 }
217 
218                 // No null or empty list
219                 List<String> entityKeyList = body.getBindingKey();
220                 if (entityKeyList == null || entityKeyList.size() == 0) {
221                         throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.NoKeys"));
222                 }
223 
224                 // Checking for duplicates and existence
225                 HashSet<String> dupCheck = new HashSet<String>();
226                 int i = 0;
227                 for (String entityKey : entityKeyList) {
228                         validateKeyLength(entityKey);
229                         // Per section 4.4: keys must be case-folded
230                         entityKey = entityKey.toLowerCase();
231                         entityKeyList.set(i, entityKey);
232 
233                         boolean inserted = dupCheck.add(entityKey);
234                         if (!inserted) {
235                                 throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.DuplicateKey", entityKey));
236                         }
237 
238                         Object obj = em.find(org.apache.juddi.model.BindingTemplate.class, entityKey);
239                         if (obj == null) {
240                                 throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.BindingTemplateNotFound", entityKey));
241                         }
242 
243                         AccessCheck(obj, entityKey);
244 
245                         i++;
246                 }
247         }
248 
249         public void validateDeleteTModel(EntityManager em, DeleteTModel body) throws DispositionReportFaultMessage {
250 
251                 // No null input
252                 if (body == null) {
253                         throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
254                 }
255 
256                 // No null or empty list
257                 List<String> entityKeyList = body.getTModelKey();
258                 if (entityKeyList == null || entityKeyList.size() == 0) {
259                         throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.NoKeys"));
260                 }
261 
262                 HashSet<String> dupCheck = new HashSet<String>();
263                 int i = 0;
264                 for (String entityKey : entityKeyList) {
265                         validateKeyLength(entityKey);
266                         // Per section 4.4: keys must be case-folded
267                         entityKey = entityKey.toLowerCase();
268                         entityKeyList.set(i, entityKey);
269 
270                         boolean inserted = dupCheck.add(entityKey);
271                         if (!inserted) {
272                                 throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.DuplicateKey", entityKey));
273                         }
274 
275                         Object obj = em.find(org.apache.juddi.model.Tmodel.class, entityKey);
276                         if (obj == null) {
277                                 throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.TModelNotFound", entityKey));
278                         }
279 
280                         AccessCheck(obj, entityKey);
281 
282                         i++;
283                 }
284         }
285 
286         private void AccessCheck(Object obj, String entityKey) throws UserMismatchException {
287                 boolean accessCheck = false; //assume access denied
288                 if (!((UddiEntity) obj).getNodeId().equals(nodeID)) {
289                         //prevent changes to data owned by another node in a replicated environment
290                         //even if you're the boss
291                         throw new UserMismatchException(new ErrorMessage("errors.usermismatch.InvalidNode", entityKey + " Owning Node: " + ((UddiEntity) obj).getNodeId()
292                                 + ", this node: " + nodeID));
293                 }
294 
295                 if (publisher.isOwner((UddiEntity) obj) && nodeID.equals(((UddiEntity) obj).getNodeId())) {
296                         accessCheck = true;
297 
298                 }
299                 //if i'm an admin, let me edit stuff on this node, but only stuff that's owned by this node
300                 if (((Publisher) publisher).isAdmin()
301                         && nodeID.equals(((UddiEntity) obj).getNodeId())) {
302                         accessCheck = true;
303                 }
304 
305                 if (!accessCheck) {
306                         throw new UserMismatchException(new ErrorMessage("errors.usermismatch.InvalidOwner", entityKey));
307                 }
308 
309         }
310 
311         public void validateDeletePublisherAssertions(EntityManager em, DeletePublisherAssertions body) throws DispositionReportFaultMessage {
312 
313                 // No null input
314                 if (body == null) {
315                         throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
316                 }
317 
318                 // No null or empty list
319                 List<org.uddi.api_v3.PublisherAssertion> entityList = body.getPublisherAssertion();
320                 if (entityList == null || entityList.size() == 0) {
321                         throw new AssertionNotFoundException(new ErrorMessage("errors.pubassertion.NoPubAssertions"));
322                 }
323 
324                 for (org.uddi.api_v3.PublisherAssertion entity : entityList) {
325                         validateKeyLength(entity.getFromKey());
326                         validateKeyLength(entity.getToKey());
327                         validatePublisherAssertion(em, entity);
328 
329                         org.apache.juddi.model.PublisherAssertionId pubAssertionId = new org.apache.juddi.model.PublisherAssertionId(entity.getFromKey(), entity.getToKey());
330                         Object obj = em.find(org.apache.juddi.model.PublisherAssertion.class, pubAssertionId);
331                         if (obj == null) {
332                                 throw new AssertionNotFoundException(new ErrorMessage("errors.pubassertion.AssertionNotFound", entity.getFromKey() + ", " + entity.getToKey()));
333                         } else {
334                                 org.apache.juddi.model.PublisherAssertion pubAssertion = (org.apache.juddi.model.PublisherAssertion) obj;
335                                 org.uddi.api_v3.KeyedReference keyedRef = entity.getKeyedReference();
336                                 if (keyedRef == null) {
337                                         throw new AssertionNotFoundException(new ErrorMessage("errors.pubassertion.AssertionNotFound", entity.getFromKey() + ", " + entity.getToKey()));
338                                 }
339 
340                                 if (!pubAssertion.getTmodelKey().equalsIgnoreCase(keyedRef.getTModelKey())
341                                         || !pubAssertion.getKeyName().equalsIgnoreCase(keyedRef.getKeyName())
342                                         || !pubAssertion.getKeyValue().equalsIgnoreCase(keyedRef.getKeyValue())) {
343                                         throw new AssertionNotFoundException(new ErrorMessage("errors.pubassertion.AssertionNotFound", entity.getFromKey() + ", " + entity.getToKey()));
344                                 }
345                                 //JUDDI-908
346                                 if (!publisher.isOwner(pubAssertion.getBusinessEntityByToKey())
347                                         && !publisher.isOwner(pubAssertion.getBusinessEntityByFromKey())) {
348                                         throw new UserMismatchException(new ErrorMessage("errors.usermismatch.assertion"));
349                                 }
350 
351                         }
352 
353                 }
354         }
355 
356         public void validateSaveBusiness(EntityManager em, SaveBusiness body, Configuration config, UddiEntityPublisher publisher) throws DispositionReportFaultMessage {
357 
358                 if (config == null) {
359                         try {
360                                 config = AppConfig.getConfiguration();
361                         } catch (ConfigurationException ce) {
362                                 log.error("Could not optain config. " + ce.getMessage(), ce);
363                         }
364                 }
365                 // No null input
366                 if (body == null) {
367                         throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
368                 }
369 
370                 // No null or empty list
371                 List<org.uddi.api_v3.BusinessEntity> entityList = body.getBusinessEntity();
372                 if (entityList == null || entityList.size() == 0) {
373                         throw new ValueNotAllowedException(new ErrorMessage("errors.savebusiness.NoInput"));
374                 }
375 
376                 for (org.uddi.api_v3.BusinessEntity entity : entityList) {
377                         validateBusinessEntity(em, entity, config, publisher);
378 
379                 }
380                 validateCheckedTModelsBE(entityList, config);
381         }
382 
383         public void validateSaveBusinessMax(EntityManager em) throws DispositionReportFaultMessage {
384 
385                 //Obtain the maxSettings for this publisher or get the defaults
386                 Publisher publisher = em.find(Publisher.class, getPublisher().getAuthorizedName());
387                 Integer maxBusinesses = publisher.getMaxBusinesses();
388                 try {
389                         if (maxBusinesses == null) {
390                                 if (AppConfig.getConfiguration().containsKey(Property.JUDDI_MAX_BUSINESSES_PER_PUBLISHER)) {
391                                         maxBusinesses = AppConfig.getConfiguration().getInteger(Property.JUDDI_MAX_BUSINESSES_PER_PUBLISHER, -1);
392                                 } else {
393                                         maxBusinesses = -1;
394                                 }
395                         }
396                 } catch (ConfigurationException e) {
397                         log.error(e.getMessage(), e);
398                         maxBusinesses = -1; //in case the configuration is not available
399                 }
400                 //if we have the maxBusinesses set for this publisher then we need to make sure we did not exceed it.
401                 if (maxBusinesses > 0) {
402                         //get the businesses owned by this publisher
403                         List<?> businessKeysFound = FindBusinessByPublisherQuery.select(em, null, publisher, null);
404                         if (businessKeysFound != null && businessKeysFound.size() > maxBusinesses) {
405                                 throw new MaxEntitiesExceededException(new ErrorMessage("errors.save.maxBusinessesExceeded"));
406                         }
407                 }
408 
409         }
410 
411         public void validateSaveService(EntityManager em, SaveService body, Configuration config, UddiEntityPublisher publisher) throws DispositionReportFaultMessage {
412 
413                 if (config == null) {
414                         try {
415                                 config = AppConfig.getConfiguration();
416                         } catch (ConfigurationException ce) {
417                                 log.error("Could not optain config. " + ce.getMessage(), ce);
418                         }
419                 }
420                 // No null input
421                 if (body == null) {
422                         throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
423                 }
424 
425                 // No null or empty list
426                 List<org.uddi.api_v3.BusinessService> entityList = body.getBusinessService();
427                 if (entityList == null || entityList.size() == 0) {
428                         throw new ValueNotAllowedException(new ErrorMessage("errors.saveservice.NoInput"));
429                 }
430 
431                 for (org.uddi.api_v3.BusinessService entity : entityList) {
432                         // Entity specific data validation
433                         validateBusinessService(em, entity, null, config, publisher);
434 
435                 }
436                 validateCheckedTModelsBS(entityList, config);
437         }
438 
439         public void validateSaveServiceMax(EntityManager em, String businessKey) throws DispositionReportFaultMessage {
440 
441                 //Obtain the maxSettings for this publisher or get the defaults
442                 Publisher publisher = em.find(Publisher.class, getPublisher().getAuthorizedName());
443                 Integer maxServices = publisher.getMaxBusinesses();
444                 try {
445                         if (maxServices == null) {
446                                 if (AppConfig.getConfiguration().containsKey(Property.JUDDI_MAX_SERVICES_PER_BUSINESS)) {
447                                         maxServices = AppConfig.getConfiguration().getInteger(Property.JUDDI_MAX_SERVICES_PER_BUSINESS, -1);
448                                 } else {
449                                         maxServices = -1;
450                                 }
451                         }
452                 } catch (ConfigurationException e) {
453                         log.error(e.getMessage(), e);
454                         maxServices = -1; //incase the configuration isn't available
455                 }
456                 //if we have the maxServices set for a business then we need to make sure we did not exceed it.
457                 if (maxServices > 0) {
458                         //get the businesses owned by this publisher
459                         org.apache.juddi.model.BusinessEntity modelBusinessEntity = em.find(org.apache.juddi.model.BusinessEntity.class, businessKey);
460                         if (modelBusinessEntity.getBusinessServices() != null && modelBusinessEntity.getBusinessServices().size() > maxServices) {
461                                 throw new MaxEntitiesExceededException(new ErrorMessage("errors.save.maxServicesExceeded"));
462                         }
463                 }
464         }
465 
466         public void validateSaveBinding(EntityManager em, SaveBinding body, Configuration config, UddiEntityPublisher publisher) throws DispositionReportFaultMessage {
467 
468                 if (config == null) {
469                         try {
470                                 config = AppConfig.getConfiguration();
471                         } catch (ConfigurationException ce) {
472                                 log.error("Could not optain config. " + ce.getMessage(), ce);
473                         }
474                 }
475                 // No null input
476                 if (body == null) {
477                         throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
478                 }
479 
480                 // No null or empty list
481                 List<org.uddi.api_v3.BindingTemplate> entityList = body.getBindingTemplate();
482                 if (entityList == null || entityList.size() == 0) {
483                         throw new ValueNotAllowedException(new ErrorMessage("errors.savebinding.NoInput"));
484                 }
485 
486                 for (org.uddi.api_v3.BindingTemplate entity : entityList) {
487                         validateBindingTemplate(em, entity, null, config, publisher);
488 
489                 }
490                 validateCheckedTModelsBT(entityList, config);
491         }
492 
493         public void validateSaveBindingMax(EntityManager em, String serviceKey) throws DispositionReportFaultMessage {
494 
495                 //Obtain the maxSettings for this publisher or get the defaults
496                 Publisher publisher = em.find(Publisher.class, getPublisher().getAuthorizedName());
497                 Integer maxBindings = publisher.getMaxBindingsPerService();
498                 try {
499                         if (maxBindings == null) {
500                                 if (AppConfig.getConfiguration().containsKey(Property.JUDDI_MAX_BINDINGS_PER_SERVICE)) {
501                                         maxBindings = AppConfig.getConfiguration().getInteger(Property.JUDDI_MAX_BINDINGS_PER_SERVICE, -1);
502                                 } else {
503                                         maxBindings = -1;
504                                 }
505                         }
506                 } catch (ConfigurationException e) {
507                         log.error(e.getMessage(), e);
508                         maxBindings = -1; //incase the config isn't available
509                 }
510                 //if we have the maxBindings set for a service then we need to make sure we did not exceed it.
511                 if (maxBindings > 0) {
512                         //get the bindings owned by this service
513                         org.apache.juddi.model.BusinessService modelBusinessService = em.find(org.apache.juddi.model.BusinessService.class, serviceKey);
514                         if (modelBusinessService.getBindingTemplates() != null && modelBusinessService.getBindingTemplates().size() > maxBindings) {
515                                 throw new MaxEntitiesExceededException(new ErrorMessage("errors.save.maxBindingsExceeded"));
516                         }
517                 }
518         }
519 
520         public void validateSaveTModel(EntityManager em, SaveTModel body, Configuration config, UddiEntityPublisher publisher) throws DispositionReportFaultMessage {
521 
522                 if (config == null) {
523                         try {
524                                 config = AppConfig.getConfiguration();
525                         } catch (ConfigurationException ce) {
526                                 log.error("Could not optain config. " + ce.getMessage(), ce);
527                         }
528                 }
529                 // No null input
530                 if (body == null) {
531                         throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
532                 }
533 
534                 // No null or empty list
535                 List<org.uddi.api_v3.TModel> entityList = body.getTModel();
536                 if (entityList == null || entityList.size() == 0) {
537                         throw new ValueNotAllowedException(new ErrorMessage("errors.savetmodel.NoInput"));
538                 }
539 
540                 for (org.uddi.api_v3.TModel entity : entityList) {
541                         validateTModel(em, entity, config, publisher);
542 
543                 }
544                 validateCheckedTModelsTM(entityList, config);
545         }
546 
547         public void validateSaveTModelMax(EntityManager em) throws DispositionReportFaultMessage {
548 
549                 //Obtain the maxSettings for this publisher or get the defaults
550                 Publisher publisher = em.find(Publisher.class, getPublisher().getAuthorizedName());
551                 Integer maxTModels = publisher.getMaxTmodels();
552                 try {
553                         if (maxTModels == null) {
554                                 if (AppConfig.getConfiguration().containsKey(Property.JUDDI_MAX_TMODELS_PER_PUBLISHER)) {
555                                         maxTModels = AppConfig.getConfiguration().getInteger(Property.JUDDI_MAX_TMODELS_PER_PUBLISHER, -1);
556                                 } else {
557                                         maxTModels = -1;
558                                 }
559                         }
560                 } catch (ConfigurationException e) {
561                         log.error(e.getMessage(), e);
562                         maxTModels = -1; //incase the config isn't available
563                 }
564                 //if we have the TModels set for a publisher then we need to make sure we did not exceed it.
565                 if (maxTModels > 0) {
566                         //get the tmodels owned by this publisher
567                         List<?> tmodelKeysFound = FindTModelByPublisherQuery.select(em, null, publisher, null);
568                         if (tmodelKeysFound != null && tmodelKeysFound.size() > maxTModels) {
569                                 throw new MaxEntitiesExceededException(new ErrorMessage("errors.save.maxTModelsExceeded"));
570                         }
571                 }
572         }
573 
574         public void validateAddPublisherAssertions(EntityManager em, AddPublisherAssertions body) throws DispositionReportFaultMessage {
575 
576                 // No null input
577                 if (body == null) {
578                         throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
579                 }
580 
581                 // No null or empty list
582                 List<org.uddi.api_v3.PublisherAssertion> entityList = body.getPublisherAssertion();
583                 if (entityList == null || entityList.size() == 0) {
584                         throw new ValueNotAllowedException(new ErrorMessage("errors.addpublisherassertions.NoInput"));
585                 }
586 
587                 for (org.uddi.api_v3.PublisherAssertion entity : entityList) {
588                         validatePublisherAssertion(em, entity);
589                 }
590         }
591 
592         public void validateSetPublisherAssertions(EntityManager em, Holder<List<org.uddi.api_v3.PublisherAssertion>> body) throws DispositionReportFaultMessage {
593 
594                 // No null input
595                 if (body == null) {
596                         throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
597                 }
598 
599                 // Assertion list can be null or empty - it signifies that publisher is deleting all their assertions
600                 List<org.uddi.api_v3.PublisherAssertion> entityList = body.value;
601                 if (entityList != null && entityList.size() > 0) {
602 
603                         for (org.uddi.api_v3.PublisherAssertion entity : entityList) {
604                                 validatePublisherAssertion(em, entity);
605                         }
606                 }
607         }
608 
609         void validateNotSigned(org.uddi.api_v3.BusinessEntity item) throws ValueNotAllowedException {
610                 if (item == null) {
611                         return;
612                 }
613                 if (item.getBusinessKey() == null && !item.getSignature().isEmpty()) {
614                         throw new ValueNotAllowedException(new ErrorMessage("errors.entity.SignedButNoKey", "businessKey"));
615                 }
616                 if (item.getBusinessServices() != null && !item.getSignature().isEmpty()) {
617                         for (int i = 0; i < item.getBusinessServices().getBusinessService().size(); i++) {
618                                 if (item.getBusinessServices().getBusinessService().get(i).getBusinessKey() == null
619                                         || item.getBusinessServices().getBusinessService().get(i).getBusinessKey().length() == 0) {
620                                         throw new ValueNotAllowedException(new ErrorMessage("errors.entity.SignedButNoKey", "business/Service(" + i + ")/businessKey"));
621                                 }
622                                 if (item.getBusinessServices().getBusinessService().get(i).getServiceKey() == null
623                                         || item.getBusinessServices().getBusinessService().get(i).getServiceKey().length() == 0) {
624                                         throw new ValueNotAllowedException(new ErrorMessage("errors.entity.SignedButNoKey", "business/Service(" + i + ")/serviceKey"));
625                                 }
626                                 if (item.getBusinessServices().getBusinessService().get(i).getBindingTemplates() != null) {
627                                         for (int k = 0; k < item.getBusinessServices().getBusinessService().get(i).getBindingTemplates().getBindingTemplate().size(); k++) {
628                                                 if (item.getBusinessServices().getBusinessService().get(i).getBindingTemplates().getBindingTemplate().get(k).getBindingKey() == null
629                                                         || item.getBusinessServices().getBusinessService().get(i).getBindingTemplates().getBindingTemplate().get(k).getBindingKey().length() == 0) {
630                                                         throw new ValueNotAllowedException(new ErrorMessage("errors.entity.SignedButNoKey", "business/Service(" + i + ")/bindingTemplate)" + k + ")/bindingKey"));
631                                                 }
632                                         }
633                                 }
634                         }
635                 }
636         }
637 
638         void validateNotSigned(org.uddi.api_v3.BindingTemplate item) throws ValueNotAllowedException {
639                 if (item == null) {
640                         return;
641                 }
642                 if (item.getBindingKey() == null && !item.getSignature().isEmpty()) {
643                         throw new ValueNotAllowedException(new ErrorMessage("errors.entity.SignedButNoKey", "bindingKey"));
644                 }
645                 if (item.getServiceKey() == null && !item.getSignature().isEmpty()) {
646                         throw new ValueNotAllowedException(new ErrorMessage("errors.entity.SignedButNoKey", "serviceKey"));
647                 }
648         }
649 
650         void validateNotSigned(org.uddi.api_v3.TModel item) throws ValueNotAllowedException {
651                 if (item == null) {
652                         return;
653                 }
654                 if (item.getTModelKey() == null && !item.getSignature().isEmpty()) {
655                         throw new ValueNotAllowedException(new ErrorMessage("errors.entity.SignedButNoKey", "tModelKey"));
656                 }
657         }
658 
659         void validateNotSigned(org.uddi.api_v3.BusinessService item) throws ValueNotAllowedException {
660                 if (item == null) {
661                         return;
662                 }
663                 if (item.getBusinessKey() == null && !item.getSignature().isEmpty()) {
664                         throw new ValueNotAllowedException(new ErrorMessage("errors.entity.SignedButNoKey", "businessKey"));
665                 }
666                 if (item.getServiceKey() == null && !item.getSignature().isEmpty()) {
667                         throw new ValueNotAllowedException(new ErrorMessage("errors.entity.SignedButNoKey", "serviceKey"));
668                 }
669                 //if i'm signed and a key isn't defined in a bt
670                 if (item.getBindingTemplates() != null && !item.getSignature().isEmpty()) {
671                         for (int i = 0; i < item.getBindingTemplates().getBindingTemplate().size(); i++) {
672                                 if (item.getBindingTemplates().getBindingTemplate().get(i).getBindingKey() == null
673                                         || item.getBindingTemplates().getBindingTemplate().get(i).getBindingKey().length() == 0) {
674                                         throw new ValueNotAllowedException(new ErrorMessage("errors.entity.SignedButNoKey", "businessService/bindingTemplate(" + i + ")/bindingKey"));
675                                 }
676                         }
677                 }
678         }
679 
680         public void validateBusinessEntity(EntityManager em, org.uddi.api_v3.BusinessEntity businessEntity,
681                 Configuration config, UddiEntityPublisher publisher) throws DispositionReportFaultMessage {
682 
683                 // A supplied businessEntity can't be null
684                 if (businessEntity == null) {
685                         throw new ValueNotAllowedException(new ErrorMessage("errors.businessentity.NullInput"));
686                 }
687 
688                 boolean entityExists = false;
689                 validateNotSigned(businessEntity);
690                 String entityKey = businessEntity.getBusinessKey();
691                 if (entityKey == null || entityKey.length() == 0) {
692                         KeyGenerator keyGen = KeyGeneratorFactory.getKeyGenerator();
693                         entityKey = keyGen.generate(publisher);
694                         businessEntity.setBusinessKey(entityKey);
695                 } else {
696                         // Per section 4.4: keys must be case-folded
697                         entityKey = entityKey.toLowerCase();
698                         businessEntity.setBusinessKey(entityKey);
699                         validateKeyLength(entityKey);
700                         Object obj = em.find(org.apache.juddi.model.BusinessEntity.class, entityKey);
701                         if (obj != null) {
702                                 entityExists = true;
703 
704                                 // Make sure publisher owns this entity.
705                                 AccessCheck(obj, entityKey);
706 
707                         } else {
708                                 // Inside this block, we have a key proposed by the publisher on a new entity
709 
710                                 // Validate key and then check to see that the proposed key is valid for this publisher
711                                 ValidateUDDIKey.validateUDDIv3Key(entityKey);
712                                 if (!publisher.isValidPublisherKey(em, entityKey)) {
713                                         throw new KeyUnavailableException(new ErrorMessage("errors.keyunavailable.BadPartition", entityKey));
714                                 }
715 
716                         }
717                 }
718 
719                 if (!entityExists) {
720                         // Check to make sure key isn't used by another entity.
721                         if (!isUniqueKey(em, entityKey)) {
722                                 throw new KeyUnavailableException(new ErrorMessage("errors.keyunavailable.KeyExists", entityKey));
723                         }
724                 }
725 
726                 // was TODO: validate "checked" categories or category groups (see section 5.2.3 of spec)? optional to support
727                 //covered by ref integrity checks
728                 validateNames(businessEntity.getName());
729                 validateDiscoveryUrls(businessEntity.getDiscoveryURLs());
730                 validateContacts(businessEntity.getContacts(), config);
731                 validateCategoryBag(businessEntity.getCategoryBag(), config, false);
732                 validateIdentifierBag(businessEntity.getIdentifierBag(), config, false);
733                 validateDescriptions(businessEntity.getDescription());
734                 validateBusinessServices(em, businessEntity.getBusinessServices(), businessEntity, config, publisher);
735                 validateSignaturesBusiness(businessEntity, config);
736 
737         }
738 
739         public void validateBusinessServices(EntityManager em, org.uddi.api_v3.BusinessServices businessServices,
740                 org.uddi.api_v3.BusinessEntity parent, Configuration config, UddiEntityPublisher publisher)
741                 throws DispositionReportFaultMessage {
742                 // Business services is optional
743                 if (businessServices == null) {
744                         return;
745                 }
746                 List<org.uddi.api_v3.BusinessService> businessServiceList = businessServices.getBusinessService();
747                 if (businessServiceList == null || businessServiceList.size() == 0) {
748                         throw new ValueNotAllowedException(new ErrorMessage("errors.businessservices.NoInput"));
749                 }
750 
751                 for (org.uddi.api_v3.BusinessService businessService : businessServiceList) {
752                         validateBusinessService(em, businessService, parent, config, publisher);
753                 }
754 
755         }
756 
757         public void validateBusinessService(EntityManager em, org.uddi.api_v3.BusinessService businessService,
758                 org.uddi.api_v3.BusinessEntity parent, Configuration config, UddiEntityPublisher publisher)
759                 throws DispositionReportFaultMessage {
760 
761                 // A supplied businessService can't be null
762                 if (businessService == null) {
763                         throw new ValueNotAllowedException(new ErrorMessage("errors.businessservice.NullInput"));
764                 }
765 
766                 validateNotSigned(businessService);
767                 // Retrieve the service's passed key
768                 String entityKey = businessService.getServiceKey();
769                 if (entityKey != null && entityKey.length() > 0) {
770                         // Per section 4.4: keys must be case-folded
771                         entityKey = entityKey.toLowerCase();
772                         validateKeyLength(entityKey);
773                         businessService.setServiceKey(entityKey);
774                 }
775 
776                 // The parent key is either supplied or provided by the higher call to the parent entity save.  If the passed-in parent's business key differs from 
777                 // the (non-null) business key retrieved from the service, then we have a possible service projection.
778                 String parentKey = businessService.getBusinessKey();
779                 if (parentKey != null && parentKey.length() > 0) {
780                         // Per section 4.4: keys must be case-folded
781                         parentKey = parentKey.toLowerCase();
782                         businessService.setBusinessKey(parentKey);
783                 }
784 
785                 boolean isProjection = false;
786                 if (parent != null) {
787                         if (parentKey != null && parentKey.length() > 0) {
788                                 if (!parentKey.equalsIgnoreCase(parent.getBusinessKey())) {
789                                         // Possible projected service - if we have differing parent businesses but a service key was not provided, this is an error as it is not possible 
790                                         // for the business that doesn't "own" the service to generate the key for it.
791                                         if (entityKey == null || entityKey.length() == 0) {
792                                                 throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.ServiceKeyNotProvidedWithProjection", parentKey + ", " + parent.getBusinessKey()));
793                                         }
794 
795                                         isProjection = true;
796                                 }
797                         } else {
798                                 parentKey = parent.getBusinessKey();
799                         }
800                 }
801 
802                 // Projections don't require as rigorous testing as only the projected service's business key and service key are examined for validity.
803                 if (isProjection) {
804 
805                         Object obj = em.find(org.apache.juddi.model.BusinessService.class, entityKey);
806                         // Can't project a service that doesn't exist!
807                         if (obj == null) {
808                                 throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.ProjectedServiceNotFound", parentKey + ", " + entityKey));
809                         } else {
810                                 // If the supplied business key doesn't match the existing service's business key, the projection is invalid.
811                                 org.apache.juddi.model.BusinessService bs = (org.apache.juddi.model.BusinessService) obj;
812                                 if (!businessService.getBusinessKey().equalsIgnoreCase(bs.getBusinessEntity().getEntityKey())) {
813                                         throw new InvalidProjectionException(new ErrorMessage("errors.invalidprojection.ParentMismatch", businessService.getBusinessKey() + ", " + bs.getBusinessEntity().getEntityKey()));
814                                 }
815                         }
816                         obj = null;
817                 } else {
818                         boolean entityExists = false;
819                         if (entityKey == null || entityKey.length() == 0) {
820                                 KeyGenerator keyGen = KeyGeneratorFactory.getKeyGenerator();
821                                 entityKey = keyGen.generate(publisher);
822                                 businessService.setServiceKey(entityKey);
823                         } else {
824 
825                                 Object obj = em.find(org.apache.juddi.model.BusinessService.class, entityKey);
826                                 if (obj != null) {
827                                         entityExists = true;
828 
829                                         org.apache.juddi.model.BusinessService bs = (org.apache.juddi.model.BusinessService) obj;
830 
831                                         // If the object exists, and the parentKey was not found to this point, then a save on an existing service with a blank
832                                         // business key has occurred.  It is set here and added to the entity being saved - a necessary step for the object to be
833                                         // persisted properly. (This condition makes some validation tests below unnecessary as the parent is "verified" but it's OK to
834                                         // still run them).
835                                         if (parentKey == null || parentKey.length() == 0) {
836                                                 parentKey = bs.getBusinessEntity().getEntityKey();
837                                                 businessService.setBusinessKey(parentKey);
838                                         }
839 
840                                         // Make sure publisher owns this entity.
841                                         AccessCheck(obj, entityKey);
842 
843                                         // If existing service trying to be saved has a different parent key, then we have a problem
844                                         if (!parentKey.equalsIgnoreCase(bs.getBusinessEntity().getEntityKey())) {
845                                                 // if both businesses are owned by this publisher then we allow it.
846                                                 // we already check the current business is owned, lets see if the old one is too
847                                                 if (!publisher.isOwner(bs.getBusinessEntity())) {
848                                                         throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.businessservice.ParentMismatch", parentKey + ", " + bs.getBusinessEntity().getEntityKey()));
849                                                 } else {
850                                                         if (log.isDebugEnabled()) {
851                                                                 log.debug("Services moved from business " + bs.getBusinessEntity() + " to " + businessService.getBusinessKey());
852                                                         }
853                                                 }
854                                         }
855 
856                                 } else {
857                                         // Inside this block, we have a key proposed by the publisher on a new entity
858 
859                                         // Validate key and then check to see that the proposed key is valid for this publisher
860                                         ValidateUDDIKey.validateUDDIv3Key(entityKey);
861                                         if (!publisher.isValidPublisherKey(em, entityKey)) {
862                                                 throw new KeyUnavailableException(new ErrorMessage("errors.keyunavailable.BadPartition", entityKey));
863                                         }
864 
865                                 }
866 
867                         }
868 
869                         // Parent key must be passed if this is a new entity
870                         if (!entityExists) {
871                                 if (parentKey == null || parentKey.length() == 0) {
872                                         throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.ParentBusinessNotFound", parentKey));
873                                 }
874                         }
875 
876                         // If parent key IS passed, whether new entity or not, it must be valid.  Additionally, the current publisher must be the owner of the parent.  Note that
877                         // if a parent ENTITY was passed in, then we don't need to check for any of this since this is part of a higher call.
878                         if (parentKey != null) {
879                                 if (parent == null) {
880                                         Object parentTemp = em.find(org.apache.juddi.model.BusinessEntity.class, parentKey);
881                                         if (parentTemp == null) {
882                                                 throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.ParentBusinessNotFound", parentKey));
883                                         }
884 
885                                         // Make sure publisher owns this parent entity.
886                                         AccessCheck(parentTemp, parentKey);
887                                         // if (!publisher.isOwner((UddiEntity) parentTemp)) {
888                                         //        throw new UserMismatchException(new ErrorMessage("errors.usermismatch.InvalidOwnerParent", parentKey));
889                                         //}
890                                 }
891                         }
892 
893                         if (!entityExists) {
894                                 // Check to make sure key isn't used by another entity.
895                                 if (!isUniqueKey(em, entityKey)) {
896                                         throw new KeyUnavailableException(new ErrorMessage("errors.keyunavailable.KeyExists", entityKey));
897                                 }
898                         }
899 
900                         // TODO: validate "checked" categories or category groups (see section 5.2.3 of spec)? optional to support
901                         validateNames(businessService.getName());
902                         validateCategoryBag(businessService.getCategoryBag(), config, false);
903                         validateDescriptions(businessService.getDescription());
904                         validateBindingTemplates(em, businessService.getBindingTemplates(), businessService, config, publisher);
905                         validateSignaturesService(businessService, config);
906                 }
907 
908         }
909 
910         public void validateBindingTemplates(EntityManager em, org.uddi.api_v3.BindingTemplates bindingTemplates,
911                 org.uddi.api_v3.BusinessService parent, Configuration config, UddiEntityPublisher publisher)
912                 throws DispositionReportFaultMessage {
913                 // Binding templates is optional
914                 if (bindingTemplates == null) {
915                         return;
916                 }
917 
918                 List<org.uddi.api_v3.BindingTemplate> bindingTemplateList = bindingTemplates.getBindingTemplate();
919                 if (bindingTemplateList == null || bindingTemplateList.size() == 0) {
920                         throw new ValueNotAllowedException(new ErrorMessage("errors.bindingtemplates.NoInput"));
921                 }
922 
923                 for (org.uddi.api_v3.BindingTemplate bindingTemplate : bindingTemplateList) {
924                         validateBindingTemplate(em, bindingTemplate, parent, config, publisher);
925                 }
926 
927         }
928 
929         public void validateBindingTemplate(EntityManager em, org.uddi.api_v3.BindingTemplate bindingTemplate,
930                 org.uddi.api_v3.BusinessService parent, Configuration config, UddiEntityPublisher publisher)
931                 throws DispositionReportFaultMessage {
932 
933                 // A supplied bindingTemplate can't be null
934                 if (bindingTemplate == null) {
935                         throw new ValueNotAllowedException(new ErrorMessage("errors.bindingtemplate.NullInput"));
936                 }
937 
938                 // Retrieve the binding's passed key
939                 String entityKey = bindingTemplate.getBindingKey();
940                 if (entityKey != null && entityKey.length() > 0) {
941                         // Per section 4.4: keys must be case-folded
942                         entityKey = entityKey.toLowerCase();
943                         bindingTemplate.setBindingKey(entityKey);
944                         validateKeyLength(entityKey);
945                 }
946 
947                 // The parent key is either supplied or provided by the higher call to the parent entity save.  If it is provided in both instances, if they differ, an 
948                 // error occurs.
949                 String parentKey = bindingTemplate.getServiceKey();
950                 if (parentKey != null && parentKey.length() > 0) {
951                         // Per section 4.4: keys must be case-folded
952                         parentKey = parentKey.toLowerCase();
953                         bindingTemplate.setServiceKey(parentKey);
954                 }
955 
956                 if (parent != null) {
957                         if (parentKey != null && parentKey.length() > 0) {
958                                 if (!parentKey.equalsIgnoreCase(parent.getServiceKey())) {
959                                         throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.bindingtemplate.ParentMismatch", parentKey + ", " + parent.getBusinessKey()));
960                                 }
961                         } else {
962                                 parentKey = parent.getServiceKey();
963                         }
964                 }
965 
966                 boolean entityExists = false;
967                 if (entityKey == null || entityKey.length() == 0) {
968                         validateNotSigned(bindingTemplate);
969                         KeyGenerator keyGen = KeyGeneratorFactory.getKeyGenerator();
970                         entityKey = keyGen.generate(publisher);
971                         bindingTemplate.setBindingKey(entityKey);
972                 } else {
973 
974                         Object obj = em.find(org.apache.juddi.model.BindingTemplate.class, entityKey);
975                         if (obj != null) {
976                                 entityExists = true;
977 
978                                 org.apache.juddi.model.BindingTemplate bt = (org.apache.juddi.model.BindingTemplate) obj;
979 
980                                 // If the object exists, and the parentKey was not found to this point, then a save on an existing binding with a blank
981                                 // service key has occurred.  It is set here and added to the entity being saved - a necessary step for the object to be
982                                 // persisted properly. (This condition makes some validation tests below unnecessary as the parent is "verified" but it's OK to
983                                 // still run them).
984                                 if (parentKey == null || parentKey.length() == 0) {
985                                         parentKey = bt.getBusinessService().getEntityKey();
986                                         bindingTemplate.setServiceKey(parentKey);
987                                 }
988 
989                                 // If existing binding trying to be saved has a different parent key, then we have a problem
990                                 // TODO: moving bindings is allowed according to spec?
991                                 if (!parentKey.equalsIgnoreCase(bt.getBusinessService().getEntityKey())) {
992                                         throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.bindingtemplate.ParentMismatch", parentKey + ", " + bt.getBusinessService().getEntityKey()));
993                                 }
994 
995                                 // Make sure publisher owns this entity.
996                                 AccessCheck(obj, entityKey);
997                                 //if (!publisher.isOwner((UddiEntity) obj)&& !((Publisher) publisher).isAdmin()) {
998 //                                        throw new UserMismatchException(new ErrorMessage("errors.usermismatch.InvalidOwner", entityKey));
999                                 //                              }
1000 
1001                         } else {
1002                                 // Inside this block, we have a key proposed by the publisher on a new entity
1003 
1004                                 // Validate key and then check to see that the proposed key is valid for this publisher
1005                                 ValidateUDDIKey.validateUDDIv3Key(entityKey);
1006                                 if (!publisher.isValidPublisherKey(em, entityKey)) {
1007                                         throw new KeyUnavailableException(new ErrorMessage("errors.keyunavailable.BadPartition", entityKey));
1008                                 }
1009 
1010                         }
1011 
1012                 }
1013 
1014                 // Parent key must be passed if this is a new entity
1015                 if (!entityExists) {
1016                         if (parentKey == null || parentKey.length() == 0) {
1017                                 throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.ParentServiceNotFound", parentKey));
1018                         }
1019                 }
1020 
1021                 // If parent key IS passed, whether new entity or not, it must be valid.  Additionally, the current publisher must be the owner of the parent.  Note that
1022                 // if a parent ENTITY was passed in, then we don't need to check for any of this since this is part of a higher call.
1023                 if (parentKey != null) {
1024                         if (parent == null) {
1025                                 Object parentTemp = em.find(org.apache.juddi.model.BusinessService.class, parentKey);
1026                                 if (parentTemp == null) {
1027                                         throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.ParentBusinessNotFound", parentKey));
1028                                 } else if (!(parentTemp instanceof org.apache.juddi.model.BusinessService)) {
1029                                         //JUDDI-848
1030                                         throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.ParentBusinessNotFound", parentKey));
1031                                 }
1032 
1033                                 // Make sure publisher owns this parent entity.
1034                                 AccessCheck(parentTemp, parentKey);
1035 //                                if (!publisher.isOwner((UddiEntity) parentTemp)) {
1036 //                                        throw new UserMismatchException(new ErrorMessage("errors.usermismatch.InvalidOwnerParent", parentKey));
1037 //                                }
1038 
1039                         }
1040                 }
1041 
1042                 if (!entityExists) {
1043                         // Check to make sure key isn't used by another entity.
1044                         if (!isUniqueKey(em, entityKey)) {
1045                                 throw new KeyUnavailableException(new ErrorMessage("errors.keyunavailable.KeyExists", entityKey));
1046                         }
1047                 }
1048 
1049                 //was TODO validate "checked" categories or category groups (see section 5.2.3 of spec)? optional to support
1050                 //at least one must be defined
1051                 if (bindingTemplate.getAccessPoint() == null && bindingTemplate.getHostingRedirector() == null) {
1052                         throw new ValueNotAllowedException(new ErrorMessage("errors.bindingtemplate.NoAccessPoint"));
1053                 }
1054                 //but not both
1055                 if (bindingTemplate.getAccessPoint() != null && bindingTemplate.getHostingRedirector() != null) {
1056                         throw new ValueNotAllowedException(new ErrorMessage("errors.bindingtemplate.NoAccessPoint"));
1057                 }
1058                 validateCategoryBag(bindingTemplate.getCategoryBag(), config, false);
1059                 validateTModelInstanceDetails(bindingTemplate.getTModelInstanceDetails(), config, false);
1060                 validateAccessPoint(em, bindingTemplate.getAccessPoint(), config);
1061                 validateDescriptions(bindingTemplate.getDescription());
1062                 validateHostingRedirector(em, bindingTemplate.getHostingRedirector(), config);
1063 
1064                 validateSignaturesBinding(bindingTemplate, config);
1065                 //validateCheckedTModels(bindingTemplate, config);
1066         }
1067 
1068         public void validateTModel(EntityManager em, org.uddi.api_v3.TModel tModel, Configuration config, UddiEntityPublisher publisher) throws DispositionReportFaultMessage {
1069                 // A supplied tModel can't be null
1070                 if (tModel == null) {
1071                         throw new ValueNotAllowedException(new ErrorMessage("errors.tmodel.NullInput"));
1072                 }
1073 
1074                 boolean entityExists = false;
1075                 String entityKey = tModel.getTModelKey();
1076                 if (entityKey == null || entityKey.length() == 0) {
1077                         KeyGenerator keyGen = KeyGeneratorFactory.getKeyGenerator();
1078                         entityKey = keyGen.generate(publisher);
1079                         validateNotSigned(tModel);
1080                         tModel.setTModelKey(entityKey);
1081                 } else {
1082                         // Per section 4.4: keys must be case-folded
1083                         entityKey = entityKey.toLowerCase();
1084                         tModel.setTModelKey(entityKey);
1085 
1086                         Object obj = em.find(org.apache.juddi.model.Tmodel.class, entityKey);
1087                         if (obj != null) {
1088                                 entityExists = true;
1089 
1090                                 // Make sure publisher owns this entity.
1091                                 AccessCheck(obj, entityKey);
1092                                 //if (!publisher.isOwner((UddiEntity) obj)&& !((Publisher) publisher).isAdmin()) {
1093                                 //        throw new UserMismatchException(new ErrorMessage("errors.usermismatch.InvalidOwner", entityKey));
1094                                 // }
1095                         } else {
1096                                 // Inside this block, we have a key proposed by the publisher on a new entity
1097 
1098                                 // First test to see if this is a Key Generator tModel. The keyGenerator suffix appearing in the key is the indicator, since this is not
1099                                 // allowed *unless* it's a key generator.
1100                                 if (entityKey.toUpperCase().contains(KeyGenerator.KEYGENERATOR_SUFFIX.toUpperCase())) {
1101                                         ValidateUDDIKey.validateUDDIv3KeyGeneratorTModel(tModel);
1102 
1103                                         // The root publisher is only allowed one key generator.  This is published in the installation.
1104                                         String rootPublisherStr = "root";
1105                                         try {
1106                                                 rootPublisherStr = AppConfig.getConfiguration().getString(Property.JUDDI_ROOT_PUBLISHER);
1107                                         } catch (ConfigurationException ce) {
1108                                                 log.error("Could not read the root publisher setting in the configuration.");
1109                                         }
1110                                         if (publisher.getAuthorizedName().equals(rootPublisherStr)) {
1111                                                 throw new FatalErrorException(new ErrorMessage("errors.tmodel.keygenerator.RootKeyGen"));
1112                                         }
1113 
1114                                         // It's a valid Key Generator, but is it available for this publisher?
1115                                         if (!publisher.isKeyGeneratorAvailable(em, entityKey)) {
1116                                                 throw new KeyUnavailableException(new ErrorMessage("errors.keyunavailable.BadPartition", entityKey));
1117                                         }
1118 
1119                                 } else {
1120                                         // If not a key generator, then simply validate key and then check to see that the proposed key is valid for this publisher
1121                                         ValidateUDDIKey.validateUDDIv3Key(entityKey);
1122                                         //fix for JUDDI-851
1123                                         if (!entityKey.toUpperCase().startsWith("UUID:")) {
1124                                                 if (!publisher.isValidPublisherKey(em, entityKey)) {
1125                                                         throw new KeyUnavailableException(new ErrorMessage("errors.keyunavailable.BadPartition", entityKey));
1126                                                 }
1127                                         }
1128                                 }
1129                         }
1130                 }
1131 
1132                 if (!entityExists) {
1133                         // Check to make sure key isn't used by another entity.
1134                         if (!isUniqueKey(em, entityKey)) {
1135                                 throw new KeyUnavailableException(new ErrorMessage("errors.keyunavailable.KeyExists", entityKey));
1136                         }
1137                 }
1138                 validateKeyLength(entityKey);
1139 
1140                 // TODO: validate "checked" categories or category groups (see section 5.2.3 of spec)? optional to support
1141                 if (tModel.getName() == null || tModel.getName().getValue() == null
1142                         || tModel.getName().getValue().equals("")) {
1143                         throw new ValueNotAllowedException(new ErrorMessage("errors.tmodel.NoName"));
1144                 }
1145 
1146                 validateCategoryBag(tModel.getCategoryBag(), config, false);
1147                 validateIdentifierBag(tModel.getIdentifierBag(), config, false);
1148                 validateDescriptions(tModel.getDescription());
1149                 validateNameLength(tModel.getName().getValue());
1150                 validateLang(tModel.getName().getLang());
1151                 List<org.uddi.api_v3.OverviewDoc> overviewDocList = tModel.getOverviewDoc();
1152                 if (overviewDocList != null) {
1153                         for (org.uddi.api_v3.OverviewDoc overviewDoc : overviewDocList) {
1154                                 validateOverviewDoc(overviewDoc);
1155                         }
1156                 }
1157                 validateSignaturesTModel(tModel, config);
1158 
1159         }
1160 
1161         public void validatePublisherAssertion(EntityManager em, org.uddi.api_v3.PublisherAssertion pubAssertion) throws DispositionReportFaultMessage {
1162                 // A supplied publisher assertion can't be null
1163                 if (pubAssertion == null) {
1164                         throw new ValueNotAllowedException(new ErrorMessage("errors.pubassertion.NullInput"));
1165                 }
1166 
1167                 // The keyedRef must not be blank and every field must contain data.
1168                 org.uddi.api_v3.KeyedReference keyedRef = pubAssertion.getKeyedReference();
1169                 if (keyedRef == null
1170                         || keyedRef.getTModelKey() == null || keyedRef.getTModelKey().length() == 0
1171                         || keyedRef.getKeyName() == null || keyedRef.getKeyName().length() == 0
1172                         || keyedRef.getKeyValue() == null || keyedRef.getKeyValue().length() == 0) {
1173                         throw new ValueNotAllowedException(new ErrorMessage("errors.pubassertion.BlankKeyedRef"));
1174                 }
1175 
1176                 String fromKey = pubAssertion.getFromKey();
1177                 if (fromKey == null || fromKey.length() == 0) {
1178                         throw new ValueNotAllowedException(new ErrorMessage("errors.pubassertion.BlankFromKey"));
1179                 }
1180 
1181                 String toKey = pubAssertion.getToKey();
1182                 if (toKey == null || toKey.length() == 0) {
1183                         throw new ValueNotAllowedException(new ErrorMessage("errors.pubassertion.BlankToKey"));
1184                 }
1185 
1186                 if (fromKey.equalsIgnoreCase(toKey)) {
1187                         throw new ValueNotAllowedException(new ErrorMessage("errors.pubassertion.SameBusinessKey"));
1188                 }
1189 
1190                 // Per section 4.4: keys must be case-folded
1191                 fromKey = fromKey.toLowerCase();
1192                 pubAssertion.setFromKey(fromKey);
1193                 toKey = toKey.toLowerCase();
1194                 pubAssertion.setToKey(toKey);
1195                 validateKeyLength(toKey);
1196                 validateKeyLength(fromKey);
1197                 Object fromObj = em.find(org.apache.juddi.model.BusinessEntity.class, fromKey);
1198                 if (fromObj == null) {
1199                         throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.BusinessNotFound", fromKey));
1200                 }
1201 
1202                 Object toObj = em.find(org.apache.juddi.model.BusinessEntity.class, pubAssertion.getToKey());
1203                 if (toObj == null) {
1204                         throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.BusinessNotFound", toKey));
1205                 }
1206 
1207                 if (!publisher.isOwner((UddiEntity) fromObj) && !publisher.isOwner((UddiEntity) toObj)) {
1208                         throw new UserMismatchException(new ErrorMessage("errors.pubassertion.UserMismatch", fromKey + " & " + toKey));
1209                 }
1210 
1211                 try {
1212                         validateKeyedReference(pubAssertion.getKeyedReference(), AppConfig.getConfiguration(), false);
1213                 } catch (ConfigurationException ce) {
1214                         log.error("Could not optain config. " + ce.getMessage(), ce);
1215                 }
1216         }
1217 
1218         public void validateNames(List<org.uddi.api_v3.Name> names) throws DispositionReportFaultMessage {
1219                 // At least one name is required
1220                 if (names == null || names.size() == 0) {
1221                         throw new ValueNotAllowedException(new ErrorMessage("errors.names.NoInput"));
1222                 }
1223 
1224                 for (Name n : names) {
1225                         if (n.getValue() == null || n.getValue().length() == 0) {
1226                                 throw new ValueNotAllowedException(new ErrorMessage("errors.names.NoValue"));
1227                         }
1228                         validateNameLength(n.getValue());
1229                         validateLang(n.getLang());
1230                 }
1231 
1232         }
1233 
1234         public void validateContacts(org.uddi.api_v3.Contacts contacts, Configuration config) throws DispositionReportFaultMessage {
1235                 // Contacts is optional
1236                 if (contacts == null) {
1237                         return;
1238                 }
1239 
1240                 // If contacts do exist, at least one contact is required
1241                 List<org.uddi.api_v3.Contact> contactList = contacts.getContact();
1242                 if (contactList == null || contactList.size() == 0) {
1243                         throw new ValueNotAllowedException(new ErrorMessage("errors.contacts.NoInput"));
1244                 }
1245 
1246                 for (org.uddi.api_v3.Contact contact : contactList) {
1247                         validateContact(contact, config);
1248                 }
1249 
1250         }
1251 
1252         public void validateContact(org.uddi.api_v3.Contact contact, Configuration config) throws DispositionReportFaultMessage {
1253                 if (log.isDebugEnabled()) {
1254                         log.debug("validateContact");
1255                 }
1256                 // A supplied contact can't be null
1257                 if (contact == null) {
1258                         throw new ValueNotAllowedException(new ErrorMessage("errors.contact.NullInput"));
1259                 }
1260 
1261                 // At least one personName is required
1262                 List<org.uddi.api_v3.PersonName> pnameList = contact.getPersonName();
1263                 if (pnameList == null || pnameList.size() == 0) {
1264                         throw new ValueNotAllowedException(new ErrorMessage("errors.contact.NoPersonName"));
1265                 }
1266                 for (org.uddi.api_v3.PersonName pn : pnameList) {
1267                         if (pn.getValue() == null || pn.getValue().length() == 0) {
1268                                 throw new ValueNotAllowedException(new ErrorMessage("errors.contacts.NoPersonName"));
1269                         }
1270                         validateNameLength(pn.getValue());
1271                         validateLang(pn.getLang());
1272                 }
1273 
1274                 List<org.uddi.api_v3.Address> addressList = contact.getAddress();
1275                 if (addressList != null) {
1276                         for (org.uddi.api_v3.Address address : addressList) {
1277                                 if (address != null) {
1278                                         validateSortCode(address.getSortCode());
1279                                         validateKeyLength(address.getTModelKey());
1280                                         validateLang(address.getLang());
1281                                         validateUseType(address.getUseType());
1282                                         boolean checked = true;
1283                                         // Per section 4.4: keys must be case-folded
1284                                         if (address.getTModelKey() != null) {
1285                                                 address.setTModelKey(address.getTModelKey().toLowerCase());
1286                                                 validatedAddressLinesIfKeyDefined(address.getAddressLine());
1287 
1288                                                 checked = verifyTModelKeyExistsAndChecked(address.getTModelKey(), config);
1289 
1290                                         }
1291                                         if (address.getAddressLine() == null || address.getAddressLine().size() == 0) {
1292                                                 throw new ValueNotAllowedException(new ErrorMessage("errors.contact.NoAddressLine"));
1293                                         }
1294 
1295                                         if (checked) {
1296                                                 validateAddressLines(address.getAddressLine(), config);
1297                                         }
1298                                 }
1299                         }
1300                 }
1301                 validateEmailAddress(contact.getEmail());
1302                 validatePhone(contact.getPhone());
1303                 validateDescriptions(contact.getDescription());
1304                 validateUseType(contact.getUseType());
1305         }
1306 
1307         public void validateDiscoveryUrls(org.uddi.api_v3.DiscoveryURLs discUrls) throws DispositionReportFaultMessage {
1308                 // Discovery Urls is optional
1309                 if (discUrls == null) {
1310                         return;
1311                 }
1312 
1313                 // If discUrls does exist, it must have at least one element
1314                 List<org.uddi.api_v3.DiscoveryURL> discUrlList = discUrls.getDiscoveryURL();
1315                 if (discUrlList == null || discUrlList.size() == 0) {
1316                         throw new ValueNotAllowedException(new ErrorMessage("errors.discurls.NoInput"));
1317                 }
1318                 for (org.uddi.api_v3.DiscoveryURL url : discUrlList) {
1319                         if (url.getValue() == null || url.getValue().length() == 0) {
1320                                 throw new ValueNotAllowedException(new ErrorMessage("errors.discurls.NoInput"));
1321                         }
1322                         validateDiscoveryUrlLength(url);
1323                 }
1324         }
1325 
1326         public void validateCategoryBag(org.uddi.api_v3.CategoryBag categories, Configuration config, boolean isRoot) throws DispositionReportFaultMessage {
1327 
1328                 // Category bag is optional
1329                 if (categories == null) {
1330                         return;
1331                 }
1332 
1333                 // If category bag does exist, it must have at least one element
1334                 List<KeyedReference> elems = categories.getKeyedReference();
1335                 List<KeyedReferenceGroup> groups = categories.getKeyedReferenceGroup();
1336                 if (groups.size() == 0 && elems.size() == 0) {
1337                         throw new ValueNotAllowedException(new ErrorMessage("errors.categorybag.NoInput"));
1338                 }
1339 
1340                 for (KeyedReferenceGroup group : groups) {
1341                         validateKeyedReferenceGroup(group, config, isRoot);
1342                 }
1343 
1344                 for (KeyedReference elem : elems) {
1345                         validateKeyedReference(elem, config, isRoot);
1346                 }
1347         }
1348 
1349         public void validateIdentifierBag(org.uddi.api_v3.IdentifierBag identifiers, Configuration config, boolean isRoot) throws DispositionReportFaultMessage {
1350 
1351                 // Identifier bag is optional
1352                 if (identifiers == null) {
1353                         return;
1354                 }
1355 
1356                 // If category bag does exist, it must have at least one element
1357                 List<org.uddi.api_v3.KeyedReference> keyedRefList = identifiers.getKeyedReference();
1358                 if (keyedRefList == null || keyedRefList.size() == 0) {
1359                         throw new ValueNotAllowedException(new ErrorMessage("errors.identifierbag.NoInput"));
1360                 }
1361 
1362                 for (org.uddi.api_v3.KeyedReference keyedRef : keyedRefList) {
1363                         validateKeyedReference(keyedRef, config, isRoot);
1364                 }
1365         }
1366 
1367         public void validateKeyedReferenceGroup(KeyedReferenceGroup krg, Configuration config, boolean isRoot) throws DispositionReportFaultMessage {
1368                 // Keyed reference groups must contain a tModelKey
1369                 if (log.isDebugEnabled()) {
1370                         log.debug("validateKeyedReferenceGroup");
1371                 }
1372                 if (krg.getTModelKey() == null || krg.getTModelKey().length() == 0) {
1373                         throw new ValueNotAllowedException(new ErrorMessage("errors.keyedreference.NoTModelKey"));
1374                 }
1375 
1376                 // Per section 4.4: keys must be case-folded
1377                 String tmodelKey = krg.getTModelKey().toLowerCase();
1378                 krg.setTModelKey(tmodelKey);
1379                 validateKeyLength(tmodelKey);
1380 
1381                 boolean checkRef = false;
1382                 try {
1383                         checkRef = config.getBoolean(Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY, false);
1384                 } catch (Exception ex) {
1385                         log.warn("Error caught reading " + Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY + " from config file", ex);
1386                 }
1387                 if (checkRef && !isRoot) {
1388                         this.verifyTModelKeyExists(tmodelKey);
1389                 }
1390 
1391                 boolean checked = verifyTModelKeyExistsAndChecked(tmodelKey, config);
1392 
1393                 if (checked) {
1394                         List<KeyedReference> keyedRefs = krg.getKeyedReference();
1395                         // Should being empty raise an error?
1396                         if (keyedRefs != null && keyedRefs.size() > 0) {
1397                                 for (KeyedReference keyedRef : keyedRefs) {
1398                                         validateKeyedReference(keyedRef, config, isRoot);
1399                                 }
1400                         }
1401                 }
1402         }
1403 
1404         /**
1405          *
1406          * @param kr
1407          * @param config
1408          * @param isRoot true during install time, otherwise false
1409          * @throws DispositionReportFaultMessage
1410          */
1411         public void validateKeyedReference(KeyedReference kr, Configuration config, boolean isRoot) throws DispositionReportFaultMessage {
1412                 if (log.isDebugEnabled()) {
1413                         log.debug("validateKeyedReference");
1414                 }
1415                 String tmodelKey = kr.getTModelKey();
1416 
1417                 if (tmodelKey == null || tmodelKey.length() == 0) {
1418                         throw new ValueNotAllowedException(new ErrorMessage("errors.keyedreference.NoTModelKey"));
1419                 }
1420 
1421                 // Per section 4.4: keys must be case-folded
1422                 tmodelKey = tmodelKey.toLowerCase();
1423                 kr.setTModelKey(tmodelKey);
1424                 validateKeyLength(tmodelKey);
1425 
1426                 if (kr.getKeyValue() == null || kr.getKeyValue().length() == 0) {
1427                         throw new ValueNotAllowedException(new ErrorMessage("errors.keyedreference.NoKeyValue"));
1428                 }
1429                 validateKeyValue(kr.getKeyValue());
1430                 validateKeyName(kr.getKeyName());
1431 
1432                 boolean checkRef = false;
1433                 try {
1434                         checkRef = config.getBoolean(Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY, false);
1435                 } catch (Exception ex) {
1436                         log.warn("Error caught reading " + Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY + " from config file", ex);
1437                 }
1438                 if (checkRef && !isRoot) {
1439                         this.verifyTModelKeyExists(tmodelKey);
1440 
1441                 }
1442 
1443                 String rootPublisherStr = config.getString(Property.JUDDI_ROOT_PUBLISHER);
1444                 // Per section 6.2.2.1 of the specification, no publishers (except the root) are allowed to use the node categorization tmodelKey
1445                 if (Constants.NODE_CATEGORY_TMODEL.equalsIgnoreCase(kr.getTModelKey())) {
1446                         if (!rootPublisherStr.equals(publisher.getAuthorizedName())) {
1447                                 throw new ValueNotAllowedException(new ErrorMessage("errors.keyedreference.NodeCategoryTModel", Constants.NODE_CATEGORY_TMODEL));
1448                         }
1449                 }
1450         }
1451 
1452         public void validateTModelInstanceDetails(org.uddi.api_v3.TModelInstanceDetails tmodelInstDetails, Configuration config, boolean isRoot) throws DispositionReportFaultMessage {
1453                 if (log.isDebugEnabled()) {
1454                         log.debug("validateTModelInstanceDetails");
1455                 }
1456                 // tModel Instance Details is optional
1457                 if (tmodelInstDetails == null) {
1458                         return;
1459                 }
1460 
1461                 // If tmodelInstDetails does exist, it must have at least one element
1462                 List<org.uddi.api_v3.TModelInstanceInfo> tmodelInstInfoList = tmodelInstDetails.getTModelInstanceInfo();
1463                 if (tmodelInstInfoList == null || tmodelInstInfoList.size() == 0) {
1464                         throw new ValueNotAllowedException(new ErrorMessage("errors.tmodelinstdetails.NoInput"));
1465                 }
1466 
1467                 for (org.uddi.api_v3.TModelInstanceInfo tmodelInstInfo : tmodelInstInfoList) {
1468                         validateTModelInstanceInfo(tmodelInstInfo, config, isRoot);
1469                 }
1470         }
1471 
1472         public void validateTModelInstanceInfo(org.uddi.api_v3.TModelInstanceInfo tmodelInstInfo, Configuration config, boolean isRoot) throws DispositionReportFaultMessage {
1473                 // tModel Instance Info can't be null
1474                 if (tmodelInstInfo == null) {
1475                         throw new ValueNotAllowedException(new ErrorMessage("errors.tmodelinstinfo.NullInput"));
1476                 }
1477 
1478                 // TModel key is required
1479                 if (tmodelInstInfo.getTModelKey() == null || tmodelInstInfo.getTModelKey().length() == 0) {
1480                         throw new ValueNotAllowedException(new ErrorMessage("errors.tmodelinstinfo.NoTModelKey"));
1481                 }
1482 
1483                 // Per section 4.4: keys must be case-folded
1484                 tmodelInstInfo.setTModelKey((tmodelInstInfo.getTModelKey().toLowerCase()));
1485 
1486                 boolean checkRef = false;
1487                 try {
1488                         checkRef = config.getBoolean(Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY, false);
1489                 } catch (Exception ex) {
1490                         log.warn("Error caught reading " + Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY + " from config file", ex);
1491                 }
1492                 if (checkRef && !isRoot) {
1493                         this.verifyTModelKeyExists(tmodelInstInfo.getTModelKey());
1494                 }
1495 
1496                 validateInstanceDetails(tmodelInstInfo.getInstanceDetails());
1497                 if (log.isDebugEnabled()) {
1498                         log.debug("validateTModelInstanceInfo");
1499                 }
1500 
1501                 validateKeyLength(tmodelInstInfo.getTModelKey());
1502                 validateDescriptions(tmodelInstInfo.getDescription());
1503 
1504         }
1505 
1506         public void validateInstanceDetails(org.uddi.api_v3.InstanceDetails instDetails) throws DispositionReportFaultMessage {
1507                 // Instance Details is optional
1508                 if (instDetails == null) {
1509                         return;
1510                 }
1511 
1512                 // At least one OverviewDoc or instanceParms must be supplied
1513                 List<OverviewDoc> elems = instDetails.getOverviewDoc();
1514                 if (instDetails.getInstanceParms() == null && elems.size() == 0) {
1515                         throw new ValueNotAllowedException(new ErrorMessage("errors.instdetails.NoOverviewOrParms"));
1516                 }
1517                 for (int i = 0; i < elems.size(); i++) {
1518                         validateDescriptions(elems.get(i).getDescription());
1519                         validateOverviewURL(elems.get(i).getOverviewURL());
1520                 }
1521                 if (instDetails.getInstanceParms()!=null){
1522                     if (instDetails.getInstanceParms().length()>8192){
1523                          throw new ValueNotAllowedException(new ErrorMessage("errors.instdetails.MaxLength",instDetails.getInstanceParms().length()+""));
1524                     }
1525                 }
1526         }
1527 
1528         public void validateOverviewDoc(org.uddi.api_v3.OverviewDoc overviewDoc) throws DispositionReportFaultMessage {
1529                 // OverviewDoc can't be null
1530                 if (overviewDoc == null) {
1531                         throw new ValueNotAllowedException(new ErrorMessage("errors.overviewdoc.NullInput"));
1532                 }
1533 
1534                 // At least one description or overview URL must be supplied
1535                 List<org.uddi.api_v3.Description> elems = overviewDoc.getDescription();
1536                 if ((elems == null || elems.size() == 0) && overviewDoc.getOverviewURL() == null) {
1537                         throw new ValueNotAllowedException(new ErrorMessage("errors.overviewdoc.NoDescOrUrl"));
1538                 }
1539                 for (int i = 0; i < elems.size(); i++) {
1540                         validateLang(elems.get(i).getLang());
1541                         validateURL(elems.get(i).getValue());
1542                 }
1543         }
1544 
1545         public void validateRegisteredInfo(org.uddi.api_v3.GetRegisteredInfo body) throws DispositionReportFaultMessage {
1546                 // No null input
1547                 if (body == null) {
1548                         throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
1549                 }
1550 
1551                 // infoSelection is required
1552                 if (body.getInfoSelection() == null) {
1553                         throw new ValueNotAllowedException(new ErrorMessage("errors.getregisteredinfo.NoInfoSelection"));
1554                 }
1555 
1556         }
1557 
1558         /**
1559          * Publishing API functions are specific to jUDDI. Requires
1560          * administrative privilege
1561          *
1562          * @param em
1563          * @param body
1564          * @throws DispositionReportFaultMessage
1565          */
1566         public void validateDeletePublisher(EntityManager em, DeletePublisher body) throws DispositionReportFaultMessage {
1567 
1568                 // No null input
1569                 if (body == null) {
1570                         throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
1571                 }
1572 
1573                 // No null or empty list
1574                 List<String> entityKeyList = body.getPublisherId();
1575                 if (entityKeyList == null || entityKeyList.size() == 0) {
1576                         throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.NoKeys"));
1577                 }
1578 
1579                 if (!((Publisher) publisher).isAdmin()) {
1580                         throw new UserMismatchException(new ErrorMessage("errors.deletepublisher.AdminReqd"));
1581                 }
1582 
1583                 HashSet<String> dupCheck = new HashSet<String>();
1584                 for (String entityKey : entityKeyList) {
1585                         validateKeyLength(entityKey);
1586                         boolean inserted = dupCheck.add(entityKey);
1587                         if (!inserted) {
1588                                 throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.DuplicateKey", entityKey));
1589                         }
1590 
1591                         Object obj = em.find(org.apache.juddi.model.Publisher.class, entityKey);
1592                         if (obj == null) {
1593                                 throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.PublisherNotFound", entityKey));
1594                         }
1595 
1596                 }
1597         }
1598 
1599         public void validateSaveSubscriptionAdmin(EntityManager em, String publisherOrUsername, List<Subscription> subscriptions) throws DispositionReportFaultMessage {
1600 
1601                 // No null input
1602                 if (subscriptions == null || subscriptions.isEmpty()) {
1603                         throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
1604                 }
1605 
1606                 if (!((Publisher) publisher).isAdmin()) {
1607                         throw new UserMismatchException(new ErrorMessage("errors.deletepublisher.AdminReqd"));
1608                 }
1609                 UddiEntityPublisher user = new UddiEntityPublisher(publisherOrUsername);
1610                 ValidateSubscription vsub = new ValidateSubscription(user);
1611                 for (int i = 0; i < subscriptions.size(); i++) {
1612                         vsub.validateSubscriptions(em, subscriptions, user);
1613                 }
1614         }
1615 
1616         public void validateSavePublisher(EntityManager em, SavePublisher body) throws DispositionReportFaultMessage {
1617 
1618                 // No null input
1619                 if (body == null) {
1620                         throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
1621                 }
1622 
1623                 // No null or empty list
1624                 List<org.apache.juddi.api_v3.Publisher> entityList = body.getPublisher();
1625                 if (entityList == null || entityList.size() == 0) {
1626                         throw new ValueNotAllowedException(new ErrorMessage("errors.savepublisher.NoInput"));
1627                 }
1628 
1629                 if (!((Publisher) publisher).isAdmin()) {
1630                         throw new UserMismatchException(new ErrorMessage("errors.savepublisher.AdminReqd", publisher.getAuthorizedName()));
1631                 }
1632 
1633                 for (org.apache.juddi.api_v3.Publisher entity : entityList) {
1634                         validatePublisher(em, entity);
1635                 }
1636         }
1637 
1638         public void validatePublisher(EntityManager em, org.apache.juddi.api_v3.Publisher publisher) throws DispositionReportFaultMessage {
1639 
1640                 // No null input
1641                 if (publisher == null) {
1642                         throw new ValueNotAllowedException(new ErrorMessage("errors.publisher.NullInput"));
1643                 }
1644 
1645                 String authorizedName = publisher.getAuthorizedName();
1646                 if (authorizedName == null || authorizedName.length() == 0) {
1647                         throw new ValueNotAllowedException(new ErrorMessage("errors.publisher.NoAuthorizedName"));
1648                 }
1649 
1650                 String publisherName = publisher.getPublisherName();
1651                 if (publisherName == null || publisherName.length() == 0) {
1652                         throw new ValueNotAllowedException(new ErrorMessage("errors.publisher.NoPublisherName"));
1653                 }
1654 //TODO identify JUDDI restrictions on publisher name
1655         }
1656 
1657         public void validateAdminDeleteTModel(EntityManager em, DeleteTModel body) throws DispositionReportFaultMessage {
1658 
1659                 // No null input
1660                 if (body == null) {
1661                         throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
1662                 }
1663 
1664                 // No null or empty list
1665                 List<String> entityKeyList = body.getTModelKey();
1666                 if (entityKeyList == null || entityKeyList.size() == 0) {
1667                         throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.NoKeys"));
1668                 }
1669 
1670                 if (!((Publisher) publisher).isAdmin()) {
1671                         throw new UserMismatchException(new ErrorMessage("errors.AdminReqd"));
1672                 }
1673 
1674                 HashSet<String> dupCheck = new HashSet<String>();
1675                 for (String entityKey : entityKeyList) {
1676                         validateKeyLength(entityKey);
1677                         boolean inserted = dupCheck.add(entityKey);
1678                         if (!inserted) {
1679                                 throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.DuplicateKey", entityKey));
1680                         }
1681 
1682                         //removed a check for checking if the entity exists which was moved to the juddi api class
1683                         //why? because we were looking up the same object twice in the database and its just not efficient
1684                 }
1685         }
1686         ////////////////////////////////////////////////////////////////////
1687         ////////////////////////// begin validation code
1688         ////////////////////////////////////////////////////////////////////
1689 
1690         private static void validateDescription(String value) throws ValueNotAllowedException {
1691                 if (value != null && value.length() > ValidationConstants.MAX_description) {
1692                         throw new ValueNotAllowedException(new ErrorMessage("errors.DescriptionTooLong"));
1693                 }
1694         }
1695 
1696         public static void validateLang(String lang) throws ValueNotAllowedException {
1697                 if (lang != null && lang.length() > ValidationConstants.MAX_xml_lang) {
1698                         throw new ValueNotAllowedException(new ErrorMessage("errors.names.LangTooLong"));
1699                 }
1700         }
1701 
1702         private static void validateUseType(String useType) throws ValueNotAllowedException {
1703                 if (useType != null && useType.length() > ValidationConstants.MAX_useType) {
1704                         throw new ValueNotAllowedException(new ErrorMessage("errors.names.UseTypeTooLong"));
1705                 }
1706         }
1707 
1708         public static void validateKeyLength(String value) throws ValueNotAllowedException {
1709                 if (value != null && value.length() > ValidationConstants.MAX_Key) {
1710                         throw new ValueNotAllowedException(new ErrorMessage("errors.keys.TooLong"));
1711                 }
1712         }
1713 
1714         private void validateAccessPoint(EntityManager em, AccessPoint value, Configuration config) throws ValueNotAllowedException {
1715                 if (log.isDebugEnabled()) {
1716                         log.debug("validateAccessPoint");
1717                 }
1718 
1719                 if (value != null) {
1720                         if (value.getValue().length() > ValidationConstants.MAX_accessPoint) {
1721                                 throw new ValueNotAllowedException(new ErrorMessage("errors.accessPoint.TooLong"));
1722                         }
1723 
1724                         validateUseType(value.getUseType());
1725                         if (value.getUseType() != null) {
1726                                 if (value.getUseType().equalsIgnoreCase(AccessPointType.BINDING_TEMPLATE.toString())) {
1727                                         //validate that the referenced binding key exists already
1728                                         Object obj = em.find(org.apache.juddi.model.BindingTemplate.class, value.getValue());
1729                                         if (obj == null) {
1730                                                 throw new ValueNotAllowedException(new ErrorMessage("errors.accessPoint.bindingtemplateRedirect.keynotexist"));
1731                                         }
1732 
1733                                 } else if (value.getUseType().equalsIgnoreCase(AccessPointType.HOSTING_REDIRECTOR.toString())) {
1734                                         try {
1735                                                 //no validation necessary other than confirm that it's a URL
1736                                                 new URL(value.getValue());
1737                                         } catch (MalformedURLException ex) {
1738                                                 throw new ValueNotAllowedException(new ErrorMessage("errors.accessPoint.hostingRedirector.notaurl"));
1739                                         }
1740                                 }
1741                                 //TODO determine if additional validation is required.
1742                                 //potentials, if its a wsdl deployment, is the Value a valid URI
1743                                 //if endpoint, is it a valid URI?
1744                         }
1745                 }
1746         }
1747 
1748         private void validateHostingRedirector(EntityManager em, HostingRedirector hostingRedirector, Configuration config) throws ValueNotAllowedException {
1749                 if (log.isDebugEnabled()) {
1750                         log.debug("validateHostingRedirector");
1751                 }
1752                 if (hostingRedirector == null) {
1753                         return;
1754                 }
1755 
1756                 if (hostingRedirector.getBindingKey() == null || hostingRedirector.getBindingKey().length() == 0) {
1757                         throw new ValueNotAllowedException(new ErrorMessage("errors.hostingredirector.noinput"));
1758                 }
1759                 if (hostingRedirector.getBindingKey().length() > ValidationConstants.MAX_Key) {
1760                         throw new ValueNotAllowedException(new ErrorMessage("errors.hostingredirector.TooLong"));
1761                 }
1762                 boolean checkRef = false;
1763                 try {
1764                         checkRef = config.getBoolean(Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY, false);
1765                 } catch (Exception ex) {
1766                         log.warn("Error caught reading " + Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY + " from config file", ex);
1767                 }
1768                 if (checkRef) {
1769                         //TODO check the spec to confirm this is logically correct
1770             /*Object obj = em.find(org.apache.juddi.model.BindingTemplate.class, hostingRedirector.getBindingKey());
1771                          if (obj == null) {
1772                          throw new ValueNotAllowedException(new ErrorMessage("errors.hostingredirector.keynotexist"));
1773                          }*/
1774                 }
1775 
1776         }
1777 
1778         private void validateNameLength(String value) throws ValueNotAllowedException {
1779                 if (value == null || value.length() == 0) {
1780                         throw new ValueNotAllowedException(new ErrorMessage("errors.names.NoInput"));
1781                 }
1782                 if (value.length() > ValidationConstants.MAX_name) {
1783                         throw new ValueNotAllowedException(new ErrorMessage("errors.names.TooLong"));
1784                 }
1785 
1786         }
1787 
1788         private void validateSortCode(String value) throws ValueNotAllowedException {
1789                 if (value != null && value.length() > ValidationConstants.MAX_sortCode) {
1790                         throw new ValueNotAllowedException(new ErrorMessage("errors.sortCode.TooLong"));
1791                 }
1792         }
1793 
1794         private void validateAddressLines(List<AddressLine> addressLine, Configuration config) throws ValueNotAllowedException {
1795                 if (log.isDebugEnabled()) {
1796                         log.debug("validateAddressLines");
1797                 }
1798                 if (addressLine != null) {
1799                         for (int i = 0; i < addressLine.size(); i++) {
1800                                 validateKeyName(addressLine.get(i).getKeyName());
1801                                 verifyTModelKeyExistsAndChecked(addressLine.get(i).getKeyName(), config);
1802 
1803                                 validateKeyValue(addressLine.get(i).getKeyValue());
1804                                 if (addressLine.get(i).getValue() == null || addressLine.get(i).getValue().length() == 0) {
1805                                         throw new ValueNotAllowedException(new ErrorMessage("errors.addressline.noinput"));
1806                                 }
1807                                 if (addressLine.get(i).getValue().length() > ValidationConstants.MAX_addressLine) {
1808                                         throw new ValueNotAllowedException(new ErrorMessage("errors.addressline.TooLong"));
1809                                 }
1810                         }
1811                 }
1812         }
1813 
1814         private void validateEmailAddress(List<Email> email) throws ValueNotAllowedException {
1815                 if (email != null) {
1816                         for (int i = 0; i < email.size(); i++) {
1817                                 validateUseType(email.get(i).getUseType());
1818                                 if (email.get(i).getValue() == null || email.get(i).getValue().length() == 0) {
1819                                         throw new ValueNotAllowedException(new ErrorMessage("errors.email.noinput"));
1820                                 }
1821                                 if (email.get(i).getValue().length() > ValidationConstants.MAX_email) {
1822                                         throw new ValueNotAllowedException(new ErrorMessage("errors.email.TooLong"));
1823                                 }
1824                         }
1825                 }
1826         }
1827 
1828         private void validatePhone(List<Phone> phone) throws ValueNotAllowedException {
1829                 if (phone != null) {
1830                         for (int i = 0; i < phone.size(); i++) {
1831                                 validateUseType(phone.get(i).getUseType());
1832                                 if (phone.get(i).getValue() == null
1833                                         || phone.get(i).getValue().length() == 0) {
1834                                         throw new ValueNotAllowedException(new ErrorMessage("errors.phone.noinput"));
1835                                 }
1836                                 if (phone.get(i).getValue().length() > ValidationConstants.MAX_phone) {
1837                                         throw new ValueNotAllowedException(new ErrorMessage("errors.phone.TooLong"));
1838                                 }
1839                         }
1840                 }
1841         }
1842 
1843         private void validateDiscoveryUrlLength(DiscoveryURL url) throws ValueNotAllowedException {
1844                 if (url != null) {
1845                         validateUseType(url.getUseType());
1846                         validateURL(url.getValue());
1847                 }
1848         }
1849 
1850         private void validateKeyValue(String value) throws ValueNotAllowedException {
1851                 if (value != null && value.length() > ValidationConstants.MAX_keyValue) {
1852                         throw new ValueNotAllowedException(new ErrorMessage("errors.keyvalue.TooLong"));
1853                 }
1854         }
1855 
1856         private void validateKeyName(String value) throws ValueNotAllowedException {
1857                 if (value != null && value.length() > ValidationConstants.MAX_keyValue) {
1858                         throw new ValueNotAllowedException(new ErrorMessage("errors.keyname.TooLong"));
1859                 }
1860 
1861         }
1862 
1863         private void validateDescriptions(List<Description> description) throws ValueNotAllowedException {
1864                 for (int i = 0; i < description.size(); i++) {
1865                         if (description.get(i).getValue() == null) {
1866                                 throw new ValueNotAllowedException(new ErrorMessage("errors.contact.EmptyDescription"));
1867                         }
1868 
1869                         validateLang(description.get(i).getLang());
1870                         validateDescription(description.get(i).getValue());
1871                 }
1872         }
1873 
1874         private void validateOverviewURL(OverviewURL overviewURL) throws ValueNotAllowedException {
1875                 if (overviewURL != null) {
1876                         validateUseType(overviewURL.getUseType());
1877                         validateURL(overviewURL.getValue());
1878                 }
1879         }
1880 
1881         private void validateURL(String value) throws ValueNotAllowedException {
1882                 if (value != null && value.length() > ValidationConstants.MAX_overviewURL) {
1883                         throw new ValueNotAllowedException(new ErrorMessage("errors.url.overviewTooLong"));
1884                 }
1885         }
1886 
1887         /**
1888          * Validates that a tmodel key is registered Alex O'Ree
1889          *
1890          * @param tmodelKey
1891          * @param em
1892          * @throws ValueNotAllowedException
1893          * @see org.apache.juddi.config.Install
1894          * @since 3.1.5
1895          */
1896         private boolean verifyTModelKeyExistsAndChecked(String tmodelKey, Configuration config) throws ValueNotAllowedException {
1897                 boolean checked = true;
1898                 if (tmodelKey == null || tmodelKey.length() == 0) {
1899                         return false;
1900                 }
1901                 if (tmodelKey.equalsIgnoreCase("uddi:uddi.org:categorization:types")) {
1902                         return false;
1903                 }
1904                 if (tmodelKey.equalsIgnoreCase("uddi:uddi.org:categorization:nodes")) {
1905                         return false;
1906                 }
1907                 if (tmodelKey.equalsIgnoreCase("uddi:uddi.org:v3_inquiry")) {
1908                         return false;
1909                 }
1910                 if (tmodelKey.equalsIgnoreCase("uddi:uddi.org:v3_publication")) {
1911                         return false;
1912                 }
1913                 if (tmodelKey.equalsIgnoreCase("uddi:uddi.org:v3_security")) {
1914                         return false;
1915                 }
1916                 if (tmodelKey.equalsIgnoreCase("uddi:uddi.org:v3_ownership_transfer")) {
1917                         return false;
1918                 }
1919                 if (tmodelKey.equalsIgnoreCase("uddi:uddi.org:v3_subscription")) {
1920                         return false;
1921                 }
1922                 if (tmodelKey.equalsIgnoreCase("uddi:uddi.org:v3_subscriptionlistener")) {
1923                         return false;
1924                 }
1925 
1926                 if (config == null) {
1927                         log.warn(new ErrorMessage("errors.tmodel.ReferentialIntegrityNullConfig"));
1928                         return false;
1929                 }
1930                 boolean checkRef = false;
1931                 try {
1932                         checkRef = config.getBoolean(Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY, false);
1933                 } catch (Exception ex) {
1934                         log.warn("Error caught reading " + Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY + " from config file", ex);
1935                 }
1936                 if (checkRef) {
1937                         if (log.isDebugEnabled()) {
1938                                 log.debug("verifyTModelKeyExists " + tmodelKey);
1939                         }
1940                         EntityManager em = PersistenceManager.getEntityManager();
1941 
1942                         if (em == null) {
1943                                 //this is normally the Install class firing up
1944                                 log.warn(new ErrorMessage("errors.tmodel.ReferentialIntegrityNullEM"));
1945                         } else {
1946                                 //Collections.sort(buildInTmodels);
1947                                 //if ((buildInTmodels, tmodelKey) == -1)
1948                                 Tmodel modelTModel = null;
1949                                 {
1950                                         EntityTransaction tx = em.getTransaction();
1951                                         try {
1952 
1953                                                 tx.begin();
1954                                                 modelTModel = em.find(org.apache.juddi.model.Tmodel.class, tmodelKey);
1955 
1956                                                 if (modelTModel == null) {
1957                                                         checked = false;
1958                                                 } else {
1959                                                      if (modelTModel.getCategoryBag()!=null)
1960                                                         for (org.apache.juddi.model.KeyedReference ref : modelTModel.getCategoryBag().getKeyedReferences()) {
1961                                                                 if ("uddi-org:types:unchecked".equalsIgnoreCase(ref.getKeyName())) {
1962                                                                         checked = false;
1963                                                                         break;
1964                                                                 }
1965                                                         }
1966                                                 }
1967 
1968                                                 tx.commit();
1969 
1970                                         } finally {
1971                                                 if (tx.isActive()) {
1972                                                         tx.rollback();
1973                                                 }
1974                                                 em.close();
1975                                         }
1976                                         if (modelTModel == null) {
1977                                                 throw new ValueNotAllowedException(new ErrorMessage("errors.tmodel.ReferencedKeyDoesNotExist", tmodelKey));
1978                                         }
1979                                 }
1980                         }
1981                 }
1982                 return checked;
1983         }
1984 
1985         private boolean verifyTModelKeyChecked(Tmodel modelTModel) {
1986                 boolean checked = true;
1987                 if (modelTModel == null) {
1988                         checked = false;
1989                 } else {
1990                         for (org.apache.juddi.model.KeyedReference ref : modelTModel.getCategoryBag().getKeyedReferences()) {
1991                                 if ("uddi-org:types:unchecked".equalsIgnoreCase(ref.getTmodelKeyRef())) {
1992                                         checked = false;
1993                                         break;
1994                                 }
1995                         }
1996                 }
1997                 return checked;
1998         }
1999 
2000         /**
2001          * throws if it doesn't exist, returns it if it does
2002          *
2003          * @param tmodelKey
2004          * @return null, or a TModel object
2005          * @throws ValueNotAllowedException
2006          * @since 3.3
2007          */
2008         private TModel verifyTModelKeyExists(String tmodelKey) throws ValueNotAllowedException, DispositionReportFaultMessage {
2009                 TModel api = null;
2010                 EntityManager em = PersistenceManager.getEntityManager();
2011                 boolean found = false;
2012                 if (em == null) {
2013                         log.warn(new ErrorMessage("errors.tmodel.ReferentialIntegrityNullEM"));
2014                 } else {
2015                         Tmodel modelTModel = null;
2016                         {
2017                                 EntityTransaction tx = em.getTransaction();
2018                                 try {
2019 
2020                                         tx.begin();
2021                                         modelTModel = em.find(org.apache.juddi.model.Tmodel.class, tmodelKey);
2022 
2023                                         if (modelTModel != null) {
2024                                                 found = true;
2025                                                 api = new TModel();
2026                                                 MappingModelToApi.mapTModel(modelTModel, api);
2027                                         }
2028                                         tx.commit();
2029 
2030                                 } finally {
2031                                         if (tx.isActive()) {
2032                                                 tx.rollback();
2033                                         }
2034                                         em.close();
2035                                 }
2036 
2037                         }
2038                 }
2039                 if (!found) {
2040                         throw new ValueNotAllowedException(new ErrorMessage("errors.tmodel.ReferencedKeyDoesNotExist", tmodelKey));
2041                 }
2042                 return api;
2043         }
2044 
2045         private List<String> GetBindingKeysCheckedTModelKeyedReferenceBT(Map<String, TModel> cache, List<BindingTemplate> obj) {
2046                 List<String> ret = new ArrayList<String>();
2047 
2048                 if (obj == null) {
2049                         return ret;
2050                 }
2051                 for (BindingTemplate bt : obj) {
2052                         if (bt.getCategoryBag() != null) {
2053                                 for (int i = 0; i < bt.getCategoryBag().getKeyedReference().size(); i++) {
2054                                         ret.addAll(GetBindingKeysCheckedTModelKeyedReference(cache, bt.getCategoryBag().getKeyedReference().get(i)));
2055                                 }
2056                         }
2057                 }
2058 
2059                 return ret;
2060         }
2061 
2062         private List<String> GetBindingKeysCheckedTModelKeyedReferenceBS(Map<String, TModel> cache, List<BusinessService> obj) {
2063                 List<String> ret = new ArrayList<String>();
2064 
2065                 if (obj == null) {
2066                         return ret;
2067                 }
2068                 for (BusinessService bt : obj) {
2069                         if (bt.getCategoryBag() != null) {
2070                                 for (int i = 0; i < bt.getCategoryBag().getKeyedReference().size(); i++) {
2071                                         ret.addAll(GetBindingKeysCheckedTModelKeyedReference(cache, bt.getCategoryBag().getKeyedReference().get(i)));
2072                                 }
2073                         }
2074                         if (bt.getBindingTemplates() != null) {
2075                                 ret.addAll(GetBindingKeysCheckedTModelKeyedReferenceBT(cache, bt.getBindingTemplates().getBindingTemplate()));
2076                         }
2077                 }
2078 
2079                 return ret;
2080         }
2081 
2082         private List<String> GetBindingKeysCheckedTModelKeyedReferenceBE(Map<String, TModel> cache, List<BusinessEntity> obj) {
2083                 List<String> ret = new ArrayList<String>();
2084 
2085                 if (obj == null) {
2086                         return ret;
2087                 }
2088                 for (BusinessEntity bt : obj) {
2089                         if (bt.getCategoryBag() != null) {
2090                                 for (int i = 0; i < bt.getCategoryBag().getKeyedReference().size(); i++) {
2091                                         ret.addAll(GetBindingKeysCheckedTModelKeyedReference(cache, bt.getCategoryBag().getKeyedReference().get(i)));
2092                                 }
2093                         }
2094                         if (bt.getIdentifierBag() != null) {
2095                                 for (int i = 0; i < bt.getIdentifierBag().getKeyedReference().size(); i++) {
2096                                         ret.addAll(GetBindingKeysCheckedTModelKeyedReference(cache, bt.getIdentifierBag().getKeyedReference().get(i)));
2097                                 }
2098                         }
2099 
2100                         if (bt.getBusinessServices() != null) {
2101                                 ret.addAll(GetBindingKeysCheckedTModelKeyedReferenceBS(cache, bt.getBusinessServices().getBusinessService()));
2102                         }
2103                 }
2104                 return ret;
2105         }
2106 
2107         private List<String> GetBindingKeysCheckedTModelKeyedReferenceTM(Map<String, TModel> cache, List<TModel> obj) {
2108                 List<String> ret = new ArrayList<String>();
2109 
2110                 if (obj == null) {
2111                         return ret;
2112                 }
2113                 for (TModel bt : obj) {
2114                         if (bt.getCategoryBag() != null) {
2115                                 for (int i = 0; i < bt.getCategoryBag().getKeyedReference().size(); i++) {
2116                                         ret.addAll(GetBindingKeysCheckedTModelKeyedReference(cache, bt.getCategoryBag().getKeyedReference().get(i)));
2117                                 }
2118                         }
2119                         if (bt.getIdentifierBag() != null) {
2120                                 for (int i = 0; i < bt.getIdentifierBag().getKeyedReference().size(); i++) {
2121                                         ret.addAll(GetBindingKeysCheckedTModelKeyedReference(cache, bt.getIdentifierBag().getKeyedReference().get(i)));
2122                                 }
2123                         }
2124                 }
2125                 return ret;
2126         }
2127 
2128         /**
2129          * this should return a list of binding keys, only if the referenced kr
2130          * contains is validated by
2131          *
2132          * @param cache
2133          * @param get
2134          * @return
2135          */
2136         private List<String> GetBindingKeysCheckedTModelKeyedReference(Map<String, TModel> cache, KeyedReference get) {
2137                 List<String> ret = new ArrayList<String>();
2138                 TModel ref = null;
2139                 log.debug("looking for is validated by for keyedref " + get.getTModelKey());
2140                 if (cache.containsKey(get.getTModelKey())) {
2141                         ref = cache.get(get.getTModelKey());
2142                 }
2143                 if (ref == null) {
2144                         try {
2145                                 ref = verifyTModelKeyExists(get.getTModelKey());
2146                                 cache.put(get.getTModelKey(), ref);
2147                         } catch (Exception ex) {
2148                                 log.error("unexpected error loading tmodel " + get.getTModelKey(), ex);
2149                         }
2150                 }
2151                 if (ref != null) {
2152 
2153                         ret.addAll(TModelContains(UDDIConstants.IS_VALIDATED_BY, ref));
2154                         ret.addAll(TModelContains(UDDIConstantsV2.IS_VALIDATED_BY, ref));
2155 
2156                 }
2157                 return ret;
2158         }
2159 
2160         /**
2161          * returns all keyvalues from ref.catbag and identbag where the tmodel
2162          * key matches
2163          *
2164          * @param key
2165          * @param ref
2166          * @return
2167          */
2168         private List<String> TModelContains(String key, TModel ref) {
2169 
2170                 if (key == null) {
2171                         return null;
2172                 }
2173                 if (ref == null || ref.getTModelKey()==null) {
2174                         return null;
2175                 }
2176                 log.debug("looking for key=" + key + " from tModel " + ref.getTModelKey());
2177                 List<String> ret = new ArrayList<String>();
2178                 
2179                 if (ref.getCategoryBag() != null) {
2180                         for (int i = 0; i < ref.getCategoryBag().getKeyedReference().size(); i++) {
2181                                 if (ref.getCategoryBag().getKeyedReference().get(i).getTModelKey().equalsIgnoreCase(key)) {
2182                                         log.debug("found reference for key=" + key + " from tModel " + ref.getTModelKey() + " validation endpoint " + ref.getCategoryBag().getKeyedReference().get(i).getKeyValue());
2183                                         ret.add(ref.getCategoryBag().getKeyedReference().get(i).getKeyValue());
2184                                 }
2185                         }
2186                         for (int i = 0; i < ref.getCategoryBag().getKeyedReferenceGroup().size(); i++) {
2187                                 for (int k = 0; k < ref.getCategoryBag().getKeyedReferenceGroup().get(i).getKeyedReference().size(); k++) {
2188                                         if (ref.getCategoryBag().getKeyedReferenceGroup().get(i).getKeyedReference().get(k).getTModelKey().equalsIgnoreCase(key)) {
2189                                                 log.debug("found reference for key=" + key + " from tModel " + ref.getTModelKey() + " validation endpoint " + ref.getCategoryBag().getKeyedReferenceGroup().get(i).getKeyedReference().get(k).getKeyValue());
2190                                                 ret.add(ref.getCategoryBag().getKeyedReferenceGroup().get(i).getKeyedReference().get(k).getKeyValue());
2191                                         }
2192                                 }
2193                         }
2194                 }
2195                 if (ref.getIdentifierBag() != null) {
2196                         for (int i = 0; i < ref.getIdentifierBag().getKeyedReference().size(); i++) {
2197                                 if (ref.getIdentifierBag().getKeyedReference().get(i).getTModelKey().equalsIgnoreCase(key)) {
2198                                         log.debug("found reference for key=" + key + " from tModel " + ref.getTModelKey() + " validation endpoint " + ref.getIdentifierBag().getKeyedReference().get(i).getKeyValue());
2199                                         ret.add(ref.getIdentifierBag().getKeyedReference().get(i).getKeyValue());
2200                                 }
2201                         }
2202                 }
2203                 return ret;
2204         }
2205 
2206         /**
2207          * JUDDI-849 Each addressLine element MAY be adorned with two optional
2208          * descriptive attributes, keyName and keyValue. Both attributes MUST be
2209          * present in each address line if a tModelKey is specified in the
2210          * address structure. When no tModelKey is provided for the address
2211          * structure, the keyName and keyValue attributes have no defined
2212          * meaning.
2213          *
2214          * @param addressLine
2215          */
2216         private void validatedAddressLinesIfKeyDefined(List<AddressLine> addressLine) throws ValueNotAllowedException {
2217                 StringBuilder err = new StringBuilder();
2218                 for (int i = 0; i < addressLine.size(); i++) {
2219 
2220                         if (addressLine.get(i).getKeyName() == null
2221                                 || addressLine.get(i).getKeyName().trim().length() == 0) {
2222                                 err.append("addressLine(").append(i).append(").keyName,");
2223                         }
2224                         if (addressLine.get(i).getKeyValue() == null
2225                                 || addressLine.get(i).getKeyValue().trim().length() == 0) {
2226                                 err.append("addressLine(").append(i).append(").keyValue,");
2227                         }
2228                         if (addressLine.get(i).getValue() == null
2229                                 || addressLine.get(i).getValue().trim().length() == 0) {
2230                                  err.append("addressLine(").append(i).append(").value,");
2231                         }
2232                 }
2233                 if (err.length() > 0) {
2234                         throw new ValueNotAllowedException(new ErrorMessage("E_invalidValueAddressLine", err.toString()));
2235                 }
2236         }
2237 
2238         private void validateCheckedTModelsBT(List<BindingTemplate> bindingTemplate, Configuration config) throws ValueNotAllowedException {
2239 
2240                 boolean checkRef = false;
2241                 try {
2242                         checkRef = config.getBoolean(Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY, false);
2243                 } catch (Exception ex) {
2244                         log.warn("Error caught reading " + Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY + " from config file", ex);
2245                 }
2246 
2247                 if (!checkRef) {
2248                         return;
2249                 }
2250                 Map<String, TModel> cache = new HashMap<String, TModel>();
2251                 List<String> bindings = GetBindingKeysCheckedTModelKeyedReferenceBT(cache, bindingTemplate);
2252 
2253                 if (!bindings.isEmpty()) {
2254                         //get a unique list
2255                         bindings = new ArrayList(new HashSet(bindings));
2256                         for (int i = 0; i < bindings.size(); i++) {
2257                                 //load binding from database
2258                                 EntityManager em = PersistenceManager.getEntityManager();
2259                                 org.apache.juddi.model.BindingTemplate find = em.find(org.apache.juddi.model.BindingTemplate.class, bindings.get(i));
2260                                 if (find != null) {
2261                                         //parse endpoint
2262                                         String url = find.getAccessPointUrl();
2263                                         if (url == null) {
2264                                                 url = find.getHostingRedirector();
2265                                         }
2266                                         if (url != null) {
2267                                                 //call ValidateValuesFromWebService
2268                                                 //optimization for localhost?
2269                                                 ValidateValuesFromWebService.ValidateBinding(Rectify(url, config), bindingTemplate);
2270                                         }
2271 
2272                                 }
2273                         }
2274                 }
2275         }
2276 
2277         private void validateCheckedTModelsBS(List<BusinessService> bizlist, Configuration config) throws ValueNotAllowedException {
2278                 boolean checkRef = false;
2279                 try {
2280                         checkRef = config.getBoolean(Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY, false);
2281                 } catch (Exception ex) {
2282                         log.warn("Error caught reading " + Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY + " from config file", ex);
2283                 }
2284                 if (!checkRef) {
2285                         return;
2286                 }
2287                 Map<String, TModel> cache = new HashMap<String, TModel>();
2288                 List<String> bindings = GetBindingKeysCheckedTModelKeyedReferenceBS(cache, bizlist);
2289 
2290                 if (!bindings.isEmpty()) {
2291                         //get a unique list
2292                         bindings = new ArrayList(new HashSet(bindings));
2293                         for (int i = 0; i < bindings.size(); i++) {
2294                                 //load binding from database
2295                                 EntityManager em = PersistenceManager.getEntityManager();
2296                                 org.apache.juddi.model.BindingTemplate find = em.find(org.apache.juddi.model.BindingTemplate.class, bindings.get(i));
2297                                 if (find != null) {
2298                                         //parse endpoint
2299                                         String url = find.getAccessPointUrl();
2300                                         if (url == null) {
2301                                                 url = find.getHostingRedirector();
2302                                         }
2303                                         if (url != null) {
2304                                                 //call ValidateValuesFromWebService
2305                                                 //optimization for localhost?
2306                                                 ValidateValuesFromWebService.ValidateService(Rectify(url, config), bizlist);
2307                                         }
2308 
2309                                 }
2310                         }
2311                 }
2312         }
2313 
2314         private void validateCheckedTModelsBE(List<BusinessEntity> entity, Configuration config) throws ValueNotAllowedException {
2315                 boolean checkRef = false;
2316                 try {
2317                         checkRef = config.getBoolean(Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY, false);
2318                 } catch (Exception ex) {
2319                         log.warn("Error caught reading " + Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY + " from config file", ex);
2320                 }
2321                 if (!checkRef) {
2322                         return;
2323                 }
2324                 Map<String, TModel> cache = new HashMap<String, TModel>();
2325                 List<String> bindings = GetBindingKeysCheckedTModelKeyedReferenceBE(cache, entity);
2326 
2327                 if (!bindings.isEmpty()) {
2328                         //get a unique list
2329                         bindings = new ArrayList(new HashSet(bindings));
2330                         for (int i = 0; i < bindings.size(); i++) {
2331                                 //load binding from database
2332                                 EntityManager em = PersistenceManager.getEntityManager();
2333                                 org.apache.juddi.model.BindingTemplate find = em.find(org.apache.juddi.model.BindingTemplate.class, bindings.get(i));
2334                                 if (find != null) {
2335                                         //parse endpoint
2336                                         String url = find.getAccessPointUrl();
2337                                         if (url == null) {
2338                                                 url = find.getHostingRedirector();
2339                                         }
2340                                         if (url != null) {
2341                                                 //call ValidateValuesFromWebService
2342                                                 //optimization for localhost?
2343                                                 ValidateValuesFromWebService.ValidateBusiness(Rectify(url, config), entity);
2344                                         }
2345 
2346                                 }
2347                         }
2348                 }
2349         }
2350 
2351         private void validateCheckedTModelsTM(List<TModel> entity, Configuration config) throws ValueNotAllowedException {
2352                 boolean checkRef = false;
2353                 try {
2354                         checkRef = config.getBoolean(Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY, false);
2355                 } catch (Exception ex) {
2356                         log.warn("Error caught reading " + Property.JUDDI_ENFORCE_REFERENTIAL_INTEGRITY + " from config file", ex);
2357                 }
2358                 if (!checkRef) {
2359                         return;
2360                 }
2361                 Map<String, TModel> cache = new HashMap<String, TModel>();
2362                 List<String> bindings = GetBindingKeysCheckedTModelKeyedReferenceTM(cache, entity);
2363 
2364                 if (!bindings.isEmpty()) {
2365                         //get a unique list
2366                         bindings = new ArrayList(new HashSet(bindings));
2367                         for (int i = 0; i < bindings.size(); i++) {
2368                                 //load binding from database
2369                                 EntityManager em = PersistenceManager.getEntityManager();
2370                                 org.apache.juddi.model.BindingTemplate find = em.find(org.apache.juddi.model.BindingTemplate.class, bindings.get(i));
2371                                 if (find != null) {
2372                                         //parse endpoint
2373                                         String url = find.getAccessPointUrl();
2374                                         if (url == null) {
2375                                                 url = find.getHostingRedirector();
2376                                         }
2377                                         if (url != null) {
2378                                                 log.debug("attempting vsv from " + url);
2379                                                 //call ValidateValuesFromWebService
2380                                                 //optimization for localhost?
2381                                                 ValidateValuesFromWebService.ValidateTModel(Rectify(url, config), entity);
2382                                         }
2383 
2384                                 }
2385                         }
2386                 }
2387         }
2388 
2389         private String Rectify(String url, Configuration config) {
2390                 //${juddi.server.baseurl}
2391                 Properties p = new Properties();
2392                 p.put("juddi.server.baseurl", config.getString("juddi.server.baseurl", Property.DEFAULT_BASE_URL));
2393 
2394                 return TokenResolver.replaceTokens(url, p);
2395         }
2396 
2397         public void validateDeleteNode(EntityManager em, DeleteNode nodeID, ReplicationConfiguration cfg) throws DispositionReportFaultMessage {
2398                 if (nodeID == null) {
2399                         throw new InvalidKeyPassedException(new ErrorMessage("errors.deleteClerk.NoInput"));
2400                 }
2401                 if (!((Publisher) publisher).isAdmin()) {
2402                         throw new UserMismatchException(new ErrorMessage("errors.deletepublisher.AdminReqd"));
2403                 }
2404                 if (nodeID.getNodeID() == null || nodeID.getNodeID().trim().equalsIgnoreCase("")) {
2405                         throw new InvalidKeyPassedException(new ErrorMessage("errors.deleteNode.NoInput"));
2406                 }
2407                 //get the latest replication config
2408                 if (cfg != null) {
2409                         if (cfg.getCommunicationGraph() != null) {
2410                                 for (String node : cfg.getCommunicationGraph().getNode()) {
2411                                         if (node.equals(nodeID.getNodeID())) {
2412                                                 throw new InvalidKeyPassedException(new ErrorMessage("errors.deleteNode.InReplicationConfig", nodeID.getNodeID()));
2413                                         }
2414                                 }
2415                                 for (int i = 0; i < cfg.getCommunicationGraph().getEdge().size(); i++) {
2416                                         if (nodeID.getNodeID().equals(cfg.getCommunicationGraph().getEdge().get(i).getMessageReceiver())) {
2417                                                 throw new InvalidKeyPassedException(new ErrorMessage("errors.deleteNode.InReplicationConfig", nodeID.getNodeID()));
2418                                         }
2419                                         if (nodeID.getNodeID().equals(cfg.getCommunicationGraph().getEdge().get(i).getMessageSender())) {
2420                                                 throw new InvalidKeyPassedException(new ErrorMessage("errors.deleteNode.InReplicationConfig", nodeID.getNodeID()));
2421                                         }
2422 
2423                                 }
2424                         }
2425                 }
2426 
2427         }
2428 
2429         public void validateDeleteClerk(EntityManager em, DeleteClerk clerkID) throws DispositionReportFaultMessage {
2430                 if (clerkID == null) {
2431                         throw new InvalidKeyPassedException(new ErrorMessage("errors.deleteClerk.NoInput"));
2432                 }
2433                 if (!((Publisher) publisher).isAdmin()) {
2434                         throw new UserMismatchException(new ErrorMessage("errors.deletepublisher.AdminReqd"));
2435                 }
2436                 if (clerkID.getClerkID() == null || clerkID.getClerkID().trim().equalsIgnoreCase("")) {
2437                         throw new InvalidKeyPassedException(new ErrorMessage("errors.deleteClerk.NoInput"));
2438                 }
2439 
2440         }
2441 
2442         public void validateGetAllNodes() throws DispositionReportFaultMessage {
2443                 if (!((Publisher) publisher).isAdmin()) {
2444                         throw new UserMismatchException(new ErrorMessage("errors.deletepublisher.AdminReqd"));
2445                 }
2446         }
2447 
2448        private org.apache.juddi.v3.client.cryptor.DigSigUtil ds = null;
2449 
2450         private synchronized void initDigSig(Configuration config) {
2451                 if (ds == null) {
2452                         
2453                         Properties p = new Properties();
2454                         /**
2455                          * <trustStorePath>truststore.jks</trustStorePath>
2456                          * <trustStoreType>JKS</trustStoreType>
2457                          * <trustStorePassword
2458                          * isPasswordEncrypted="false"
2459                          * cryptoProvider="org.apache.juddi.v3.client.crypto.AES128Cryptor">password</trustStorePassword>
2460                          *
2461                          * <checkTimestamps>true</checkTimestamps>
2462                          * <checkTrust>true</checkTrust>
2463                          * <checkRevocationCRL>true</checkRevocationCRL>
2464                          */
2465                         p.put(DigSigUtil.TRUSTSTORE_FILE, config.getString(Property.JUDDI_REJECT_ENTITIES_WITH_INVALID_SIG_PREFIX + "trustStorePath", ""));
2466                         p.put(DigSigUtil.TRUSTSTORE_FILETYPE, config.getString(Property.JUDDI_REJECT_ENTITIES_WITH_INVALID_SIG_PREFIX + "trustStoreType", ""));
2467 
2468                         String enc = config.getString(Property.JUDDI_REJECT_ENTITIES_WITH_INVALID_SIG_PREFIX + "trustStorePassword", "");
2469                         if (config.getBoolean(Property.JUDDI_REJECT_ENTITIES_WITH_INVALID_SIG_PREFIX + "trustStorePassword[@isPasswordEncrypted]", false)) {
2470                                 log.debug("trust password is encrypted, decrypting...");
2471                                 
2472                                 String prov = config.getString(Property.JUDDI_REJECT_ENTITIES_WITH_INVALID_SIG_PREFIX + "trustStorePassword[@cryptoProvider]", "");
2473                                 try {
2474                                         p.setProperty(DigSigUtil.TRUSTSTORE_FILE_PASSWORD, CryptorFactory.getCryptor(prov).decrypt(enc));
2475                                 } catch (Exception ex) {
2476                                         log.warn("unable to decrypt trust store password " + ex.getMessage());
2477                                         log.debug("unable to decrypt trust store password " + ex.getMessage(), ex);
2478                                 }
2479 
2480                         } else if (!"".equals(enc)){
2481                                 log.warn("Hey, you should consider encrypting your trust store password!");
2482                                 p.setProperty(DigSigUtil.TRUSTSTORE_FILE_PASSWORD, enc);
2483                         }
2484 
2485                         p.put(DigSigUtil.CHECK_REVOCATION_STATUS_CRL, config.getString(Property.JUDDI_REJECT_ENTITIES_WITH_INVALID_SIG_PREFIX + "checkRevocationCRL", "true"));
2486                         p.put(DigSigUtil.CHECK_TRUST_CHAIN, config.getString(Property.JUDDI_REJECT_ENTITIES_WITH_INVALID_SIG_PREFIX + "checkTrust", "true"));
2487                         p.put(DigSigUtil.CHECK_TIMESTAMPS, config.getString(Property.JUDDI_REJECT_ENTITIES_WITH_INVALID_SIG_PREFIX + "checkTimestamps", "true"));
2488 
2489                         try {
2490                                 ds = new DigSigUtil(p);
2491                         } catch (CertificateException ex) {
2492                                 log.error("", ex);
2493                         }
2494                         //System.out.println("loaded from " + AppConfig.getConfigFileURL());
2495                         //p.list(System.out);
2496                 }
2497         }
2498 
2499         private void validateSignaturesBinding(BindingTemplate bindingTemplate, Configuration config) throws FatalErrorException {
2500                 boolean shouldcheck = config.getBoolean(Property.JUDDI_REJECT_ENTITIES_WITH_INVALID_SIG_ENABLE, false);
2501                 initDigSig(config);
2502                 if (shouldcheck && !bindingTemplate.getSignature().isEmpty() && ds != null) {
2503                         AtomicReference<String> outmsg = new AtomicReference<String>();
2504                         boolean ok = ds.verifySignedUddiEntity(bindingTemplate, outmsg);
2505                         if (!ok) {
2506                                 throw new FatalErrorException(new ErrorMessage("errors.digitalsignature.validationfailure", bindingTemplate.getBindingKey() + " " + outmsg.get()));
2507                         }
2508 
2509                 }
2510         }
2511 
2512         private void validateSignaturesService(BusinessService businessService, Configuration config) throws FatalErrorException {
2513                 boolean shouldcheck = config.getBoolean(Property.JUDDI_REJECT_ENTITIES_WITH_INVALID_SIG_ENABLE, false);
2514                 initDigSig(config);
2515                 if (shouldcheck && !businessService.getSignature().isEmpty() && ds != null) {
2516                         AtomicReference<String> outmsg = new AtomicReference<String>();
2517                         boolean ok = ds.verifySignedUddiEntity(businessService, outmsg);
2518                         if (!ok) {
2519                                 throw new FatalErrorException(new ErrorMessage("errors.digitalsignature.validationfailure", businessService.getServiceKey() + " " + outmsg.get()));
2520                         }
2521 
2522                 }
2523         }
2524 
2525         private void validateSignaturesTModel(TModel tModel, Configuration config) throws FatalErrorException {
2526                 boolean shouldcheck = config.getBoolean(Property.JUDDI_REJECT_ENTITIES_WITH_INVALID_SIG_ENABLE, false);
2527                 initDigSig(config);
2528                 if (shouldcheck && !tModel.getSignature().isEmpty() && ds != null) {
2529                         AtomicReference<String> outmsg = new AtomicReference<String>();
2530                         boolean ok = ds.verifySignedUddiEntity(tModel, outmsg);
2531                         if (!ok) {
2532                                 throw new FatalErrorException(new ErrorMessage("errors.digitalsignature.validationfailure", tModel.getTModelKey() + " " + outmsg.get()));
2533                         }
2534 
2535                 }
2536         }
2537 
2538         private void validateSignaturesBusiness(BusinessEntity businessEntity, Configuration config) throws FatalErrorException {
2539                 boolean shouldcheck = config.getBoolean(Property.JUDDI_REJECT_ENTITIES_WITH_INVALID_SIG_ENABLE, false);
2540                 initDigSig(config);
2541                 if (shouldcheck && !businessEntity.getSignature().isEmpty() && ds != null) {
2542                         AtomicReference<String> outmsg = new AtomicReference<String>();
2543                         boolean ok = ds.verifySignedUddiEntity(businessEntity, outmsg);
2544                         if (!ok) {
2545                                 throw new FatalErrorException(new ErrorMessage("errors.digitalsignature.validationfailure", businessEntity.getBusinessKey() + " " + outmsg.get()));
2546                         }
2547 
2548                 }
2549         }
2550 
2551 }