public User createUser(String userName, String password, Boolean isAdmin, String description) throws PersistenceException {
User user = null;
if (userName == null || userName.length() < 0 || userName.length() > 25) {
logger.error("event=create_user error_code=invalid_user_name user_name=" + userName);
throw new PersistenceException(CQSErrorCodes.InvalidRequest, "Invalid user name " + userName);
}
if (password == null || password.length() < 0 || password.length() > 25) {
logger.error("event=create_user error_code=invalid_password");
throw new PersistenceException(CQSErrorCodes.InvalidRequest, "Invalid password");
}
if (getUserByName(userName) != null) {
logger.error("event=create_user error_code=user_already_exists user_name=" + userName);
throw new PersistenceException(CQSErrorCodes.InvalidRequest, "User with user name " + userName + " already exists");
}
try {
String userId = Long.toString(System.currentTimeMillis()).substring(1);
String hashedPassword = AuthUtil.hashPassword(password);
String accessSecret = AuthUtil.generateRandomAccessSecret();
String accessKey = AuthUtil.generateRandomAccessKey();
user = new User(userId, userName, hashedPassword, accessKey, accessSecret, isAdmin, description);
Map<String, String> userDataMap = new HashMap<String, String>();
userDataMap.put(USER_ID, user.getUserId());
//userDataMap.put(USER_NAME, user.getUserName());
userDataMap.put(HASH_PASSWORD, user.getHashPassword());
userDataMap.put(ACCESS_SECRET, user.getAccessSecret());
userDataMap.put(ACCESS_KEY, user.getAccessKey());
userDataMap.put(IS_ADMIN, user.getIsAdmin().toString());
userDataMap.put(USER_DESC, user.getDescription());
cassandraHandler.insertRow(AbstractDurablePersistence.CMB_KEYSPACE, user.getUserName(), COLUMN_FAMILY_USERS, userDataMap, CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER, null);
} catch (Exception e) {
logger.error("event=create_user", e);
throw new PersistenceException(CQSErrorCodes.InvalidRequest, e.getMessage());
}
return user;
}