Search in sources :

Example 1 with TechnicalException

use of io.gravitee.am.repository.exceptions.TechnicalException in project gravitee-access-management by gravitee-io.

the class AuthenticationRequestAcknowledgeHandlerTest method shouldNotGenerateAuthReqId_RegistrationFailure.

@Test
public void shouldNotGenerateAuthReqId_RegistrationFailure() throws Exception {
    CibaAuthenticationRequest cibaRequest = new CibaAuthenticationRequest();
    cibaRequest.setLoginHint("username");
    cibaRequest.setSubject("usernameuuid");
    router.route().order(-1).handler(routingContext -> {
        routingContext.put(ConstantKeys.CLIENT_CONTEXT_KEY, client);
        routingContext.put(ConstantKeys.CIBA_AUTH_REQUEST_KEY, cibaRequest);
        routingContext.next();
    });
    when(jwtService.encode(any(JWT.class), any(Client.class))).thenReturn(Single.just("signed_jwt"));
    when(authReqService.register(any(), any())).thenReturn(Single.error(new TechnicalException()));
    testRequest(HttpMethod.POST, CIBAProvider.CIBA_PATH + CIBAProvider.AUTHENTICATION_ENDPOINT + "?request=fakejwt", null, HttpStatusCode.INTERNAL_SERVER_ERROR_500, "Internal Server Error", null);
    verify(authReqService).register(any(), any());
    verify(authReqService, never()).updateAuthDeviceInformation(any());
    verify(notifier, never()).notify(any());
}
Also used : TechnicalException(io.gravitee.am.repository.exceptions.TechnicalException) JWT(io.gravitee.am.common.jwt.JWT) CibaAuthenticationRequest(io.gravitee.am.gateway.handler.ciba.service.request.CibaAuthenticationRequest) Client(io.gravitee.am.model.oidc.Client) Test(org.junit.Test)

Example 2 with TechnicalException

use of io.gravitee.am.repository.exceptions.TechnicalException in project gravitee-access-management by gravitee-io.

the class InstallationCommandHandlerTest method handleWithException.

@Test
public void handleWithException() {
    final Installation installation = new Installation();
    installation.setId(INSTALLATION_ID);
    installation.getAdditionalInformation().put(CUSTOM_KEY, CUSTOM_VALUE);
    InstallationPayload installationPayload = new InstallationPayload();
    InstallationCommand command = new InstallationCommand(installationPayload);
    installationPayload.setId(INSTALLATION_ID);
    installationPayload.setStatus("ACCEPTED");
    when(installationService.getOrInitialize()).thenReturn(Single.just(installation));
    when(installationService.setAdditionalInformation(anyMap())).thenReturn(Single.error(new TechnicalException()));
    TestObserver<InstallationReply> obs = cut.handle(command).test();
    obs.awaitTerminalEvent();
    obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.ERROR));
}
Also used : Installation(io.gravitee.am.model.Installation) InstallationCommand(io.gravitee.cockpit.api.command.installation.InstallationCommand) TechnicalException(io.gravitee.am.repository.exceptions.TechnicalException) InstallationPayload(io.gravitee.cockpit.api.command.installation.InstallationPayload) InstallationReply(io.gravitee.cockpit.api.command.installation.InstallationReply) Test(org.junit.Test)

Example 3 with TechnicalException

use of io.gravitee.am.repository.exceptions.TechnicalException in project gravitee-access-management by gravitee-io.

the class UserCommandHandlerTest method handleWithException.

@Test
public void handleWithException() {
    UserPayload userPayload = new UserPayload();
    UserCommand command = new UserCommand(userPayload);
    userPayload.setId("user#1");
    userPayload.setOrganizationId("orga#1");
    when(userService.createOrUpdate(eq(ReferenceType.ORGANIZATION), eq("orga#1"), any(NewUser.class))).thenReturn(Single.error(new TechnicalException()));
    TestObserver<UserReply> obs = cut.handle(command).test();
    obs.awaitTerminalEvent();
    obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.ERROR));
}
Also used : UserCommand(io.gravitee.cockpit.api.command.user.UserCommand) TechnicalException(io.gravitee.am.repository.exceptions.TechnicalException) UserPayload(io.gravitee.cockpit.api.command.user.UserPayload) NewUser(io.gravitee.am.service.model.NewUser) UserReply(io.gravitee.cockpit.api.command.user.UserReply) Test(org.junit.Test)

Example 4 with TechnicalException

use of io.gravitee.am.repository.exceptions.TechnicalException in project gravitee-access-management by gravitee-io.

the class CallFactorProvider method sendChallenge.

@Override
public Completable sendChallenge(FactorContext context) {
    final EnrolledFactor enrolledFactor = context.getData(FactorContext.KEY_ENROLLED_FACTOR, EnrolledFactor.class);
    ResourceManager component = context.getComponent(ResourceManager.class);
    ResourceProvider provider = component.getResourceProvider(configuration.getGraviteeResource());
    if (provider instanceof MFAResourceProvider) {
        MFAResourceProvider mfaProvider = (MFAResourceProvider) provider;
        MFALink link = new MFALink(MFAType.CALL, enrolledFactor.getChannel().getTarget());
        return mfaProvider.send(link);
    } else {
        return Completable.error(new TechnicalException("Resource referenced can't be used for MultiFactor Authentication  with type SMS"));
    }
}
Also used : TechnicalException(io.gravitee.am.repository.exceptions.TechnicalException) EnrolledFactor(io.gravitee.am.model.factor.EnrolledFactor) MFAResourceProvider(io.gravitee.am.resource.api.mfa.MFAResourceProvider) ResourceProvider(io.gravitee.am.resource.api.ResourceProvider) MFALink(io.gravitee.am.resource.api.mfa.MFALink) MFAResourceProvider(io.gravitee.am.resource.api.mfa.MFAResourceProvider) ResourceManager(io.gravitee.am.gateway.handler.manager.resource.ResourceManager)

Example 5 with TechnicalException

use of io.gravitee.am.repository.exceptions.TechnicalException in project gravitee-access-management by gravitee-io.

the class CallFactorProvider method verify.

@Override
public Completable verify(FactorContext context) {
    final String code = context.getData(FactorContext.KEY_CODE, String.class);
    final EnrolledFactor enrolledFactor = context.getData(FactorContext.KEY_ENROLLED_FACTOR, EnrolledFactor.class);
    ResourceManager component = context.getComponent(ResourceManager.class);
    ResourceProvider provider = component.getResourceProvider(configuration.getGraviteeResource());
    if (provider instanceof MFAResourceProvider) {
        var mfaProvider = (MFAResourceProvider) provider;
        var challenge = new MFAChallenge(enrolledFactor.getChannel().getTarget(), code);
        return mfaProvider.verify(challenge);
    } else {
        return Completable.error(new TechnicalException("Resource referenced can't be used for MultiFactor Authentication with type Call"));
    }
}
Also used : MFAChallenge(io.gravitee.am.resource.api.mfa.MFAChallenge) TechnicalException(io.gravitee.am.repository.exceptions.TechnicalException) EnrolledFactor(io.gravitee.am.model.factor.EnrolledFactor) MFAResourceProvider(io.gravitee.am.resource.api.mfa.MFAResourceProvider) ResourceProvider(io.gravitee.am.resource.api.ResourceProvider) MFAResourceProvider(io.gravitee.am.resource.api.mfa.MFAResourceProvider) ResourceManager(io.gravitee.am.gateway.handler.manager.resource.ResourceManager)

Aggregations

TechnicalException (io.gravitee.am.repository.exceptions.TechnicalException)16 Test (org.junit.Test)8 ResourceManager (io.gravitee.am.gateway.handler.manager.resource.ResourceManager)5 EnrolledFactor (io.gravitee.am.model.factor.EnrolledFactor)5 ResourceProvider (io.gravitee.am.resource.api.ResourceProvider)5 MFAResourceProvider (io.gravitee.am.resource.api.mfa.MFAResourceProvider)4 JWT (io.gravitee.am.common.jwt.JWT)2 CibaAuthenticationRequest (io.gravitee.am.gateway.handler.ciba.service.request.CibaAuthenticationRequest)2 ReferenceType (io.gravitee.am.model.ReferenceType)2 Client (io.gravitee.am.model.oidc.Client)2 MFAChallenge (io.gravitee.am.resource.api.mfa.MFAChallenge)2 MFALink (io.gravitee.am.resource.api.mfa.MFALink)2 TestObserver (io.reactivex.observers.TestObserver)2 TestSubscriber (io.reactivex.subscribers.TestSubscriber)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BasicDBObject (com.mongodb.BasicDBObject)1 InvalidCodeException (io.gravitee.am.common.exception.mfa.InvalidCodeException)1 EmailService (io.gravitee.am.gateway.handler.common.email.EmailService)1 UserService (io.gravitee.am.gateway.handler.root.service.user.UserService)1 DefaultUser (io.gravitee.am.identityprovider.api.DefaultUser)1