Search in sources :

Example 1 with TechnicalManagementException

use of io.gravitee.am.service.exception.TechnicalManagementException in project gravitee-access-management by gravitee-io.

the class BotDetectionHandler method handle.

@Override
public void handle(RoutingContext routingContext) {
    Client client = routingContext.get(CLIENT_CONTEXT_KEY);
    AccountSettings accountSettings = AccountSettings.getInstance(domain, client);
    if (accountSettings == null || !accountSettings.isUseBotDetection()) {
        routingContext.next();
        return;
    }
    if (StringUtils.isEmpty(accountSettings.getBotDetectionPlugin())) {
        LOGGER.error("Bot Detection enable without plugin identifier for domain '{}' and application '{}'", domain.getId(), client.getId());
        routingContext.fail(INTERNAL_SERVER_ERROR_500, new TechnicalManagementException(DEFAULT_ERROR_MSG));
        return;
    }
    final MultiMap headers = routingContext.request().headers();
    final MultiMap params = routingContext.request().params();
    BotDetectionContext context = new BotDetectionContext(accountSettings.getBotDetectionPlugin(), headers, params);
    botDetectionManager.validate(context).subscribe((isValid) -> {
        if (isValid) {
            LOGGER.debug("No bot detected for domain '{}' and client '{}'", domain.getId(), client.getId());
            routingContext.next();
        } else {
            LOGGER.warn("Bot detected for domain '{}' and client '{}'", domain.getId(), client.getId());
            routingContext.fail(BAD_REQUEST_400, new BotDetectedException(DEFAULT_ERROR_MSG));
        }
    }, (error) -> {
        LOGGER.error("BotDetection failed for domain '{}' and client '{}'", domain.getId(), client.getId(), error);
        routingContext.fail(INTERNAL_SERVER_ERROR_500, new TechnicalManagementException(DEFAULT_ERROR_MSG));
    });
}
Also used : AccountSettings(io.gravitee.am.model.account.AccountSettings) MultiMap(io.vertx.reactivex.core.MultiMap) BotDetectedException(io.gravitee.am.service.exception.BotDetectedException) BotDetectionContext(io.gravitee.am.botdetection.api.BotDetectionContext) Client(io.gravitee.am.model.oidc.Client) TechnicalManagementException(io.gravitee.am.service.exception.TechnicalManagementException)

Example 2 with TechnicalManagementException

use of io.gravitee.am.service.exception.TechnicalManagementException in project gravitee-access-management by gravitee-io.

the class RolesResourceTest method shouldGetRoles_technicalManagementException.

@Test
public void shouldGetRoles_technicalManagementException() {
    final String domainId = "domain-1";
    doReturn(Single.error(new TechnicalManagementException("error occurs"))).when(roleService).findByDomain(domainId);
    final Response response = target("domains").path(domainId).path("roles").request().get();
    assertEquals(HttpStatusCode.INTERNAL_SERVER_ERROR_500, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) TechnicalManagementException(io.gravitee.am.service.exception.TechnicalManagementException) Test(org.junit.Test) JerseySpringTest(io.gravitee.am.management.handlers.management.api.JerseySpringTest)

Example 3 with TechnicalManagementException

use of io.gravitee.am.service.exception.TechnicalManagementException in project gravitee-access-management by gravitee-io.

the class TagsResourceTest method shouldGetTags_technicalManagementException.

@Test
public void shouldGetTags_technicalManagementException() {
    doReturn(Flowable.error(new TechnicalManagementException("error occurs"))).when(tagService).findAll(anyString());
    final Response response = target("organizations").path("DEFAULT").path("tags").request().get();
    assertEquals(HttpStatusCode.INTERNAL_SERVER_ERROR_500, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) TechnicalManagementException(io.gravitee.am.service.exception.TechnicalManagementException) Test(org.junit.Test) JerseySpringTest(io.gravitee.am.management.handlers.management.api.JerseySpringTest)

Example 4 with TechnicalManagementException

use of io.gravitee.am.service.exception.TechnicalManagementException in project gravitee-access-management by gravitee-io.

the class UserConsentsResourceTest method shouldGetUserConsents_technicalManagementException.

@Test
public void shouldGetUserConsents_technicalManagementException() {
    final String domainId = "domain-1";
    doReturn(Maybe.error(new TechnicalManagementException("error occurs"))).when(domainService).findById(domainId);
    final Response response = target("domains").path(domainId).path("users").path("user1").path("consents").request().get();
    assertEquals(HttpStatusCode.INTERNAL_SERVER_ERROR_500, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) TechnicalManagementException(io.gravitee.am.service.exception.TechnicalManagementException) Test(org.junit.Test) JerseySpringTest(io.gravitee.am.management.handlers.management.api.JerseySpringTest)

Example 5 with TechnicalManagementException

use of io.gravitee.am.service.exception.TechnicalManagementException in project gravitee-access-management by gravitee-io.

the class UserCredentialsResourceTest method shouldGetUserFactors_technicalManagementException.

@Test
public void shouldGetUserFactors_technicalManagementException() {
    final String domainId = "domain-1";
    doReturn(Maybe.error(new TechnicalManagementException("error occurs"))).when(domainService).findById(domainId);
    final Response response = target("domains").path(domainId).path("users").path("user1").path("credentials").request().get();
    assertEquals(HttpStatusCode.INTERNAL_SERVER_ERROR_500, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) TechnicalManagementException(io.gravitee.am.service.exception.TechnicalManagementException) Test(org.junit.Test) JerseySpringTest(io.gravitee.am.management.handlers.management.api.JerseySpringTest)

Aggregations

TechnicalManagementException (io.gravitee.am.service.exception.TechnicalManagementException)80 Test (org.junit.Test)46 JerseySpringTest (io.gravitee.am.management.handlers.management.api.JerseySpringTest)41 Response (javax.ws.rs.core.Response)41 AbstractManagementException (io.gravitee.am.service.exception.AbstractManagementException)25 Autowired (org.springframework.beans.factory.annotation.Autowired)25 EventType (io.gravitee.am.common.audit.EventType)23 ReferenceType (io.gravitee.am.model.ReferenceType)22 Logger (org.slf4j.Logger)22 LoggerFactory (org.slf4j.LoggerFactory)22 Maybe (io.reactivex.Maybe)21 Single (io.reactivex.Single)21 AuditBuilder (io.gravitee.am.service.reporter.builder.AuditBuilder)18 Completable (io.reactivex.Completable)18 Lazy (org.springframework.context.annotation.Lazy)18 Component (org.springframework.stereotype.Component)18 Action (io.gravitee.am.common.event.Action)17 RandomString (io.gravitee.am.common.utils.RandomString)17 Event (io.gravitee.am.model.common.event.Event)17 Payload (io.gravitee.am.model.common.event.Payload)17