Java Code Examples for org.springframework.web.bind.support.SessionStatus#setComplete()

The following examples show how to use org.springframework.web.bind.support.SessionStatus#setComplete() . 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: PdfAutomationController.java    From website with GNU Affero General Public License v3.0 6 votes vote down vote up
@RequestMapping(value = "/product", method = RequestMethod.POST)
public String update(@ModelAttribute ToProduct toProduct, BindingResult result, Model model, SessionStatus sessionStatus) {
	if (result.hasErrors()) {
		return "pdf/product";
	}
	Product product = toProduct.getProduct();
	if (toProduct.getJacketImage() != null && !toProduct.getJacketImage().isEmpty()) {
		String jacketImageFilename;
		try {
			jacketImageFilename = saveJacketImageFile(toProduct.getJacketImage());
		} catch (Exception e) {
			result.reject(e.getMessage());
			return "pdf/product";
		}
		product.setJacketImageFilename(FilenameUtils.getName(jacketImageFilename));
	}
	PdfConversion pdfConversion = toProduct.getPdfConversion();
	product = product.merge();
	pdfConversion.setProduct(product);
	pdfConversion.merge();
	sessionStatus.setComplete();
	return "redirect:/product/update/" + product.getId();
}
 
Example 2
Source File: WidgetControllerTest.java    From attic-rave with Apache License 2.0 6 votes vote down vote up
@Test(expected = SecurityException.class)
public void updateWidget_wrongToken() {
    WidgetImpl widget = new WidgetImpl();
    BindingResult errors = new BeanPropertyBindingResult(widget, "widget");
    SessionStatus sessionStatus = createMock(SessionStatus.class);
    ModelMap modelMap = new ExtendedModelMap();

    sessionStatus.setComplete();
    expectLastCall();
    replay(sessionStatus);

    String otherToken = AdminControllerUtil.generateSessionToken();

    controller.updateWidgetDetail(widget, errors, "sessionToken", otherToken,REFERRER_ID, modelMap, sessionStatus);

    verify(sessionStatus);
    assertFalse("Can't come here", true);
}
 
Example 3
Source File: OrderController.java    From spring-in-action-5-samples with Apache License 2.0 6 votes vote down vote up
@PostMapping
public String processOrder(@Valid Order order, Errors errors, 
    SessionStatus sessionStatus, 
    @AuthenticationPrincipal User user) {
  
  if (errors.hasErrors()) {
    return "orderForm";
  }

  order.setUser(user);
  
  orderRepo.save(order);
  sessionStatus.setComplete();
  
  return "redirect:/";
}
 
Example 4
Source File: CategoryControllerTest.java    From attic-rave with Apache License 2.0 6 votes vote down vote up
@Test(expected = SecurityException.class)
public void deleteCategory_invalidToken(){
    Model model = new ExtendedModelMap();
    User user = new UserImpl();
    String id = "1";
    String categoryText = "Social";
    String invalidToken = AdminControllerUtil.generateSessionToken();
    CategoryImpl category = new CategoryImpl();
    category.setCreatedUserId(user.getId());
    category.setText(categoryText);
    category.setId(id);
    SessionStatus sessionStatus = createMock(SessionStatus.class);
    expect(userService.getAuthenticatedUser()).andReturn(user).once();
    expect(categoryService.get(id)).andReturn(category);
    categoryService.delete(category);
    expectLastCall();
    sessionStatus.setComplete();
    expectLastCall();
    replay(userService, categoryService,sessionStatus);
    String view = controller.deleteCategory(category, validToken, invalidToken, "true",REFERRER_ID, model, sessionStatus);assertTrue("Test should catch exception and never hit this test", false);
    assertTrue("Test should catch exception and never hit this test", false);
}
 
Example 5
Source File: OrderController.java    From spring-in-action-5-samples with Apache License 2.0 6 votes vote down vote up
@PostMapping
public String processOrder(@Valid Order order, Errors errors, 
    SessionStatus sessionStatus, 
    @AuthenticationPrincipal User user) {
  
  if (errors.hasErrors()) {
    return "orderForm";
  }
  
  order.setUser(user);
  
  orderRepo.save(order);
  sessionStatus.setComplete();
  
  return "redirect:/";
}
 
Example 6
Source File: OrderController.java    From spring-in-action-5-samples with Apache License 2.0 6 votes vote down vote up
@PostMapping
public String processOrder(@Valid Order order, Errors errors, 
    SessionStatus sessionStatus, 
    @AuthenticationPrincipal User user) {
  
  if (errors.hasErrors()) {
    return "orderForm";
  }
  
  order.setUser(user);
  
  orderRepo.save(order);
  sessionStatus.setComplete();
  
  return "redirect:/";
}
 
Example 7
Source File: RoleHtmlController.java    From spring-boot-doma2-sample with Apache License 2.0 6 votes vote down vote up
/**
 * 編集画面 更新処理
 *
 * @param form
 * @param br
 * @param roleId
 * @param sessionStatus
 * @param attributes
 * @return
 */
@PostMapping("/edit/{roleId}")
public String editRole(@Validated @ModelAttribute("roleForm") RoleForm form, BindingResult br,
        @PathVariable Long roleId, SessionStatus sessionStatus, RedirectAttributes attributes) {
    // 入力チェックエラーがある場合は、元の画面にもどる
    if (br.hasErrors()) {
        setFlashAttributeErrors(attributes, br);
        return "redirect:/system/roles/edit/" + roleId;
    }

    // 更新対象を取得する
    val role = roleService.findById(roleId);

    // 入力値を詰め替える
    modelMapper.map(form, role);

    // 更新する
    val updatedRole = roleService.update(role);

    // セッションのroleFormをクリアする
    sessionStatus.setComplete();

    return "redirect:/system/roles/show/" + updatedRole.getId();
}
 
Example 8
Source File: UserControllerTest.java    From attic-rave with Apache License 2.0 6 votes vote down vote up
@Test
public void deleteUserDetail_success() {
    ModelMap modelMap = new ExtendedModelMap();
    String userid = "123";
    final String email = "[email protected]";
    User user = new UserImpl(userid, "john.doe.sr");
    user.setPassword("secrect");
    user.setConfirmPassword(user.getConfirmPassword());
    user.setEmail(email);

    SessionStatus sessionStatus = createMock(SessionStatus.class);

    userService.deleteUser(user.getId());
    sessionStatus.setComplete();
    expectLastCall();
    replay(userService, sessionStatus);

    final String view = controller.deleteUserDetail(user, validToken, validToken, "true",REFERRER_ID, modelMap, sessionStatus);
    verify(userService, sessionStatus);

    assertEquals("redirect:/app/admin/users?action=delete&referringPageId=" + REFERRER_ID, view);

}
 
Example 9
Source File: ApplicationController.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
@RequestMapping(value = "/application/config", method = RequestMethod.POST)
public String update(@ModelAttribute Application application, BindingResult result, Model model, SessionStatus sessionStatus, RedirectAttributes redirectAttributes) {
	if (result.hasErrors()) {
		return "application/config";
	}
	refreshWebsiteApplicationSettings();
	sessionStatus.setComplete();
	redirectAttributes.addFlashAttribute("notificationType", "success");
	redirectAttributes.addFlashAttribute("notificationMessage", "Application configuration updated");
	return "redirect:/application/config";
}
 
Example 10
Source File: UserSearchController.java    From wallride with Apache License 2.0 5 votes vote down vote up
@RequestMapping(params = "query")
public String search(
		@PathVariable String language,
		String query,
		Model model,
		SessionStatus sessionStatus,
		RedirectAttributes redirectAttributes) {
	sessionStatus.setComplete();

	for (Map.Entry<String, Object> mapEntry : model.asMap().entrySet()) {
		redirectAttributes.addFlashAttribute(mapEntry.getKey(), mapEntry.getValue());
	}
	String url = UriComponentsBuilder.fromPath("/_admin/{language}/users/index").query(query).buildAndExpand(language).encode().toUriString();
	return "redirect:" + url;
}
 
Example 11
Source File: EditPetForm.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@RequestMapping(method = RequestMethod.POST)
public String processSubmit(@ModelAttribute("pet") Pet pet, BindingResult result, SessionStatus status) {
	new PetValidator().validate(pet, result);
	if (result.hasErrors()) {
		return "petForm";
	}
	else {
		this.clinic.storePet(pet);
		status.setComplete();
		return "redirect:owner.do?ownerId=" + pet.getOwner().getId();
	}
}
 
Example 12
Source File: AddVisitForm.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@RequestMapping(method = RequestMethod.POST)
public String processSubmit(@ModelAttribute("visit") Visit visit, BindingResult result, SessionStatus status) {
	new VisitValidator().validate(visit, result);
	if (result.hasErrors()) {
		return "visitForm";
	}
	else {
		this.clinic.storeVisit(visit);
		status.setComplete();
		return "redirect:owner.do?ownerId=" + visit.getPet().getOwner().getId();
	}
}
 
Example 13
Source File: ProductController.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
@RequestMapping(value = "/product/update", method = RequestMethod.POST)
public String update(@ModelAttribute Product product, BindingResult result, Model model, SessionStatus sessionStatus) {
	if (result.hasErrors()) {
		return "product/update";
	}
	product = product.merge();
	sessionStatus.setComplete();
	return "redirect:/product/update/" + product.getId();
}
 
Example 14
Source File: PageSearchController.java    From wallride with Apache License 2.0 5 votes vote down vote up
@RequestMapping(params = "query")
public String search(
		@PathVariable String language,
		String query,
		Model model,
		SessionStatus sessionStatus,
		RedirectAttributes redirectAttributes) {
	sessionStatus.setComplete();

	for (Map.Entry<String, Object> mapEntry : model.asMap().entrySet()) {
		redirectAttributes.addFlashAttribute(mapEntry.getKey(), mapEntry.getValue());
	}
	String url = UriComponentsBuilder.fromPath("/_admin/{language}/pages/index").query(query).buildAndExpand(language).encode().toUriString();
	return "redirect:" + url;
}
 
Example 15
Source File: OwnerController.java    From audit4j-demo with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/owners/{ownerId}/edit", method = RequestMethod.PUT)
public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, SessionStatus status) {
    if (result.hasErrors()) {
        return "owners/createOrUpdateOwnerForm";
    } else {
        this.clinicService.saveOwner(owner);
        status.setComplete();
        return "redirect:/owners/{ownerId}";
    }
}
 
Example 16
Source File: OwnerController.java    From docker-workflow-plugin with MIT License 5 votes vote down vote up
@RequestMapping(value = "/owners/new", method = RequestMethod.POST)
public String processCreationForm(@Valid Owner owner, BindingResult result, SessionStatus status) {
    if (result.hasErrors()) {
        return "owners/createOrUpdateOwnerForm";
    } else {
        this.clinicService.saveOwner(owner);
        status.setComplete();
        return "redirect:/owners/" + owner.getId();
    }
}
 
Example 17
Source File: PetController.java    From audit4j-demo with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/owners/{ownerId}/pets/{petId}/edit", method = {RequestMethod.PUT, RequestMethod.POST})
public String processUpdateForm(@ModelAttribute("pet") Pet pet, BindingResult result, SessionStatus status) {
    // we're not using @Valid annotation here because it is easier to define such validation rule in Java
    new PetValidator().validate(pet, result);
    if (result.hasErrors()) {
        return "pets/createOrUpdatePetForm";
    } else {
        this.clinicService.savePet(pet);
        status.setComplete();
        return "redirect:/owners/{ownerId}";
    }
}
 
Example 18
Source File: UserController.java    From spring-boot-study with MIT License 5 votes vote down vote up
@GetMapping("/logout")
String logout(HttpSession session, SessionStatus sessionStatus, Model model) {
    //会员中心退出登录 当使用这两属性session属性退出
    session.removeAttribute("userData");
    sessionStatus.setComplete();
    SecurityUtils.getSubject().logout();
    return "redirect:/login";

}
 
Example 19
Source File: AuthorizationEndpoint.java    From MaxKey with Apache License 2.0 4 votes vote down vote up
@RequestMapping(value = "/oauth/v20/authorize", method = RequestMethod.POST, params = OAuth2Utils.USER_OAUTH_APPROVAL)
public View approveOrDeny(@RequestParam Map<String, String> approvalParameters, Map<String, ?> model,
		SessionStatus sessionStatus) {
	Principal principal=(Principal)WebContext.getAuthentication().getPrincipal();
	if (!(principal instanceof Authentication)) {
		sessionStatus.setComplete();
		throw new InsufficientAuthenticationException(
				"User must be authenticated with Spring Security before authorizing an access token.");
	}

	AuthorizationRequest authorizationRequest = (AuthorizationRequest) model.get("authorizationRequest");

	if (authorizationRequest == null) {
		sessionStatus.setComplete();
		throw new InvalidRequestException("Cannot approve uninitialized authorization request.");
	}

	try {
		Set<String> responseTypes = authorizationRequest.getResponseTypes();

		authorizationRequest.setApprovalParameters(approvalParameters);
		authorizationRequest = userApprovalHandler.updateAfterApproval(authorizationRequest,
				(Authentication) principal);
		boolean approved = userApprovalHandler.isApproved(authorizationRequest, (Authentication) principal);
		authorizationRequest.setApproved(approved);

		if (authorizationRequest.getRedirectUri() == null) {
			sessionStatus.setComplete();
			throw new InvalidRequestException("Cannot approve request when no redirect URI is provided.");
		}

		if (!authorizationRequest.isApproved()) {
			return new RedirectView(getUnsuccessfulRedirect(authorizationRequest,
					new UserDeniedAuthorizationException("User denied access"), responseTypes.contains("token")),
					false, true, false);
		}

		if (responseTypes.contains("token")) {
			return getImplicitGrantResponse(authorizationRequest).getView();
		}

		return getAuthorizationCodeResponse(authorizationRequest, (Authentication) principal);
	}
	finally {
		sessionStatus.setComplete();
	}

}
 
Example 20
Source File: RequestMappingHandlerAdapterIntegrationTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public void handleAndCompleteSession(SessionStatus sessionStatus) {
	sessionStatus.setComplete();
}