use of org.craftercms.studio.api.v1.exception.ServiceLayerException in project studio by craftercms.
the class UserServiceInternalImpl method isUserMemberOfGroup.
@Override
public boolean isUserMemberOfGroup(String username, String groupName) throws UserNotFoundException, ServiceLayerException {
if (!userExists(-1, username)) {
throw new UserNotFoundException("No user found for username '" + username + "'");
}
Map<String, Object> params = new HashMap<>();
params.put(GROUP_NAME, groupName);
params.put(USERNAME, username);
try {
int result = userDao.isUserMemberOfGroup(params);
return result > 0;
} catch (Exception e) {
throw new ServiceLayerException("Unknown database error", e);
}
}
use of org.craftercms.studio.api.v1.exception.ServiceLayerException in project studio by craftercms.
the class UserServiceInternalImpl method enableUsers.
@RetryingOperation
@Override
public List<User> enableUsers(List<Long> userIds, List<String> usernames, boolean enabled) throws ServiceLayerException, UserNotFoundException {
List<User> users = getUsersByIdOrUsername(userIds, usernames);
Map<String, Object> params = new HashMap<>();
params.put(USER_IDS, users.stream().map(User::getId).collect(Collectors.toList()));
params.put(ENABLED, enabled ? 1 : 0);
try {
userDao.enableUsers(params);
return getUsersByIdOrUsername(userIds, usernames);
} catch (Exception e) {
throw new ServiceLayerException("Unknown database error", e);
}
}
use of org.craftercms.studio.api.v1.exception.ServiceLayerException in project studio by craftercms.
the class UserServiceInternalImpl method setUserPassword.
@RetryingOperation
@Override
public boolean setUserPassword(String username, String newPassword) throws UserNotFoundException, UserExternallyManagedException, ServiceLayerException {
if (!userExists(-1, username)) {
throw new UserNotFoundException();
} else {
if (verifyPasswordRequirements(newPassword)) {
Map<String, Object> params = new HashMap<String, Object>();
params.put(USER_ID, -1);
params.put(USERNAME, username);
try {
User user = userDao.getUserByIdOrUsername(params);
if (user.isExternallyManaged()) {
throw new UserExternallyManagedException();
} else {
String hashedPassword = CryptoUtils.hashPassword(newPassword);
params = new HashMap<String, Object>();
params.put(USERNAME, username);
params.put(PASSWORD, hashedPassword);
userDao.setUserPassword(params);
return true;
}
} catch (Exception e) {
throw new ServiceLayerException("Unknown database error", e);
}
} else {
throw new PasswordRequirementsFailedException("User password does not fulfill requirements");
}
}
}
use of org.craftercms.studio.api.v1.exception.ServiceLayerException in project studio by craftercms.
the class UserServiceInternalImpl method updateUser.
@RetryingOperation
@Override
public void updateUser(User user) throws UserNotFoundException, ServiceLayerException {
long userId = user.getId();
String username = user.getUsername() != null ? user.getUsername() : StringUtils.EMPTY;
User oldUser = getUserByIdOrUsername(userId, username);
Map<String, Object> params = new HashMap<>();
params.put(USER_ID, oldUser.getId());
params.put(FIRST_NAME, user.getFirstName());
params.put(LAST_NAME, user.getLastName());
params.put(EMAIL, user.getEmail());
params.put(TIMEZONE, StringUtils.EMPTY);
params.put(LOCALE, StringUtils.EMPTY);
try {
userDao.updateUser(params);
} catch (Exception e) {
throw new ServiceLayerException("Unknown database error", e);
}
}
use of org.craftercms.studio.api.v1.exception.ServiceLayerException in project studio by craftercms.
the class UserServiceInternalImpl method getUserGroups.
@Override
public List<Group> getUserGroups(long userId, String username) throws UserNotFoundException, ServiceLayerException {
if (!userExists(userId, username)) {
throw new UserNotFoundException("No user found for username '" + username + "' or id '" + userId + "'");
}
Map<String, Object> params = new HashMap<>();
params.put(USER_ID, userId);
params.put(USERNAME, username);
try {
return userDao.getUserGroups(params);
} catch (Exception e) {
throw new ServiceLayerException("Unknown database error", e);
}
}
Aggregations