use of io.gravitee.am.authdevice.notifier.api.AuthenticationDeviceNotifierProvider in project gravitee-access-management by gravitee-io.
the class AuthenticationDeviceNotifierManagerImpl method unloadDeviceNotifierProvider.
private void unloadDeviceNotifierProvider(String notifierId) {
try {
AuthenticationDeviceNotifierProvider provider = getAuthDeviceNotifierProvider(notifierId);
if (provider != null) {
provider.stop();
this.deviceNotifierProviders.remove(notifierId);
}
} catch (Exception e) {
logger.error("Authentication Device Notifier '{}' stopped with error", e);
}
}
use of io.gravitee.am.authdevice.notifier.api.AuthenticationDeviceNotifierProvider in project gravitee-access-management by gravitee-io.
the class AuthenticationRequestServiceTest method shouldNotUpdateStatus_UnknownRequestId.
@Test
public void shouldNotUpdateStatus_UnknownRequestId() {
final String STATE = "state";
final String EXTERNAL_ID = "externalId";
final String AUTH_REQ_ID = "auth_red_id";
final boolean requestValidated = new Random().nextBoolean();
AuthenticationDeviceNotifierProvider provider = mock(AuthenticationDeviceNotifierProvider.class);
when(notifierManager.getAuthDeviceNotifierProviders()).thenReturn(List.of(provider));
when(provider.extractUserResponse(any())).thenReturn(Single.just(Optional.of(new ADUserResponse(EXTERNAL_ID, STATE, requestValidated))));
final JWT stateJwt = new JWT();
stateJwt.setJti(EXTERNAL_ID);
when(this.jwtService.decode(STATE)).thenReturn(Single.just(stateJwt));
when(this.clientService.findByClientId(any())).thenReturn(Maybe.just(new Client()));
when(this.jwtService.decodeAndVerify(anyString(), any(Client.class))).thenReturn(Single.just(stateJwt));
final CibaAuthRequest cibaRequest = new CibaAuthRequest();
cibaRequest.setId(AUTH_REQ_ID);
when(this.requestRepository.findByExternalId(EXTERNAL_ID)).thenReturn(Maybe.empty());
final ADCallbackContext context = new ADCallbackContext(MultiMap.caseInsensitiveMultiMap(), MultiMap.caseInsensitiveMultiMap());
final TestObserver<Void> observer = this.service.validateUserResponse(context).test();
observer.awaitTerminalEvent();
observer.assertError(InvalidRequestException.class);
verify(clientService).findByClientId(any());
verify(jwtService).decodeAndVerify(anyString(), any(Client.class));
verify(requestRepository, never()).updateStatus(any(), any());
}
use of io.gravitee.am.authdevice.notifier.api.AuthenticationDeviceNotifierProvider in project gravitee-access-management by gravitee-io.
the class AuthenticationRequestServiceTest method shouldUpdateAuthReqStatus.
@Test
public void shouldUpdateAuthReqStatus() {
final String STATE = "state";
final String EXTERNAL_ID = "externalId";
final String AUTH_REQ_ID = "auth_red_id";
final boolean requestValidated = new Random().nextBoolean();
AuthenticationDeviceNotifierProvider provider = mock(AuthenticationDeviceNotifierProvider.class);
when(notifierManager.getAuthDeviceNotifierProviders()).thenReturn(List.of(provider));
when(provider.extractUserResponse(any())).thenReturn(Single.just(Optional.of(new ADUserResponse(EXTERNAL_ID, STATE, requestValidated))));
final JWT stateJwt = new JWT();
stateJwt.setJti(EXTERNAL_ID);
when(this.jwtService.decode(STATE)).thenReturn(Single.just(stateJwt));
when(this.clientService.findByClientId(any())).thenReturn(Maybe.just(new Client()));
when(this.jwtService.decodeAndVerify(anyString(), any(Client.class))).thenReturn(Single.just(stateJwt));
final CibaAuthRequest cibaRequest = new CibaAuthRequest();
cibaRequest.setId(AUTH_REQ_ID);
when(this.requestRepository.findByExternalId(EXTERNAL_ID)).thenReturn(Maybe.just(cibaRequest));
final String status = requestValidated ? AuthenticationRequestStatus.SUCCESS.name() : AuthenticationRequestStatus.REJECTED.name();
when(this.requestRepository.updateStatus(AUTH_REQ_ID, status)).thenReturn(Single.just(cibaRequest));
final ADCallbackContext context = new ADCallbackContext(MultiMap.caseInsensitiveMultiMap(), MultiMap.caseInsensitiveMultiMap());
final TestObserver<Void> observer = this.service.validateUserResponse(context).test();
observer.awaitTerminalEvent();
observer.assertNoErrors();
verify(requestRepository).updateStatus(AUTH_REQ_ID, status);
}
use of io.gravitee.am.authdevice.notifier.api.AuthenticationDeviceNotifierProvider in project gravitee-access-management by gravitee-io.
the class AuthenticationDeviceNotifierManagerImpl method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
// load all known resource for the domain on startup
deviceNotifierService.findByDomain(this.domain.getId()).subscribeOn(Schedulers.io()).subscribe(notifier -> {
AuthenticationDeviceNotifierProvider provider = deviceNotifierPluginManager.create(notifier.getType(), notifier.getConfiguration());
provider.start();
deviceNotifierProviders.put(notifier.getId(), provider);
logger.info("Authentication Device Notifier {} loaded for domain {}", notifier.getName(), domain.getName());
}, error -> logger.error("Unable to initialize Authentication Device Notifiers for domain {}", domain.getName(), error));
}
use of io.gravitee.am.authdevice.notifier.api.AuthenticationDeviceNotifierProvider in project gravitee-access-management by gravitee-io.
the class AuthenticationRequestServiceTest method shouldNotUpdateStatus_StateMismatch.
@Test
public void shouldNotUpdateStatus_StateMismatch() {
final String STATE = "state";
final String EXTERNAL_ID = "externalId";
final boolean requestValidated = new Random().nextBoolean();
AuthenticationDeviceNotifierProvider provider = mock(AuthenticationDeviceNotifierProvider.class);
when(notifierManager.getAuthDeviceNotifierProviders()).thenReturn(List.of(provider));
when(provider.extractUserResponse(any())).thenReturn(Single.just(Optional.of(new ADUserResponse("unknown", STATE, requestValidated))));
final JWT stateJwt = new JWT();
stateJwt.setJti(EXTERNAL_ID);
when(this.jwtService.decode(STATE)).thenReturn(Single.just(stateJwt));
when(this.clientService.findByClientId(any())).thenReturn(Maybe.just(new Client()));
when(this.jwtService.decodeAndVerify(anyString(), any(Client.class))).thenReturn(Single.just(stateJwt));
final ADCallbackContext context = new ADCallbackContext(MultiMap.caseInsensitiveMultiMap(), MultiMap.caseInsensitiveMultiMap());
final TestObserver<Void> observer = this.service.validateUserResponse(context).test();
observer.awaitTerminalEvent();
observer.assertError(InvalidRequestException.class);
verify(clientService).findByClientId(any());
verify(requestRepository, never()).updateStatus(any(), any());
}
Aggregations