List of usage examples for org.springframework.mail MailException getMostSpecificCause
public Throwable getMostSpecificCause()
From source file:org.openmrs.contrib.metadatarepository.webapp.controller.SignupController.java
@RequestMapping(method = RequestMethod.POST) public String onSubmit(User user, BindingResult errors, HttpServletRequest request, HttpServletResponse response) throws Exception { if (request.getParameter("cancel") != null) { return getCancelView(); }//w w w.j a va 2s . c om if (log.isDebugEnabled()) { log.debug("entering 'onSubmit' method..."); } Locale locale = request.getLocale(); user.setEnabled(true); // Set the default user role on this new user user.addRole(roleManager.getRole(Constants.USER_ROLE)); try { this.getUserManager().saveUser(user); } catch (AccessDeniedException ade) { // thrown by UserSecurityAdvice configured in aop:advisor userManagerSecurity log.warn(ade.getMessage()); response.sendError(HttpServletResponse.SC_FORBIDDEN); return null; } catch (UserExistsException e) { errors.rejectValue("username", "errors.existing.user", new Object[] { user.getUsername(), user.getEmail() }, "duplicate user"); // redisplay the unencrypted passwords user.setPassword(user.getConfirmPassword()); return "signup"; } saveMessage(request, getText("user.registered", user.getUsername(), locale)); request.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 user an e-mail if (log.isDebugEnabled()) { log.debug("Sending user '" + user.getUsername() + "' an account information e-mail"); } // Send an account information e-mail message.setSubject(getText("signup.email.subject", locale)); try { sendUserMessage(user, getText("signup.email.message", locale), RequestUtil.getAppURL(request)); } catch (MailException me) { saveError(request, me.getMostSpecificCause().getMessage()); } return getSuccessView(); }
From source file:ejportal.webapp.action.SignupAction.java
/** * Save the user, encrypting their passwords if necessary. * /*from www. j a v a2 s. c om*/ * @return success when good things happen * @throws Exception * when bad things happen */ public String save() throws Exception { this.user.setEnabled(true); // Set the default user role on this new user // user.addRole(roleManager.getRole(Constants.USER_ROLE)); // TODO hier geaendert -- evtl nicht so schoen this.user.addRole(this.roleManager.getRole("ROLE_EXTERN")); try { this.userManager.saveUser(this.user); } catch (final AccessDeniedException ade) { // thrown by UserSecurityAdvice configured in aop:advisor // userManagerSecurity this.log.warn(ade.getMessage()); this.getResponse().sendError(HttpServletResponse.SC_FORBIDDEN); return null; } catch (final UserExistsException e) { this.log.warn(e.getMessage()); final List<Object> args = new ArrayList<Object>(); args.add(this.user.getUsername()); args.add(this.user.getEmail()); this.addActionError(this.getText("errors.existing.user", args)); // redisplay the unencrypted passwords this.user.setPassword(this.user.getConfirmPassword()); return Action.INPUT; } this.saveMessage(this.getText("user.registered")); this.getSession().setAttribute(Constants.REGISTERED, Boolean.TRUE); // log user in automatically final UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken( this.user.getUsername(), this.user.getConfirmPassword(), this.user.getAuthorities()); auth.setDetails(this.user); SecurityContextHolder.getContext().setAuthentication(auth); // Send an account information e-mail this.mailMessage.setSubject(this.getText("signup.email.subject")); try { this.sendUserMessage(this.user, this.getText("signup.email.message"), RequestUtil.getAppURL(this.getRequest())); } catch (final MailException me) { this.addActionError(me.getMostSpecificCause().getMessage()); } return Action.SUCCESS; }
From source file:alpha.portal.webapp.controller.SignupController.java
/** * On submit./*from w w w . ja v a 2s. com*/ * * @param user * the user * @param errors * the errors * @param request * the request * @param response * the response * @return the string * @throws Exception * the exception */ @RequestMapping(method = RequestMethod.POST) public String onSubmit(final User user, final BindingResult errors, final HttpServletRequest request, final HttpServletResponse response) throws Exception { if (request.getParameter("cancel") != null) return this.getCancelView(); if (this.log.isDebugEnabled()) { this.log.debug("entering 'onSubmit' method..."); } final Locale locale = request.getLocale(); user.setEnabled(true); // Set the default user role on this new user user.addRole(this.roleManager.getRole(Constants.USER_ROLE)); try { this.getUserManager().saveUser(user); } catch (final AccessDeniedException ade) { // thrown by UserSecurityAdvice configured in aop:advisor // userManagerSecurity this.log.warn(ade.getMessage()); response.sendError(HttpServletResponse.SC_FORBIDDEN); return null; } catch (final UserExistsException e) { errors.rejectValue("username", "errors.existing.user", new Object[] { user.getUsername(), user.getEmail() }, "duplicate user"); // redisplay the unencrypted passwords user.setPassword(user.getConfirmPassword()); return "signup"; } this.saveMessage(request, this.getText("user.registered", user.getUsername(), locale)); request.getSession().setAttribute(Constants.REGISTERED, Boolean.TRUE); // log user in automatically final UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(user.getUsername(), user.getConfirmPassword(), user.getAuthorities()); auth.setDetails(user); SecurityContextHolder.getContext().setAuthentication(auth); // Send user an e-mail if (this.log.isDebugEnabled()) { this.log.debug("Sending user '" + user.getUsername() + "' an account information e-mail"); } // Send an account information e-mail this.message.setSubject(this.getText("signup.email.subject", locale)); try { this.sendUserMessage(user, this.getText("signup.email.message", locale), RequestUtil.getAppURL(request)); } catch (final MailException me) { this.saveError(request, me.getMostSpecificCause().getMessage()); } return this.getSuccessView(); }
From source file:org.musicrecital.webapp.pages.Signup.java
@Log Object onSuccess() throws UserExistsException, IOException { try {/*from w ww .java 2s . com*/ user = userManager.saveUser(user); } catch (AccessDeniedException ade) { // thrown by UserSecurityAdvice configured in aop:advisor logger.warn(ade.getMessage()); return new HttpError(HttpServletResponse.SC_FORBIDDEN, "Resource not available"); } catch (UserExistsException e) { // TODO #1: FIXME: only username should be highlighted.. move to onValidate()? alertManager.error(messages.format("errors.existing.user", user.getUsername(), user.getEmail())); // redisplay the unencrypted passwords user.setPassword(user.getConfirmPassword()); //TODO: somehow returning current page doesn't work //return this; response.sendRedirect("signup"); return null; } // log user in automatically securityContext.login(user); // Send user an e-mail logger.debug(String.format("Sending user '%s' an account information e-mail", user.getUsername())); try { String msg = messages.get("signup.email.message"); String subject = messages.get("signup.email.subject"); emailService.send(user, subject, msg, RequestUtil.getAppURL(request), false); } catch (MailException me) { request.getSession(true).setAttribute("error", me.getMostSpecificCause().getMessage()); } alertManager.alert(Duration.TRANSIENT, Severity.INFO, messages.get("user.registered")); return Home.class; }