use of org.eclipse.che.api.user.server.model.impl.UserImpl in project che by eclipse.
the class JpaUserDao method doUpdate.
@Transactional
protected void doUpdate(UserImpl update) throws NotFoundException {
final EntityManager manager = managerProvider.get();
final UserImpl user = manager.find(UserImpl.class, update.getId());
if (user == null) {
throw new NotFoundException(format("Couldn't update user with id '%s' because it doesn't exist", update.getId()));
}
final String password = update.getPassword();
if (password != null) {
update.setPassword(encryptor.encrypt(password));
} else {
update.setPassword(user.getPassword());
}
manager.merge(update);
manager.flush();
}
use of org.eclipse.che.api.user.server.model.impl.UserImpl in project che by eclipse.
the class JpaUserDao method getByAliasAndPassword.
@Override
@Transactional
public UserImpl getByAliasAndPassword(String emailOrName, String password) throws NotFoundException, ServerException {
requireNonNull(emailOrName, "Required non-null email or name");
requireNonNull(password, "Required non-null password");
try {
final UserImpl user = managerProvider.get().createNamedQuery("User.getByAliasAndPassword", UserImpl.class).setParameter("alias", emailOrName).getSingleResult();
if (!encryptor.test(password, user.getPassword())) {
throw new NotFoundException(format("User with email or name '%s' and given password doesn't exist", emailOrName));
}
return erasePassword(user);
} catch (NoResultException x) {
throw new NotFoundException(format("User with email or name '%s' and given password doesn't exist", emailOrName));
} catch (RuntimeException x) {
throw new ServerException(x.getLocalizedMessage(), x);
}
}
use of org.eclipse.che.api.user.server.model.impl.UserImpl in project che by eclipse.
the class JpaUserDao method getAll.
@Override
@Transactional
public Page<UserImpl> getAll(int maxItems, long skipCount) throws ServerException {
// TODO need to ensure that 'getAll' query works with same data as 'getTotalCount'
checkArgument(maxItems >= 0, "The number of items to return can't be negative.");
checkArgument(skipCount >= 0 && skipCount <= Integer.MAX_VALUE, "The number of items to skip can't be negative or greater than " + Integer.MAX_VALUE);
try {
final List<UserImpl> list = managerProvider.get().createNamedQuery("User.getAll", UserImpl.class).setMaxResults(maxItems).setFirstResult((int) skipCount).getResultList().stream().map(JpaUserDao::erasePassword).collect(toList());
return new Page<>(list, skipCount, maxItems, getTotalCount());
} catch (RuntimeException x) {
throw new ServerException(x.getLocalizedMessage(), x);
}
}
use of org.eclipse.che.api.user.server.model.impl.UserImpl in project che by eclipse.
the class UserManagerTest method shouldGetUserById.
@Test
public void shouldGetUserById() throws Exception {
final User user = new UserImpl("identifier", "test@email.com", "testName", "password", Collections.singletonList("alias"));
when(manager.getById(user.getId())).thenReturn(user);
assertEquals(manager.getById(user.getId()), user);
}
use of org.eclipse.che.api.user.server.model.impl.UserImpl in project che by eclipse.
the class UserManagerTest method shouldThrowConflictExceptionOnCreationIfUserNameIsReserved.
@Test(expectedExceptions = ConflictException.class)
public void shouldThrowConflictExceptionOnCreationIfUserNameIsReserved() throws Exception {
final User user = new UserImpl("id", "test@email.com", "reserved");
manager.create(user, false);
}
Aggregations