Search in sources :

Example 1 with UserProvider

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);
        }
    }
}
Also used : UserProvider(io.gravitee.am.identityprovider.api.UserProvider) AuthenticationProvider(io.gravitee.am.identityprovider.api.AuthenticationProvider)

Example 2 with UserProvider

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());
}
Also used : DefaultUser(io.gravitee.am.identityprovider.api.DefaultUser) NewUser(io.gravitee.am.service.model.NewUser) UpdateUser(io.gravitee.am.service.model.UpdateUser) UserProvider(io.gravitee.am.identityprovider.api.UserProvider) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 3 with UserProvider

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());
}
Also used : AccountSettings(io.gravitee.am.model.account.AccountSettings) ApplicationSettings(io.gravitee.am.model.application.ApplicationSettings) DefaultUser(io.gravitee.am.identityprovider.api.DefaultUser) DefaultUser(io.gravitee.am.identityprovider.api.DefaultUser) NewUser(io.gravitee.am.service.model.NewUser) UpdateUser(io.gravitee.am.service.model.UpdateUser) UserProvider(io.gravitee.am.identityprovider.api.UserProvider) Matchers.anyString(org.mockito.Matchers.anyString) NewUser(io.gravitee.am.service.model.NewUser) Test(org.junit.Test)

Example 4 with UserProvider

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();
}
Also used : DefaultUser(io.gravitee.am.identityprovider.api.DefaultUser) NewUser(io.gravitee.am.service.model.NewUser) UpdateUser(io.gravitee.am.service.model.UpdateUser) UserProvider(io.gravitee.am.identityprovider.api.UserProvider) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 5 with UserProvider

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());
}
Also used : AccountSettings(io.gravitee.am.model.account.AccountSettings) DefaultUser(io.gravitee.am.identityprovider.api.DefaultUser) DefaultUser(io.gravitee.am.identityprovider.api.DefaultUser) NewUser(io.gravitee.am.service.model.NewUser) UpdateUser(io.gravitee.am.service.model.UpdateUser) UserProvider(io.gravitee.am.identityprovider.api.UserProvider) Matchers.anyString(org.mockito.Matchers.anyString) NewUser(io.gravitee.am.service.model.NewUser) Test(org.junit.Test)

Aggregations

UserProvider (io.gravitee.am.identityprovider.api.UserProvider)28 Test (org.junit.Test)24 DefaultUser (io.gravitee.am.identityprovider.api.DefaultUser)18 TestObserver (io.reactivex.observers.TestObserver)16 User (io.gravitee.am.model.User)14 Client (io.gravitee.am.model.oidc.Client)13 FilterCriteria (io.gravitee.am.repository.management.api.search.FilterCriteria)8 AccountSettings (io.gravitee.am.model.account.AccountSettings)6 NewUser (io.gravitee.am.service.model.NewUser)6 UpdateUser (io.gravitee.am.service.model.UpdateUser)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 Matchers.anyString (org.mockito.Matchers.anyString)4 User (io.gravitee.am.gateway.handler.scim.model.User)3 IdentityProvider (io.gravitee.am.model.IdentityProvider)3 AuthenticationProvider (io.gravitee.am.identityprovider.api.AuthenticationProvider)2 Role (io.gravitee.am.model.Role)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 HashSet (java.util.HashSet)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 TextNode (com.fasterxml.jackson.databind.node.TextNode)1