Commit 554bfd45 authored by Sascha Herzinger's avatar Sascha Herzinger
Browse files

Merge remote-tracking branch 'remotes/origin/563-spring-security-frontend' into 563-spring-security

parents 15bcc1b6 b25bdb73
......@@ -354,24 +354,20 @@ EditUserDialog.prototype.initProjectsTab = function () {
columns: columns
});
$(projectsTable).on("click", "[name='project-privilege-checkbox']", function () {
var data = $(this).attr("data").split("-");
var privilegeType = data[0];
var objectId = data[1];
var data = $(this).attr("data");
if ($(this).is(":checked")) {
return self.grantPrivilege({privilegeType: privilegeType, objectId: objectId});
return self.grantPrivilege({privilegeType: data});
} else {
return self.revokePrivilege({privilegeType: privilegeType, objectId: objectId});
return self.revokePrivilege({privilegeType: data});
}
});
$("[name='defaultProjectsRow']", self.getElement()).on("click", "[name='project-privilege-checkbox']", function () {
var data = $(this).attr("data").split("-");
var privilegeType = data[0];
var objectId = "*";
var data = $(this).attr("data");
if ($(this).is(":checked")) {
return self.grantPrivilege({privilegeType: privilegeType, objectId: objectId});
return self.grantPrivilege({privilegeType: data});
} else {
return self.revokePrivilege({privilegeType: privilegeType, objectId: objectId});
return self.revokePrivilege({privilegeType: data});
}
});
};
......@@ -430,8 +426,8 @@ EditUserDialog.prototype.grantPrivilege = function (privilege) {
*/
EditUserDialog.prototype.revokePrivilege = function (privilege) {
var self = this;
if (self._isNewUser()) {
self.getUser().removePrivilege(privilege);
if (self._isNewUser) {
self.getUser().revokePrivilege(privilege);
return Promise.resolve();
} else {
GuiConnector.showProcessing();
......@@ -464,7 +460,7 @@ EditUserDialog.prototype.refreshPrivilegesTab = function () {
option = this.getConfiguration().getOption('DEFAULT_' + privilege.getName());
if (option !== null && option !== undefined) {
if (option.getValue().toLowerCase() === "true") {
self.getUser().setPrivilege({type: privilege});
self.getUser().setPrivilege({privilegeType: privilege.getName()});
checked = "checked";
}
}
......@@ -508,7 +504,7 @@ EditUserDialog.prototype.setProjects = function (projects) {
defaultRow.innerHTML = "";
defaultRow.appendChild(Functions.createElement({
type: "span",
content: rowData[0],
content: "<b>DEFAULT PRIVILEGE FOR NEW PROJECT</b>",
xss: false
}));
defaultRow.appendChild(Functions.createElement({type: "br"}));
......@@ -541,7 +537,7 @@ EditUserDialog.prototype.projectToTableRow = function (project, columns) {
var user = this.getUser();
var row = [];
var id = null;
var projectId = "<b>DEFAULT PRIVILEGE FOR NEW PROJECT</b>";
var projectId = "*";
if (project !== null) {
id = project.getId();
projectId = project.getProjectId();
......@@ -559,12 +555,12 @@ EditUserDialog.prototype.projectToTableRow = function (project, columns) {
if (option !== null && option !== undefined) {
if (option.getValue().toLowerCase() === "true") {
user.setPrivilege({type: privilege, objectId: projectId});
user.setPrivilege({privilegeType: privilege, objectId: projectId});
checked = "checked";
}
}
}
row.push("<input type='checkbox' name='project-privilege-checkbox' data='" + privilege.getName() + "-" + id + "' " + checked + " />");
row.push("<input type='checkbox' name='project-privilege-checkbox' data='" + privilege.getName() + ":" + projectId + "' " + checked + " />");
}
return row;
......
......@@ -162,7 +162,7 @@ describe('ServerConnector', function () {
assert.equal(result.length, 1);
var layoutAlias = result[0];
assert.ok(layoutAlias instanceof LayoutAlias);
assert.equal(-7602176, layoutAlias.getColor().rgb);
assert.equal(-65536, layoutAlias.getColor().rgb);
assert.equal(15781, layoutAlias.getModelId());
assert.equal(329163, layoutAlias.getId());
});
......@@ -258,7 +258,9 @@ describe('ServerConnector', function () {
it('getModelDownloadUrl', function () {
return ServerConnector.getModelDownloadUrl({
backgroundOverlayId: "cv14081"
backgroundOverlayId: 14081,
modelId: 1,
handlerClass: "lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser"
}).then(function (url) {
assert.ok(url);
});
......
......@@ -25,8 +25,9 @@ import org.junit.runners.Suite.SuiteClasses;
SpringSecurityGeneralIntegrationTest.class,
SpringSecurityLdapIntegrationTest.class,
TaxonomiesControllerIntegrationTest.class,
UserControllerAnonymousIntegrationTest.class,
UserControllerIntegrationTest.class,
UserControllerAnonymousIntegrationTest.class
UserControllerIntegrationTestWithoutTransaction.class
})
public class AllIntegrationTests {
......
......@@ -3,9 +3,13 @@ package lcsb.mapviewer.web;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import java.awt.geom.Point2D;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.*;
import java.util.function.Supplier;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.servlet.Filter;
import org.apache.logging.log4j.core.LogEvent;
......@@ -32,8 +36,10 @@ import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.GenericProtein;
import lcsb.mapviewer.model.security.PrivilegeType;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.persist.DbUtils;
import lcsb.mapviewer.persist.dao.ProjectDao;
import lcsb.mapviewer.persist.dao.cache.UploadedFileEntryDao;
import lcsb.mapviewer.persist.dao.user.UserDao;
import lcsb.mapviewer.services.interfaces.IUserService;
import lcsb.mapviewer.web.config.SpringWebConfig;
......@@ -53,22 +59,35 @@ abstract public class ControllerIntegrationTest {
@Autowired
private ProjectDao projectDao;
@Autowired
private UserDao userDao;
@Autowired
private PasswordEncoder passwordEncoder;
@Autowired
private UploadedFileEntryDao fileDao;
@Autowired
private DbUtils dbUtils;
protected MockMvc mockMvc;
private MinervaLoggerAppender appender;
private ExecutorService executorService;
@PostConstruct
public void construct() {
mockMvc = MockMvcBuilders.webAppContextSetup(context)
.addFilter(springSecurityFilterChain)
.build();
executorService = Executors.newFixedThreadPool(1);
}
@PreDestroy
public void tearDown() throws Exception {
executorService.shutdown();
}
/**
......@@ -152,7 +171,6 @@ abstract public class ControllerIntegrationTest {
return user;
}
protected Project createProject(String projectId) {
Project project = new Project(projectId);
ModelData map = new ModelData();
......@@ -190,5 +208,35 @@ abstract public class ControllerIntegrationTest {
return file;
}
/**
* Executes lambda function in new thread with separate hibernate session. The
* function returns type <T> which can be void.
*
* @param fun
* lambda to be executed in separate thread
* @return
* @throws Exception
*/
protected <T> T callInSeparateThread(Supplier<T> fun) throws Exception {
List<Future<T>> elements = executorService.invokeAll(Arrays.asList(new Callable<T>() {
@Override
public T call() throws Exception {
try {
dbUtils.createSessionForCurrentThread();
return fun.get();
} finally {
dbUtils.closeSessionForCurrentThread();
}
}
}));
return elements.get(0).get();
}
protected void removeUserInSeparateThread(User user) throws Exception {
callInSeparateThread(() -> {
userDao.delete(userDao.getById(user.getId()));
return null;
});
}
}
......@@ -40,8 +40,6 @@ import lcsb.mapviewer.services.interfaces.IUserService;
@RunWith(SpringJUnit4ClassRunner.class)
public class ProjectControllerIntegrationTestForAsyncCalls extends ControllerIntegrationTest {
private ExecutorService executorService;
private static final String TEST_PROJECT = "test_project";
Logger logger = LogManager.getLogger();
......@@ -64,12 +62,8 @@ public class ProjectControllerIntegrationTestForAsyncCalls extends ControllerInt
@Autowired
private IUserService userService;
@Autowired
private DbUtils dbUtils;
@Before
public void setup() throws Exception {
executorService = Executors.newFixedThreadPool(1);
}
@After
......@@ -78,7 +72,6 @@ public class ProjectControllerIntegrationTestForAsyncCalls extends ControllerInt
if (project != null) {
removeProjectInSeparateThread(project);
}
executorService.shutdown();
}
@Test(timeout = 10000)
......@@ -416,13 +409,6 @@ public class ProjectControllerIntegrationTestForAsyncCalls extends ControllerInt
});
}
private void removeUserInSeparateThread(User user) throws Exception {
callInSeparateThread(() -> {
userDao.delete(userDao.getById(user.getId()));
return null;
});
}
private void removeProjectInSeparateThread(Project project) throws Exception {
removeProjectInSeparateThread(project.getProjectId());
}
......@@ -437,27 +423,4 @@ public class ProjectControllerIntegrationTestForAsyncCalls extends ControllerInt
});
}
/**
* Executes lambda function in new thread with separate hibernate session. The
* function returns type <T> which can be void.
*
* @param fun
* lambda to be executed in separate thread
* @return
* @throws Exception
*/
private <T> T callInSeparateThread(Supplier<T> fun) throws Exception {
List<Future<T>> elements = executorService.invokeAll(Arrays.asList(new Callable<T>() {
@Override
public T call() throws Exception {
try {
dbUtils.createSessionForCurrentThread();
return fun.get();
} finally {
dbUtils.closeSessionForCurrentThread();
}
}
}));
return elements.get(0).get();
}
}
package lcsb.mapviewer.web;
import static org.junit.Assert.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import java.util.*;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.RequestBuilder;
import org.springframework.transaction.annotation.Transactional;
import com.google.gson.*;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.security.Privilege;
import lcsb.mapviewer.model.security.PrivilegeType;
import lcsb.mapviewer.model.user.ConfigurationElementType;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.persist.dao.ProjectDao;
import lcsb.mapviewer.services.interfaces.IConfigurationService;
import lcsb.mapviewer.services.interfaces.IUserService;
@RunWith(SpringJUnit4ClassRunner.class)
@Rollback
public class UserControllerIntegrationTestWithoutTransaction extends ControllerIntegrationTest {
Logger logger = LogManager.getLogger();
private static final String TEST_USER_PASSWORD = "test_pass";
private static final String TEST_USER_LOGIN = "test_user";
private static final String ADMIN_PASSWORD = "admin";
private static final String ADMIN_LOGIN = "admin";
@Autowired
private IUserService userService;
@Before
public void setup() {
}
@Test
public void createUser() throws Exception {
try {
MockHttpSession session = createSession(ADMIN_LOGIN, ADMIN_PASSWORD);
String body = EntityUtils.toString(new UrlEncodedFormEntity(Arrays.asList(
new BasicNameValuePair("login", TEST_USER_LOGIN),
new BasicNameValuePair("password", TEST_USER_PASSWORD),
new BasicNameValuePair("name", ""),
new BasicNameValuePair("surname", ""),
new BasicNameValuePair("email", ""))));
RequestBuilder request = post("/users/" + TEST_USER_LOGIN)
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.content(body)
.session(session);
mockMvc.perform(request)
.andExpect(status().is2xxSuccessful());
} finally {
removeUserInSeparateThread(userService.getUserByLogin(TEST_USER_LOGIN));
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment