Java Code Examples for org.springframework.web.servlet.support.ServletUriComponentsBuilder#path()

The following examples show how to use org.springframework.web.servlet.support.ServletUriComponentsBuilder#path() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PasswordResetterImpl.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
private URI createPasswordResetUri(String username, String token) {
  ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentServletMapping();
  builder.encode();
  builder.path("/account/password/change");
  builder.queryParam("username", username);
  builder.queryParam("token", token);
  return builder.build().toUri();
}
 
Example 2
Source File: UriUtils.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static UriComponents createEntityTypeMetadataAttributeUriComponents(
    String entityTypeId, String attributeName) {
  ServletUriComponentsBuilder builder = createBuilder();
  builder.path(ApiNamespace.API_PATH);
  builder.pathSegment(RestController.API_VERSION, entityTypeId, "meta", attributeName);
  return builder.build();
}
 
Example 3
Source File: UriUtils.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static UriComponents createEntityAttributeUriComponents(
    String entityTypeId, Object entityId, String attributeName) {
  ServletUriComponentsBuilder builder = createBuilder();
  builder.path(ApiNamespace.API_PATH);
  builder.pathSegment(
      RestController.API_VERSION, entityTypeId, entityId.toString(), attributeName);
  return builder.build();
}
 
Example 4
Source File: UriUtils.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static UriComponents createEntityCollectionUriComponents(
    ServletUriComponentsBuilder builder, String entityTypeId) {
  builder = builder.cloneBuilder();
  builder.path(ApiNamespace.API_PATH);
  builder.pathSegment(RestControllerV2.API_VERSION, entityTypeId);
  return builder.build();
}
 
Example 5
Source File: UriUtils.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static UriComponents createEntityTypeMetadataAttributeUriComponents(
    ServletUriComponentsBuilder builder, String entityTypeId, String attributeName) {
  builder = builder.cloneBuilder();
  builder.path(ApiNamespace.API_PATH);
  builder.pathSegment(RestControllerV2.API_VERSION, entityTypeId, "meta", attributeName);
  return builder.build();
}
 
Example 6
Source File: UriUtils.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static UriComponents createEntityUriComponents(
    ServletUriComponentsBuilder builder, String entityTypeId, Object entityId) {
  builder = builder.cloneBuilder();
  builder.path(ApiNamespace.API_PATH);
  builder.pathSegment(RestControllerV2.API_VERSION, entityTypeId, entityId.toString());
  return builder.build();
}
 
Example 7
Source File: UriUtils.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static UriComponents createEntityAttributeUriComponents(
    ServletUriComponentsBuilder builder,
    String entityTypeId,
    Object entityId,
    String attributeName) {
  builder = builder.cloneBuilder();
  builder.path(ApiNamespace.API_PATH);
  builder.pathSegment(
      RestControllerV2.API_VERSION, entityTypeId, entityId.toString(), attributeName);
  return builder.build();
}
 
Example 8
Source File: UriUtils.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static UriComponents createEntitiesUriComponents(
    ServletUriComponentsBuilder builder,
    String entityTypeId,
    String idAttributeName,
    Collection<String> entityIds) {
  builder = builder.cloneBuilder();
  builder.path(ApiNamespace.API_PATH);
  builder.pathSegment(RestControllerV2.API_VERSION, entityTypeId);
  builder.queryParam("q", createEntitiesUriQuery(idAttributeName, entityIds));
  return builder.build();
}
 
Example 9
Source File: UserService.java    From wallride with Apache License 2.0 4 votes vote down vote up
public PasswordResetToken createPasswordResetToken(PasswordResetTokenCreateRequest request) {
	User user = userRepository.findOneByEmail(request.getEmail());
	if (user == null) {
		throw new EmailNotFoundException();
	}

	LocalDateTime now = LocalDateTime.now();
	PasswordResetToken passwordResetToken = new PasswordResetToken();
	passwordResetToken.setUser(user);
	passwordResetToken.setEmail(user.getEmail());
	passwordResetToken.setExpiredAt(now.plusHours(24));
	passwordResetToken.setCreatedAt(now);
	passwordResetToken.setCreatedBy(user.toString());
	passwordResetToken.setUpdatedAt(now);
	passwordResetToken.setUpdatedBy(user.toString());
	passwordResetToken = passwordResetTokenRepository.saveAndFlush(passwordResetToken);

	try {
		Blog blog = blogService.getBlogById(Blog.DEFAULT_ID);
		String blogTitle = blog.getTitle(LocaleContextHolder.getLocale().getLanguage());

		ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentContextPath();
		if (blog.isMultiLanguage()) {
			builder.path("/{language}");
		}
		builder.path("/password-reset");
		builder.path("/{token}");

		Map<String, Object> urlVariables = new LinkedHashMap<>();
		urlVariables.put("language", request.getLanguage());
		urlVariables.put("token", passwordResetToken.getToken());
		String resetLink = builder.buildAndExpand(urlVariables).toString();

		Context ctx = new Context(LocaleContextHolder.getLocale());
		ctx.setVariable("passwordResetToken", passwordResetToken);
		ctx.setVariable("resetLink", resetLink);

		MimeMessage mimeMessage = mailSender.createMimeMessage();
		MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, "UTF-8"); // true = multipart
		message.setSubject(MessageFormat.format(
				messageSourceAccessor.getMessage("PasswordResetSubject", LocaleContextHolder.getLocale()),
				blogTitle));
		message.setFrom(mailProperties.getProperties().get("mail.from"));
		message.setTo(passwordResetToken.getEmail());

		String htmlContent = templateEngine.process("password-reset", ctx);
		message.setText(htmlContent, true); // true = isHtml

		mailSender.send(mimeMessage);
	} catch (MessagingException e) {
		throw new ServiceException(e);
	}

	return passwordResetToken;
}
 
Example 10
Source File: UserService.java    From wallride with Apache License 2.0 4 votes vote down vote up
@CacheEvict(value = WallRideCacheConfiguration.USER_CACHE, allEntries = true)
public User updatePassword(PasswordUpdateRequest request, PasswordResetToken passwordResetToken) {
	User user = userRepository.findOneForUpdateById(request.getUserId());
	if (user == null) {
		throw new IllegalArgumentException("The user does not exist");
	}
	PasswordEncoder passwordEncoder = new StandardPasswordEncoder();
	user.setLoginPassword(passwordEncoder.encode(request.getPassword()));
	user.setUpdatedAt(LocalDateTime.now());
	user.setUpdatedBy(passwordResetToken.getUser().toString());
	user = userRepository.saveAndFlush(user);

	passwordResetTokenRepository.delete(passwordResetToken);

	try {
		Blog blog = blogService.getBlogById(Blog.DEFAULT_ID);
		String blogTitle = blog.getTitle(LocaleContextHolder.getLocale().getLanguage());

		ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentContextPath();
		if (blog.isMultiLanguage()) {
			builder.path("/{language}");
		}
		builder.path("/login");

		Map<String, Object> urlVariables = new LinkedHashMap<>();
		urlVariables.put("language", request.getLanguage());
		urlVariables.put("token", passwordResetToken.getToken());
		String loginLink = builder.buildAndExpand(urlVariables).toString();

		Context ctx = new Context(LocaleContextHolder.getLocale());
		ctx.setVariable("passwordResetToken", passwordResetToken);
		ctx.setVariable("resetLink", loginLink);

		MimeMessage mimeMessage = mailSender.createMimeMessage();
		MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, "UTF-8"); // true = multipart
		message.setSubject(MessageFormat.format(
				messageSourceAccessor.getMessage("PasswordChangedSubject", LocaleContextHolder.getLocale()),
				blogTitle));
		message.setFrom(mailProperties.getProperties().get("mail.from"));
		message.setTo(passwordResetToken.getEmail());

		String htmlContent = templateEngine.process("password-changed", ctx);
		message.setText(htmlContent, true); // true = isHtml

		mailSender.send(mimeMessage);
	} catch (MessagingException e) {
		throw new ServiceException(e);
	}

	return user;
}
 
Example 11
Source File: UriUtils.java    From molgenis with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static UriComponents createEntityCollectionUriComponents(String entityTypeId) {
  ServletUriComponentsBuilder builder = createBuilder();
  builder.path(ApiNamespace.API_PATH);
  builder.pathSegment(RestController.API_VERSION, entityTypeId);
  return builder.build();
}
 
Example 12
Source File: UriUtils.java    From molgenis with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static UriComponents createEntityTypeMetadataUriComponents(String entityTypeId) {
  ServletUriComponentsBuilder builder = createBuilder();
  builder.path(ApiNamespace.API_PATH);
  builder.pathSegment(RestController.API_VERSION, entityTypeId, "meta");
  return builder.build();
}
 
Example 13
Source File: UriUtils.java    From molgenis with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static UriComponents createEntityUriComponents(String entityTypeId, Object entityId) {
  ServletUriComponentsBuilder builder = createBuilder();
  builder.path(ApiNamespace.API_PATH);
  builder.pathSegment(RestController.API_VERSION, entityTypeId, entityId.toString());
  return builder.build();
}