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");
}
}
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());
}
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);
}
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");
}
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);
}
Aggregations