use of org.batfish.coordinator.authorizer.Authorizer in project batfish by batfish.
the class WorkMgrServiceV2Test method correctApiKeyHeader.
/**
* Test that the ApiKey is extracted from the correct header
*/
@Test
public void correctApiKeyHeader() {
// Set up by making a call to authorize container
String containerName = "someContainer";
String myKey = "ApiKey";
Authorizer auth = new MapAuthorizer();
Main.setAuthorizer(auth);
auth.authorizeContainer(myKey, containerName);
Main.getWorkMgr().initContainer(containerName, null);
// Test that subsequent calls return 200 with correct API key
Response resp = getContainersTarget().path(containerName).request().header(CoordConstsV2.HTTP_HEADER_BATFISH_APIKEY, myKey).get();
assertThat(resp.getStatus(), equalTo(OK.getStatusCode()));
// Test that subsequent calls return 403 forbidden with wrong API key
resp = getContainersTarget().path(containerName).request().header(CoordConstsV2.HTTP_HEADER_BATFISH_APIKEY, "wrongKey").get();
assertThat(resp.getStatus(), equalTo(FORBIDDEN.getStatusCode()));
}
use of org.batfish.coordinator.authorizer.Authorizer in project batfish by batfish.
the class Main method initAuthorizer.
static void initAuthorizer() throws Exception {
Settings settings = getSettings();
Authorizer.Type type = settings.getAuthorizationType();
switch(type) {
case none:
_authorizer = NoneAuthorizer.INSTANCE;
break;
case file:
_authorizer = FileAuthorizer.createFromSettings(settings);
break;
case database:
_authorizer = DbAuthorizer.createFromSettings(settings);
break;
default:
System.err.print("org.batfish.coordinator: Initialization failed. Unsupported authorizer type " + type);
System.exit(1);
}
getLogger().infof("Using authorizer %s\n", _authorizer);
}
Aggregations