/** * {@inheritDoc} */ @Async @Override public void sendMailWithUsername( @NotBlank @Email final String email, @NotBlank final String username ) { log.info("Called with e-mail {}, username {}", email, username); try { final JavaMailSenderImpl sender = new JavaMailSenderImpl(); final MimeMessage message = sender.createMimeMessage(); final MimeMessageHelper helper = new MimeMessageHelper(message); helper.setTo(email); helper.setSubject("Recover username"); helper.setText("Your username: " + "<b>" + username + "</b>", true); sendMail(message); } catch (MessagingException e) { e.printStackTrace(); } }
/** * {@inheritDoc} */ @Async @Override public void sendMailWithNewPassword( @NotBlank @Email final String email, @NotBlank final String newPassword ) { log.info("Called with e-mail {}, newPassword {}", email, newPassword); try { final JavaMailSenderImpl sender = new JavaMailSenderImpl(); final MimeMessage message = sender.createMimeMessage(); final MimeMessageHelper helper = new MimeMessageHelper(message); helper.setTo(email); helper.setSubject("Recover password"); helper.setText("Your new password: " + "<b>" + newPassword + "</b>", true); sendMail(message); } catch (MessagingException e) { e.printStackTrace(); } }
/** * Creates a new organisation. The email address and password of one Account are used * to connect it with this organisation. So the email address and password are mandatory for * authentication otherwise a warning with the hint for wrong credentials is returned. * All further Accounts which should be associated to this organisation are added with the * method addManager. * In the response the account's password isn't returned because of security reasons. * * @param name * The name of the developer or the manager of the account. * @param email * The required valid email address. * @param password * Required header parameter associated with the email address. * @return A Response of Organisation in JSON. */ @POST @Path("/") @TypeHint(Organisation.class) public Response create(@QueryParam("name") String name, @QueryParam("email") @NotNull @Email String email, @HeaderParam("password") @NotNull String password) { LOGGER.debug("create organisation requested"); String encryptedPassword = SecurityTools.encryptWithSHA512(password); if (!accountDao.checkCredentials(email, encryptedPassword)) { throw new CredentialException(email); } Organisation organisation = new Organisation(name); organisation.addManager(accountDao.getAccount(email, encryptedPassword)); organisation.setApiKey(SecurityTools.generateApiKey()); LOGGER.debug("Organisation created"); organisationDao.insertOrganisation(organisation); return ResponseSurrogate.created(organisation); }
/** * Returns a specific organisation which id is equal to the transfered path parameter. * Additionally the email address and the associated password are mandatory and have to be * correct otherwise an exception is returned that the given credentials are wrong. * In the response the account's password isn't returned because of security reasons. * * @param id * The path parameter of the organisation, that should be returned. * @param email * The valid email address. * @param password * Required header parameter to connect it with the given * email address. * @return A response of Organisation in JSON. */ @GET @Path("/{id}") @TypeHint(Organisation.class) public Response get(@PathParam("id") @NotNull String id, @QueryParam("email") @NotNull @Email String email, @HeaderParam("password") @NotNull String password) { LOGGER.debug("get organisation requested"); if (!accountDao.checkCredentials(email, SecurityTools.encryptWithSHA512(password))) { throw new CredentialException(email); } int intId = Integer.parseInt(id); Organisation organisation = organisationDao.getOrganisation(intId); return ResponseSurrogate.of(organisation); }
/** * Generates an API key for the given organisation which matches the id, email address and the * associated password. Otherwise an exception is returned that the given credentials are wrong. * If the API key field is already set the method resets it and replaced it with the new generated * API key. * In the response the account's password isn't returned because of security reasons. * * @param id * The path parameter of the organisation, for which the API key should be generated. * @param email * The valid email address. * @param password * Required header parameter to connect it with the given email address. * @return A Response of Organisation in JSON. */ @PUT @Path("/{id}/generateapikey") @TypeHint(Organisation.class) public Response generateApiKey(@PathParam("id") @NotNull String id, @QueryParam("email") @Email String email, @HeaderParam("password") @NotNull String password) { Notification notification = new Notification(); LOGGER.debug("generate api key requested"); if (!accountDao.checkCredentials(email, SecurityTools.encryptWithSHA512(password))) { throw new CredentialException(email); } int intId = Integer.parseInt(id); Organisation organisation = organisationDao.getOrganisation(intId); organisation.setApiKey(SecurityTools.generateApiKey()); return ResponseSurrogate.updated(organisation, notification); }
/** * Creates a new account. For this an unique email address and a * password are mandatory. By the creation of an organisation this * email address is connected with it. Optionally the first and last * name can also be set. * In the response the password isn't returned because of security * reasons. * * @param email * A required valid email address. * @param password * Required query parameter to connect it with the given * email address. * @param firstName * Optionally the first name of the Account's owner can be set. * @param lastName * Optionally the last name of the Account's owner can be set. * @return A Response of Account in JSON. */ @POST @Path("/") @TypeHint(Account.class) public Response create(@QueryParam("email") @NotNull @Email String email, @QueryParam("password") @NotNull String password, @QueryParam("firstName") String firstName, @QueryParam("lastName") String lastName) { LOGGER.debug("create account requested"); if(accountDao.getAccount(email)!=null){ throw new ApiError(Response.Status.FORBIDDEN, "This mail address is already used."); } Account account = new Account(email); account.setPassword(SecurityTools.encryptWithSHA512(password)); account.setFirstName(firstName); account.setLastName(lastName); accountDao.persist(account); LOGGER.debug("Persisted account: %s", account); return ResponseSurrogate.created(account); }
/** * Returns an account corresponding to the given email address but only * if the combination with password is correct. By the creation of an * organisation this email address is connected with it. * So the method requires valid credentials otherwise a warning with the * hint for wrong credentials is returned. * In the response the password isn't returned because of security * reasons. * * @param email * A required valid unique email address. * @param password * Required header parameter associated with the email address. * @return A Response of Account in JSON. */ @GET @Path("/") @TypeHint(Account.class) public Response get(@QueryParam("email") @NotNull @Email String email, @HeaderParam("password") @NotNull String password) { LOGGER.debug("get account requested"); String encryptedPassword = SecurityTools.encryptWithSHA512(password); if (!accountDao.checkCredentials(email, encryptedPassword)) { LOGGER.warn("Account with wrong credentials (email:\"%s\", pass:\"%s\") requested", email, password); throw new CredentialException(email); } Account account = accountDao.getAccount(email, encryptedPassword); LOGGER.debug("Account requested: %s", account); return ResponseSurrogate.of(account); }
/** * Updates the first and last name of an existing account. For this the * specific email address and associated password are mandatory. * Otherwise a warning with the hint for wrong credentials is returned. * In the response the password isn't returned because of security * reasons. * * @param email * A required valid email address. * @param password * Required header parameter to connect it with the given * email address. * @param firstName * Optionally the first name of the Account's owner can be set. * @param lastName * Optionally the last name of the Account's owner can be set. * * @return A Response of Account in JSON. */ @PUT @Path("/") @TypeHint(Account.class) public Response update(@QueryParam("email") @NotNull @Email String email, @HeaderParam("password") @NotNull String password, @QueryParam("firstName") String firstName, @QueryParam("lastName") String lastName) { LOGGER.debug("update account requested"); String encryptedPassword = SecurityTools.encryptWithSHA512(password); if (!accountDao.checkCredentials(email, encryptedPassword)) { LOGGER.warn("Account with wrong credentials (email:\"%s\", pass:\"%s\") requested", email, password); throw new CredentialException(email); } Account account = accountDao.getAccount(email, encryptedPassword); Optional.ofNullable(encryptedPassword).ifPresent(account::setPassword); Optional.ofNullable(firstName).ifPresent(account::setFirstName); Optional.ofNullable(lastName).ifPresent(account::setLastName); accountDao.persist(account); LOGGER.debug("Updated account: %s", account); return ResponseSurrogate.updated(account); }
@Test public void testEmail() { Set<ConstraintViolation<ObjectWithValidation>> violations = validator.validate(obj, Email.class); assertNotNull(violations); assertEquals(violations.size(), 1); if (runPeformance) { long time = System.currentTimeMillis(); for (int index = 0; index < 10000; index++) { validator.validate(obj, Email.class); } long used = System.currentTimeMillis() - time; System.out.println("Hibernate Validator [Email] check used " + used + "ms, avg. " + ((double) used) / 10000 + "ms."); } }
@Override protected String getType() { String type = javaToHtmlTypes.get(valueType); if (type != null) { return type; } type = "text"; if (annotations != null) { if (annotations.containsKey(Email.class)) { type = "email"; } else if (annotations.containsKey(URL.class)) { type = "url"; } else if (annotations.containsKey(Max.class) || annotations.containsKey(Min.class)) { type = "number"; } } return type; }
/** * {@inheritDoc} */ @Override public User getUserByEmail( @NotBlank @Email final String email ) throws ResourceNotFoundException { log.info("Called with email {}", email); return this.userRepository.findByEmailIgnoreCaseAndEnabledTrue(email) .map(ServiceUtils::toUserDto) .orElseThrow(() -> new ResourceNotFoundException("No user found with e-mail " + email)); }
/** * {@inheritDoc} */ @Override public boolean existsUserByEmail( @NotBlank @Email final String email ) { log.info("Called with email {}", email); return this.userRepository.existsByEmailIgnoreCase(email); }
/** * {@inheritDoc} */ @Async @Override public void sendMailWithActivationToken( @NotBlank @Email final String email, @NotBlank final String token ) { log.info("Called with e-mail {}, token {}", email, token); try { final JavaMailSenderImpl sender = new JavaMailSenderImpl(); final MimeMessage message = sender.createMimeMessage(); final MimeMessageHelper helper = new MimeMessageHelper(message); helper.setTo(email); helper.setSubject("Complete registration"); helper.setText("To activation your account, click the link below:<br />" + "<a href='" + "https://localhost:8443" + "/register/thanks?token=" + token + "'>" + "Click here to complete your registration" + "</a>", true); sendMail(message); } catch (MessagingException e) { e.printStackTrace(); } }
/** * {@inheritDoc} */ @Async @Override public void sendMailWithEmailChangeToken( @NotBlank @Email final String email, @NotBlank final String token ) { log.info("Called with e-mail {}, token {}", email, token); try { final JavaMailSenderImpl sender = new JavaMailSenderImpl(); final MimeMessage message = sender.createMimeMessage(); final MimeMessageHelper helper = new MimeMessageHelper(message); helper.setTo(email); helper.setSubject("Change e-mail"); helper.setText("Change e-mail address, click the link below:<br />" + "<a href='" + "https://localhost:8443" + "/settings/changeEmail/thanks?token=" + token + "'>" + "Click here to complete the change of your e-mail" + "</a>", true); sendMail(message); } catch (MessagingException e) { e.printStackTrace(); } }
@Test public void testEmail() { AssertAnnotations.assertField( User.class, "email", Column.class, Email.class); Column c = ReflectTool.getFieldAnnotation(User.class, "email", Column.class); assertEquals("column email: name is not equal", "email", c.name()); assertEquals("column email: unique is false", true, c.unique()); assertEquals("column email: nullable is true", false, c.nullable()); }
@ValidQueryParams @GET public Collection<User> query(@QueryParam("name") String name, @Email @QueryParam("email") String email) { if (!SecurityUtils.canAccessPublic()) throw new UnauthorizedException("Unauthorized access to user profiles"); EntityCriteria<User> criteria = EntityCriteria.of(User.class); if (name != null) criteria.add(Restrictions.eq("name", name)); if (email != null) criteria.add(Restrictions.eq("email", email)); return userManager.findAll(criteria); }
private boolean areWrongPreconditions(Object objectValue, Annotation annotation) { if (objectValue == null) return true; if (!(annotation instanceof Email)) throw new WrongAnnotationTypeException(); return false; }
private void mockEmailValidator() throws Exception { emailValidator = mock(EmailValidator.class); whenNew(EmailValidator.class) .withAnyArguments() .thenReturn(emailValidator); when(emailValidator.getAnnotationType()) .thenReturn(Email.class); }
public MessageList findMessages(@Null @Email String recipientEmail, Pageable pageRequest) { List<MessageEntity> entities; if (StringUtils.isBlank(recipientEmail)) { entities = messageRepository.findAllByOrderByReceivedDateDesc(pageRequest); } else { entities = messageRepository.findAllForRecipientOrderByReceivedDateDesc(recipientEmail, pageRequest); } return messageListMapper.toMessageList(entities); }
@RequestMapping() public MessageList getMessages( @RequestParam(name = "recipient", required = false) @Email String recipientEmail, Pageable pageRequest) { return messageService.findMessages(recipientEmail, pageRequest); }
/** * Retorna o endereço de e-mail. * * @return o endereço de e-mail armazenado no campo email. */ @NotBlank @Email @Column(nullable = false, length = 254) // @Column(nullable = false, length = 254, unique = true) public String getEmail() { return this.email; }
/** * 获取E-mail * * @return E-mail */ @NotEmpty @Email @Length(max = 200) @Column(nullable = false) public String getEmail() { return email; }
/** * 获取E-mail * * @return E-mail */ @NotEmpty @Email @Length(max = 200) @Column(nullable = false, updatable = false) public String getEmail() { return email; }
/** * 获取发件人邮箱 * * @return 发件人邮箱 */ @NotEmpty @Email @Length(max = 200) public String getSmtpFromMail() { return smtpFromMail; }
/** * * @return */ @NotBlank(message="Email não pode ser branco",groups=VGroupUsuario.class) @Email(message="E-mail inválido",groups=VGroupUsuario.class) @JazzProp(name="E-mail", stereotype=PropertyStereotype.EMAIL) public String getEmail() { return email; }
/** * * @return */ //@NotBlank(message="Email não pode ser branco",groups=VGroupUsuario.class) //@Email(message="E-mail inválido",groups=VGroupUsuario.class) @JazzProp(name="E-mail", stereotype=PropertyStereotype.EMAIL) @Email(message="Email inválido!") @NotBlank(message="Email não pode ficar em branco") public String getEmail() { return email; }
/** * Adds a new developer to the organisation's list of manager. The email address and * password are mandatory for authentication otherwise a warning with the hint for * wrong credentials is returned. If the manager who should be added is already in the * list, a message is given with the hint that she/he is already added. * In the response the account's password isn't returned because of security reasons. * * @param manager * The required valid email address for the new manager. * @param managerPw * The required new password of the new maanger. * @param firstName * Optionally the first name of the Account's owner can be set. * @param lastName * Optionally the last name of the Account's owner can be set. * @param apiKey * The API key of the organisation to which the manager belongs to. * @return A Response of Organisation in JSON. */ @POST @Path("/addManager") @TypeHint(Organisation.class) public Response addManager(@QueryParam("manager") @NotNull @Email String manager, @QueryParam("managerPW") @NotNull String managerPw, @QueryParam("firstName") String firstName, @QueryParam("lastName") String lastName, @QueryParam("apiKey") @ValidApiKey String apiKey) { LOGGER.debug("add organisation requested"); Organisation organisation = organisationDao.getOrganisationByApiKey(apiKey); if(organisation == null){ throw new ApiError(Response.Status.NOT_FOUND, "Organisation %s not found"); } if (organisation.getManagers().contains(accountDao.getAccount(manager))) { throw new ApiError(Response.Status.NOT_ACCEPTABLE, "Account %s already in managers list", manager); } Account newManager = new Account(manager); newManager.setPassword(SecurityTools.encryptWithSHA512(managerPw)); newManager.setFirstName(firstName); newManager.setLastName(lastName); organisation.addManager(newManager); return ResponseSurrogate.created(organisation); }
/** * Returns all organisations which are associated with the combination of the two * query parameters. Otherwise an exception is sent that the given credentials are wrong. * In the response the account's password isn't returned because of security reasons. * * @param email * A required valid email address. * @param password * Required header parameter to connect it with the given email address. * @return A Response as List of Organisations in JSON. */ @GET @Path("/*") @TypeHint(Organisation[].class) public Response get(@QueryParam("email") @NotNull @Email String email, @HeaderParam("password") @NotNull String password) { LOGGER.debug("get organisation requested"); if (!accountDao.checkCredentials(email, SecurityTools.encryptWithSHA512(password))) { throw new CredentialException(email); } List<Organisation> organisation = organisationDao.getAllOrganisations(email); return ResponseSurrogate.of(organisation); }
@Test public void testCreateAccountNotAnEmail() throws NoSuchMethodException { String wrongEmail = "not an email"; String password = SecurityTools.encryptWithSHA512("123456"); Method method = AccountApi.class.getMethod("create", String.class, String.class, String.class, String.class); Object[] parameterValues = { wrongEmail, password, null, null }; Set<ConstraintViolation<AccountApi>> violations = executableValidator.validateParameters(accountApi, method, parameterValues); assertThat(violations.size()).is(1); Class<? extends Annotation> constraintType = violations.iterator().next().getConstraintDescriptor().getAnnotation().annotationType(); assertThat(constraintType).isEqualTo(Email.class); }
@Test public void testCreateOrganisationNotAnEmail() throws NoSuchMethodException { String id = "1"; String wrongEmail = "not an email"; String password = "123456"; Method method = OrganisationApi.class.getMethod("create", String.class, String.class, String.class); Object[] parameterValues = { id, wrongEmail, password }; Set<ConstraintViolation<OrganisationApi>> violations = executableValidator.validateParameters(organisationApi, method, parameterValues); assertThat(violations.size()).is(1); Class<? extends Annotation> constraintType = violations.iterator().next().getConstraintDescriptor().getAnnotation().annotationType(); assertThat(constraintType).isEqualTo(Email.class); }
/** * Gets the mail. * * @return the mail */ @NotEmpty(message = "common.form.profile.field.mail.empty") @NotNull(message = "common.form.profile.field.mail.empty") @NotBlank(message = "common.form.profile.field.mail.empty") @Email(message = "common.form.profile.field.mail.pattern") public String getMail() { return this.m_strMail; }
/** * Gets the contact snd mail. * * @return the contact snd mail */ @NotEmpty(message = "org.form.offer.field.contactMail.empty") @NotNull(message = "org.form.offer.field.contactMail.empty") @NotBlank(message = "org.form.offer.field.contactMail.empty") @Email(message = "org.form.offer.field.contactMail.pattern") public String getContactSndMail() { return this.m_strContactSndMail; }
/** * Gets the mail. * * @return the mail */ @NotEmpty(message = "user.form.register.field.mail.empty") @NotNull(message = "user.form.register.field.mail.empty") @NotBlank(message = "user.form.register.field.mail.empty") @Email(message = "user.form.register.field.mail.pattern") public String getMail() { return this.m_strMail; }