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