Initial commit

This commit is contained in:
Paulo Gustavo Veiga 2020-11-07 11:56:38 -08:00
parent ad9cea069a
commit e4af8acdc2
27 changed files with 436 additions and 328 deletions

View File

@ -9,7 +9,7 @@
<groupId>org.wisemapping</groupId>
<artifactId>wisemapping</artifactId>
<relativePath>../pom.xml</relativePath>
<version>4.0.6-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
</parent>
<scm>
<developerConnection>scm:git:git@bitbucket.org:wisemapping/wisemapping-open-source.git</developerConnection>

View File

@ -2,25 +2,44 @@
# Database Configuration
##################################################################################
# MySQL 5.X configuration properties
database.url=jdbc:mysql://localhost/wisemapping?useUnicode=yes&characterEncoding=UTF-8
database.driver=com.mysql.jdbc.Driver
database.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
# MariaDB configuration properties
database.url=jdbc:mariadb://localhost/wisemapping?useUnicode=yes&characterEncoding=UTF-8
database.driver=org.mariadb.jdbc.Driver
database.hibernate.dialect=org.hibernate.dialect.MariaDBDialect
database.username=wisemapping
database.password=password
database.password=mappingwise
database.validation.enabled=true
database.validation.query=SELECT 1
## PostgreSQL configuration properties
#database.url=jdbc:postgresql://<hostname:port>/wisemapping
#database.driver=org.postgresql.Driver
#database.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
#database.username=<username>
#database.password=<password>
# MySQL 5.X configuration properties
#database.url=jdbc:mysql://localhost/wisemapping?useUnicode=yes&characterEncoding=UTF-8
#database.driver=com.mysql.jdbc.Driver
#database.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
#database.username=wisemapping
#database.password=password
#database.validation.enabled=true
#database.validation.query=SELECT 1
## PostgreSQL configuration properties
#database.url=jdbc:mariadb://localhost:3306/wisemapping
#database.driver=org.mariadb.jdbc.Driver
#database.hibernate.dialect=org.hibernate.dialect.MariaDBDialect
#database.username=wisemapping
#database.password=password
#database.validation.query=
#database.validation.enabled=false
# HSQL Configuration properties
#database.url=jdbc:hsqldb:file:${database.base.url}/db/wisemapping
#database.driver=org.hsqldb.jdbc.JDBCDriver
#database.hibernate.dialect=org.hibernate.dialect.HSQLDialect
#database.username=sa
#database.password=
#database.validation.enabled=false
#database.validation.query=
##################################################################################
# Mail configuration. Must be configured to enable user registration confirmation.
##################################################################################
@ -135,13 +154,7 @@ security.openid.enabled=false
#
# This properties are used for REST API Documentation( http://localhost:8080/wisemapping/doc/rest/index.html)
# Change the URL for proper documentation console setup.
documentation.services.basePath=http://localhost:8080/wisemapping/service
documentation.services.basePath=http://localhost:8080/service
documentation.services.version=3.0.1

View File

@ -9,7 +9,7 @@
<groupId>org.wisemapping</groupId>
<artifactId>wisemapping</artifactId>
<relativePath>../pom.xml</relativePath>
<version>4.0.6-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
</parent>
<dependencies>

View File

@ -4,7 +4,7 @@
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<properties>
<com.wisemapping.version>4.0.6-SNAPSHOT</com.wisemapping.version>
<com.wisemapping.version>5.0.0-SNAPSHOT</com.wisemapping.version>
<superpom.dir>${project.basedir}/wise-webapps</superpom.dir>
</properties>
@ -16,7 +16,7 @@
<groupId>org.wisemapping</groupId>
<artifactId>wisemapping</artifactId>
<name>WiseMapping Project</name>
<version>4.0.6-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<licenses>

View File

@ -9,7 +9,7 @@
<groupId>org.wisemapping</groupId>
<artifactId>wisemapping</artifactId>
<relativePath>../pom.xml</relativePath>
<version>4.0.6-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
</parent>
<build>

View File

@ -9,7 +9,7 @@
<groupId>org.wisemapping</groupId>
<artifactId>wisemapping</artifactId>
<relativePath>../pom.xml</relativePath>
<version>4.0.6-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
</parent>
<dependencies>

View File

@ -9,7 +9,7 @@
<groupId>org.wisemapping</groupId>
<artifactId>wisemapping</artifactId>
<relativePath>../pom.xml</relativePath>
<version>4.0.6-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
</parent>
<repositories>
@ -28,8 +28,10 @@
</repositories>
<properties>
<org.springframework.version>4.3.29.RELEASE</org.springframework.version>
<org.springframework.addons>4.2.9.RELEASE</org.springframework.addons>
<org.springframework.version>5.2.10.RELEASE</org.springframework.version>
<org.springframework.addons>5.2.5.RELEASE</org.springframework.addons>
<hibernate.version>5.4.23.Final</hibernate.version>
</properties>
<dependencies>
@ -101,6 +103,23 @@
<version>${org.springframework.version}</version>
<scope>compile</scope>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>

View File

@ -1,10 +1,27 @@
/*
* Copyright [2015] [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.dao;
import com.wisemapping.model.Label;
import com.wisemapping.model.User;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
import java.util.List;
@ -18,27 +35,34 @@ public class LabelManagerImpl extends HibernateDaoSupport
@Override
public void saveLabel(@NotNull final Label label) {
getSession().save(label);
currentSession().save(label);
}
@NotNull
@Override
@SuppressWarnings("unchecked")
public List<Label> getAllLabels(@NotNull final User user) {
return (List<Label>) getHibernateTemplate().find("from com.wisemapping.model.Label wisemapping where creator_id=?", user.getId());
var query = currentSession().createQuery("from com.wisemapping.model.Label wisemapping where creator_id=:creatorId");
query.setParameter("creatorId", user.getId());
return query.list();
}
@Nullable
@Override
public Label getLabelById(int id, @NotNull final User user) {
List<Label> labels = (List<Label>) getHibernateTemplate().find("from com.wisemapping.model.Label wisemapping where id=? and creator=?", new Object[]{id, user});
return getFirst(labels);
var query = currentSession().createQuery("from com.wisemapping.model.Label wisemapping where id=:id and creator=:creator");
query.setParameter("id", id);
query.setParameter("creator", user);
return getFirst(query.list());
}
@Nullable
@Override
public Label getLabelByTitle(@NotNull String title, @NotNull final User user) {
final List<Label> labels = (List<Label>) getHibernateTemplate().find("from com.wisemapping.model.Label wisemapping where title=? and creator=?", new Object[]{title, user});
return getFirst(labels);
var query = currentSession().createQuery("from com.wisemapping.model.Label wisemapping where title=:title and creator=:creator");
query.setParameter("title", title);
query.setParameter("creator", user);
return getFirst(query.list());
}
@Override

View File

@ -20,9 +20,11 @@ package com.wisemapping.dao;
import com.wisemapping.model.*;
import com.wisemapping.util.ZipUtils;
import org.hibernate.Query;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
import org.hibernate.criterion.Restrictions;
import org.hibernate.criterion.SimpleExpression;
import org.hibernate.criterion.Junction;
@ -40,7 +42,10 @@ public class MindmapManagerImpl
@Override
public Collaborator findCollaborator(@NotNull final String email) {
final Collaborator collaborator;
final List<Collaborator> collaborators = (List<Collaborator>) getHibernateTemplate().find("from com.wisemapping.model.Collaborator collaborator where email=?", email);
Query query = currentSession().createQuery("from com.wisemapping.model.Collaborator collaborator where email=:email");
query.setParameter("email", email);
final List<Collaborator> collaborators = query.list();
if (collaborators != null && !collaborators.isEmpty()) {
assert collaborators.size() == 1 : "More than one user with the same email!";
collaborator = collaborators.get(0);
@ -57,7 +62,7 @@ public class MindmapManagerImpl
@Override
public List<MindMapHistory> getHistoryFrom(int mindmapId) {
final Criteria hibernateCriteria = getSession().createCriteria(MindMapHistory.class);
final Criteria hibernateCriteria = currentSession().createCriteria(MindMapHistory.class);
hibernateCriteria.add(Restrictions.eq("mindmapId", mindmapId));
hibernateCriteria.addOrder(Order.desc("creationTime"));
@ -78,7 +83,7 @@ public class MindmapManagerImpl
@Override
public void purgeHistory(int mapId) throws IOException {
final Criteria hibernateCriteria = getSession().createCriteria(MindMapHistory.class);
final Criteria hibernateCriteria = currentSession().createCriteria(MindMapHistory.class);
hibernateCriteria.add(Restrictions.eq("mindmapId", mapId));
hibernateCriteria.addOrder(Order.desc("creationTime"));
@ -92,17 +97,18 @@ public class MindmapManagerImpl
// If the map has not been modified in the last months, it means that I don't need to keep all the history ...
int max = mindmap.getLastModificationTime().before(yearAgo) ? 10 : 25;
final HibernateTemplate hibernateTemplate = getHibernateTemplate();
for (MindMapHistory history : historyList) {
byte[] zippedXml = history.getZippedXml();
if (new String(zippedXml).startsWith("<map")) {
history.setZippedXml(ZipUtils.bytesToZip(zippedXml));
getHibernateTemplate().update(history);
hibernateTemplate.update(history);
}
}
if (historyList.size() > max) {
for (int i = max; i < historyList.size(); i++) {
getHibernateTemplate().delete(historyList.get(i));
hibernateTemplate.delete(historyList.get(i));
}
}
}
@ -110,7 +116,7 @@ public class MindmapManagerImpl
@Override
public List<Mindmap> search(MindMapCriteria criteria, int maxResult) {
final Criteria hibernateCriteria = getSession().createCriteria(Mindmap.class);
final Criteria hibernateCriteria = currentSession().createCriteria(Mindmap.class);
//always search public maps
hibernateCriteria.add(Restrictions.like("public", Boolean.TRUE));
@ -154,19 +160,28 @@ public class MindmapManagerImpl
@Override
public List<Collaboration> findCollaboration(final long collaboratorId) {
return (List<Collaboration>) getHibernateTemplate().find("from com.wisemapping.model.Collaboration collaboration where colaborator_id=?", collaboratorId);
Query query = currentSession().createQuery("from com.wisemapping.model.Collaboration collaboration where colaboratorId=:colaboratorId");
query.setParameter("colaboratorId", collaboratorId);
return query.list();
}
@Override
public List<Collaboration> findCollaboration(final CollaborationRole collaborationRole) {
return (List<Collaboration>) getHibernateTemplate().find("from com.wisemapping.model.Collaboration collaboration where roleId=?", collaborationRole.ordinal());
Query query = currentSession().createQuery("from com.wisemapping.model.Collaboration collaboration where roleId=:roleId");
query.setParameter("roleId", collaborationRole.ordinal());
return query.list();
}
@Override
public Collaboration findCollaboration(final int mindmapId, final User user) {
final Collaboration result;
final List<Collaboration> mindMaps = (List<Collaboration>) getHibernateTemplate().find("from com.wisemapping.model.Collaboration collaboration where mindMap.id=? and colaborator_id=?", new Object[]{mindmapId, user.getId()});
Query query = currentSession().createQuery("from com.wisemapping.model.Collaboration collaboration where mindMap.id=:mindMapId and colaborator_id=:collaboratorId");
query.setParameter("mindMap", mindmapId);
query.setParameter("collaboratorId", user.getId());
final List<Collaboration> mindMaps = query.list();
if (mindMaps != null && !mindMaps.isEmpty()) {
result = mindMaps.get(0);
} else {
@ -193,8 +208,9 @@ public class MindmapManagerImpl
}
@Override
@SuppressWarnings("unchecked")
public List<Mindmap> getAllMindmaps() {
return (List<Mindmap>) getHibernateTemplate().find("from com.wisemapping.model.Mindmap wisemapping");
return currentSession().createQuery("from com.wisemapping.model.Mindmap wisemapping").list();
}
@Override
@ -206,7 +222,12 @@ public class MindmapManagerImpl
@Override
public Mindmap getMindmapByTitle(final String title, final User user) {
final Mindmap result;
List<Mindmap> mindMaps = (List<Mindmap>) getHibernateTemplate().find("from com.wisemapping.model.Mindmap wisemapping where title=? and creator=?", new Object[]{title, user});
Query query = currentSession().createQuery("from com.wisemapping.model.Mindmap wisemapping where title=:title and creator=:creator");
query.setParameter("title", title);
query.setParameter("creator", user);
List<Mindmap> mindMaps = query.list();
if (mindMaps != null && !mindMaps.isEmpty()) {
result = mindMaps.get(0);
} else {
@ -223,7 +244,7 @@ public class MindmapManagerImpl
@Override
public void saveMindmap(Mindmap mindMap) {
assert mindMap != null : "Save Mindmap: Mindmap is required!";
getSession().save(mindMap);
currentSession().save(mindMap);
}
@Override
@ -238,7 +259,7 @@ public class MindmapManagerImpl
@Override
public void removeMindmap(@NotNull final Mindmap mindMap) {
// Delete history first ...
final Criteria hibernateCriteria = getSession().createCriteria(MindMapHistory.class);
final Criteria hibernateCriteria = currentSession().createCriteria(MindMapHistory.class);
hibernateCriteria.add(Restrictions.eq("mindmapId", mindMap.getId()));
List list = hibernateCriteria.list();
getHibernateTemplate().deleteAll(list);
@ -257,4 +278,3 @@ public class MindmapManagerImpl
getHibernateTemplate().saveOrUpdate(history);
}
}

View File

@ -25,9 +25,8 @@ import com.wisemapping.model.AccessAuditory;
import org.hibernate.ObjectNotFoundException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.security.authentication.encoding.PasswordEncoder;
//import org.acegisecurity.providers.encoding.PasswordEncoder;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
import org.springframework.security.crypto.password.PasswordEncoder;
import java.util.List;
import java.util.Set;
@ -42,29 +41,39 @@ public class UserManagerImpl
this.passwordEncoder = passwordEncoder;
}
@SuppressWarnings("unchecked")
public List<User> getAllUsers() {
return (List<User>) getHibernateTemplate().find("from com.wisemapping.model.User user");
return currentSession().createQuery("from com.wisemapping.model.User user").list();
}
@Override
public User getUserBy(@NotNull final String email) {
User user = null;
final List<User> users = (List<User>) getHibernateTemplate().find("from com.wisemapping.model.User colaborator where email=?", email);
var query = currentSession().createQuery("from com.wisemapping.model.User colaborator where email=:email");
query.setParameter("email", email);
final List<User> users = query.list();
if (users != null && !users.isEmpty()) {
assert users.size() == 1 : "More than one user with the same email!";
user = users.get(0);
}
return user;
}
@Override
public Collaborator getCollaboratorBy(final String email) {
final Collaborator cola;
final List cols = getHibernateTemplate().find("from com.wisemapping.model.Collaborator colaborator where email=?", email);
var query = currentSession().createQuery("from com.wisemapping.model.Collaborator colaborator where " +
"email=:email");
query.setParameter("email", email);
final List<User> cols = query.list();
if (cols != null && !cols.isEmpty()) {
assert cols.size() == 1 : "More than one colaborator with the same email!";
cola = (Collaborator) cols.get(0);
cola = cols.get(0);
} else {
cola = null;
}
@ -85,13 +94,13 @@ public class UserManagerImpl
@Override
public void createUser(User user) {
assert user != null : "Trying to store a null user";
user.setPassword(passwordEncoder.encodePassword(user.getPassword(), null));
user.setPassword(passwordEncoder.encode(user.getPassword()));
getHibernateTemplate().saveOrUpdate(user);
}
@Override
public User createUser(@NotNull User user, @NotNull Collaborator col) {
user.setPassword(passwordEncoder.encodePassword(user.getPassword(), null));
user.setPassword(passwordEncoder.encode(user.getPassword()));
assert user != null : "Trying to store a null user";
final Set<Collaboration> set = col.getCollaborations();
@ -121,14 +130,20 @@ public class UserManagerImpl
public void updateUser(@NotNull User user) {
assert user != null : "user is null";
user.setPassword(passwordEncoder.encodePassword(user.getPassword(), null));
user.setPassword(passwordEncoder.encode(user.getPassword()));
getHibernateTemplate().update(user);
}
public User getUserByActivationCode(long code) {
final User user;
final List users = getHibernateTemplate().find("from com.wisemapping.model.User user where activationCode=?", code);
var query = currentSession().createQuery("from com.wisemapping.model.User user where " +
"activationCode=:activationCode");
query.setParameter("activationCode", code);
final List users = query.list();
if(users != null && !users.isEmpty()) {
assert users.size() == 1 : "More than one user with the same username!";
user = (User) users.get(0);
} else {

View File

@ -19,12 +19,12 @@
package com.wisemapping.mail;
import org.apache.velocity.app.VelocityEngine;
import com.wisemapping.util.VelocityEngineUtils;
import com.wisemapping.util.VelocityEngineWrapper;
import org.jetbrains.annotations.NotNull;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.mail.javamail.MimeMessagePreparator;
import org.springframework.ui.velocity.VelocityEngineUtils;
import javax.mail.internet.MimeMessage;
import java.util.Map;
@ -34,7 +34,7 @@ public final class Mailer {
//~ Instance fields ......................................................................................
private JavaMailSender mailSender;
private VelocityEngine velocityEngine;
private VelocityEngineWrapper velocityEngineWrapper;
private String serverFromEmail;
private String supportEmail;
private String errorReporterEmail;
@ -62,7 +62,7 @@ public final class Mailer {
message.setFrom(from);
message.setSubject(subject);
final String messageBody = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "/mail/" + templateMail, model);
final String messageBody = VelocityEngineUtils.mergeTemplateIntoString(velocityEngineWrapper.getVelocityEngine(), "/mail/" + templateMail, model);
message.setText(messageBody, true);
}
};
@ -74,8 +74,8 @@ public final class Mailer {
this.mailSender = mailer;
}
public void setVelocityEngine(VelocityEngine engine) {
this.velocityEngine = engine;
public void setVelocityEngineWrapper(VelocityEngineWrapper engine) {
this.velocityEngineWrapper = engine;
}
public String getSupportEmail() {

View File

@ -53,7 +53,6 @@ import com.wisemapping.service.MindmapService;
import com.wisemapping.validator.MapInfoValidator;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiParam;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@ -73,6 +72,7 @@ import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
@ -85,7 +85,6 @@ import java.util.Set;
@Api(value = "mindmap", description = "User Mindmap Objects.")
@Controller
public class MindmapController extends BaseController {
private final static Logger logger = Logger.getLogger("com.wisemapping");
private static final String LATEST_HISTORY_REVISION = "latest";
@ -257,15 +256,13 @@ public class MindmapController extends BaseController {
}
@ApiIgnore
@RequestMapping(method = RequestMethod.GET, value = {"/maps/{id}/document/xml", "/maps/{id}/document/xml-pub"}, consumes = {"text/plain"}, produces = {"application/xml"})
@RequestMapping(method = RequestMethod.GET, value = {"/maps/{id}/document/xml", "/maps/{id}/document/xml-pub"}, consumes = {"text/plain"}, produces = {"application/xml; charset=UTF-8"})
@ResponseBody
public byte[] retrieveDocument(@PathVariable int id, @NotNull HttpServletResponse response) throws WiseMappingException, IOException {
// I should not return byte, but there is some encoding issue here. Further research needed.
response.setCharacterEncoding("UTF-8");
final Mindmap mindmap = findMindmapById(id);
String xmlStr = mindmap.getXmlStr();
return xmlStr.getBytes("UTF-8");
return xmlStr.getBytes(StandardCharsets.UTF_8);
}
@ApiIgnore
@ -284,11 +281,9 @@ public class MindmapController extends BaseController {
}
@RequestMapping(method = RequestMethod.GET, value = {"/maps/{id}/{hid}/document/xml"}, consumes = {"text/plain"}, produces = {"application/xml"})
@RequestMapping(method = RequestMethod.GET, value = {"/maps/{id}/{hid}/document/xml"}, consumes = {"text/plain"}, produces = {"application/xml; charset=UTF-8"})
@ResponseBody
public byte[] retrieveDocument(@PathVariable int id, @PathVariable int hid, @NotNull HttpServletResponse response) throws WiseMappingException, IOException {
// I should not return byte, but there is some encoding issue here. Further research needed.
response.setCharacterEncoding("UTF-8");
final MindMapHistory mindmapHistory = mindmapService.findMindmapHistory(id, hid);
return mindmapHistory.getUnzipXml();
}
@ -304,20 +299,16 @@ public class MindmapController extends BaseController {
final LockInfo lockInfo = lockManager.getLockInfo(mindmap);
if (lockInfo.getUser().identityEquality(user)) {
long savedTimestamp = mindmap.getLastModificationTime().getTimeInMillis();
final boolean outdated = savedTimestamp > timestamp;
final boolean outdated = mindmap.getLastModificationTime().getTimeInMillis() > timestamp;
if (lockInfo.getSession() == session) {
// Timestamp might not be returned to the client. This try to cover this case, ignoring the client timestamp check.
final User lastEditor = mindmap.getLastEditor();
boolean editedBySameUser = lastEditor == null || user.identityEquality(lastEditor);
if (outdated && !editedBySameUser) {
throw new SessionExpiredException("Map has been updated by " + (lastEditor.getEmail()) + ",Timestamp:" + timestamp + "," + savedTimestamp + ", User:" + lastEditor.getId() + ":" + user.getId() + ",Mail:'" + lastEditor.getEmail() + "':'" + user.getEmail(), lastEditor);
throw new SessionExpiredException("Map has been updated by " + (lastEditor.getEmail()) + ",Timestamp:" + timestamp + "," + mindmap.getLastModificationTime().getTimeInMillis() + ", User:" + lastEditor.getId() + ":" + user.getId() + ",Mail:'" + lastEditor.getEmail() + "':'" + user.getEmail(), lastEditor);
}
} else if (outdated) {
logger.warn("Sessions:" + session + ":" + lockInfo.getSession() + ",Timestamp: " + timestamp + ": " + savedTimestamp);
// @Todo: Temporally disabled to unblock save action. More research needed.
// throw new MultipleSessionsOpenException("Sessions:" + session + ":" + lockInfo.getSession() + ",Timestamp: " + timestamp + ": " + savedTimestamp);
throw new MultipleSessionsOpenException("Sessions:" + session + ":" + lockInfo.getSession() + ",Timestamp: " + timestamp + ": " + lockInfo.getTimestamp() + ",User:");
}
} else {
throw new SessionExpiredException("Different Users.", lockInfo.getUser());
@ -395,7 +386,7 @@ public class MindmapController extends BaseController {
// Update map ...
final Mindmap mindmap = findMindmapById(id);
mindmap.setTitle(title);
mindmapService.updateMindmap(mindMap, !true);
mindmapService.updateMindmap(mindMap, false);
}
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/collabs", consumes = {"application/json", "application/xml"}, produces = {"application/json", "application/xml"})
@ -464,7 +455,7 @@ public class MindmapController extends BaseController {
// Update map ...
final Mindmap mindmap = findMindmapById(id);
mindmap.setDescription(description);
mindmapService.updateMindmap(mindMap, !true);
mindmapService.updateMindmap(mindMap, false);
}
@RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/publish", consumes = {"text/plain"}, produces = {"application/json", "application/xml"})
@ -480,7 +471,7 @@ public class MindmapController extends BaseController {
// Update map status ...
mindMap.setPublic(Boolean.parseBoolean(value));
mindmapService.updateMindmap(mindMap, !true);
mindmapService.updateMindmap(mindMap, false);
}
@ -530,7 +521,7 @@ public class MindmapController extends BaseController {
@ResponseStatus(value = HttpStatus.NO_CONTENT)
public void batchDelete(@RequestParam(required = true) String ids) throws IOException, WiseMappingException {
final User user = Utils.getUser();
final String[] mapsIds = ids.split(",");
final String[] mapsIds = ",".split(ids);
for (final String mapId : mapsIds) {
final Mindmap mindmap = findMindmapById(Integer.parseInt(mapId));
mindmapService.removeMindmap(mindmap, user);
@ -651,11 +642,12 @@ public class MindmapController extends BaseController {
final User user = Utils.getUser();
final Label delegated = restLabel.getDelegated();
delegated.setCreator(user);
final Label found = labelService.getLabelById(labelId, user);
if (found == null) {
throw new LabelCouldNotFoundException("Label could not be found. Id: " + labelId);
}
for (String id : ids.split(",")) {
for (String id : ",".split(ids)) {
final int mindmapId = Integer.parseInt(id);
final Mindmap mindmap = findMindmapById(mindmapId);
final Label label = mindmap.findLabel(labelId);

View File

@ -55,7 +55,7 @@ public class TransformView extends AbstractView {
}
@Override
protected void renderMergedOutputModel(@NotNull Map<String, Object> viewMap, @NotNull HttpServletRequest request, @NotNull final HttpServletResponse response) throws Exception {
protected void renderMergedOutputModel(@NotNull Map<String, Object> viewMap, @NotNull HttpServletRequest request, @NotNull final HttpServletResponse response) {
final String content = (String) viewMap.get("content");
final String filename = (String) viewMap.get("filename");
@ -80,21 +80,22 @@ public class TransformView extends AbstractView {
this.setContentDisposition(request, response, fileName);
// Change image link URL.
final ServletContext servletContext = request.getSession().getServletContext();
final ServletContext servletContext = getServletContext();
final ExporterFactory factory = new ExporterFactory(servletContext);
try {
// Write the conversion content ...
final ServletOutputStream outputStream = response.getOutputStream();
if (exportFormat == ExportFormat.FREEMIND) {
response.setCharacterEncoding("ASCII");
response.setContentType(String.format("%s; charset=%s", contentType, "ASCII"));
factory.export(properties, content, outputStream, null);
} else if (exportFormat == ExportFormat.WISEMAPPING) {
response.setCharacterEncoding(DEFAULT_ENCODING);
response.setContentType(String.format("%s; charset=%s", contentType, DEFAULT_ENCODING));
final Object mindmap = viewMap.get("mindmap");
final StreamResult result = new StreamResult(outputStream);
jaxbMarshaller.marshal(mindmap, result);
} else if (exportFormat == ExportFormat.MICROSOFT_EXCEL || exportFormat == ExportFormat.TEXT || exportFormat == ExportFormat.OPEN_OFFICE_WRITER || exportFormat == ExportFormat.MINDJET) {
response.setCharacterEncoding(DEFAULT_ENCODING);
response.setContentType(String.format("%s; charset=%s", contentType, DEFAULT_ENCODING));
factory.export(properties, content, outputStream, null);
} else {
// Image export ...
@ -112,9 +113,9 @@ public class TransformView extends AbstractView {
String disposition = fileName;
try {
byte[] fileNameBytes = fileName.getBytes((isInternetExplorer) ? ("windows-1250") : ("utf-8"));
String dispositionFileName = "";
final StringBuilder dispositionFileName = new StringBuilder();
for (byte b : fileNameBytes) {
dispositionFileName += (char) (b & 0xff);
dispositionFileName.append((char) (b & 0xff));
}
disposition = "attachment; filename=\"" + dispositionFileName + "\"";
} catch (UnsupportedEncodingException ence) {

View File

@ -23,9 +23,9 @@ import com.wisemapping.model.User;
import org.jetbrains.annotations.NotNull;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.authentication.encoding.PasswordEncoder;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.crypto.password.PasswordEncoder;
public class AuthenticationProvider implements org.springframework.security.authentication.AuthenticationProvider {
@ -41,7 +41,8 @@ public class AuthenticationProvider implements org.springframework.security.auth
final UserDetails userDetails = getUserDetailsService().loadUserByUsername(email);
final User user = userDetails.getUser();
final String credentials = (String) auth.getCredentials();
if (user == null || credentials == null || !encoder.isPasswordValid(user.getPassword(), credentials, null)) {
if (user == null || credentials == null || !encoder.matches(user.getPassword(), credentials)) {
throw new BadCredentialsException("Username/Password does not match for " + auth.getPrincipal());
}
userDetailsService.getUserService().auditLogin(user);
@ -49,7 +50,7 @@ public class AuthenticationProvider implements org.springframework.security.auth
}
@Override
public boolean supports(final Class<? extends Object> authentication) {
public boolean supports(final Class<?> authentication) {
return (UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication));
}

View File

@ -18,37 +18,27 @@
package com.wisemapping.security;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.dao.DataAccessException;
import org.springframework.security.authentication.encoding.PasswordEncoder;
import org.springframework.security.authentication.encoding.ShaPasswordEncoder;
public class CustomPasswordEncoder
implements PasswordEncoder {
private PasswordEncoder delegateEncoder = new ShaPasswordEncoder();
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
public class CustomPasswordEncoder implements PasswordEncoder {
private static final String ENC_PREFIX = "ENC:";
private BCryptPasswordEncoder delegateEncoder = new BCryptPasswordEncoder(16);
public String encodePassword(@NotNull String rawPass, @Nullable Object salt) throws DataAccessException {
String password = rawPass;
if (!rawPass.startsWith(ENC_PREFIX)) {
password = ENC_PREFIX + delegateEncoder.encodePassword(rawPass, salt);
@Override
public String encode(CharSequence rawPassword) {
String password = rawPassword.toString();
if(!rawPassword.toString().startsWith(ENC_PREFIX)) {
password = ENC_PREFIX + delegateEncoder.encode(rawPassword);
}
return password;
}
public boolean isPasswordValid(@NotNull String encPass, @NotNull String rawPass, Object salt) throws DataAccessException {
@Override
public boolean matches(CharSequence rawPassword, String encodedPassword) {
String encodedRawPassword = delegateEncoder.encode(rawPassword);
String pass1 = "" + encPass;
String pass2 = rawPass;
if (pass1.startsWith(ENC_PREFIX)) {
pass2 = encodePassword(rawPass, salt);
}
return pass1.equals(pass2);
return delegateEncoder.matches(encodedRawPassword, encodedPassword);
}
}

View File

@ -21,23 +21,15 @@ package com.wisemapping.service;
import com.wisemapping.dao.UserManager;
import com.wisemapping.exceptions.WiseMappingException;
import com.wisemapping.mail.NotificationService;
import com.wisemapping.model.AccessAuditory;
import com.wisemapping.model.AuthenticationType;
import com.wisemapping.model.Collaborator;
import com.wisemapping.model.Mindmap;
import com.wisemapping.model.User;
import org.apache.velocity.app.VelocityEngine;
import com.wisemapping.model.*;
import com.wisemapping.util.VelocityEngineUtils;
import com.wisemapping.util.VelocityEngineWrapper;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.ui.velocity.VelocityEngineUtils;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import java.util.*;
public class UserServiceImpl
implements UserService {
@ -45,7 +37,7 @@ public class UserServiceImpl
private MindmapService mindmapService;
private NotificationService notificationService;
private MessageSource messageSource;
private VelocityEngine velocityEngine;
private VelocityEngineWrapper velocityEngineWrapper;
@Override
@ -165,7 +157,9 @@ public class UserServiceImpl
model.put("noArgs", new Object[]{});
model.put("locale", locale);
final String mapXml = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "/samples/tutorial.vm", model);
final String mapXml = VelocityEngineUtils
.mergeTemplateIntoString(velocityEngineWrapper
.getVelocityEngine(), "/samples/tutorial.vm", model);
result.setXmlStr(mapXml);
result.setTitle(messageSource.getMessage("WELCOME", null, locale) + " " + firstName);
@ -212,8 +206,8 @@ public class UserServiceImpl
this.messageSource = messageSource;
}
public void setVelocityEngine(VelocityEngine velocityEngine) {
this.velocityEngine = velocityEngine;
public void setVelocityEngineWrapper(VelocityEngineWrapper velocityEngineWrapper) {
this.velocityEngineWrapper = velocityEngineWrapper;
}
@Override

View File

@ -0,0 +1,38 @@
package com.wisemapping.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.VelocityException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Map;
public class VelocityEngineUtils {
private static final Log logger = LogFactory.getLog(VelocityEngineUtils.class);
public static void mergeTemplate(
VelocityEngine velocityEngine, String templateLocation,
Map<String, Object> model, Writer writer
) throws VelocityException {
try {
VelocityContext velocityContext = new VelocityContext(model);
velocityEngine.mergeTemplate(templateLocation, "UTF-8", velocityContext, writer);
} catch (RuntimeException ex) {
throw ex;
} catch (Exception ex) {
logger.error("Why does VelocityEngine throw a generic checked exception, after all?", ex);
throw new VelocityException(ex.toString());
}
}
public static String mergeTemplateIntoString(
VelocityEngine velocityEngine, String templateLocation, Map<String, Object> model
) throws VelocityException {
StringWriter result = new StringWriter();
mergeTemplate(velocityEngine, templateLocation, model, result);
return result.toString();
}
}

View File

@ -0,0 +1,24 @@
package com.wisemapping.util;
import org.apache.commons.collections.ExtendedProperties;
import org.apache.velocity.app.VelocityEngine;
import org.jetbrains.annotations.NotNull;
public class VelocityEngineWrapper {
private VelocityEngine velocityEngine;
public VelocityEngineWrapper() {
ExtendedProperties extendedProperties = new ExtendedProperties();
extendedProperties.setProperty("resource.loader", "class");
extendedProperties.setProperty("class.resource.loader.class",
"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
this.velocityEngine = new VelocityEngine();
velocityEngine.setExtendedProperties(extendedProperties);
}
@NotNull
public VelocityEngine getVelocityEngine() {
return velocityEngine;
}
}

View File

@ -53,7 +53,7 @@
<filter>
<filter-name>hibernate</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>

View File

@ -2,13 +2,11 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="viewSecurityAdvisor"
class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor">
<property name="advice">
<ref local="viewSecurityAdvice"/>
</property>
<property name="advice" ref="viewSecurityAdvice"/>
<property name="mappedNames">
<list>
<value>getMindmapUserBy</value>
@ -22,9 +20,7 @@
<bean id="updateSecurityAdvisor"
class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor">
<property name="advice">
<ref local="updateSecurityAdvice"/>
</property>
<property name="advice" ref="updateSecurityAdvice"/>
<property name="mappedNames">
<list>
<value>save*</value>

View File

@ -2,7 +2,7 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="wiseDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${database.driver}"/>
@ -13,14 +13,14 @@
<property name="validationQuery" value="${database.validation.query}"/>
</bean>
<!--Disconnect this lines for production environments -->
<!--Descoment this lines for production environments -->
<!--<bean id="wiseDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">-->
<!--<property name="jndiName">-->
<!--<value>java:comp/env/jdbc/wisemapping</value>-->
<!--</property>-->
<!--</bean>-->
<bean id="mindmapSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<bean id="mindmapSessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="wiseDataSource"/>
<property name="mappingResources">
<list>
@ -40,21 +40,13 @@
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="mindmapSessionFactory"/>
</property>
</bean>
<!-- Spring Data Access Exception Translator Defintion -->
<bean id="jdbcExceptionTranslator" class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator">
<property name="dataSource" ref="wiseDataSource"/>
<bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="mindmapSessionFactory"/>
</bean>
<!-- Hibernate Template Definition -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">
<property name="sessionFactory" ref="mindmapSessionFactory"/>
<property name="jdbcExceptionTranslator" ref="jdbcExceptionTranslator"/>
</bean>
<bean id="txAttributes"
@ -66,8 +58,7 @@
</property>
</bean>
<bean id="txInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<bean id="txInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributeSource" ref="txAttributes"/>
</bean>

View File

@ -6,11 +6,11 @@
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd">
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.wisemapping.rest"/>
<context:annotation-config/>

View File

@ -4,9 +4,9 @@
xmlns:sec="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-4.2.xsd">
http://www.springframework.org/schema/security/spring-security.xsd">
<sec:authentication-manager alias="authenticationManager">
<sec:authentication-provider ref="dbAuthenticationProvider"/>

View File

@ -3,9 +3,9 @@
xmlns:sec="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-4.2.xsd">
http://www.springframework.org/schema/security/spring-security.xsd">
<sec:authentication-manager>

View File

@ -4,9 +4,9 @@
xmlns:sec="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-4.2.xsd">
http://www.springframework.org/schema/security/spring-security.xsd">
<sec:http pattern="/css/**" security="none"/>
<sec:http pattern="/js/**" security="none"/>

View File

@ -3,19 +3,19 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd">
http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="/WEB-INF/app.properties" ignore-unresolvable="true"/>
<bean id="mailer" class="com.wisemapping.mail.Mailer" scope ="singleton">
<bean id="mailer" class="com.wisemapping.mail.Mailer">
<constructor-arg index="0" value="${mail.serverSendEmail}"/>
<constructor-arg index="1" value="${mail.supportEmail}"/>
<constructor-arg index="2" value="${mail.errorReporterEmail}"/>
<property name="mailSender" ref="mailSender"/>
<property name="velocityEngine" ref="velocityEngine"/>
<property name="velocityEngineWrapper" ref="velocityEngineWrapper"/>
</bean>
<bean id="userServiceTarget" class="com.wisemapping.service.UserServiceImpl">
@ -23,14 +23,12 @@
<property name="mindmapService" ref="mindMapServiceTarget"/>
<property name="notificationService" ref="notificationService"/>
<property name="messageSource" ref="messageSource"/>
<property name="velocityEngine" ref="velocityEngine"/>
<property name="velocityEngineWrapper" ref="velocityEngineWrapper"/>
</bean>
<bean id="userService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
<property name="target">
<ref local="userServiceTarget"/>
</property>
<property name="target" ref="userServiceTarget" />
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
@ -68,9 +66,7 @@
<bean id="labelService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
<property name="target">
<ref local="labelServiceTarget"/>
</property>
<property name="target" ref="labelServiceTarget" />
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
@ -93,16 +89,10 @@
</property>
</bean>
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<property name="velocityProperties">
<value>
resource.loader=class
class.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
</value>
</property>
<bean id="velocityEngineWrapper" class="com.wisemapping.util.VelocityEngineWrapper">
</bean>
<bean id="notificationService" class="com.wisemapping.mail.NotificationService" scope ="singleton">
<bean id="notificationService" class="com.wisemapping.mail.NotificationService">
<property name="baseUrl" value="${site.baseurl}"/>
<property name="mailer" ref="mailer"/>
</bean>

View File

@ -5,11 +5,11 @@
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd">
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.wisemapping.webmvc"/>
<context:annotation-config/>
@ -71,7 +71,7 @@
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
<property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView"/>
</bean>
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">