protected void sendNoPublicKey(String subsystemIdentifier, String email) throws MessageSendException { try { emailService.sendNoPublicKeyMessage(subsystemIdentifier, email); } catch (RuntimeMessagingException e) { logger.error("Could not send a message to " + email, e); throw new MessageSendException(e); } }
public UserCreationResult createUser(UIUserForCreate user, String subsystemIdentifier) { UIUserForCreate userForDao = new UIUserForCreate(); copyUserAndEncryptPassword(user, userForDao); userForDao.setHotpSalt(hotpSaltGenerator.generate()); RoutineResult result = createUserStrategy.createUser(userForDao); loggerSink.info(logger, "CREATE_USER", result.isOk(), userForDao.getUsername()); UserCreationResult userCreationResult = new UserCreationResult(); userCreationResult.setResult(result); if (result.isOk()) { try { hotpService.sendTableIfSupported( subsystemIdentifier, userForDao.getId()); } catch (MessageSendException e) { userCreationResult.setMailSendError(e.getMessage()); } } return userCreationResult; // we're not notifying about this as user does not yet have any roles // or actions }
public UserCloningResult cloneUser(long templateUserId, String newUsername, String newPassword, String newEmail, String newPublicKey, String subsystemForEmailIdentifier) { UICloneUserRequest request = new UICloneUserRequest(); request.setTemplateUserId(templateUserId); request.setUsername(newUsername); request.setEmail(newEmail); request.setSalt(saltSource.getSalt(newUsername)); request.setHotpSalt(hotpSaltGenerator.generate()); request.setPassword(passwordEncoder.encode(newPassword, request.getSalt())); request.setPublicKey(newPublicKey); RoutineResult result = createUserStrategy.cloneUser(request); UserCloningResult userCloningResult = new UserCloningResult(); if (request.getId() != null) { userCloningResult.setCloneId(request.getId()); } if (result.isOk()) { try { hotpService.sendTableIfSupported(subsystemForEmailIdentifier, request.getId()); } catch (MessageSendException e) { userCloningResult.setMailSendError(e.getMessage()); } notificationService.notifyAboutUsersChanged(); } loggerSink.info(logger, "CLONE_USER", result.isOk(), String.format("%s->%s", templateUserId, newUsername)); return userCloningResult; }
protected void actuallySendTable(String subsystemIdentifier, UIUser user) throws MessageSendException, ExportException { String filename = hotpProvider.getSequenceForDownloadFileName(user.getUsername()); // TODO: use streams, not buffers ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { hotpProvider.outputSequenceForDownload(user.getUsername(), baos); byte[] bytes = baos.toByteArray(); baos = new ByteArrayOutputStream(); publicKeyCrypto.encrypt(bytes, filename, user.getPublicKey(), baos); } catch (IOException e) { // should not get IOException as we're working in-memory throw new IllegalStateException(e); } try { emailService.sendHOTPTable(subsystemIdentifier, user.getEmail(), filename, baos.toByteArray()); } catch (RuntimeMessagingException e) { logger.error("Could not send a message to " + user.getEmail(), e); throw new MessageSendException(e); } }