Search in sources :

Example 36 with SystemServiceId

use of io.cdap.cdap.proto.id.SystemServiceId in project cdap by cdapio.

the class MonitorHandlerAuthorizationTest method testResetServiceLogLevelsAuthorization.

@Test
public void testResetServiceLogLevelsAuthorization() throws Exception {
    SystemServiceId systemServiceId = new SystemServiceId(SERVICE_NAME);
    MonitorHandler handler = createMonitorHandler(Authorizable.fromEntityId(systemServiceId), Arrays.asList(StandardPermission.UPDATE));
    List<String> bodyArgs = new ArrayList<>();
    DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "system/services/service/resetloglevels", Unpooled.copiedBuffer(GSON.toJson(bodyArgs), StandardCharsets.UTF_8));
    HttpResponder responder = mock(HttpResponder.class);
    AuthenticationTestContext.actAsPrincipal(UNPRIVILEGED_PRINCIPAL);
    try {
        handler.resetServiceLogLevels(request, responder, SERVICE_NAME);
    } catch (UnauthorizedException e) {
    // expected
    }
    AuthenticationTestContext.actAsPrincipal(MASTER_PRINCIPAL);
    handler.resetServiceLogLevels(request, responder, SERVICE_NAME);
}
Also used : SystemServiceId(io.cdap.cdap.proto.id.SystemServiceId) HttpResponder(io.cdap.http.HttpResponder) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) MonitorHandler(io.cdap.cdap.gateway.handlers.MonitorHandler) ArrayList(java.util.ArrayList) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) Test(org.junit.Test)

Example 37 with SystemServiceId

use of io.cdap.cdap.proto.id.SystemServiceId in project cdap by cdapio.

the class MonitorHandlerAuthorizationTest method testGetLatestRestartServiceInstanceStatusAuthorization.

@Test
public void testGetLatestRestartServiceInstanceStatusAuthorization() throws Exception {
    SystemServiceId systemServiceId = new SystemServiceId(SERVICE_NAME);
    MonitorHandler handler = createMonitorHandler(Authorizable.fromEntityId(systemServiceId), Arrays.asList(StandardPermission.GET));
    HttpRequest request = mock(HttpRequest.class);
    HttpResponder responder = mock(HttpResponder.class);
    AuthenticationTestContext.actAsPrincipal(UNPRIVILEGED_PRINCIPAL);
    try {
        handler.getLatestRestartServiceInstanceStatus(request, responder, SERVICE_NAME);
    } catch (UnauthorizedException e) {
    // expected
    }
    AuthenticationTestContext.actAsPrincipal(MASTER_PRINCIPAL);
    handler.getLatestRestartServiceInstanceStatus(request, responder, SERVICE_NAME);
}
Also used : SystemServiceId(io.cdap.cdap.proto.id.SystemServiceId) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) HttpResponder(io.cdap.http.HttpResponder) MonitorHandler(io.cdap.cdap.gateway.handlers.MonitorHandler) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) Test(org.junit.Test)

Example 38 with SystemServiceId

use of io.cdap.cdap.proto.id.SystemServiceId in project cdap by cdapio.

the class MonitorHandlerAuthorizationTest method testSetServiceInstanceAuthorization.

@Test
public void testSetServiceInstanceAuthorization() throws Exception {
    SystemServiceId systemServiceId = new SystemServiceId(SERVICE_NAME);
    MonitorHandler handler = createMonitorHandler(Authorizable.fromEntityId(systemServiceId), Arrays.asList(StandardPermission.UPDATE));
    Instances instances = new Instances(1);
    DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, "system/services/service/instances", Unpooled.copiedBuffer(GSON.toJson(instances), StandardCharsets.UTF_8));
    HttpResponder responder = mock(HttpResponder.class);
    AuthenticationTestContext.actAsPrincipal(UNPRIVILEGED_PRINCIPAL);
    try {
        handler.setServiceInstance(request, responder, SERVICE_NAME);
    } catch (UnauthorizedException e) {
    // expected
    }
    AuthenticationTestContext.actAsPrincipal(MASTER_PRINCIPAL);
    handler.setServiceInstance(request, responder, SERVICE_NAME);
}
Also used : SystemServiceId(io.cdap.cdap.proto.id.SystemServiceId) Instances(io.cdap.cdap.proto.Instances) HttpResponder(io.cdap.http.HttpResponder) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) MonitorHandler(io.cdap.cdap.gateway.handlers.MonitorHandler) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) Test(org.junit.Test)

Aggregations

SystemServiceId (io.cdap.cdap.proto.id.SystemServiceId)38 NotFoundException (io.cdap.cdap.common.NotFoundException)22 Test (org.junit.Test)16 MonitorHandler (io.cdap.cdap.gateway.handlers.MonitorHandler)14 UnauthorizedException (io.cdap.cdap.security.spi.authorization.UnauthorizedException)14 HttpResponder (io.cdap.http.HttpResponder)14 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)14 BadRequestException (io.cdap.cdap.common.BadRequestException)12 ForbiddenException (io.cdap.cdap.common.ForbiddenException)12 MasterServiceManager (io.cdap.cdap.common.twill.MasterServiceManager)12 Path (javax.ws.rs.Path)12 HttpResponse (io.cdap.common.http.HttpResponse)8 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)8 URL (java.net.URL)8 JsonSyntaxException (com.google.gson.JsonSyntaxException)6 ServiceUnavailableException (io.cdap.cdap.common.ServiceUnavailableException)6 GET (javax.ws.rs.GET)6 Instances (io.cdap.cdap.proto.Instances)4 HttpRequest (io.netty.handler.codec.http.HttpRequest)4 PUT (javax.ws.rs.PUT)4