1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package edu.internet2.middleware.shibboleth.common.profile;
19
20 import java.io.IOException;
21 import java.net.URLEncoder;
22
23 import javax.servlet.ServletConfig;
24 import javax.servlet.ServletException;
25 import javax.servlet.http.HttpServlet;
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28
29 import org.opensaml.ws.transport.http.HTTPInTransport;
30 import org.opensaml.ws.transport.http.HTTPOutTransport;
31 import org.opensaml.ws.transport.http.HttpServletRequestAdapter;
32 import org.opensaml.ws.transport.http.HttpServletResponseAdapter;
33 import org.opensaml.xml.util.DatatypeHelper;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37 import edu.internet2.middleware.shibboleth.common.log.AccessLogEntry;
38
39
40
41
42 public class ProfileRequestDispatcherServlet extends HttpServlet {
43
44
45 private static final long serialVersionUID = 3750548606378986211L;
46
47
48 private final Logger log = LoggerFactory.getLogger(ProfileRequestDispatcherServlet.class);
49
50
51 private final Logger accessLog = LoggerFactory.getLogger(AccessLogEntry.ACCESS_LOGGER_NAME);
52
53
54 private ProfileHandlerManager handlerManager;
55
56
57 public void init(ServletConfig config) throws ServletException {
58 super.init(config);
59
60 String handlerManagerId = config.getInitParameter("handlerManagerId");
61 if (DatatypeHelper.isEmpty(handlerManagerId)) {
62 handlerManagerId = "shibboleth.HandlerManager";
63 }
64
65 handlerManager = (ProfileHandlerManager) getServletContext().getAttribute(handlerManagerId);
66 }
67
68
69 @SuppressWarnings("unchecked")
70 protected void service(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws ServletException,
71 IOException {
72 if (accessLog.isInfoEnabled()) {
73 AccessLogEntry accessEntry = new AccessLogEntry(httpRequest);
74 accessLog.info(accessEntry.toString());
75 }
76
77 HTTPInTransport profileReq = new HttpServletRequestAdapter(httpRequest);
78 HTTPOutTransport profileResp = new HttpServletResponseAdapter(httpResponse, httpRequest.isSecure());
79
80 AbstractErrorHandler errorHandler = handlerManager.getErrorHandler();
81 ProfileHandler handler = handlerManager.getProfileHandler(httpRequest);
82 if (handler != null) {
83 try {
84 handler.processRequest(profileReq, profileResp);
85 return;
86 }catch(ProfileException e){
87 httpRequest.setAttribute(AbstractErrorHandler.ERROR_KEY, e);
88 } catch (Throwable t) {
89 log.error("Error occurred while processing request", t);
90 }
91 } else {
92 log.warn("No profile handler configured for request at path: {}", httpRequest.getPathInfo());
93 httpRequest.setAttribute(AbstractErrorHandler.ERROR_KEY, new NoProfileHandlerException(
94 "No profile handler configured for request at path: " + httpRequest.getPathInfo()));
95 }
96
97 errorHandler.processRequest(profileReq, profileResp);
98 return;
99 }
100 }