1 /*
2 * Copyright [2006] [University Corporation for Advanced Internet Development, Inc.]
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package edu.internet2.middleware.shibboleth.idp.authn.provider;
18
19 import java.io.IOException;
20
21 import javax.servlet.http.HttpServletRequest;
22 import javax.servlet.http.HttpServletResponse;
23
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 import edu.internet2.middleware.shibboleth.idp.util.HttpServletHelper;
28
29 /**
30 * Authentication Handler that redirects to servlet protected by a Web Single-Sign-On system.
31 */
32 public class RemoteUserLoginHandler extends AbstractLoginHandler {
33
34 /** Class logger. */
35 private final Logger log = LoggerFactory.getLogger(RemoteUserLoginHandler.class);
36
37 /** The URL of the SSO-protected servlet. */
38 private String servletURL;
39
40 /**
41 * Set the SSO-protected servlet's URL.
42 *
43 * @param url The URL of the SSO-protected servlet.
44 */
45 public void setServletURL(String url) {
46 servletURL = url;
47 }
48
49 /**
50 * Get the URL of the SSO-protected servlet.
51 *
52 * @return The URL of the SSO-protected servlet.
53 */
54 public String getServletURL() {
55 return servletURL;
56 }
57
58 /** {@inheritDoc} */
59 public void login(HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
60
61 // forward control to the servlet.
62 try {
63 String profileUrl = HttpServletHelper.getContextRelativeUrl(httpRequest, servletURL).buildURL();
64
65 log.debug("Redirecting to {}", profileUrl);
66 httpResponse.sendRedirect(profileUrl);
67 return;
68 } catch (IOException ex) {
69 log.error("Unable to redirect to remote user authentication servlet.", ex);
70 }
71 }
72 }