Search in sources :

Example 6 with LogException

use of org.activityinfo.server.util.logging.LogException in project activityinfo by bedatadriven.

the class SignUpAddressExistsController method resetPassword.

@POST
@Produces(MediaType.TEXT_HTML)
@LogException(emailAlert = true)
@Transactional
public Viewable resetPassword(@FormParam("email") String email) {
    try {
        User user = userDAO.get().findUserByEmail(email);
        user.setChangePasswordKey(SecureTokenGenerator.generate());
        user.setDateChangePasswordKeyIssued(new Date());
        mailer.send(new ResetPasswordMessage(user));
        return new SignUpAddressExistsPageModel(email).asEmailSent();
    } catch (NoResultException e) {
        return new SignUpAddressExistsPageModel().asLoginError();
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Failed to send password reset email", e);
        return new SignUpAddressExistsPageModel().asEmailError();
    }
}
Also used : SignUpAddressExistsPageModel(org.activityinfo.server.login.model.SignUpAddressExistsPageModel) User(org.activityinfo.server.database.hibernate.entity.User) NoResultException(javax.persistence.NoResultException) Date(java.util.Date) NoResultException(javax.persistence.NoResultException) LogException(org.activityinfo.server.util.logging.LogException) ResetPasswordMessage(org.activityinfo.server.mail.ResetPasswordMessage) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) LogException(org.activityinfo.server.util.logging.LogException) Transactional(org.activityinfo.server.database.hibernate.dao.Transactional)

Example 7 with LogException

use of org.activityinfo.server.util.logging.LogException in project activityinfo by bedatadriven.

the class SignUpController method signUp.

@POST
@Produces(MediaType.TEXT_HTML)
@LogException(emailAlert = true)
@Transactional
public Response signUp(@FormParam("name") String name, @FormParam("organization") String organization, @FormParam("jobtitle") String jobtitle, @FormParam("email") String email, @FormParam("locale") String locale) {
    LOGGER.info("New user signing up! [name: " + name + ", email: " + email + ", locale: " + locale + ", organization: " + organization + ", job title: " + jobtitle + "]");
    if (!domainProvider.get().isSignUpAllowed()) {
        LOGGER.severe("Blocked attempt to signup via " + domainProvider.get().getHost());
        return Response.status(Status.FORBIDDEN).build();
    }
    // checking parameter values
    try {
        checkParam(name, true);
        checkParam(organization, false);
        checkParam(jobtitle, false);
        checkParam(email, true);
        checkParam(locale, true);
    } catch (IllegalArgumentException e) {
        LOGGER.log(Level.INFO, "User " + name + " (" + email + ") failed to sign up", e);
        return Response.ok(SignUpPageModel.formErrorModel().set(email, name, organization, jobtitle, locale).asViewable()).build();
    }
    try {
        // check duplicate email
        if (userDAO.get().doesUserExist(email)) {
            return Response.ok(new SignUpAddressExistsPageModel(email).asViewable()).type(MediaType.TEXT_HTML).build();
        }
        // persist new user
        User user = UserDAOImpl.createNewUser(email, name, organization, jobtitle, locale);
        userDAO.get().persist(user);
        // send confirmation email
        mailer.send(new SignUpConfirmationMessage(user));
        // return to page with positive result
        return Response.seeOther(new URI("/signUp/sent")).build();
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "User " + name + " (" + email + ") failed to sign up", e);
        entityManager.getTransaction().rollback();
        return Response.ok(SignUpPageModel.genericErrorModel().set(email, name, organization, jobtitle, locale).asViewable()).build();
    }
}
Also used : SignUpAddressExistsPageModel(org.activityinfo.server.login.model.SignUpAddressExistsPageModel) User(org.activityinfo.server.database.hibernate.entity.User) SignUpConfirmationMessage(org.activityinfo.server.mail.SignUpConfirmationMessage) URI(java.net.URI) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) LogException(org.activityinfo.server.util.logging.LogException) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) LogException(org.activityinfo.server.util.logging.LogException) Transactional(org.activityinfo.server.database.hibernate.dao.Transactional)

Example 8 with LogException

use of org.activityinfo.server.util.logging.LogException in project activityinfo by bedatadriven.

the class SmtpMailSender method send.

@Override
@LogException
public void send(Message message) {
    try {
        Properties props = new Properties();
        Session session = Session.getDefaultInstance(props, null);
        MimeMessage mimeMessage = new MimeMessage(session);
        mimeMessage.setSubject(message.getSubject(), Charsets.UTF_8.name());
        mimeMessage.addRecipients(RecipientType.TO, toArray(message.getTo()));
        mimeMessage.addRecipients(RecipientType.BCC, toArray(message.getBcc()));
        mimeMessage.setFrom(new InternetAddress(configuration.getProperty("smtp.from", "activityinfo@configure-me.com"), configuration.getProperty("smtp.from.name", "ActivityInfo")));
        if (message.getReplyTo() != null) {
            mimeMessage.setReplyTo(new Address[] { message.getReplyTo() });
        }
        String body;
        if (message.hasHtmlBody()) {
            body = message.getHtmlBody();
            mimeMessage.setDataHandler(new DataHandler(new HTMLDataSource(body)));
        } else {
            body = message.getTextBody();
            mimeMessage.setText(body, Charsets.UTF_8.name());
        }
        LOGGER.finest("message to " + message.getTo() + ":\n" + body);
        if (!message.getAttachments().isEmpty()) {
            Multipart multipart = new MimeMultipart();
            for (MessageAttachment attachment : message.getAttachments()) {
                MimeBodyPart part = new MimeBodyPart();
                part.setFileName(attachment.getFilename());
                DataSource src = new ByteArrayDataSource(attachment.getContent(), attachment.getContentType());
                part.setDataHandler(new DataHandler(src));
                multipart.addBodyPart(part);
            }
            mimeMessage.setContent(multipart);
        }
        mimeMessage.saveChanges();
        Transport.send(mimeMessage);
    } catch (MessagingException e) {
        throw new RuntimeException(e);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) Multipart(javax.mail.Multipart) MimeMultipart(javax.mail.internet.MimeMultipart) MessagingException(javax.mail.MessagingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DataHandler(javax.activation.DataHandler) Properties(java.util.Properties) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) DataSource(javax.activation.DataSource) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) MimeBodyPart(javax.mail.internet.MimeBodyPart) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) Session(javax.mail.Session) LogException(org.activityinfo.server.util.logging.LogException)

Example 9 with LogException

use of org.activityinfo.server.util.logging.LogException in project activityinfo by bedatadriven.

the class CommandServlet method handleCommands.

/**
 * Publicly visible for testing *
 */
@LogException
public List<CommandResult> handleCommands(List<Command> commands) {
    applyUserFilters();
    List<CommandResult> results = new ArrayList<CommandResult>();
    for (Command command : commands) {
        LOGGER.log(Level.INFO, authProvider.get().getEmail() + ": " + command.getClass().getSimpleName());
        try {
            results.add(handleCommand(command));
        } catch (CommandException e) {
            results.add(e);
        }
    }
    return results;
}
Also used : Command(org.activityinfo.shared.command.Command) ArrayList(java.util.ArrayList) CommandException(org.activityinfo.shared.exception.CommandException) CommandResult(org.activityinfo.shared.command.result.CommandResult) LogException(org.activityinfo.server.util.logging.LogException)

Example 10 with LogException

use of org.activityinfo.server.util.logging.LogException in project activityinfo by bedatadriven.

the class CommandServlet method handleCommand.

@LogException(emailAlert = true)
protected CommandResult handleCommand(Command command) throws CommandException {
    RemoteExecutionContext context = null;
    try {
        long timeStart = System.currentTimeMillis();
        context = new RemoteExecutionContext(injector);
        CommandResult result = context.startExecute(command);
        long timeElapsed = System.currentTimeMillis() - timeStart;
        if (timeElapsed > 1000) {
            LOGGER.warning("Command " + command.toString() + " completed in " + timeElapsed + "ms");
        }
        return result;
    } catch (Exception e) {
        throw new CommandException(command, context, e);
    }
}
Also used : CommandException(org.activityinfo.shared.exception.CommandException) LogException(org.activityinfo.server.util.logging.LogException) InvalidAuthTokenException(org.activityinfo.shared.exception.InvalidAuthTokenException) CommandException(org.activityinfo.shared.exception.CommandException) CommandResult(org.activityinfo.shared.command.result.CommandResult) LogException(org.activityinfo.server.util.logging.LogException)

Aggregations

LogException (org.activityinfo.server.util.logging.LogException)12 POST (javax.ws.rs.POST)6 User (org.activityinfo.server.database.hibernate.entity.User)6 NoResultException (javax.persistence.NoResultException)4 Produces (javax.ws.rs.Produces)4 IOException (java.io.IOException)3 Date (java.util.Date)3 Transactional (org.activityinfo.server.database.hibernate.dao.Transactional)3 CommandException (org.activityinfo.shared.exception.CommandException)3 ServletException (javax.servlet.ServletException)2 InvalidInvitePageModel (org.activityinfo.server.login.model.InvalidInvitePageModel)2 SignUpAddressExistsPageModel (org.activityinfo.server.login.model.SignUpAddressExistsPageModel)2 ResetPasswordMessage (org.activityinfo.server.mail.ResetPasswordMessage)2 CommandResult (org.activityinfo.shared.command.result.CommandResult)2 StringWriter (java.io.StringWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 DataHandler (javax.activation.DataHandler)1