Browse Source

Implement /autherror POST end point; update list page method name

Signed-off-by: Pekka Helenius <fincer89@hotmail.com>
v0.0.3-alpha
Pekka Helenius 4 years ago
parent
commit
491df00b1a
1 changed files with 38 additions and 2 deletions
  1. +38
    -2
      bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java

+ 38
- 2
bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java View File

@ -27,6 +27,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.fjordtek.bookstore.model.book.AuthorRepository; import com.fjordtek.bookstore.model.book.AuthorRepository;
import com.fjordtek.bookstore.model.book.Book; import com.fjordtek.bookstore.model.book.Book;
@ -127,17 +128,52 @@ public class BookController {
value = bookListPageView, value = bookListPageView,
method = { RequestMethod.GET, RequestMethod.POST } method = { RequestMethod.GET, RequestMethod.POST }
) )
public String defaultWebFormGet(
public String defaultWebFormGetPost(
HttpServletRequest requestData, HttpServletRequest requestData,
HttpServletResponse responseData, HttpServletResponse responseData,
Model dataModel Model dataModel
) { ) {
dataModel.addAttribute("books", bookRepository.findAll()); dataModel.addAttribute("books", bookRepository.findAll());
httpServerLogger.log(requestData, responseData); httpServerLogger.log(requestData, responseData);
return bookListPageView; return bookListPageView;
}
//////////////////////////////
// AUTHENTICATION ERROR
/**
* @see com.fjordtek.bookstore.service.session.BookStoreAuthenticationFailureHandler
* @see com.fjordtek.bookstore.config.WebSecurityConfig
*/
@RequestMapping(
value = "/autherror",
method = RequestMethod.POST
)
public String authErrorWebFormPost(
HttpServletRequest requestData,
HttpServletResponse responseData,
RedirectAttributes redirectAttributes
) {
/*
* We get these parameters from BookStoreAuthenticationFailureHandler
*/
String authfailure = (String) requestData.getAttribute("authfailure");
String username = (String) requestData.getAttribute("username");
if (!username.trim().isEmpty()) {
authfailure = authfailure + " (" + username + ")";
}
/*
* Add authfailure attribute to the model
* This attribute is referred in file templates/fragments/loginout.html
*/
redirectAttributes.addFlashAttribute("authfailure", authfailure);
return "redirect:/" + bookListPageView;
} }


Loading…
Cancel
Save