Add embedded and public view compatibility.

Remove Utils method
This commit is contained in:
Paulo Gustavo Veiga 2012-06-18 00:40:42 -03:00
parent f25ea3a377
commit 251ea5edb6
15 changed files with 76 additions and 46 deletions

View File

@ -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);

View File

@ -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());

View File

@ -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();

View File

@ -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);

View File

@ -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;

View File

@ -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/");

View File

@ -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);

View File

@ -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");
}

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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() {

View File

@ -26,13 +26,17 @@
<sec:http pattern="/c/user/registration" security="none"/>
<sec:http pattern="/c/user/resetpassword" security="none"/>
<sec:http pattern="/c/home" security="none"/>
<sec:http pattern="/c/maps/*/embed" security="none"/>
<sec:http pattern="/c/maps/*/public" security="none"/>
<sec:http pattern="/c/publicview.htm" security="none"/>
<sec:http pattern="/c/embeddedview.htm" security="none"/>
<sec:http pattern="/c/termsOfUse" security="none"/>
<sec:http pattern="/c/keyboard" security="none"/>
<sec:http pattern="/c/activation" security="none"/>
<sec:http pattern="/c/try" security="none"/>
<sec:http pattern="/c/publicview" security="none"/>
<sec:http pattern="/c/termsOfUse" security="none"/>
<sec:http pattern="/c/keyboard" security="none"/>
<sec:http use-expressions="true" create-session="never" pattern="/service/**">
<sec:intercept-url pattern="/service/admin/users/**" access="isAuthenticated() and hasRole('ROLE_ADMIN')"/>

View File

@ -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;

View File

@ -45,12 +45,12 @@
</div>
<label><spring:message code="BLOG_SNIPPET"/></label>
<pre id="embedCode">&lt;iframe style="width:600px;height:400px;border: 1px
solid black" src="http://www.wisemapping.com/c/maps/${mindmap.id}/embed?zoom=1"&gt; &lt;/iframe&gt;</pre>
solid black" src="${baseUrl}/c/maps/${mindmap.id}/embed?zoom=1"&gt; &lt;/iframe&gt;</pre>
</div>
<div class="tab-pane fade" id="publicUrlTab">
<spring:message code="URL"/>:
<input name="url" value="???"
<input name="url" value="${baseUrl}/c/maps/${mindmap.id}/public"
style="width:400px"
readonly="readonly"/>
</div>

View File

@ -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);
}