From 91a6fc7aebfb210812b5d5f876e0925e1672cad1 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer <paul-christian.volkmer@mni.thm.de> Date: Tue, 20 May 2014 13:11:44 +0200 Subject: [PATCH] Do not include spring-security.xml in spring-main.xml --- .../webapp/WEB-INF/spring/spring-main.xml | 2 -- src/main/webapp/WEB-INF/web.xml | 6 ++--- .../controller/FeedbackControllerTest.java | 1 + .../controller/LoginControllerTest.java | 1 + .../controller/SessionControllerTest.java | 1 + .../controller/StatisticsControllerTest.java | 1 + .../arsnova/services/FeedbackServiceTest.java | 19 +++++++-------- .../arsnova/services/QuestionServiceTest.java | 21 +++++++++-------- .../arsnova/services/SessionServiceTest.java | 23 +++++++++++-------- .../services/StatisticsServiceTest.java | 9 ++++---- 10 files changed, 46 insertions(+), 38 deletions(-) diff --git a/src/main/webapp/WEB-INF/spring/spring-main.xml b/src/main/webapp/WEB-INF/spring/spring-main.xml index 5c1803e9..5308d696 100644 --- a/src/main/webapp/WEB-INF/spring/spring-main.xml +++ b/src/main/webapp/WEB-INF/spring/spring-main.xml @@ -25,8 +25,6 @@ </property> </bean> - <import resource="spring-security.xml" /> - <context:component-scan base-package="de.thm.arsnova.dao,de.thm.arsnova.services,de.thm.arsnova.events" /> <context:annotation-config /> diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 75b4f85d..65258940 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -7,7 +7,8 @@ <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/spring/spring-main.xml - </param-value> + /WEB-INF/spring/spring-security.xml + </param-value> </context-param> <context-param> <param-name>log4jConfigLocation</param-name> @@ -95,8 +96,5 @@ <session-config> <tracking-mode>COOKIE</tracking-mode> - - <!-- delete sessions after 6 hours --> - <session-timeout>360</session-timeout> </session-config> </web-app> diff --git a/src/test/java/de/thm/arsnova/controller/FeedbackControllerTest.java b/src/test/java/de/thm/arsnova/controller/FeedbackControllerTest.java index 0c9ae13d..ee8364a3 100644 --- a/src/test/java/de/thm/arsnova/controller/FeedbackControllerTest.java +++ b/src/test/java/de/thm/arsnova/controller/FeedbackControllerTest.java @@ -23,6 +23,7 @@ import de.thm.arsnova.services.StubUserService; @ContextConfiguration(locations = { "file:src/main/webapp/WEB-INF/spring/arsnova-servlet.xml", "file:src/main/webapp/WEB-INF/spring/spring-main.xml", + "file:src/main/webapp/WEB-INF/spring/spring-security.xml", "file:src/test/resources/test-config.xml", "file:src/test/resources/test-socketioconfig.xml" }) diff --git a/src/test/java/de/thm/arsnova/controller/LoginControllerTest.java b/src/test/java/de/thm/arsnova/controller/LoginControllerTest.java index 2b2287dd..83b01fa6 100644 --- a/src/test/java/de/thm/arsnova/controller/LoginControllerTest.java +++ b/src/test/java/de/thm/arsnova/controller/LoginControllerTest.java @@ -45,6 +45,7 @@ import de.thm.arsnova.services.StubUserService; @ContextConfiguration(locations = { "file:src/main/webapp/WEB-INF/spring/arsnova-servlet.xml", "file:src/main/webapp/WEB-INF/spring/spring-main.xml", + "file:src/main/webapp/WEB-INF/spring/spring-security.xml", "file:src/test/resources/test-config.xml", "file:src/test/resources/test-socketioconfig.xml" }) diff --git a/src/test/java/de/thm/arsnova/controller/SessionControllerTest.java b/src/test/java/de/thm/arsnova/controller/SessionControllerTest.java index 3b8ff887..ea36714a 100644 --- a/src/test/java/de/thm/arsnova/controller/SessionControllerTest.java +++ b/src/test/java/de/thm/arsnova/controller/SessionControllerTest.java @@ -23,6 +23,7 @@ import de.thm.arsnova.services.StubUserService; @ContextConfiguration(locations = { "file:src/main/webapp/WEB-INF/spring/arsnova-servlet.xml", "file:src/main/webapp/WEB-INF/spring/spring-main.xml", + "file:src/main/webapp/WEB-INF/spring/spring-security.xml", "file:src/test/resources/test-config.xml", "file:src/test/resources/test-socketioconfig.xml" }) diff --git a/src/test/java/de/thm/arsnova/controller/StatisticsControllerTest.java b/src/test/java/de/thm/arsnova/controller/StatisticsControllerTest.java index 788c22d3..79f86fcc 100644 --- a/src/test/java/de/thm/arsnova/controller/StatisticsControllerTest.java +++ b/src/test/java/de/thm/arsnova/controller/StatisticsControllerTest.java @@ -20,6 +20,7 @@ import org.springframework.web.context.WebApplicationContext; @ContextConfiguration(locations = { "file:src/main/webapp/WEB-INF/spring/arsnova-servlet.xml", "file:src/main/webapp/WEB-INF/spring/spring-main.xml", + "file:src/main/webapp/WEB-INF/spring/spring-security.xml", "file:src/test/resources/test-config.xml", "file:src/test/resources/test-socketioconfig.xml" }) diff --git a/src/test/java/de/thm/arsnova/services/FeedbackServiceTest.java b/src/test/java/de/thm/arsnova/services/FeedbackServiceTest.java index 06409e42..fa1b8ae9 100644 --- a/src/test/java/de/thm/arsnova/services/FeedbackServiceTest.java +++ b/src/test/java/de/thm/arsnova/services/FeedbackServiceTest.java @@ -1,6 +1,6 @@ /* * Copyright (C) 2012 THM webMedia - * + * * This file is part of ARSnova. * * ARSnova is free software: you can redistribute it and/or modify @@ -39,6 +39,7 @@ import de.thm.arsnova.exceptions.NotFoundException; @ContextConfiguration(locations = { "file:src/main/webapp/WEB-INF/spring/arsnova-servlet.xml", "file:src/main/webapp/WEB-INF/spring/spring-main.xml", + "file:src/main/webapp/WEB-INF/spring/spring-security.xml", "file:src/test/resources/test-config.xml" }) public class FeedbackServiceTest { @@ -48,14 +49,14 @@ public class FeedbackServiceTest { @Autowired StubUserService userService; - + @Autowired private StubDatabaseDao databaseDao; @Before public final void setup() { userService.setUserAuthenticated(false); - + feedbackService.saveFeedback("87654321", 0, new TestUser("testuser01")); feedbackService.saveFeedback("87654321", 0, new TestUser("testuser02")); feedbackService.saveFeedback("87654321", 1, new TestUser("testuser11")); @@ -73,8 +74,8 @@ public class FeedbackServiceTest { feedbackService.saveFeedback("87654321", 3, new TestUser("testuser35")); feedbackService.saveFeedback("87654321", 3, new TestUser("testuser36")); feedbackService.saveFeedback("87654321", 3, new TestUser("testuser37")); - - + + feedbackService.saveFeedback("18273645", 0, new TestUser("testuser01")); feedbackService.saveFeedback("18273645", 0, new TestUser("testuser02")); feedbackService.saveFeedback("18273645", 1, new TestUser("testuser11")); @@ -96,9 +97,9 @@ public class FeedbackServiceTest { feedbackService.saveFeedback("18273645", 3, new TestUser("testuser39")); feedbackService.saveFeedback("18273645", 3, new TestUser("testuser310")); feedbackService.saveFeedback("18273645", 3, new TestUser("testuser311")); - + } - + @After public final void cleanup() { databaseDao.cleanupTestData(); @@ -162,10 +163,10 @@ public class FeedbackServiceTest { userService.setUserAuthenticated(true); assertEquals(2.1904, feedbackService.getAverageFeedback("18273645"), 0.001); } - + public static class TestUser extends User { private static final long serialVersionUID = 1L; - + public TestUser(String username) { super( new UsernamePasswordAuthenticationToken(username, "secret") ); } diff --git a/src/test/java/de/thm/arsnova/services/QuestionServiceTest.java b/src/test/java/de/thm/arsnova/services/QuestionServiceTest.java index 96e81937..8113ce0b 100644 --- a/src/test/java/de/thm/arsnova/services/QuestionServiceTest.java +++ b/src/test/java/de/thm/arsnova/services/QuestionServiceTest.java @@ -1,6 +1,6 @@ /* * Copyright (C) 2012 THM webMedia - * + * * This file is part of ARSnova. * * ARSnova is free software: you can redistribute it and/or modify @@ -18,7 +18,9 @@ */ package de.thm.arsnova.services; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import org.junit.After; import org.junit.Test; @@ -36,6 +38,7 @@ import de.thm.arsnova.exceptions.UnauthorizedException; @ContextConfiguration(locations = { "file:src/main/webapp/WEB-INF/spring/arsnova-servlet.xml", "file:src/main/webapp/WEB-INF/spring/spring-main.xml", + "file:src/main/webapp/WEB-INF/spring/spring-security.xml", "file:src/test/resources/test-config.xml" }) public class QuestionServiceTest { @@ -45,7 +48,7 @@ public class QuestionServiceTest { @Autowired StubUserService userService; - + @Autowired private StubDatabaseDao databaseDao; @@ -73,7 +76,7 @@ public class QuestionServiceTest { userService.setUserAuthenticated(true); assertEquals(1, questionService.getSkillQuestionCount("12345678")); } - + @Test public void testShouldMarkInterposedQuestionAsReadIfSessionCreator() throws Exception { userService.setUserAuthenticated(true); @@ -82,12 +85,12 @@ public class QuestionServiceTest { theQ.set_id("the internal id"); theQ.setSessionId("12345678"); databaseDao.interposedQuestion = theQ; - + questionService.readInterposedQuestion(theQ.get_id()); - + assertTrue(theQ.isRead()); } - + @Test public void testShouldNotMarkInterposedQuestionAsReadIfRegularUser() throws Exception { userService.setUserAuthenticated(true, "regular user"); @@ -96,9 +99,9 @@ public class QuestionServiceTest { theQ.set_id("the internal id"); theQ.setSessionId("12345678"); databaseDao.interposedQuestion = theQ; - + questionService.readInterposedQuestion(theQ.get_id()); - + assertFalse(theQ.isRead()); } } diff --git a/src/test/java/de/thm/arsnova/services/SessionServiceTest.java b/src/test/java/de/thm/arsnova/services/SessionServiceTest.java index 06956f11..6fb1f06a 100644 --- a/src/test/java/de/thm/arsnova/services/SessionServiceTest.java +++ b/src/test/java/de/thm/arsnova/services/SessionServiceTest.java @@ -1,6 +1,6 @@ /* * Copyright (C) 2012 THM webMedia - * + * * This file is part of ARSnova. * * ARSnova is free software: you can redistribute it and/or modify @@ -21,11 +21,13 @@ package de.thm.arsnova.services; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.util.Arrays; -import static org.mockito.Mockito.*; - import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; @@ -47,7 +49,8 @@ import de.thm.arsnova.exceptions.UnauthorizedException; @ContextConfiguration(locations = { "file:src/main/webapp/WEB-INF/spring/arsnova-servlet.xml", "file:src/main/webapp/WEB-INF/spring/spring-main.xml", - "file:src/test/resources/test-config.xml" }) + "file:src/main/webapp/WEB-INF/spring/spring-security.xml", +"file:src/test/resources/test-config.xml" }) public class SessionServiceTest { @Autowired @@ -55,7 +58,7 @@ public class SessionServiceTest { @Autowired private StubUserService userService; - + @Autowired private StubDatabaseDao databaseDao; @@ -64,7 +67,7 @@ public class SessionServiceTest { databaseDao.cleanupTestData(); userService.setUserAuthenticated(false); } - + @Test public void testShouldGenerateSessionKeyword() { assertTrue(sessionService.generateKeyword().matches("^[0-9]{8}$")); @@ -118,19 +121,19 @@ public class SessionServiceTest { IDatabaseDao tempDatabase = (IDatabaseDao) ReflectionTestUtils.getField(getTargetObject(sessionService), "databaseDao"); try { userService.setUserAuthenticated(true); - + Session session = new Session(); session.setCreator(userService.getCurrentUser().getUsername()); Question q1 = new Question(); Question q2 = new Question(); - + IDatabaseDao mockDatabase = mock(IDatabaseDao.class); when(mockDatabase.getSkillQuestions(userService.getCurrentUser(), session)).thenReturn(Arrays.asList(q1, q2)); when(mockDatabase.getSession(anyString())).thenReturn(session); ReflectionTestUtils.setField(getTargetObject(sessionService), "databaseDao", mockDatabase); - + sessionService.deleteSession(session.getKeyword(), userService.getCurrentUser()); - + verify(mockDatabase).deleteQuestionWithAnswers(q1); verify(mockDatabase).deleteQuestionWithAnswers(q2); verify(mockDatabase).deleteSession(session); diff --git a/src/test/java/de/thm/arsnova/services/StatisticsServiceTest.java b/src/test/java/de/thm/arsnova/services/StatisticsServiceTest.java index ec348f3b..33ab4921 100644 --- a/src/test/java/de/thm/arsnova/services/StatisticsServiceTest.java +++ b/src/test/java/de/thm/arsnova/services/StatisticsServiceTest.java @@ -18,6 +18,7 @@ import de.thm.arsnova.entities.Statistics; @ContextConfiguration(locations = { "file:src/main/webapp/WEB-INF/spring/arsnova-servlet.xml", "file:src/main/webapp/WEB-INF/spring/spring-main.xml", + "file:src/main/webapp/WEB-INF/spring/spring-security.xml", "file:src/test/resources/test-config.xml" }) public class StatisticsServiceTest { @@ -39,12 +40,12 @@ public class StatisticsServiceTest { session.setActive(false); databaseDao.saveSession(session); } - + @After public final void cleanup() { databaseDao.cleanupTestData(); } - + @Test public final void testShouldReturnNoActiveUsers() { int actual = statisticsService.countActiveUsers(); @@ -55,7 +56,7 @@ public class StatisticsServiceTest { public final void testShouldReturnCurrentActiveUsers() { Session session = new Session(); session.setKeyword("1278127812"); - + userService.setUserAuthenticated(true); databaseDao.registerAsOnlineUser(userService.getCurrentUser(), session); @@ -63,7 +64,7 @@ public class StatisticsServiceTest { assertEquals(1, actual); userService.setUserAuthenticated(false); } - + @Test public final void testShouldReturnStatistics() { Statistics actual = statisticsService.getStatistics(); -- GitLab