Change symblink to moootols
Add editor issue.
This commit is contained in:
@@ -38,17 +38,6 @@ public abstract class BaseMultiActionController
|
||||
private MindmapService mindmapService;
|
||||
private UserService userService;
|
||||
|
||||
protected List<MindmapUser> getMindmapUsersFromRequest(HttpServletRequest request) {
|
||||
List<MindmapUser> result = new ArrayList<MindmapUser>();
|
||||
final String mindmapIds = request.getParameter("mindmapIds");
|
||||
|
||||
final String ids[] = mindmapIds.split(",");
|
||||
for (String id : ids)
|
||||
if (mindmapIds.length()!=0){
|
||||
result.add(getMindmapUser(Integer.parseInt(id), request));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected List<MindMap> getMindmapsFromRequest(HttpServletRequest request) {
|
||||
List<MindMap> result = new ArrayList<MindMap>();
|
||||
|
@@ -1,117 +0,0 @@
|
||||
package com.wisemapping.controller;
|
||||
|
||||
|
||||
import com.wisemapping.exceptions.WiseMappingException;
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.rest.BaseController;
|
||||
import com.wisemapping.rest.model.RestUser;
|
||||
import com.wisemapping.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
@Controller
|
||||
public class ExportController extends BaseController {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = "admin/users/{id}", produces = {"application/json", "text/html", "application/xml"})
|
||||
@ResponseBody
|
||||
public ModelAndView getUserById(@PathVariable long id) throws IOException {
|
||||
final User userBy = userService.getUserBy(id);
|
||||
if (userBy == null) {
|
||||
throw new IllegalArgumentException("User could not be found");
|
||||
}
|
||||
return new ModelAndView("userView", "user", new RestUser(userBy));
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = "admin/users/email/{email}", produces = {"application/json", "text/html", "application/xml"})
|
||||
@ResponseBody
|
||||
public ModelAndView getUserByEmail(@PathVariable String email) throws IOException {
|
||||
final User user = userService.getUserBy(email);
|
||||
if (user == null) {
|
||||
throw new IllegalArgumentException("User '" + email + "' could not be found");
|
||||
}
|
||||
return new ModelAndView("userView", "user", new RestUser(user));
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = "admin/users/username/{username}", produces = {"application/json", "text/html", "application/xml"})
|
||||
@ResponseBody
|
||||
public ModelAndView getUserByUsername(@PathVariable String username) throws IOException {
|
||||
final User user = userService.getUserByUsername(username);
|
||||
if (user == null) {
|
||||
throw new IllegalArgumentException("User '" + username + "' could not be found");
|
||||
}
|
||||
return new ModelAndView("userView", "user", new RestUser(user));
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST, value = "admin/users", consumes = {"application/xml", "application/json"}, produces = {"application/json", "text/html", "application/xml"})
|
||||
@ResponseStatus(value = HttpStatus.CREATED)
|
||||
public void createUser(@RequestBody RestUser user, HttpServletResponse response) throws IOException, WiseMappingException {
|
||||
if (user == null) {
|
||||
throw new IllegalArgumentException("User could not be found");
|
||||
}
|
||||
|
||||
// User already exists ?
|
||||
final String email = user.getEmail();
|
||||
if (userService.getUserBy(email) != null) {
|
||||
throw new IllegalArgumentException("User already exists with this email.");
|
||||
}
|
||||
|
||||
final String username = user.getUsername();
|
||||
if (username == null || username.isEmpty()) {
|
||||
throw new IllegalArgumentException("username can not be null");
|
||||
}
|
||||
|
||||
if (userService.getUserByUsername(username) != null) {
|
||||
throw new IllegalArgumentException("User already exists with this username.");
|
||||
}
|
||||
|
||||
// Run some other validations ...
|
||||
final User delegated = user.getDelegated();
|
||||
final String lastname = delegated.getLastname();
|
||||
if (lastname == null || lastname.isEmpty()) {
|
||||
throw new IllegalArgumentException("lastname can not be null");
|
||||
}
|
||||
|
||||
final String firstName = delegated.getFirstname();
|
||||
if (firstName == null || firstName.isEmpty()) {
|
||||
throw new IllegalArgumentException("firstname can not be null");
|
||||
}
|
||||
|
||||
// Finally create the user ...
|
||||
userService.createUser(delegated, false);
|
||||
response.setHeader("Location", "/service/admin/users/" + user.getId());
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "admin/users/{id}/password", consumes = {"text/plain"})
|
||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||
public void changePassword(@RequestBody String password, @PathVariable long id) throws IOException, WiseMappingException {
|
||||
if (password == null) {
|
||||
throw new IllegalArgumentException("Password can not be null");
|
||||
}
|
||||
|
||||
final User user = userService.getUserBy(id);
|
||||
if (user == null) {
|
||||
throw new IllegalArgumentException("User '" + id + "' could not be found");
|
||||
}
|
||||
user.setPassword(password);
|
||||
userService.changePassword(user);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.DELETE)
|
||||
@ResponseStatus(value = HttpStatus.NO_CONTENT)
|
||||
public void getUserByEmail(@PathVariable long id) throws IOException, WiseMappingException {
|
||||
final User user = userService.getUserBy(id);
|
||||
if (user == null) {
|
||||
throw new IllegalArgumentException("User '" + id + "' could not be found");
|
||||
}
|
||||
userService.deleteUser(user);
|
||||
}
|
||||
|
||||
}
|
@@ -1,144 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.controller;
|
||||
|
||||
import com.wisemapping.model.MindMap;
|
||||
import com.wisemapping.model.MindmapUser;
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.security.Utils;
|
||||
import com.wisemapping.view.MindMapBean;
|
||||
import com.wisemapping.filter.UserAgent;
|
||||
import com.wisemapping.exceptions.WiseMappingException;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.util.List;
|
||||
|
||||
public class MindmapController extends BaseMultiActionController {
|
||||
protected ModelAndView handleNoSuchRequestHandlingMethod(NoSuchRequestHandlingMethodException noSuchRequestHandlingMethodException, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
|
||||
return list(httpServletRequest, httpServletResponse);
|
||||
}
|
||||
|
||||
public ModelAndView list(HttpServletRequest request, HttpServletResponse response) {
|
||||
logger.info("Mindmap Controller: myMindmap action");
|
||||
final HttpSession session = request.getSession(false);
|
||||
|
||||
// Try to loaded from the request ...
|
||||
UserAgent userAgent = null;
|
||||
if (session != null) {
|
||||
userAgent = (UserAgent) session.getAttribute(USER_AGENT);
|
||||
}
|
||||
|
||||
// I could not loaded. I will create a new one...
|
||||
if (userAgent == null) {
|
||||
userAgent = UserAgent.create(request);
|
||||
if (session != null) {
|
||||
session.setAttribute(USER_AGENT, userAgent);
|
||||
}
|
||||
}
|
||||
|
||||
// It's a supported browser ?.
|
||||
final UserAgent.OS os = userAgent.getOs();
|
||||
|
||||
final User user = Utils.getUser(request);
|
||||
final ModelAndView view = new ModelAndView("mindmapList", "wisemapsList", getMindMapBeanList(user));
|
||||
view.addObject("isMAC", os == UserAgent.OS.MAC);
|
||||
view.addObject("user", user);
|
||||
return view;
|
||||
}
|
||||
|
||||
public ModelAndView edit(HttpServletRequest request, HttpServletResponse response) {
|
||||
logger.info("Mindmap Controller: EDIT action");
|
||||
final MindMap mindmap = getMindmapFromRequest(request);
|
||||
return new ModelAndView("mindmapEditor", "wisemapsList", new MindMapBean(mindmap));
|
||||
}
|
||||
|
||||
public ModelAndView collaborator(HttpServletRequest request, HttpServletResponse response) {
|
||||
logger.info("Mindmap Controller: COLLABORATE action");
|
||||
final MindMap mindmap = getMindmapFromRequest(request);
|
||||
return new ModelAndView("mindmapCollaborator", "mindmap", new MindMapBean(mindmap));
|
||||
}
|
||||
|
||||
public ModelAndView viewer(HttpServletRequest request, HttpServletResponse response) {
|
||||
logger.info("Mindmap Controller: VIEWER action");
|
||||
final MindMap mindmap = getMindmapFromRequest(request);
|
||||
return new ModelAndView("mindmapViewer", "wisemapsList", new MindMapBean(mindmap));
|
||||
}
|
||||
|
||||
public ModelAndView delete(HttpServletRequest request, HttpServletResponse response) throws WiseMappingException {
|
||||
logger.info("Mindmap Controller: DELETE action");
|
||||
final User user = Utils.getUser(request);
|
||||
|
||||
final MindMap mindmap = getMindmapFromRequest(request);
|
||||
getMindmapService().removeCollaboratorFromMindmap(mindmap, user.getId());
|
||||
|
||||
return list(request, response);
|
||||
}
|
||||
|
||||
public ModelAndView deleteAll(HttpServletRequest request, HttpServletResponse response) throws WiseMappingException {
|
||||
logger.info("Mindmap Controller: DELETE ALL action");
|
||||
|
||||
final List<MindmapUser> mindmaps = getMindmapUsersFromRequest(request);
|
||||
final User user = Utils.getUser(request);
|
||||
for (MindmapUser mindmap : mindmaps)
|
||||
getMindmapService().removeMindmap(mindmap.getMindMap(), user);
|
||||
return list(request, response);
|
||||
}
|
||||
|
||||
public ModelAndView detail(HttpServletRequest request, HttpServletResponse response) {
|
||||
logger.info("Mindmap Controller: DETAIL action");
|
||||
final MindMap mindMap = getMindmapFromRequest(request);
|
||||
final ModelAndView view = new ModelAndView("mindmapDetail", "wisemapDetail", new MindMapBean(mindMap));
|
||||
view.addObject("user", Utils.getUser());
|
||||
return view;
|
||||
}
|
||||
|
||||
public ModelAndView changeStatus(HttpServletRequest request, HttpServletResponse response) throws WiseMappingException {
|
||||
final MindMap mindmap = getMindmapFromRequest(request);
|
||||
boolean isPublic = !mindmap.isPublic();
|
||||
mindmap.setPublic(isPublic);
|
||||
getMindmapService().updateMindmap(mindmap, false);
|
||||
return new ModelAndView("mindmapDetail", "wisemapDetail", new MindMapBean(mindmap));
|
||||
}
|
||||
|
||||
public ModelAndView editMindmap(HttpServletRequest request, HttpServletResponse response) throws WiseMappingException {
|
||||
final MindMap mindmap = getMindmapFromRequest(request);
|
||||
final ModelAndView view = new ModelAndView("editMindmap", "mindmap", new MindMapBean(mindmap));
|
||||
view.addObject("user", Utils.getUser());
|
||||
return view;
|
||||
}
|
||||
|
||||
public ModelAndView updateMindmap(HttpServletRequest request, HttpServletResponse response) throws WiseMappingException {
|
||||
final MindMap mindmap = getMindmapFromRequest(request);
|
||||
|
||||
final String title = request.getParameter("title");
|
||||
final String description = request.getParameter("description");
|
||||
|
||||
mindmap.setTitle(title);
|
||||
mindmap.setDescription(description);
|
||||
|
||||
getMindmapService().updateMindmap(mindmap, false);
|
||||
return list(request, response);
|
||||
}
|
||||
|
||||
private static final String USER_AGENT = "wisemapping.userAgent";
|
||||
}
|
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright [2011] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.wisemapping.dwr;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public class JavaScriptErrorLoggerService
|
||||
{
|
||||
final Log logger = LogFactory.getLog(JavaScriptErrorLoggerService.class);
|
||||
private static final int ERROR_MESSAGE = 3;
|
||||
private static final int FATAL_MESSAGE = 4;
|
||||
private static final String USER_AGENT = "User-Agent";
|
||||
|
||||
JavaScriptErrorLoggerService() {
|
||||
LogFactory.getLog(JavaScriptErrorLoggerService.class);
|
||||
}
|
||||
//~ Methods ..............................................................................................
|
||||
|
||||
public void logError(final int severity, final String logMsg)
|
||||
throws IOException {
|
||||
|
||||
// final User user = getUser();
|
||||
|
||||
|
||||
// final String userAgent = request.getHeader(USER_AGENT);
|
||||
// synchronized (logger) {
|
||||
// // Log user info ...
|
||||
// if (user != null) {
|
||||
// log(severity, "UserId:" + user.getId() + ", UserEmail:" + user.getEmail());
|
||||
// } else {
|
||||
// log(severity, "Anonymous user");
|
||||
// }
|
||||
//
|
||||
// // Log browser details ...
|
||||
// log(severity, "Browser:" + userAgent);
|
||||
//
|
||||
// // Log error message ...
|
||||
// log(severity, logMsg);
|
||||
// }
|
||||
}
|
||||
|
||||
void log(final int severity, final String msg) {
|
||||
// Log error message ...
|
||||
if (severity == ERROR_MESSAGE && logger.isErrorEnabled()) {
|
||||
logger.error(msg);
|
||||
} else if (severity == FATAL_MESSAGE && logger.isFatalEnabled()) {
|
||||
logger.fatal(msg);
|
||||
} else if (logger.isInfoEnabled()) {
|
||||
logger.info(msg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -222,7 +222,7 @@ public class MindMap {
|
||||
public static String getDefaultMindmapXml(@NotNull final String title) {
|
||||
|
||||
final StringBuilder result = new StringBuilder();
|
||||
result.append("<result version='tango'>");
|
||||
result.append("<map version=\"tango\">");
|
||||
result.append("<topic central=\"true\" text=\"");
|
||||
result.append(title);
|
||||
result.append("\"/></result>");
|
||||
|
@@ -131,4 +131,5 @@ public class User
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,148 @@
|
||||
package com.wisemapping.ncontroller;
|
||||
|
||||
|
||||
import com.wisemapping.exceptions.WiseMappingException;
|
||||
import com.wisemapping.filter.UserAgent;
|
||||
import com.wisemapping.model.MindMap;
|
||||
import com.wisemapping.model.MindmapUser;
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.security.Utils;
|
||||
import com.wisemapping.service.MindmapService;
|
||||
import com.wisemapping.view.MindMapBean;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/c/")
|
||||
public class MindmapController {
|
||||
@Autowired
|
||||
private MindmapService mindmapService;
|
||||
|
||||
@RequestMapping(value = "export")
|
||||
public ModelAndView export(@RequestParam(required = true) long mapId) throws IOException {
|
||||
final MindMapBean modelObject = findMindmapBean(mapId);
|
||||
return new ModelAndView("mindmapExport", "mindmap", modelObject);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "edit")
|
||||
public ModelAndView edit(@RequestParam(required = true) long mapId) {
|
||||
final MindMapBean modelObject = findMindmapBean(mapId);
|
||||
return new ModelAndView("mindmapEditor", "wisemapsList", modelObject);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "collaborator")
|
||||
public ModelAndView collaborator(@RequestParam(required = true) long mapId) {
|
||||
final MindMapBean modelObject = findMindmapBean(mapId);
|
||||
return new ModelAndView("mindmapCollaborator", "mindmap", modelObject);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "viewer")
|
||||
public ModelAndView viewer(@RequestParam(required = true) long mapId) {
|
||||
final MindMapBean modelObject = findMindmapBean(mapId);
|
||||
return new ModelAndView("mindmapViewer", "wisemapsList", modelObject);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "detail")
|
||||
public ModelAndView detail(@RequestParam(required = true) long mapId) {
|
||||
final MindMapBean modelObject = findMindmapBean(mapId);
|
||||
final ModelAndView view = new ModelAndView("mindmapDetail", "wisemapDetail", modelObject);
|
||||
view.addObject("user", Utils.getUser());
|
||||
return view;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "changeStatus")
|
||||
public ModelAndView changeStatus(@RequestParam(required = true) long mapId) throws WiseMappingException {
|
||||
final MindMap mindmap = findMindmap(mapId);
|
||||
boolean isPublic = !mindmap.isPublic();
|
||||
mindmap.setPublic(isPublic);
|
||||
mindmapService.updateMindmap(mindmap, false);
|
||||
return new ModelAndView("mindmapDetail", "wisemapDetail", new MindMapBean(mindmap));
|
||||
}
|
||||
|
||||
@RequestMapping(value = "editMindmap")
|
||||
public ModelAndView editMindmap(@RequestParam(required = true) long mapId) throws WiseMappingException {
|
||||
final MindMapBean mindmap = findMindmapBean(mapId);
|
||||
final ModelAndView view = new ModelAndView("editMindmap", "mindmap", mindmap);
|
||||
view.addObject("user", Utils.getUser());
|
||||
return view;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "mymaps")
|
||||
public ModelAndView list(@NotNull HttpServletRequest request) {
|
||||
final HttpSession session = request.getSession(false);
|
||||
|
||||
// Try to loaded from the request ...
|
||||
UserAgent userAgent = null;
|
||||
if (session != null) {
|
||||
userAgent = (UserAgent) session.getAttribute(USER_AGENT);
|
||||
}
|
||||
|
||||
// I could not loaded. I will create a new one...
|
||||
if (userAgent == null) {
|
||||
userAgent = UserAgent.create(request);
|
||||
if (session != null) {
|
||||
session.setAttribute(USER_AGENT, userAgent);
|
||||
}
|
||||
}
|
||||
|
||||
// It's a supported browser ?.
|
||||
final UserAgent.OS os = userAgent.getOs();
|
||||
|
||||
final User user = Utils.getUser();
|
||||
final ModelAndView view = new ModelAndView("mindmapList", "wisemapsList", findMindMapBeanList(user));
|
||||
view.addObject("isMAC", os == UserAgent.OS.MAC);
|
||||
view.addObject("user", user);
|
||||
return view;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "delete")
|
||||
public ModelAndView delete(@RequestParam(required = true) long mapId, @NotNull HttpServletRequest request) throws WiseMappingException {
|
||||
final User user = Utils.getUser();
|
||||
final MindMap mindmap = findMindmap(mapId);
|
||||
mindmapService.removeCollaboratorFromMindmap(mindmap, user.getId());
|
||||
return list(request);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "updateMindmap")
|
||||
public ModelAndView updateMindmap(@RequestParam(required = true) long mapId, @RequestParam(required = true) String title, @RequestParam(required = true) String description, @NotNull HttpServletRequest request) throws WiseMappingException {
|
||||
final MindMap mindmap = findMindmap(mapId);
|
||||
mindmap.setTitle(title);
|
||||
mindmap.setDescription(description);
|
||||
|
||||
mindmapService.updateMindmap(mindmap, false);
|
||||
return list(request);
|
||||
}
|
||||
|
||||
private MindMap findMindmap(long mapId) {
|
||||
final MindMap mindmap = mindmapService.getMindmapById((int) mapId);
|
||||
if (mindmap == null) {
|
||||
throw new IllegalArgumentException("Mindmap could not be found");
|
||||
}
|
||||
return mindmap;
|
||||
}
|
||||
|
||||
private List<MindMapBean> findMindMapBeanList(@NotNull User user) {
|
||||
final List<MindmapUser> userMindmaps = mindmapService.getMindmapUserByUser(user);
|
||||
|
||||
final List<MindMapBean> mindMapBeans = new ArrayList<MindMapBean>(userMindmaps.size());
|
||||
for (MindmapUser mindmap : userMindmaps) {
|
||||
mindMapBeans.add(new MindMapBean(mindmap.getMindMap()));
|
||||
}
|
||||
return mindMapBeans;
|
||||
}
|
||||
|
||||
private MindMapBean findMindmapBean(long mapId) {
|
||||
return new MindMapBean(findMindmap(mapId));
|
||||
}
|
||||
|
||||
private static final String USER_AGENT = "wisemapping.userAgent";
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
package com.wisemapping.ncontroller;
|
||||
|
||||
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.rest.model.RestUser;
|
||||
import com.wisemapping.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Controller
|
||||
public class NMindmapController {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = "admin/users/{id}", produces = {"application/json", "text/html", "application/xml"})
|
||||
@ResponseBody
|
||||
public ModelAndView getUserById(@PathVariable long id) throws IOException {
|
||||
final User userBy = userService.getUserBy(id);
|
||||
if (userBy == null) {
|
||||
throw new IllegalArgumentException("User could not be found");
|
||||
}
|
||||
return new ModelAndView("userView", "user", new RestUser(userBy));
|
||||
}
|
||||
}
|
@@ -29,43 +29,35 @@ import org.aopalliance.intercept.MethodInvocation;
|
||||
public abstract class BaseSecurityAdvice {
|
||||
private MindmapService mindmapService = null;
|
||||
|
||||
public void checkRole(MethodInvocation methodInvocation) throws UnexpectedArgumentException,AccessDeniedSecurityException
|
||||
{
|
||||
public void checkRole(MethodInvocation methodInvocation) throws UnexpectedArgumentException, AccessDeniedSecurityException {
|
||||
final User user = Utils.getUser();
|
||||
|
||||
final Object argument = methodInvocation.getArguments()[0];
|
||||
|
||||
boolean isAllowed;
|
||||
|
||||
if (argument instanceof MindMap)
|
||||
{
|
||||
isAllowed = isAllowed(user,(MindMap) argument);
|
||||
}
|
||||
else if (argument instanceof Integer)
|
||||
{
|
||||
isAllowed = isAllowed(user, ((Integer)argument));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnexpectedArgumentException("Argument " +argument);
|
||||
if (argument instanceof MindMap) {
|
||||
isAllowed = isAllowed(user, (MindMap) argument);
|
||||
} else if (argument instanceof Integer) {
|
||||
isAllowed = isAllowed(user, ((Integer) argument));
|
||||
} else {
|
||||
throw new UnexpectedArgumentException("Argument " + argument);
|
||||
}
|
||||
|
||||
if (!isAllowed)
|
||||
{
|
||||
throw new AccessDeniedSecurityException("User not allowed to invoke:" + methodInvocation);
|
||||
if (!isAllowed) {
|
||||
throw new AccessDeniedSecurityException("User '" + user.getEmail() + "' not allowed to invoke:" + methodInvocation);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract boolean isAllowed(User user, MindMap map);
|
||||
|
||||
protected abstract boolean isAllowed(User user, int mapId);
|
||||
|
||||
protected MindmapService getMindmapService()
|
||||
{
|
||||
protected MindmapService getMindmapService() {
|
||||
return mindmapService;
|
||||
}
|
||||
|
||||
public void setMindmapService(MindmapService service)
|
||||
{
|
||||
public void setMindmapService(MindmapService service) {
|
||||
this.mindmapService = service;
|
||||
}
|
||||
}
|
||||
|
@@ -23,25 +23,23 @@ import org.aopalliance.intercept.MethodInvocation;
|
||||
import com.wisemapping.model.UserRole;
|
||||
import com.wisemapping.model.User;
|
||||
import com.wisemapping.model.MindMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ViewBaseSecurityAdvise
|
||||
extends BaseSecurityAdvice
|
||||
implements MethodInterceptor
|
||||
{
|
||||
implements MethodInterceptor {
|
||||
private UserRole grantedRole = UserRole.VIEWER;
|
||||
|
||||
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
|
||||
public Object invoke(@NotNull MethodInvocation methodInvocation) throws Throwable {
|
||||
checkRole(methodInvocation);
|
||||
return methodInvocation.proceed();
|
||||
}
|
||||
|
||||
protected boolean isAllowed(User user, MindMap map)
|
||||
{
|
||||
return getMindmapService().isAllowedToView(user,map,grantedRole);
|
||||
protected boolean isAllowed(User user, MindMap map) {
|
||||
return getMindmapService().isAllowedToView(user, map, grantedRole);
|
||||
}
|
||||
|
||||
protected boolean isAllowed(User user, int mapId)
|
||||
{
|
||||
return getMindmapService().isAllowedToView(user,mapId,grantedRole);
|
||||
}
|
||||
protected boolean isAllowed(User user, int mapId) {
|
||||
return getMindmapService().isAllowedToView(user, mapId, grantedRole);
|
||||
}
|
||||
}
|
||||
|
@@ -47,16 +47,15 @@ public class MindmapServiceImpl
|
||||
}
|
||||
|
||||
public boolean isAllowedToView(User user, MindMap map, UserRole grantedRole) {
|
||||
boolean isAllowed = false;
|
||||
boolean result = false;
|
||||
if (map != null) {
|
||||
|
||||
if (map.isPublic()) {
|
||||
isAllowed = true;
|
||||
result = true;
|
||||
} else if (user != null) {
|
||||
isAllowed = isAllowedToCollaborate(user, map, grantedRole);
|
||||
result = isAllowedToCollaborate(user, map, grantedRole);
|
||||
}
|
||||
}
|
||||
return isAllowed;
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean isAllowedToCollaborate(@NotNull User user, @Nullable MindMap map, UserRole grantedRole) {
|
||||
|
Reference in New Issue
Block a user