Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); String name; if (principal instanceof UserDetails) { name = ((UserDetails)principal).getUsername(); } else { name = principal.toString(); }
public String write(@RequestParam("title") String title, @RequestParam("contents") String contents, Model model, Principal principal) { ... page.edit(contents, userRepository.get(principal.getName())); ... }
<%@ taglib uri="http://www.springframework.org/security/tags" prefix="sec" %> ... <sec:authorize ifAllGranted="ROLE_USER"> <input id="contents_edit" type="textarea" class="page_edit" value="${page.contents}" /> <a href="#" class="page_edit" id="save">save</a> </sec:authorize> ... <sec:authorize url="/login"> <a href="logout">Logout</a> </sec:authorize>
<dependency> <groupId>org.pegdown</groupId> <artifactId>pegdown</artifactId> <version>1.1.0</version> </dependency>
String html = new PegDownProcessor().markdownToHtml("markdown text");