Search in sources :

Example 1 with Authorizer

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()));
}
Also used : Response(javax.ws.rs.core.Response) Authorizer(org.batfish.coordinator.authorizer.Authorizer) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 2 with Authorizer

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);
}
Also used : Authorizer(org.batfish.coordinator.authorizer.Authorizer) FileAuthorizer(org.batfish.coordinator.authorizer.FileAuthorizer) DbAuthorizer(org.batfish.coordinator.authorizer.DbAuthorizer) NoneAuthorizer(org.batfish.coordinator.authorizer.NoneAuthorizer) Settings(org.batfish.coordinator.config.Settings)

Aggregations

Authorizer (org.batfish.coordinator.authorizer.Authorizer)2 Response (javax.ws.rs.core.Response)1 DbAuthorizer (org.batfish.coordinator.authorizer.DbAuthorizer)1 FileAuthorizer (org.batfish.coordinator.authorizer.FileAuthorizer)1 NoneAuthorizer (org.batfish.coordinator.authorizer.NoneAuthorizer)1 Settings (org.batfish.coordinator.config.Settings)1 JerseyTest (org.glassfish.jersey.test.JerseyTest)1 Test (org.junit.Test)1