2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.web;
12 import java.io.IOException;
14 import javax.servlet.ServletException;
15 import javax.servlet.http.HttpServletRequest;
16 import javax.servlet.http.HttpServletResponse;
18 import org.springframework.security.core.AuthenticationException;
19 import org.springframework.security.web.DefaultRedirectStrategy;
20 import org.springframework.security.web.RedirectStrategy;
21 import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
22 import org.springframework.security.web.util.RedirectUrlBuilder;
24 @SuppressWarnings("deprecation")
25 public class ControllerLoginUrlAuthEntryPoint extends
26 LoginUrlAuthenticationEntryPoint {
28 private String loginFormUrl = "/login";
29 private final RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
31 //This entry point always re-directs to root login page.
34 public void commence(HttpServletRequest request,
35 HttpServletResponse response, AuthenticationException authException)
36 throws IOException, ServletException {
38 String redirectUrl = request.getRequestURL().toString();
39 RedirectUrlBuilder urlBuilder = new RedirectUrlBuilder();
40 urlBuilder.setScheme(request.getScheme());
41 urlBuilder.setServerName(request.getServerName());
42 urlBuilder.setPort(getPortResolver().getServerPort(request));
43 // urlBuilder.setContextPath(request.getContextPath());
44 urlBuilder.setPathInfo(loginFormUrl);
45 redirectUrl = urlBuilder.getUrl();
46 redirectStrategy.sendRedirect(request, response, redirectUrl);