Skip to content
Permalink
Browse files
JUDDI-256 adding basic unit test for transfer to/from publishers on t…
…he same node

JUDDI-272 adding hooks for node to node transfer
  • Loading branch information
spyhunter99 committed Dec 23, 2014
1 parent 47d1280 commit 70903c27054e1ebb8c064cc3a1afce9842c07cb5
Show file tree
Hide file tree
Showing 8 changed files with 480 additions and 123 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

@@ -97,20 +97,19 @@ public void populateKeyGeneratorKeys(EntityManager em) {
* @return true/false
*/
public boolean isOwner(UddiEntity entity){
boolean ret = false;
try {
AppConfig instance = AppConfig.getInstance();

if (entity != null) {
if (entity.getAuthorizedName().equals(getAuthorizedName())
&& entity.getNodeId().equals((AppConfig.getConfiguration().getString(Property.JUDDI_NODE_ID)))) {
ret = true;
return true;
}
}
} catch (Exception ex) {
logger.log(Level.WARNING, "Error caught determining node id! Defaulting to access denied", ex);
}
return ret;
return false;
}


@@ -17,7 +17,6 @@
package org.apache.juddi.replication;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Queue;
import java.util.Timer;
@@ -40,7 +39,6 @@
import org.apache.juddi.model.ReplicationConfiguration;
import org.apache.juddi.v3.client.UDDIService;
import org.uddi.repl_v3.ChangeRecordIDType;
import org.uddi.repl_v3.CommunicationGraph;
import org.uddi.repl_v3.HighWaterMarkVectorType;
import org.uddi.repl_v3.NotifyChangeRecordsAvailable;
import org.uddi.repl_v3.Operator;
@@ -123,9 +123,9 @@ public void validateGetTransferToken(EntityManager em, KeyBag keyBag) throws Dis
throw new UserMismatchException(new ErrorMessage("errors.usermismatch.InvalidOwner", key));

// Creating parameters for key-checking query
DynamicQuery.Parameter param = new DynamicQuery.Parameter("UPPER(ttk.entityKey)",
key.toUpperCase(),
DynamicQuery.PREDICATE_EQUALS);
DynamicQuery.Parameter param = new DynamicQuery.Parameter("UPPER(ttk.entityKey)",
key.toUpperCase(),
DynamicQuery.PREDICATE_EQUALS);
params.add(param);

}
@@ -142,8 +142,16 @@ public void validateGetTransferToken(EntityManager em, KeyBag keyBag) throws Dis

}

public void validateTransferEntities(EntityManager em, TransferEntities body) throws DispositionReportFaultMessage {

/**
* returns true if all items to be transfered are within this node (no node to node transfers)
* @param em
* @param body
* @return
* @throws DispositionReportFaultMessage
*/
public boolean validateTransferEntities(EntityManager em, TransferEntities body) throws DispositionReportFaultMessage {

boolean ret = true;
// No null input
if (body == null)
throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
@@ -193,10 +201,11 @@ public void validateTransferEntities(EntityManager em, TransferEntities body) th
UddiEntity uddiEntity = em.find(UddiEntity.class, key);
if (uddiEntity == null)
throw new InvalidKeyPassedException(new ErrorMessage("errors.invalidkey.EntityNotFound", key));

if (!uddiEntity.getNodeId().equalsIgnoreCase(nodeID))
ret = false;
count++;
}

return ret;
}

}
@@ -26,11 +26,13 @@
import org.apache.juddi.v3.error.FatalErrorException;
import org.apache.juddi.v3.error.InvalidValueException;
import org.apache.juddi.v3.error.ValueNotAllowedException;
import org.uddi.custody_v3.TransferEntities;
import org.uddi.repl_v3.CommunicationGraph.Edge;
import org.uddi.repl_v3.HighWaterMarkVectorType;
import org.uddi.repl_v3.NotifyChangeRecordsAvailable;
import org.uddi.repl_v3.Operator;
import org.uddi.repl_v3.ReplicationConfiguration;
import org.uddi.repl_v3.TransferCustody;
import org.uddi.v3_service.DispositionReportFaultMessage;

/**
@@ -177,4 +179,32 @@ private boolean Contains(List<Operator> operator, String s) {
return false;
}

public void validateTransfer(EntityManager em, TransferCustody body) throws DispositionReportFaultMessage {

if (body == null)
throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
if (body.getTransferToken()==null)
throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
if (body.getKeyBag()==null)
throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
if (body.getTransferOperationalInfo()==null)
throw new FatalErrorException(new ErrorMessage("errors.NullInput"));

if (body.getTransferOperationalInfo().getNodeID()==null)
throw new FatalErrorException(new ErrorMessage("errors.NullInput"));
if (body.getTransferOperationalInfo().getAuthorizedName()==null)
throw new FatalErrorException(new ErrorMessage("errors.NullInput"));


//confirm i own the records in question
//confirm i issued the transfer token

TransferEntities x = new TransferEntities();
x.setKeyBag(body.getKeyBag());
x.setTransferToken(body.getTransferToken());
new ValidateCustodyTransfer(null).validateTransferEntities(em, x);


}

}
@@ -52,6 +52,7 @@ E_tokenAlreadyExists=Key already exists in transfer request
E_tooManyOptions=Too many options
E_transferAborted=Transfer Aborted
E_transferNotAllowed=The transfer request is not allowed
E_transferNotAllowedUnknownNode=The transfer request is not allowed because the destination node is not in the replication config.
E_unknownUser=The user ID and password pair passed in a get_authToken API is not known to the UDDI node or is not valid.
E_unrecognizedVersion=The value of the namespace attribute is unsupported by the node being queried.
E_unsupported=Unsupported feature or API.
@@ -0,0 +1,129 @@
/*
* Copyright 2014 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.juddi.api.impl;

import java.rmi.RemoteException;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.ws.Holder;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.juddi.Registry;
import org.apache.juddi.v3.tck.TckBusiness;
import org.apache.juddi.v3.tck.TckFindEntity;
import org.apache.juddi.v3.tck.TckPublisher;
import org.apache.juddi.v3.tck.TckSecurity;
import org.apache.juddi.v3.tck.TckTModel;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.uddi.api_v3.BusinessDetail;
import org.uddi.api_v3.GetBusinessDetail;
import org.uddi.api_v3.GetOperationalInfo;
import org.uddi.api_v3.OperationalInfos;
import org.uddi.custody_v3.KeyBag;
import org.uddi.custody_v3.TransferEntities;
import org.uddi.custody_v3.TransferToken;
import org.uddi.v3_service.UDDISecurityPortType;

/**
*
* @author alex
*/
public class API_170_CustodyTransferTest {

private static Log logger = LogFactory.getLog(API_030_BusinessEntityTest.class);
private static API_010_PublisherTest api010 = new API_010_PublisherTest();
private static TckTModel tckTModel = new TckTModel(new UDDIPublicationImpl(), new UDDIInquiryImpl());
private static TckBusiness tckBusiness = new TckBusiness(new UDDIPublicationImpl(), new UDDIInquiryImpl());
private static TckFindEntity tckFindEntity = new TckFindEntity(new UDDIInquiryImpl());
private static String authInfoMary = null;
private static String authInfoSam = null;

@BeforeClass
public static void setup() throws ConfigurationException {
Registry.start();
logger.info("API_030_BusinessEntityTest");
logger.debug("Getting auth token..");
try {
api010.saveJoePublisher();
api010.saveSamSyndicator();
UDDISecurityPortType security = new UDDISecurityImpl();
authInfoMary = TckSecurity.getAuthToken(security, TckPublisher.getMaryPublisherId(), TckPublisher.getMaryPassword());
authInfoSam = TckSecurity.getAuthToken(security, TckPublisher.getSamPublisherId(), TckPublisher.getSamPassword());
String authInfoUDDI = TckSecurity.getAuthToken(security, TckPublisher.getUDDIPublisherId(), TckPublisher.getUDDIPassword());
tckTModel.saveUDDIPublisherTmodel(authInfoUDDI);
tckTModel.saveTModels(authInfoUDDI, TckTModel.TMODELS_XML);
tckTModel.saveMaryPublisherTmodel(authInfoMary);
tckTModel.saveSamSyndicatorTmodel(authInfoSam);
} catch (RemoteException e) {
logger.error(e.getMessage(), e);
Assert.fail("Could not obtain authInfo token.");
}
}

@AfterClass
public static void stopRegistry() throws ConfigurationException {
tckTModel.deleteCreatedTModels(authInfoMary);
tckTModel.deleteCreatedTModels(authInfoSam);
Registry.stop();
}


@Test
public void testTransfer() throws Exception{
UDDIInquiryImpl inquire = new UDDIInquiryImpl();


//save sam's business
tckBusiness.saveSamSyndicatorBusiness(authInfoSam);

//save mary's business
tckBusiness.saveMaryPublisherBusiness(authInfoMary);

GetOperationalInfo goi = new GetOperationalInfo();
goi.getEntityKey().add(TckBusiness.SAM_BUSINESS_KEY);

OperationalInfos operationalInfo = inquire.getOperationalInfo(goi);
Assert.assertEquals(operationalInfo.getOperationalInfo().get(0).getAuthorizedName(), TckPublisher.getSamPublisherId());

//sam wants to transfer to mary, get a token
UDDICustodyTransferImpl custody = new UDDICustodyTransferImpl();
KeyBag kb = new KeyBag();
kb.getKey().add(TckBusiness.SAM_BUSINESS_KEY);
Holder<String> node = new Holder<String>();
Holder<XMLGregorianCalendar> expires = new Holder<XMLGregorianCalendar>();
Holder<byte[]> token = new Holder<byte[]>();
custody.getTransferToken(authInfoSam,kb , node, expires, token);

//use mary's account to accept and transfer
TransferEntities te = new TransferEntities();
te.setAuthInfo(authInfoMary);
te.setKeyBag(kb);
te.setTransferToken(new TransferToken());
te.getTransferToken().setExpirationTime(expires.value);
te.getTransferToken().setNodeID(node.value);
te.getTransferToken().setOpaqueToken(token.value);
custody.transferEntities(te);



operationalInfo = inquire.getOperationalInfo(goi);

Assert.assertEquals(operationalInfo.getOperationalInfo().get(0).getAuthorizedName(), TckPublisher.getMaryPublisherId());
}
}

0 comments on commit 70903c2

Please sign in to comment.