package edu.internet2.middleware.shibboleth.idp;
import java.io.IOException;
-import java.net.MalformedURLException;
import java.net.URI;
-import java.net.URL;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Random;
import javax.servlet.RequestDispatcher;
import edu.internet2.middleware.shibboleth.artifact.ArtifactMapperFactory;
import edu.internet2.middleware.shibboleth.artifact.provider.MemoryArtifactMapper;
import edu.internet2.middleware.shibboleth.common.Credentials;
+import edu.internet2.middleware.shibboleth.common.IdPConfigLoader;
import edu.internet2.middleware.shibboleth.common.NameIdentifierMapping;
import edu.internet2.middleware.shibboleth.common.NameIdentifierMappingException;
import edu.internet2.middleware.shibboleth.common.NameMapper;
-import edu.internet2.middleware.shibboleth.common.IdPConfigLoader;
import edu.internet2.middleware.shibboleth.common.ServiceProviderMapper;
import edu.internet2.middleware.shibboleth.common.ServiceProviderMapperException;
import edu.internet2.middleware.shibboleth.common.ShibbolethConfigurationException;
log.debug("Recieved a request via GET for location (" + request.getRequestURL() + ").");
try {
- // Determine which protocol we are responding to (at this point normally Shibv1 vs. EAuth)
- String requestURL = request.getRequestURL().toString();
- IdPProtocolHandler activeHandler = (IdPProtocolHandler) protocolHandlers.get(requestURL);
- if (activeHandler == null) {
- log.debug("No protocol handler registered for location (" + request.getRequestURL()
- + "). Attempting to match against relative path.");
- try {
- activeHandler = (IdPProtocolHandler) protocolHandlers.get(new URL(requestURL).getPath());
- } catch (MalformedURLException e) {
- // squelch, we will just fail to find a handler
- }
- }
-
- if (activeHandler == null) {
- log.error("No protocol handler registered for location (" + request.getRequestURL() + ").");
- throw new SAMLException("Request submitted to an invalid location.");
- }
-
+ IdPProtocolHandler activeHandler = lookupProtocolHandler(request);
// Pass request to the appropriate handler
log.info("Processing " + activeHandler.getHandlerName() + " request.");
if (activeHandler.processRequest(request, response, null, protocolSupport) != null) {
+ samlRequest.toString());
}
- // Determine which protocol handler is active for this endpoint
- String requestURL = request.getRequestURL().toString();
- IdPProtocolHandler activeHandler = (IdPProtocolHandler) protocolHandlers.get(requestURL);
- if (activeHandler == null) {
- log.debug("No protocol handler registered for location (" + request.getRequestURL()
- + "). Attempting to match against relative path.");
- try {
- activeHandler = (IdPProtocolHandler) protocolHandlers.get(new URL(requestURL).getPath());
- } catch (MalformedURLException e) {
- // squelch, we will just fail to find a handler
- }
- }
-
- if (activeHandler == null) {
- log.error("No protocol handler registered for location (" + request.getRequestURL() + ").");
- throw new SAMLException("Request submitted to an invalid location.");
- }
-
+ IdPProtocolHandler activeHandler = lookupProtocolHandler(request);
// Pass request to the appropriate handler and respond
log.info("Processing " + activeHandler.getHandlerName() + " request.");
}
}
+ private IdPProtocolHandler lookupProtocolHandler(HttpServletRequest request) throws SAMLException {
+
+ // Determine which protocol handler is active for this endpoint
+ String requestURL = request.getRequestURL().toString();
+ IdPProtocolHandler activeHandler = null;
+
+ Iterator registeredLocations = protocolHandlers.keySet().iterator();
+ while (registeredLocations.hasNext()) {
+ String handlerLocation = (String) registeredLocations.next();
+ if (requestURL.matches(handlerLocation)) {
+ log.debug("Matched handler location: (" + handlerLocation + ").");
+ activeHandler = (IdPProtocolHandler) protocolHandlers.get(handlerLocation);
+ break;
+ }
+ }
+
+ if (activeHandler == null) {
+ log.error("No protocol handler registered for location (" + request.getRequestURL() + ").");
+ throw new SAMLException("Request submitted to an invalid location.");
+ }
+ return activeHandler;
+ }
+
private void sendFailureToSAMLBinding(HttpServletResponse httpResponse, SAMLRequest samlRequest,
SAMLException exception) throws ServletException {