Search in sources :

Example 1 with User

use of org.eclipse.che.api.core.model.user.User in project che by eclipse.

the class FactoryService method processDefaults.

/**
     * Checks the current user if it is not temporary then
     * adds to the factory creator information and time of creation
     */
private void processDefaults(FactoryDto factory) throws ForbiddenException {
    try {
        final String userId = EnvironmentContext.getCurrent().getSubject().getUserId();
        final User user = userManager.getById(userId);
        if (user == null || parseBoolean(preferenceManager.find(userId).get("temporary"))) {
            throw new ForbiddenException("Current user is not allowed to use this method.");
        }
        factory.setCreator(DtoFactory.newDto(AuthorDto.class).withUserId(userId).withName(user.getName()).withEmail(user.getEmail()).withCreated(System.currentTimeMillis()));
    } catch (NotFoundException | ServerException ex) {
        throw new ForbiddenException("Current user is not allowed to use this method");
    }
}
Also used : AuthorDto(org.eclipse.che.api.factory.shared.dto.AuthorDto) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) User(org.eclipse.che.api.core.model.user.User) ServerException(org.eclipse.che.api.core.ServerException) NotFoundException(org.eclipse.che.api.core.NotFoundException)

Example 2 with User

use of org.eclipse.che.api.core.model.user.User in project che by eclipse.

the class UserManagerTest method shouldGeneratePasswordWhenCreatingUserAndItIsMissing.

@Test
public void shouldGeneratePasswordWhenCreatingUserAndItIsMissing() throws Exception {
    final User user = new UserImpl(null, "test@email.com", "testName", null, null);
    manager.create(user, false);
    final ArgumentCaptor<UserImpl> userCaptor = ArgumentCaptor.forClass(UserImpl.class);
    verify(userDao).create(userCaptor.capture());
    assertNotNull(userCaptor.getValue().getPassword());
}
Also used : User(org.eclipse.che.api.core.model.user.User) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Test(org.testng.annotations.Test)

Example 3 with User

use of org.eclipse.che.api.core.model.user.User in project che by eclipse.

the class UserManagerTest method shouldGetUserByName.

@Test
public void shouldGetUserByName() throws Exception {
    final User user = new UserImpl("identifier", "test@email.com", "testName", "password", Collections.singletonList("alias"));
    when(manager.getByName(user.getName())).thenReturn(user);
    assertEquals(manager.getByName(user.getName()), user);
}
Also used : User(org.eclipse.che.api.core.model.user.User) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Test(org.testng.annotations.Test)

Example 4 with User

use of org.eclipse.che.api.core.model.user.User in project che by eclipse.

the class UserManagerTest method shouldNotGenerateIdentifierWhenCreatingUserWithNotNullId.

@Test
public void shouldNotGenerateIdentifierWhenCreatingUserWithNotNullId() throws Exception {
    final User user = new UserImpl("identifier", "test@email.com", "testName", null, null);
    manager.create(user, false);
    final ArgumentCaptor<UserImpl> userCaptor = ArgumentCaptor.forClass(UserImpl.class);
    verify(userDao).create(userCaptor.capture());
    final String id = userCaptor.getValue().getId();
    assertNotNull(id);
    assertEquals(id, "identifier");
}
Also used : User(org.eclipse.che.api.core.model.user.User) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 5 with User

use of org.eclipse.che.api.core.model.user.User in project che by eclipse.

the class UserManagerTest method shouldGetUserByEmail.

@Test
public void shouldGetUserByEmail() throws Exception {
    final User user = new UserImpl("identifier", "test@email.com", "testName", "password", Collections.singletonList("alias"));
    when(manager.getByEmail(user.getEmail())).thenReturn(user);
    assertEquals(manager.getByEmail(user.getEmail()), user);
}
Also used : User(org.eclipse.che.api.core.model.user.User) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Test(org.testng.annotations.Test)

Aggregations

User (org.eclipse.che.api.core.model.user.User)17 Test (org.testng.annotations.Test)15 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)14 Response (com.jayway.restassured.response.Response)4 NotFoundException (org.eclipse.che.api.core.NotFoundException)4 Arrays (java.util.Arrays)3 HashSet (java.util.HashSet)3 List (java.util.List)3 ArrayList (java.util.ArrayList)2 Arrays.asList (java.util.Arrays.asList)2 Inject (javax.inject.Inject)2 ConflictException (org.eclipse.che.api.core.ConflictException)2 Page (org.eclipse.che.api.core.Page)2 ServerException (org.eclipse.che.api.core.ServerException)2 EventService (org.eclipse.che.api.core.notification.EventService)2 EventSubscriber (org.eclipse.che.api.core.notification.EventSubscriber)2 Constants (org.eclipse.che.api.user.server.Constants)2 BeforeUserRemovedEvent (org.eclipse.che.api.user.server.event.BeforeUserRemovedEvent)2 PostUserPersistedEvent (org.eclipse.che.api.user.server.event.PostUserPersistedEvent)2 UserRemovedEvent (org.eclipse.che.api.user.server.event.UserRemovedEvent)2