Search in sources :

Example 1 with UserExistsException

use of org.appfuse.service.UserExistsException in project vaadin-jsf-integration by alejandro-du.

the class SignupForm method save.

public String save() throws Exception {
    user.setEnabled(true);
    // Set the default user role on this new user
    user.addRole(roleManager.getRole(Constants.USER_ROLE));
    try {
        user = userManager.saveUser(user);
    } catch (AccessDeniedException ade) {
        // thrown by UserSecurityAdvice configured in aop:advisor userManagerSecurity
        log.warn(ade.getMessage());
        getResponse().sendError(HttpServletResponse.SC_FORBIDDEN);
        return null;
    } catch (UserExistsException e) {
        addMessage("errors.existing.user", new Object[] { user.getUsername(), user.getEmail() });
        // redisplay the unencrypted passwords
        user.setPassword(user.getConfirmPassword());
        return null;
    }
    addMessage("user.registered");
    getSession().setAttribute(Constants.REGISTERED, Boolean.TRUE);
    // log user in automatically
    UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(user.getUsername(), user.getConfirmPassword(), user.getAuthorities());
    auth.setDetails(user);
    SecurityContextHolder.getContext().setAuthentication(auth);
    // Send an account information e-mail
    message.setSubject(getText("signup.email.subject"));
    try {
        sendUserMessage(user, getText("signup.email.message"), RequestUtil.getAppURL(getRequest()));
    } catch (MailException me) {
        addError(me.getMostSpecificCause().getMessage());
        return null;
    }
    return "home";
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) UserExistsException(org.appfuse.service.UserExistsException) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) MailException(org.springframework.mail.MailException)

Aggregations

UserExistsException (org.appfuse.service.UserExistsException)1 MailException (org.springframework.mail.MailException)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1