diff --git a/src/main/java/de/thm/arsnova/controller/LoginController.java b/src/main/java/de/thm/arsnova/controller/v2/AuthenticationController.java similarity index 95% rename from src/main/java/de/thm/arsnova/controller/LoginController.java rename to src/main/java/de/thm/arsnova/controller/v2/AuthenticationController.java index 6f59e286154e290f13e194622060c83df041eba5..145a5f962bb5df94124933556efb6f2b31b3131a 100644 --- a/src/main/java/de/thm/arsnova/controller/LoginController.java +++ b/src/main/java/de/thm/arsnova/controller/v2/AuthenticationController.java @@ -15,8 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package de.thm.arsnova.controller; +package de.thm.arsnova.controller.v2; +import de.thm.arsnova.controller.AbstractController; import de.thm.arsnova.entities.ServiceDescription; import de.thm.arsnova.entities.UserAuthentication; import de.thm.arsnova.entities.migration.v2.Room; @@ -69,7 +70,8 @@ import java.util.List; * Handles authentication specific requests. */ @Controller -public class LoginController extends AbstractController { +@RequestMapping("/v2/auth") +public class AuthenticationController extends AbstractController { private static final int MAX_USERNAME_LENGTH = 15; private static final int MAX_GUESTHASH_LENGTH = 10; @@ -147,7 +149,7 @@ public class LoginController extends AbstractController { @Autowired private UserRoomService userRoomService; - private static final Logger logger = LoggerFactory.getLogger(LoginController.class); + private static final Logger logger = LoggerFactory.getLogger(AuthenticationController.class); @PostConstruct private void init() { @@ -156,7 +158,7 @@ public class LoginController extends AbstractController { } } - @RequestMapping(value = { "/auth/login", "/doLogin" }, method = { RequestMethod.POST, RequestMethod.GET }) + @RequestMapping(value = { "/login", "/doLogin" }, method = { RequestMethod.POST, RequestMethod.GET }) public void doLogin( @RequestParam("type") final String type, @RequestParam(value = "user", required = false) String username, @@ -238,7 +240,7 @@ public class LoginController extends AbstractController { } } - @RequestMapping(value = { "/auth/dialog" }, method = RequestMethod.GET) + @RequestMapping(value = { "/dialog" }, method = RequestMethod.GET) @ResponseBody public View dialog( @RequestParam("type") final String type, @@ -297,14 +299,14 @@ public class LoginController extends AbstractController { return result; } - @RequestMapping(value = { "/auth/", "/whoami" }, method = RequestMethod.GET) + @RequestMapping(value = { "/", "/whoami" }, method = RequestMethod.GET) @ResponseBody public UserAuthentication whoami() { userRoomService.setUser(userService.getCurrentUser()); return userService.getCurrentUser(); } - @RequestMapping(value = { "/auth/logout", "/logout" }, method = { RequestMethod.POST, RequestMethod.GET }) + @RequestMapping(value = { "/logout" }, method = { RequestMethod.POST, RequestMethod.GET }) public View doLogout(final HttpServletRequest request) { final Authentication auth = SecurityContextHolder.getContext().getAuthentication(); userService.removeUserFromMaps(userService.getCurrentUser()); @@ -316,13 +318,13 @@ public class LoginController extends AbstractController { return new RedirectView(request.getHeader("referer") != null ? request.getHeader("referer") : "/"); } - @RequestMapping(value = { "/auth/services" }, method = RequestMethod.GET) + @RequestMapping(value = { "/services" }, method = RequestMethod.GET) @ResponseBody public List<ServiceDescription> getServices(final HttpServletRequest request) { List<ServiceDescription> services = new ArrayList<>(); /* The first parameter is replaced by the backend, the second one by the frondend */ - String dialogUrl = apiPath + "/auth/dialog?type={0}&successurl='{0}'"; + String dialogUrl = apiPath + "/v2/auth/dialog?type={0}&successurl='{0}'"; if (guestEnabled) { ServiceDescription sdesc = new ServiceDescription( diff --git a/src/test/java/de/thm/arsnova/controller/LoginControllerTest.java b/src/test/java/de/thm/arsnova/controller/v2/AuthenticationControllerTest.java similarity index 89% rename from src/test/java/de/thm/arsnova/controller/LoginControllerTest.java rename to src/test/java/de/thm/arsnova/controller/v2/AuthenticationControllerTest.java index 99c2bfd83915bf036561f4c1559dc5e51b368804..526b86c61262942d3ea61a373dec9060e8be9ea7 100644 --- a/src/test/java/de/thm/arsnova/controller/LoginControllerTest.java +++ b/src/test/java/de/thm/arsnova/controller/v2/AuthenticationControllerTest.java @@ -15,8 +15,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -package de.thm.arsnova.controller; +package de.thm.arsnova.controller.v2; +import de.thm.arsnova.controller.AbstractControllerTest; import de.thm.arsnova.services.StubUserService; import org.junit.Before; import org.junit.Ignore; @@ -34,7 +35,7 @@ import static org.junit.Assert.assertEquals; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -public class LoginControllerTest extends AbstractControllerTest { +public class AuthenticationControllerTest extends AbstractControllerTest { @Autowired private StubUserService userService; @@ -52,7 +53,7 @@ public class LoginControllerTest extends AbstractControllerTest { @Test public void testGuestLogin() throws Exception { mockMvc.perform( - get("/doLogin") + get("/v2/auth/doLogin") .param("type", "guest") ).andExpect(status().isOk()); } @@ -60,7 +61,7 @@ public class LoginControllerTest extends AbstractControllerTest { @Test public void testReuseGuestLogin() throws Exception { mockMvc.perform( - get("/doLogin") + get("/v2/auth/doLogin") .param("type", "guest").param("user","Guest1234567890") ).andExpect(status().isOk()); @@ -76,7 +77,7 @@ public class LoginControllerTest extends AbstractControllerTest { public void testUser() throws Exception { userService.setUserAuthenticated(true); - mockMvc.perform(get("/whoami").accept(MediaType.APPLICATION_JSON)) + mockMvc.perform(get("/v2/auth/whoami").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.username").value("ptsr00")) @@ -85,7 +86,7 @@ public class LoginControllerTest extends AbstractControllerTest { @Test public void testLogoutWithoutRedirect() throws Exception { - mockMvc.perform(get("/logout")) + mockMvc.perform(get("/v2/auth/logout")) .andExpect(status().is3xxRedirection()) .andExpect(redirectedUrl("/")); }