Skip to content
Snippets Groups Projects
Commit 58ac72b3 authored by Daniel Gerhardt's avatar Daniel Gerhardt
Browse files

Move existing controller for auth to /v2

parent ba08cf4b
Branches
No related merge requests found
......@@ -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(
......
......@@ -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("/"));
}
......
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