36a192e0e90d2ee0ede171c886bddaf33a0397da
[controller.git] / opendaylight / web / root / src / main / java / org / opendaylight / controller / web / ControllerLoginUrlAuthEntryPoint.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9
10 package org.opendaylight.controller.web;
11
12 import java.io.IOException;
13
14 import javax.servlet.ServletException;
15 import javax.servlet.http.HttpServletRequest;
16 import javax.servlet.http.HttpServletResponse;
17
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;
23
24 @SuppressWarnings("deprecation")
25 public class ControllerLoginUrlAuthEntryPoint extends
26         LoginUrlAuthenticationEntryPoint {
27
28     private String loginFormUrl = "/login";
29     private final RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
30
31     //This entry point always re-directs to root login page.
32
33    @Override
34    public void commence(HttpServletRequest request,
35             HttpServletResponse response, AuthenticationException authException)
36             throws IOException, ServletException {
37
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);  
47
48     }
49
50 }