From 251ea5edb6353d7793796619956319581e59ba02 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Mon, 18 Jun 2012 00:40:42 -0300 Subject: [PATCH] Add embedded and public view compatibility. Remove Utils method --- .../controller/ChangePasswordController.java | 4 +-- .../controller/EditProfileController.java | 4 +-- .../controller/TagsController.java | 2 +- .../wisemapping/mail/NotificationService.java | 1 - .../model/CollaborationProperties.java | 2 +- .../ncontroller/LoginController.java | 4 +-- .../ncontroller/MindmapController.java | 30 ++++++++++++++++--- .../wisemapping/rest/MindmapController.java | 2 +- .../java/com/wisemapping/security/Utils.java | 20 +++++-------- .../security/aop/ViewBaseSecurityAdvise.java | 5 ++-- .../com/wisemapping/view/MindMapBean.java | 11 +++++-- .../webapp/WEB-INF/wisemapping-security.xml | 10 +++++-- wise-webapp/src/main/webapp/jsp/init.jsp | 2 +- .../src/main/webapp/jsp/mindmapPublish.jsp | 4 +-- .../test/rest/RestMindmapTCase.java | 21 ++++++------- 15 files changed, 76 insertions(+), 46 deletions(-) diff --git a/wise-webapp/src/main/java/com/wisemapping/controller/ChangePasswordController.java b/wise-webapp/src/main/java/com/wisemapping/controller/ChangePasswordController.java index 9c95482d..ac4a4c23 100644 --- a/wise-webapp/src/main/java/com/wisemapping/controller/ChangePasswordController.java +++ b/wise-webapp/src/main/java/com/wisemapping/controller/ChangePasswordController.java @@ -38,8 +38,8 @@ public class ChangePasswordController BindException errors) throws ServletException { final ChangePasswordBean bean = (ChangePasswordBean) command; - // Reload user only in case of beeing necessary... - final User model = Utils.getUser(request); + // Reload user only in case of being necessary... + final User model = Utils.getUser(); final UserService userService = this.getUserService(); final User user = userService.reloadUser(model); diff --git a/wise-webapp/src/main/java/com/wisemapping/controller/EditProfileController.java b/wise-webapp/src/main/java/com/wisemapping/controller/EditProfileController.java index 5f474784..f0e3199c 100755 --- a/wise-webapp/src/main/java/com/wisemapping/controller/EditProfileController.java +++ b/wise-webapp/src/main/java/com/wisemapping/controller/EditProfileController.java @@ -34,7 +34,7 @@ public class EditProfileController extends BaseSimpleFormController { protected Object formBackingObject(HttpServletRequest httpServletRequest) throws Exception { - final User model = Utils.getUser(httpServletRequest); + final User model = Utils.getUser(); return new UserBean(model); } @@ -47,7 +47,7 @@ public class EditProfileController extends BaseSimpleFormController { final UserService userService = this.getUserService(); // Reload user only in case of beeing necessary... - final User model = Utils.getUser(request); + final User model = Utils.getUser(); final User user = userService.reloadUser(model); user.setFirstname(bean.getFirstname()); diff --git a/wise-webapp/src/main/java/com/wisemapping/controller/TagsController.java b/wise-webapp/src/main/java/com/wisemapping/controller/TagsController.java index 90be67cb..f4178383 100644 --- a/wise-webapp/src/main/java/com/wisemapping/controller/TagsController.java +++ b/wise-webapp/src/main/java/com/wisemapping/controller/TagsController.java @@ -38,7 +38,7 @@ public class TagsController protected Object formBackingObject(HttpServletRequest httpServletRequest) throws Exception { final MindMap mindmap = null; - final User user = Utils.getUser(httpServletRequest); + final User user = Utils.getUser(); final User dbUser = getUserService().getUserBy(user.getId()); final TagBean tagBean = new TagBean(); diff --git a/wise-webapp/src/main/java/com/wisemapping/mail/NotificationService.java b/wise-webapp/src/main/java/com/wisemapping/mail/NotificationService.java index 7303bc1f..e56f81e8 100644 --- a/wise-webapp/src/main/java/com/wisemapping/mail/NotificationService.java +++ b/wise-webapp/src/main/java/com/wisemapping/mail/NotificationService.java @@ -62,7 +62,6 @@ final public class NotificationService { model.put("message", message); model.put("supportEmail", mailer.getSupportEmail()); - mailer.sendEmail(formMail, collabEmail, subject, model, "newCollaboration.vm"); } catch (Exception e) { handleException(e); diff --git a/wise-webapp/src/main/java/com/wisemapping/model/CollaborationProperties.java b/wise-webapp/src/main/java/com/wisemapping/model/CollaborationProperties.java index 8fab926d..23393c6a 100644 --- a/wise-webapp/src/main/java/com/wisemapping/model/CollaborationProperties.java +++ b/wise-webapp/src/main/java/com/wisemapping/model/CollaborationProperties.java @@ -21,7 +21,7 @@ package com.wisemapping.model; import org.jetbrains.annotations.NotNull; public class CollaborationProperties { - private static final String DEFAULT_JSON_PROPERTIES = "{zoom:0.8}"; + public static final String DEFAULT_JSON_PROPERTIES = "{zoom:0.8}"; private int id; private boolean starred; private String mindmapProperties; diff --git a/wise-webapp/src/main/java/com/wisemapping/ncontroller/LoginController.java b/wise-webapp/src/main/java/com/wisemapping/ncontroller/LoginController.java index bfd0b13c..c34e7463 100644 --- a/wise-webapp/src/main/java/com/wisemapping/ncontroller/LoginController.java +++ b/wise-webapp/src/main/java/com/wisemapping/ncontroller/LoginController.java @@ -35,8 +35,8 @@ public class LoginController { private String driver; @RequestMapping(value = "login", method = RequestMethod.GET) - protected ModelAndView showLoginPage(HttpServletRequest request) { - final User user = Utils.getUser(request); + protected ModelAndView showLoginPage() { + final User user = Utils.getUser(false); ModelAndView result; if (user != null) { result = new ModelAndView("forward:/c/maps/"); diff --git a/wise-webapp/src/main/java/com/wisemapping/ncontroller/MindmapController.java b/wise-webapp/src/main/java/com/wisemapping/ncontroller/MindmapController.java index ef89aba3..7aea2030 100644 --- a/wise-webapp/src/main/java/com/wisemapping/ncontroller/MindmapController.java +++ b/wise-webapp/src/main/java/com/wisemapping/ncontroller/MindmapController.java @@ -29,6 +29,7 @@ import com.wisemapping.view.MindMapBean; import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; @@ -40,10 +41,15 @@ import java.util.List; @Controller public class MindmapController { + @Qualifier("mindmapService") @Autowired private MindmapService mindmapService; + @Value("${site.baseurl}") + String siteBaseUrl; + + @RequestMapping(value = "maps/import") public String showImportPage() { return "mindmapImport"; @@ -58,7 +64,7 @@ public class MindmapController { @RequestMapping(value = "maps/{id}/print") public String showPrintPage(@PathVariable int id, @NotNull Model model) { - final MindMap mindmap = findMindmap(id); + final MindMapBean mindmap = findMindmapBean(id); model.addAttribute("mindmap", mindmap); return "mindmapPrint"; } @@ -93,6 +99,7 @@ public class MindmapController { public String showPublishPage(@PathVariable int id, @NotNull Model model) { final MindMap mindmap = findMindmap(id); model.addAttribute("mindmap", mindmap); + model.addAttribute("baseUrl", siteBaseUrl); return "mindmapPublish"; } @@ -155,15 +162,30 @@ public class MindmapController { } @RequestMapping(value = "maps/{id}/embed") - public ModelAndView embeddedView(@PathVariable int id, @RequestParam(required = false) Float zoom) { + public ModelAndView showEmbeddedPage(@PathVariable int id, @RequestParam(required = false) Float zoom) { ModelAndView view; - final MindMap mindmap = mindmapService.findMindmapById(id); + final MindMapBean mindmap = findMindmapBean(id); view = new ModelAndView("mindmapEmbedded", "mindmap", mindmap); - view.addObject("user", Utils.getUser()); view.addObject("zoom", zoom == null ? 1 : zoom); return view; } + @RequestMapping(value = "maps/{id}/public", method = RequestMethod.GET) + public String showPublicViewPage(@PathVariable int id, @NotNull Model model) throws WiseMappingException { + return this.showPrintPage(id, model); + } + + @Deprecated + @RequestMapping(value = "publicView", method = RequestMethod.GET) + public String showPublicViewPageLegacy(@RequestParam(required = true) int mapId, @NotNull Model model) throws WiseMappingException { + return "redirect:maps/" + mapId + "/public"; + } + + @Deprecated + @RequestMapping(value = "embeddedView", method = RequestMethod.GET) + public String showPublicViewLegacyPage(@RequestParam(required = true) int mapId, @RequestParam(required = false) int zoom, @NotNull Model model) throws WiseMappingException { + return "redirect:maps/" + mapId + "/embed?zoom=" + zoom; + } private MindMap findMindmap(long mapId) { final MindMap mindmap = mindmapService.findMindmapById((int) mapId); diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java index 6e2195f6..f4ca0ab6 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java @@ -293,7 +293,7 @@ public class MindmapController extends BaseController { final MindMap mindMap = mindmapService.findMindmapById(id); final User user = Utils.getUser(); - if (!!mindMap.hasPermissions(user, CollaborationRole.OWNER)) { + if (!mindMap.hasPermissions(user, CollaborationRole.OWNER)) { throw new IllegalArgumentException("No enough to execute this operation"); } diff --git a/wise-webapp/src/main/java/com/wisemapping/security/Utils.java b/wise-webapp/src/main/java/com/wisemapping/security/Utils.java index e71c6c67..97ae2904 100644 --- a/wise-webapp/src/main/java/com/wisemapping/security/Utils.java +++ b/wise-webapp/src/main/java/com/wisemapping/security/Utils.java @@ -20,6 +20,7 @@ package com.wisemapping.security; import com.wisemapping.model.User; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.springframework.security.authentication.AbstractAuthenticationToken; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; @@ -30,19 +31,14 @@ final public class Utils { private Utils() { } - public static User getUser(@NotNull final HttpServletRequest request) { - - final AbstractAuthenticationToken token = (AbstractAuthenticationToken) request.getUserPrincipal(); - User result = null; - if (token != null) { - final UserDetails userDetails = (UserDetails) token.getPrincipal(); - result = userDetails.getUser(); - } - return result; - } - + @SuppressWarnings({"ConstantConditions"}) @NotNull public static User getUser() { + return getUser(false); + } + + @Nullable + public static User getUser(boolean forceCheck) { User result = null; final Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth != null && auth.getDetails() != null) @@ -53,7 +49,7 @@ final public class Utils { } } - if(result==null){ + if(result==null && forceCheck){ throw new IllegalStateException("User could not be retrieved"); } return result; diff --git a/wise-webapp/src/main/java/com/wisemapping/security/aop/ViewBaseSecurityAdvise.java b/wise-webapp/src/main/java/com/wisemapping/security/aop/ViewBaseSecurityAdvise.java index c5fddfce..5c8f5fcb 100755 --- a/wise-webapp/src/main/java/com/wisemapping/security/aop/ViewBaseSecurityAdvise.java +++ b/wise-webapp/src/main/java/com/wisemapping/security/aop/ViewBaseSecurityAdvise.java @@ -24,6 +24,7 @@ import com.wisemapping.model.CollaborationRole; import com.wisemapping.model.User; import com.wisemapping.model.MindMap; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class ViewBaseSecurityAdvise extends BaseSecurityAdvice @@ -34,11 +35,11 @@ public class ViewBaseSecurityAdvise return methodInvocation.proceed(); } - protected boolean isAllowed(@NotNull User user, MindMap map) { + protected boolean isAllowed(@Nullable User user, MindMap map) { return getMindmapService().hasPermissions(user, map, CollaborationRole.VIEWER); } - protected boolean isAllowed(@NotNull User user, int mapId) { + protected boolean isAllowed(@Nullable User user, int mapId) { return getMindmapService().hasPermissions(user, mapId, CollaborationRole.VIEWER); } } diff --git a/wise-webapp/src/main/java/com/wisemapping/view/MindMapBean.java b/wise-webapp/src/main/java/com/wisemapping/view/MindMapBean.java index 59466d6e..0726c564 100644 --- a/wise-webapp/src/main/java/com/wisemapping/view/MindMapBean.java +++ b/wise-webapp/src/main/java/com/wisemapping/view/MindMapBean.java @@ -125,8 +125,15 @@ public class MindMapBean { } public String getProperties() throws WiseMappingException { - final CollaborationProperties collaboration = this.mindmap.findCollaborationProperties(collaborator); - return collaboration.getMindmapProperties(); + String result; + if (collaborator != null) { + final CollaborationProperties properties = this.mindmap.findCollaborationProperties(collaborator); + result = properties.getMindmapProperties(); + } else { + // It must be public view ... + result = CollaborationProperties.DEFAULT_JSON_PROPERTIES; + } + return result; } public User getCreator() { diff --git a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security.xml b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security.xml index 32e0262a..428d421b 100644 --- a/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security.xml +++ b/wise-webapp/src/main/webapp/WEB-INF/wisemapping-security.xml @@ -26,13 +26,17 @@ + + + + + + - - - + diff --git a/wise-webapp/src/main/webapp/jsp/init.jsp b/wise-webapp/src/main/webapp/jsp/init.jsp index fd3a9545..f3f9ff45 100644 --- a/wise-webapp/src/main/webapp/jsp/init.jsp +++ b/wise-webapp/src/main/webapp/jsp/init.jsp @@ -8,7 +8,7 @@ <%@taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <% - User user = Utils.getUser(request); + User user = Utils.getUser(false); request.setAttribute("principal", user); UserAgent userAgent = null; diff --git a/wise-webapp/src/main/webapp/jsp/mindmapPublish.jsp b/wise-webapp/src/main/webapp/jsp/mindmapPublish.jsp index 52286ea1..4f29ef90 100644 --- a/wise-webapp/src/main/webapp/jsp/mindmapPublish.jsp +++ b/wise-webapp/src/main/webapp/jsp/mindmapPublish.jsp @@ -45,12 +45,12 @@
<iframe style="width:600px;height:400px;border: 1px
-solid black" src="http://www.wisemapping.com/c/maps/${mindmap.id}/embed?zoom=1"> </iframe>
+solid black" src="${baseUrl}/c/maps/${mindmap.id}/embed?zoom=1"> </iframe>
: -
diff --git a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestMindmapTCase.java b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestMindmapTCase.java index 6a6adad5..6d914221 100644 --- a/wise-webapp/src/test/java/com/wisemapping/test/rest/RestMindmapTCase.java +++ b/wise-webapp/src/test/java/com/wisemapping/test/rest/RestMindmapTCase.java @@ -1,6 +1,7 @@ package com.wisemapping.test.rest; +import com.wisemapping.exceptions.WiseMappingException; import com.wisemapping.rest.model.RestMindmapInfo; import com.wisemapping.rest.model.RestMindmap; import com.wisemapping.rest.model.RestMindmapList; @@ -41,7 +42,7 @@ public class RestMindmapTCase { } @Test(dataProvider = "ContentType-Provider-Function") - public void listMaps(final @NotNull MediaType mediaType) throws IOException { // Configure media types ... + public void listMaps(final @NotNull MediaType mediaType) throws IOException, WiseMappingException { // Configure media types ... final HttpHeaders requestHeaders = createHeaders(mediaType); final RestTemplate template = createTemplate(); @@ -74,7 +75,7 @@ public class RestMindmapTCase { } @Test(dataProvider = "ContentType-Provider-Function") - public void deleteMap(final @NotNull MediaType mediaType) throws IOException { // Configure media types ... + public void deleteMap(final @NotNull MediaType mediaType) throws IOException, WiseMappingException { // Configure media types ... final HttpHeaders requestHeaders = createHeaders(mediaType); final RestTemplate template = createTemplate(); @@ -94,7 +95,7 @@ public class RestMindmapTCase { } @Test(dataProvider = "ContentType-Provider-Function") - public void changeMapTitle(final @NotNull MediaType mediaType) throws IOException { // Configure media types ... + public void changeMapTitle(final @NotNull MediaType mediaType) throws IOException, WiseMappingException { // Configure media types ... final HttpHeaders requestHeaders = createHeaders(mediaType); final RestTemplate template = createTemplate(); @@ -113,7 +114,7 @@ public class RestMindmapTCase { } @Test(dataProvider = "ContentType-Provider-Function") - public void validateMapsCreation(final @NotNull MediaType mediaType) throws IOException { // Configure media types ... + public void validateMapsCreation(final @NotNull MediaType mediaType) throws IOException, WiseMappingException { // Configure media types ... final HttpHeaders requestHeaders = createHeaders(mediaType); final RestTemplate template = createTemplate(); @@ -140,7 +141,7 @@ public class RestMindmapTCase { @Test(dataProvider = "ContentType-Provider-Function") - public void changeMapDescription(final @NotNull MediaType mediaType) throws IOException { // Configure media types ... + public void changeMapDescription(final @NotNull MediaType mediaType) throws IOException, WiseMappingException { // Configure media types ... final HttpHeaders requestHeaders = createHeaders(mediaType); final RestTemplate template = createTemplate(); @@ -159,7 +160,7 @@ public class RestMindmapTCase { } @Test(dataProvider = "ContentType-Provider-Function") - public void updateMapXml(final @NotNull MediaType mediaType) throws IOException { // Configure media types ... + public void updateMapXml(final @NotNull MediaType mediaType) throws IOException, WiseMappingException { // Configure media types ... final HttpHeaders requestHeaders = createHeaders(mediaType); final RestTemplate template = createTemplate(); @@ -180,7 +181,7 @@ public class RestMindmapTCase { } @Test(dataProvider = "ContentType-Provider-Function") - public void cloneMap(final @NotNull MediaType mediaType) throws IOException { // Configure media types ... + public void cloneMap(final @NotNull MediaType mediaType) throws IOException, WiseMappingException { // Configure media types ... final HttpHeaders requestHeaders = createHeaders(mediaType); final RestTemplate template = createTemplate(); @@ -205,7 +206,7 @@ public class RestMindmapTCase { @Test(dataProvider = "ContentType-Provider-Function") - public void updateMap(final @NotNull MediaType mediaType) throws IOException { // Configure media types ... + public void updateMap(final @NotNull MediaType mediaType) throws IOException, WiseMappingException { // Configure media types ... final HttpHeaders requestHeaders = createHeaders(mediaType); final RestTemplate template = createTemplate(); @@ -237,7 +238,7 @@ public class RestMindmapTCase { return response.getBody(); } - private URI addNewMap(@NotNull HttpHeaders requestHeaders, @NotNull RestTemplate template, @NotNull String title, @Nullable String xml) throws IOException { + private URI addNewMap(@NotNull HttpHeaders requestHeaders, @NotNull RestTemplate template, @NotNull String title, @Nullable String xml) throws IOException, WiseMappingException { final RestMindmap restMindmap = new RestMindmap(); restMindmap.setTitle(title); restMindmap.setDescription("My Map Desc"); @@ -251,7 +252,7 @@ public class RestMindmapTCase { } - private URI addNewMap(@NotNull HttpHeaders requestHeaders, @NotNull RestTemplate template, @NotNull String title) throws IOException { + private URI addNewMap(@NotNull HttpHeaders requestHeaders, @NotNull RestTemplate template, @NotNull String title) throws IOException, WiseMappingException { return addNewMap(requestHeaders, template, title, null); }