Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to deny service proxy values for places #505

Merged
merged 12 commits into from
Aug 24, 2023
2 changes: 1 addition & 1 deletion src/main/java/emissary/core/HDMobileAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ protected void switchPrimaryPayload(final int i) {
}

/**
* Do work now that we have arrived a the specified place
* Do work now that we have arrived at the specified place
*
* @param place the place we are asking to work for us
* @param payloadListArg list of IBaseDataObject for the place to operate on
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emissary/core/MobileAgent.java
drivenflywheel marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ protected void agentControl(final IServiceProviderPlace currentPlaceArg) {
}

/**
* Do work now that we have arrived a the specified place
* Do work now that we have arrived at the specified place
*
* @param place the place we are asking to work for us
* @param payloadArg the data for the place to operate on
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/emissary/core/constants/Configurations.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Configurations {
public static final String SERVICE_QUALITY = "SERVICE_QUALITY";
public static final String SERVICE_PROXY = "SERVICE_PROXY";
public static final String SERVICE_KEY = "SERVICE_KEY";
public static final String SERVICE_PROXY_DISALLOW = "SERVICE_PROXY_DISALLOW";

/**
* The list of reserved service config keys for service/place creation
Expand All @@ -34,6 +35,7 @@ public class Configurations {
SERVICE_KEY,
SERVICE_NAME,
SERVICE_PROXY,
SERVICE_PROXY_DISALLOW,
SERVICE_QUALITY,
SERVICE_TYPE));

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/emissary/place/IServiceProviderPlace.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,8 @@ public interface IServiceProviderPlace {
*/
MobileAgent getAgent() throws NamespaceException;

/**
* Returns whether form is disallowed
*/
boolean isDisallowed(String s);
}
17 changes: 16 additions & 1 deletion src/main/java/emissary/place/ServiceProviderPlace.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import static emissary.core.constants.Configurations.SERVICE_KEY;
import static emissary.core.constants.Configurations.SERVICE_NAME;
import static emissary.core.constants.Configurations.SERVICE_PROXY;
import static emissary.core.constants.Configurations.SERVICE_PROXY_DISALLOW;
import static emissary.core.constants.Configurations.SERVICE_QUALITY;
import static emissary.core.constants.Configurations.SERVICE_TYPE;

Expand Down Expand Up @@ -86,6 +87,11 @@ public abstract class ServiceProviderPlace implements emissary.place.IServicePro
*/
protected List<String> keys = new ArrayList<>();

/**
* List of disallowed places in SERVICE_PROXY_DISALLOW
*/
protected List<String> disallowList = new ArrayList<>();

// Items that are going to be deprecated, but here now to
// make the transition easier, for compatibility
protected String myKey = null;
Expand Down Expand Up @@ -293,7 +299,7 @@ protected void setupPlace(String theDir, String placeLocation) throws IOExceptio
}

/**
* Get a local reference to the directpry.
* Get a local reference to the directory.
*
* @param theDir key for the directory to use, if null will look up default name
* @return true if it worked
Expand Down Expand Up @@ -438,6 +444,11 @@ protected void configureServicePlace(@Nullable String placeLocation) throws IOEx
DirectoryEntry de = new DirectoryEntry(sp, serviceName, serviceType, locationPart, serviceDescription, serviceCost, serviceQuality);
keys.add(de.getFullKey());
}
// pick up the disallowed proxies(save full 4-tuple keys!)
for (String sp : configG.findEntries(SERVICE_PROXY_DISALLOW)) {
DirectoryEntry de = new DirectoryEntry(sp, serviceName, serviceType, locationPart, serviceDescription, serviceCost, serviceQuality);
disallowList.add(de.getDataType());
}
} else {
// May be configured the new way, but warn if there is a mixture of
// null and non-null items using the old-fashioned way. Perhaps the
Expand Down Expand Up @@ -1125,6 +1136,10 @@ protected IBaseDataObject getTLD() {
return null;
}

public boolean isDisallowed(String s) {
return disallowList.contains(s);
}

/**
* This method should return a list of all the parameters that a subclass Place will potentially modify (this includes
* adding, removing, or changing the value of).
Expand Down
30 changes: 30 additions & 0 deletions src/test/java/emissary/place/ServiceProviderPlaceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ class ServiceProviderPlaceTest extends UnitTest {
private static final byte[] configBadKeyData = ("TGT_HOST = \"localhost\"\n" + "TGT_PORT = \"8001\"\n"
+ "SERVICE_KEY = \"TP4.TNAME.http://@{TGT_HOST}:@{TGT_PORT}/TPlaceName$8050\"\n" + "SERVICE_DESCRIPTION = \"bogus\"\n").getBytes();

private static final byte[] configDisallowedData = ("PLACE_NAME = \"PlaceTest\"\n" + "SERVICE_NAME = \"TEST_SERVICE_NAME\"\n"
+ "SERVICE_TYPE = \"ANALYZE\"\n" + "SERVICE_DESCRIPTION = \"test place with disallowed list\"\n" + "SERVICE_COST = 60\n"
+ "SERVICE_QUALITY = 90\n" + "SERVICE_PROXY = \"TEST_SERVICE_PROXY\"\n" + "SERVICE_PROXY = \"TEST_SERVICE_PROXY2\"\n"
+ "SERVICE_PROXY_DISALLOW = \"TEST_SERVICE_PROXY\"\n" + "SERVICE_PROXY_DISALLOW = \"TEST_SERVICE_PROXY3\"\n"
+ "SERVICE_PROXY_DISALLOW != \"TEST_SERVICE_PROXY3\"\n").getBytes();

private static final byte[] configDisallowedData2 = ("PLACE_NAME = \"PlaceTest\"\n" + "SERVICE_NAME = \"TEST_SERVICE_NAME\"\n"
+ "SERVICE_TYPE = \"ANALYZE\"\n" + "SERVICE_DESCRIPTION = \"test place with disallowed list\"\n" + "SERVICE_COST = 60\n"
+ "SERVICE_QUALITY = 90\n" + "SERVICE_PROXY = \"TEST_SERVICE_PROXY\"\n"
+ "SERVICE_PROXY_DISALLOW = \"TEST_SERVICE_PROXY\"\n" + "SERVICE_PROXY_DISALLOW != \"*\"\n").getBytes();

String CFGDIR = System.getProperty(ConfigUtil.CONFIG_DIR_PROPERTY);

@Override
Expand Down Expand Up @@ -531,6 +542,25 @@ void testBogusKeyRemoval() {
}
}

@Test
void testDisallowedServiceProxy() {
try {
InputStream config = new ByteArrayInputStream(configDisallowedData);
IServiceProviderPlace p = new PlaceTest(config);
assertEquals("PlaceTest", p.getPlaceName(), "Configured place name");
assertTrue(p.isDisallowed("TEST_SERVICE_PROXY"), "TEST_SERVICE_PROXY should be disallowed");
assertTrue(!p.isDisallowed("TEST_SERVICE_PROXY2"), "TEST_SERVICE_PROXY2 should be allowed");
assertTrue(!p.isDisallowed("TEST_SERVICE_PROXY3"), "TEST_SERVICE_PROXY3 should be allowed");

InputStream config2 = new ByteArrayInputStream(configDisallowedData2);
IServiceProviderPlace p2 = new PlaceTest(config2);
assertTrue(!p2.isDisallowed("TEST_SERVICE_PROXY"), "TEST_SERVICE_PROXY should be allowed");
assertTrue(!p2.isDisallowed("TEST_SERVICE_PROXY2"), "TEST_SERVICE_PROXY2 should be allowed");
} catch (IOException iox) {
fail("Place should have configured with SERVICE_KEY", iox);
}
}

private static final class PlaceTest extends ServiceProviderPlace {

public PlaceTest() throws IOException {
Expand Down