Browse Source

Return different book JSON based on user login data & book publish

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

+ 10
- 2
bookstore/src/main/java/com/fjordtek/bookstore/web/BookRestController.java View File

@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
@ -55,12 +56,19 @@ public class BookRestController {
) )
public @ResponseBody Iterable<Book> getAllBooksRestData( public @ResponseBody Iterable<Book> getAllBooksRestData(
HttpServletRequest requestData, HttpServletRequest requestData,
HttpServletResponse responseData
HttpServletResponse responseData,
Authentication authData
) { ) {
String authorities = authData.getAuthorities().toString();
httpServerLogger.log(requestData, responseData); httpServerLogger.log(requestData, responseData);
return bookRepository.findAll();
if (authorities.contains("MARKETING")) {
return bookRepository.findAll();
} else {
return bookRepository.findAllPublished();
}
} }
@RequestMapping( @RequestMapping(


Loading…
Cancel
Save