use of io.gravitee.am.identityprovider.api.UserProvider in project gravitee-access-management by gravitee-io.
the class IdentityProviderManagerImpl method clearProvider.
private void clearProvider(String identityProviderId) {
AuthenticationProvider authenticationProvider = providers.remove(identityProviderId);
UserProvider userProvider = userProviders.remove(identityProviderId);
identities.remove(identityProviderId);
if (authenticationProvider != null) {
// stop the authentication provider
try {
authenticationProvider.stop();
} catch (Exception e) {
logger.error("An error has occurred while stopping the authentication provider : {}", identityProviderId, e);
}
}
if (userProvider != null) {
// stop the user provider
try {
userProvider.stop();
} catch (Exception e) {
logger.error("An error has occurred while stopping the user provider : {}", identityProviderId, e);
}
}
}
use of io.gravitee.am.identityprovider.api.UserProvider in project gravitee-access-management by gravitee-io.
the class UserServiceTest method shouldResetPassword_idpUserNotFound.
@Test
public void shouldResetPassword_idpUserNotFound() {
Domain domain = new Domain();
domain.setId("domain");
String password = "password";
User user = new User();
user.setId("user-id");
user.setSource("idp-id");
io.gravitee.am.identityprovider.api.User idpUser = mock(io.gravitee.am.identityprovider.api.DefaultUser.class);
when(idpUser.getId()).thenReturn("idp-id");
UserProvider userProvider = mock(UserProvider.class);
when(userProvider.findByUsername(user.getUsername())).thenReturn(Maybe.empty());
when(userProvider.create(any())).thenReturn(Single.just(idpUser));
when(passwordService.isValid(eq(password), eq(null), any())).thenReturn(true);
when(commonUserService.findById(eq(ReferenceType.DOMAIN), eq(domain.getId()), eq("user-id"))).thenReturn(Single.just(user));
when(identityProviderManager.getUserProvider(user.getSource())).thenReturn(Maybe.just(userProvider));
when(commonUserService.update(any())).thenReturn(Single.just(user));
when(loginAttemptService.reset(any())).thenReturn(Completable.complete());
userService.resetPassword(domain, user.getId(), password, null).test().assertComplete().assertNoErrors();
verify(userProvider, times(1)).create(any());
}
use of io.gravitee.am.identityprovider.api.UserProvider in project gravitee-access-management by gravitee-io.
the class UserServiceTest method shouldPreRegisterUser_dynamicUserRegistration_clientLevel.
@Test
public void shouldPreRegisterUser_dynamicUserRegistration_clientLevel() {
String domainId = "domain";
AccountSettings accountSettings = new AccountSettings();
accountSettings.setDynamicUserRegistration(true);
accountSettings.setInherited(false);
Domain domain = new Domain();
domain.setId(domainId);
NewUser newUser = new NewUser();
newUser.setUsername("username");
newUser.setSource("idp");
newUser.setClient("client");
newUser.setPreRegistration(true);
UserProvider userProvider = mock(UserProvider.class);
doReturn(Single.just(new DefaultUser(newUser.getUsername()))).when(userProvider).create(any());
Application client = new Application();
client.setDomain("domain");
ApplicationSettings settings = new ApplicationSettings();
settings.setAccount(accountSettings);
client.setSettings(settings);
when(jwtBuilder.sign(any())).thenReturn("token");
when(commonUserService.findByDomainAndUsernameAndSource(anyString(), anyString(), anyString())).thenReturn(Maybe.empty());
when(identityProviderManager.getUserProvider(anyString())).thenReturn(Maybe.just(userProvider));
when(applicationService.findById(newUser.getClient())).thenReturn(Maybe.just(client));
when(commonUserService.create(any())).thenReturn(Single.just(new User()));
when(domainService.buildUrl(any(Domain.class), eq("/confirmRegistration"))).thenReturn("http://localhost:8092/test/confirmRegistration");
when(emailService.getEmailTemplate(eq(Template.REGISTRATION_CONFIRMATION), any())).thenReturn(new Email());
userService.create(domain, newUser, null).test().assertComplete().assertNoErrors();
verify(commonUserService, times(1)).create(any());
ArgumentCaptor<User> argument = ArgumentCaptor.forClass(User.class);
verify(commonUserService).create(argument.capture());
Assert.assertNotNull(argument.getValue().getRegistrationUserUri());
assertEquals("http://localhost:8092/test/confirmRegistration", argument.getValue().getRegistrationUserUri());
Assert.assertNotNull(argument.getValue().getRegistrationAccessToken());
assertEquals("token", argument.getValue().getRegistrationAccessToken());
}
use of io.gravitee.am.identityprovider.api.UserProvider in project gravitee-access-management by gravitee-io.
the class UserServiceTest method shouldResetPassword_externalIdEmpty.
@Test
public void shouldResetPassword_externalIdEmpty() {
Domain domain = new Domain();
domain.setId("domain");
String password = "password";
User user = new User();
user.setId("user-id");
user.setSource("idp-id");
io.gravitee.am.identityprovider.api.User idpUser = mock(io.gravitee.am.identityprovider.api.DefaultUser.class);
when(idpUser.getId()).thenReturn("idp-id");
UserProvider userProvider = mock(UserProvider.class);
when(userProvider.findByUsername(user.getUsername())).thenReturn(Maybe.just(idpUser));
when(userProvider.update(anyString(), any())).thenReturn(Single.just(idpUser));
doReturn(true).when(passwordService).isValid(eq(password), eq(null), any());
when(commonUserService.findById(eq(ReferenceType.DOMAIN), eq(domain.getId()), eq("user-id"))).thenReturn(Single.just(user));
when(identityProviderManager.getUserProvider(user.getSource())).thenReturn(Maybe.just(userProvider));
when(commonUserService.update(any())).thenReturn(Single.just(user));
when(loginAttemptService.reset(any())).thenReturn(Completable.complete());
userService.resetPassword(domain, user.getId(), password, null).test().assertComplete().assertNoErrors();
}
use of io.gravitee.am.identityprovider.api.UserProvider in project gravitee-access-management by gravitee-io.
the class UserServiceTest method shouldPreRegisterUser.
@Test
public void shouldPreRegisterUser() throws InterruptedException {
String domainId = "domain";
AccountSettings accountSettings = new AccountSettings();
accountSettings.setDynamicUserRegistration(false);
Domain domain = new Domain();
domain.setId(domainId);
domain.setAccountSettings(accountSettings);
NewUser newUser = new NewUser();
newUser.setUsername("username");
newUser.setSource("idp");
newUser.setClient("client");
newUser.setPreRegistration(true);
User preRegisteredUser = new User();
preRegisteredUser.setId("userId");
preRegisteredUser.setReferenceId("domain");
preRegisteredUser.setPreRegistration(true);
UserProvider userProvider = mock(UserProvider.class);
doReturn(Single.just(new DefaultUser(newUser.getUsername()))).when(userProvider).create(any());
Application client = new Application();
client.setDomain("domain");
when(domainService.findById(domainId)).thenReturn(Maybe.just(domain));
when(commonUserService.findByDomainAndUsernameAndSource(anyString(), anyString(), anyString())).thenReturn(Maybe.empty());
when(identityProviderManager.getUserProvider(anyString())).thenReturn(Maybe.just(userProvider));
when(applicationService.findById(newUser.getClient())).thenReturn(Maybe.just(client));
when(commonUserService.create(any())).thenReturn(Single.just(preRegisteredUser));
when(commonUserService.findById(any(), anyString(), anyString())).thenReturn(Single.just(preRegisteredUser));
userService.create(domain, newUser, null).test().assertComplete().assertNoErrors();
verify(commonUserService, times(1)).create(any());
ArgumentCaptor<User> argument = ArgumentCaptor.forClass(User.class);
verify(commonUserService).create(argument.capture());
// Wait few ms to let time to background thread to be executed.
Thread.sleep(500);
verify(emailService).send(any(Domain.class), eq(null), eq(Template.REGISTRATION_CONFIRMATION), any(User.class));
Assert.assertNull(argument.getValue().getRegistrationUserUri());
Assert.assertNull(argument.getValue().getRegistrationAccessToken());
}
Aggregations