Commit 93fc622e authored by Piotr Gawron's avatar Piotr Gawron
Browse files

when checking if session is valid provide also info who is logged in

parent db4906b8
......@@ -40,8 +40,10 @@ public class UserController extends BaseController {
*/
@GetMapping(value = "/isSessionValid")
@PreAuthorize("isAuthenticated() and authentication.name != '" + Configuration.ANONYMOUS_LOGIN + "'")
public Object isSessionValid() {
return new TreeMap<>();
public Object isSessionValid(Authentication authentication) {
Map<String,Object> result = new TreeMap<>();
result.put("login", authentication.getName());
return result;
}
@PreAuthorize("hasAnyAuthority('IS_ADMIN', 'IS_CURATOR') or #login == authentication.name")
......
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.*;
......@@ -15,6 +16,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.RequestBuilder;
import org.springframework.transaction.annotation.Transactional;
import com.google.gson.JsonParser;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.model.user.User;
......@@ -94,8 +97,15 @@ public class UserControllerAnonymousIntegrationTest extends ControllerIntegratio
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
mockMvc.perform(request)
.andExpect(status().is2xxSuccessful());
String response = mockMvc.perform(request)
.andExpect(status().is2xxSuccessful())
.andReturn().getResponse().getContentAsString();
String login = new JsonParser()
.parse(response)
.getAsJsonObject()
.get("login")
.getAsString();
assertEquals(TEST_ADMIN_LOGIN, login);
}
@Test
......
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