Removed old HS
authorwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Tue, 11 Jun 2002 19:51:02 +0000 (19:51 +0000)
committerwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Tue, 11 Jun 2002 19:51:02 +0000 (19:51 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@61 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/hs/HandleService.java [deleted file]
src/edu/internet2/middleware/shibboleth/hs/HandleServiceConfig.java [deleted file]
src/edu/internet2/middleware/shibboleth/hs/HandleServiceException.java [deleted file]
src/edu/internet2/middleware/shibboleth/hs/HsConfigDigester.java [deleted file]

diff --git a/src/edu/internet2/middleware/shibboleth/hs/HandleService.java b/src/edu/internet2/middleware/shibboleth/hs/HandleService.java
deleted file mode 100755 (executable)
index a7794c1..0000000
+++ /dev/null
@@ -1,363 +0,0 @@
-package edu.internet2.middleware.shibboleth.hs;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.security.KeyPairGenerator;
-import java.security.PrivateKey;
-import java.security.SecureRandom;
-import java.security.Security;
-import java.util.Date;
-
-import javax.crypto.SecretKey;
-import javax.crypto.SecretKeyFactory;
-import javax.crypto.spec.DESedeKeySpec;
-import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.log4j.Logger;
-import org.apache.log4j.PropertyConfigurator;
-import org.bouncycastle.jce.provider.BouncyCastleProvider;
-import org.opensaml.SAMLException;
-import org.xml.sax.SAXException;
-
-import edu.internet2.middleware.shibboleth.common.AttributeQueryHandle;
-import edu.internet2.middleware.shibboleth.common.Base64;
-import edu.internet2.middleware.shibboleth.common.Constants;
-import edu.internet2.middleware.shibboleth.common.HandleException;
-import edu.internet2.middleware.shibboleth.common.ShibPOSTProfile;
-import edu.internet2.middleware.shibboleth.common.ShibPOSTProfileFactory;
-
-/**
- * 
- * A servlet implementation of the Shibboleth Handle Service.  Accepts 
- * Shibboleth Attribute Query Handle Requests via HTTP GET and generates 
- * SAML authN assertions containing an opaque user handle.  These assertions are 
- * embedded in an HTML that auto-POSTs to the referring SHIRE.
- * 
- * @author Walter Hoehn wassa&#064;columbia.edu
- * @author Barbara Jenson blk&#064;cmu.edu
- *
- */
-
-public class HandleService extends HttpServlet {
-
-       private static Logger log = Logger.getLogger(HandleService.class.getName());
-       private ShibPOSTProfile assertionFactory;
-       private String hsConfigFileLocation;
-       private String log4jConfigFileLocation;
-       private SecretKey handleKey;
-       private PrivateKey responseKey;
-
-       /**
-        * @see GenericServlet#init()
-        */
-
-       public void init() throws ServletException {
-
-               super.init();
-               loadInitParams();
-               initLogger();
-               initConfig();
-               initViewConfig();
-               initSecretKeys();
-               initAuthNFactory();
-       }
-
-       /**
-        * Initializes symmetric handleKey for use in AQH creation
-        */
-
-       private void initSecretKeys() throws ServletException {
-
-               //Currently hardcoded to use Bouncy Castle
-               //Decide to change this or not based on overall shibboleth policy
-               Security.addProvider(new BouncyCastleProvider());
-               try {
-
-                       SecretKeyFactory keyFactory =
-                               SecretKeyFactory.getInstance("DESede");
-                       DESedeKeySpec keySpec =
-                               new DESedeKeySpec(
-                                       Base64.decode(HandleServiceConfig.getSecretKey()));
-                       handleKey = keyFactory.generateSecret(keySpec);
-               } catch (Exception t) {
-                       log.fatal("Error reading Handle Key from configuration.", t);
-                       throw new ServletException("Error reading Handle Key from configuration.");
-               }
-               try {
-                       
-                       KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA");
-                       gen.initialize(1024, new SecureRandom());
-                       responseKey = gen.generateKeyPair().getPrivate();
-
-               } catch (Exception t) {
-                       log.fatal("Error reading Response Key from configuration.", t);
-                       throw new ServletException("Error reading Response Key from configuration.");
-               }
-
-       }
-
-       /**
-        * Retrieves location of HS configuration files from the servlet configuration.
-        */
-
-       private void loadInitParams() {
-
-               hsConfigFileLocation =
-                       getServletConfig().getInitParameter("HSConfigFileLocation");
-               if (hsConfigFileLocation == null) {
-                       hsConfigFileLocation = "/WEB-INF/conf/hsconfig.xml";
-               }
-               log4jConfigFileLocation =
-                       getServletConfig().getInitParameter("log4jConfigFileLocation");
-               if (log4jConfigFileLocation == null) {
-                       log4jConfigFileLocation = "/WEB-INF/conf/log4j.properties";
-               }
-
-       }
-
-       /**
-        * Loads HS configuration.  Populates a <code>HandleServiceConfig</code> object based
-        * on administrator supplied configuration.
-        */
-
-       private void initConfig() throws ServletException {
-
-               InputStream is =
-                       getServletContext().getResourceAsStream(hsConfigFileLocation);
-
-               try {
-                       HsConfigDigester digester =
-                               new HsConfigDigester(getServletContext());
-                       digester.setValidating(true);
-                       digester.parse(is);
-               } catch (SAXException se) {
-                       log.fatal("Error parsing HS configuration file.", se);
-                       throw new ServletException(
-                               "Error parsing HS configuration file.",
-                               se);
-               } catch (IOException ioe) {
-                       log.fatal("Error reading HS configuration file.", ioe);
-                       throw new ServletException(
-                               "Error reading HS configuration file.",
-                               ioe);
-               }
-
-       }
-
-       /**
-        * Starts up Log4J.
-        */
-
-       private void initLogger() {
-
-               PropertyConfigurator.configure(
-                       getServletContext().getRealPath("/") + log4jConfigFileLocation);
-
-       }
-
-       /**
-        * Places configuration parameters in the <code>ServletContext</code> so that they may 
-        * be retreived by view components.
-        */
-
-       private void initViewConfig() {
-               getServletContext().setAttribute(
-                       "hs_supportContact",
-                       HandleServiceConfig.getSupportContact());
-               getServletContext().setAttribute(
-                       "hs_logoLocation",
-                       HandleServiceConfig.getLogoLocation());
-               getServletContext().setAttribute(
-                       "hs_helpText",
-                       HandleServiceConfig.getHelpText());
-               getServletContext().setAttribute(
-                       "hs_detailedHelpURL",
-                       HandleServiceConfig.getDetailedHelpURL());
-       }
-
-       /**
-        * Initializes SAML AuthN Factory
-        */
-
-       private void initAuthNFactory() throws ServletException {
-               try {
-                       
-                       String[] policies={Constants.POLICY_CLUBSHIB};
-                       assertionFactory=ShibPOSTProfileFactory.getInstance(policies, HandleServiceConfig.getIssuer());
-
-               } catch (SAMLException se) {
-                       log.fatal("Error initializing SAML library: ", se);
-                       throw new ServletException("Error initializing SAML library: ", se);
-               }
-       }
-
-       /**
-        * @see HttpServlet#doGet(HttpServletRequest, HttpServletResponse)
-        */
-
-       public void doGet(HttpServletRequest req, HttpServletResponse resp)
-               throws ServletException, IOException {
-
-               try {
-                       validateRequestParameters(req);
-                       req.setAttribute("shire", req.getParameter("shire"));
-                       req.setAttribute("target", req.getParameter("target"));
-                       log.info("Generating assertion...");
-                       long startTime = System.currentTimeMillis();
-                       byte[] assertion =
-                               generateAssertion(
-                                       req.getParameter("shire"),
-                                       req.getRemoteAddr(),
-                                       req.getRemoteUser(),
-                                       req.getAuthType(),
-                                       req.getRequestURL().toString());
-                       log.info(
-                               "Assertion Generated: "
-                                       + "elapsed time "
-                                       + (System.currentTimeMillis() - startTime)
-                                       + " milliseconds.");
-                       log.debug("Assertion: " + new String(Base64.decode(assertion)));
-                       handleForm(req, resp, assertion);
-               } catch (HandleServiceException e) {
-                       handleError(req, resp, e);
-               }
-
-       }
-
-       /**
-        * Deals with HS runtime exceptions.  Logs errors locally and then 
-        * formats them for output to user.
-        * 
-        * @param e The Exception to be handled
-        */
-
-       private void handleError(
-               HttpServletRequest req,
-               HttpServletResponse res,
-               Exception e)
-               throws ServletException {
-
-               log.warn("Handle Service Failure: " + e);
-
-               req.setAttribute("errorText", e.toString());
-               req.setAttribute("requestURL", req.getRequestURL().toString());
-               RequestDispatcher rd = req.getRequestDispatcher("/hserror.jsp");
-
-               try {
-                       rd.forward(req, res);
-               } catch (IOException ioe) {
-                       log.info(
-                               "IO operation interrupted when displaying Handle Service error page: "
-                                       + ioe);
-               } catch (ServletException se) {
-                       log.error(
-                               "Problem trying to display Handle Service error page: " + se);
-                       throw se;
-               }
-       }
-
-       /**
-        * Method for auto-POSTing a Base64 encoded SAML assertion.
-        * 
-        * @param assertion Base64 encoded SAML authN assertion
-        */
-
-       private void handleForm(
-               HttpServletRequest req,
-               HttpServletResponse res,
-               byte[] assertion)
-               throws HandleServiceException {
-
-               try {
-                       //Hardcoded to ASCII to ensure Base64 encoding compatibility
-                       req.setAttribute("assertion", new String(assertion, "ASCII"));
-                       RequestDispatcher rd = req.getRequestDispatcher("/hs.jsp");
-                       log.info("POSTing assertion to SHIRE.");
-                       rd.forward(req, res);
-               } catch (IOException ioe) {
-                       throw new HandleServiceException(
-                               "IO interruption while displaying Handle Service UI." + ioe);
-               } catch (ServletException se) {
-                       throw new HandleServiceException(
-                               "Problem displaying Handle Service UI." + se);
-               }
-       }
-
-       /**
-        * Generates a new <code>AttributeQueryHandle</code> and includes it in a 
-        * <code>SAMLAuthenticationAssertion</code>.
-        */
-
-       private byte[] generateAssertion(
-               String shireURL,
-               String clientAddress,
-               String remoteUser,
-               String authType,
-               String hsURL)
-               throws HandleServiceException {
-               try {
-
-                       AttributeQueryHandle aqh =
-                               new AttributeQueryHandle(
-                                       remoteUser,
-                                       handleKey,
-                                       Long.parseLong(HandleServiceConfig.getValidityPeriod()),
-                                       hsURL);
-
-                       log.info("Acquired Handle: " + aqh.getHandleID());
-                                       
-                       return assertionFactory.prepare(
-                               shireURL,
-                               new String(aqh.serialize(), "ASCII"),
-                               HandleServiceConfig.getDomain(),
-                               clientAddress,
-                               authType,
-                               new Date(),
-                               null, responseKey, null, null, null).toBase64();
-
-               } catch (SAMLException se) {
-                       throw new HandleServiceException(
-                               "Error creating SAML assertion: " + se);
-               } catch (IOException ioe) {
-                       throw new HandleServiceException(
-                               "Error creating SAML assertion: " + ioe);
-               } catch (HandleException he) {
-                       throw new HandleServiceException(
-                               "Error creating User Handle: " + he);
-               }
-       }
-
-       /**
-        * Ensures that <code>HttpServletRequest</code> contains all of the parameters necessary
-        * for generation of an <code>AttributeQueryHandle</code>.
-        */
-
-       private void validateRequestParameters(HttpServletRequest req)
-               throws HandleServiceException {
-
-               if ((req.getParameter("shire") == null)
-                       || (req.getParameter("shire").equals(""))) {
-                       throw new HandleServiceException("Invalid data from SHIRE: No acceptance URL received.");
-               }
-               if ((req.getParameter("target") == null)
-                       || (req.getParameter("target").equals(""))) {
-                       throw new HandleServiceException("Invalid data from SHIRE: No target URL received.");
-               }
-               if ((req.getRemoteUser() == null)
-                       || (req.getRemoteUser().equals(""))) {
-                       throw new HandleServiceException("No authentication received from webserver.");
-               }
-               if ((req.getAuthType() == null) || (req.getAuthType().equals(""))) {
-                       throw new HandleServiceException("Unable to ascertain authentication type.");
-               }
-               if ((req.getRemoteAddr() == null)
-                       || (req.getRemoteAddr().equals(""))) {
-                       throw new HandleServiceException("Unable to ascertain client address.");
-               }
-       }
-
-}
\ No newline at end of file
diff --git a/src/edu/internet2/middleware/shibboleth/hs/HandleServiceConfig.java b/src/edu/internet2/middleware/shibboleth/hs/HandleServiceConfig.java
deleted file mode 100755 (executable)
index 3e760eb..0000000
+++ /dev/null
@@ -1,197 +0,0 @@
-package edu.internet2.middleware.shibboleth.hs;
-
-/**
- * Class used by the  WAYF service to determine runtime options.  
- * Most of the fields of this class should have reasonable defaults.
- * 
- * @author Walter Hoehn wassa&#064;columbia.edu
- */
-
-public class HandleServiceConfig {
-
-       private static String logoLocation = "images/internet2.gif";
-       private static String supportContact = "mailto:shib-support@internet2.org";
-       private static String helpText =
-               "In order to fulfill the request for the web"
-                       + " resource you have just chosen, information must be sent from your home institution to the "
-                       + "provider of the resource.  The web resource should load automatically.  If it does not load within "
-                       + "five seconds, click on the Transmit button.";
-       private static String detailedHelpURL = "http://blah";
-       private static String handleRepositoryImplementation =
-               "edu.internet2.middleware.shibboleth.common.provider.MemoryHandleRepository";
-       private static String validityPeriod = "1400000";
-       private static String domain = "internet2.edu";
-       private static String issuer = "shib2.internet2.edu";
-       private static String aaURL = "https://shib2.internet2.edu/shibb/servlet/AAServlet";
-       private static String secretKey;
-
-       /**
-        * Constructor for HandleServiceConfig.
-        */
-       public HandleServiceConfig() {
-               super();
-       }
-
-       /**
-        * Gets the logoLocation.
-        * @return Returns a String
-        */
-       public static String getLogoLocation() {
-               return logoLocation;
-       }
-
-       /**
-        * Sets the logoLocation.
-        * @param logoLocation The logoLocation to set
-        */
-       public static void setLogoLocation(String logoLocation) {
-               HandleServiceConfig.logoLocation = logoLocation;
-       }
-
-       /**
-        * Gets the supportContact.
-        * @return Returns a String
-        */
-       public static String getSupportContact() {
-               return supportContact;
-       }
-
-       /**
-        * Sets the supportContact.
-        * @param supportContact The supportContact to set
-        */
-       public static void setSupportContact(String supportContact) {
-               HandleServiceConfig.supportContact = supportContact;
-       }
-
-       /**
-        * Gets the helpText.
-        * @return Returns a String
-        */
-       public static String getHelpText() {
-               return helpText;
-       }
-
-       /**
-        * Sets the helpText.
-        * @param helpText The helpText to set
-        */
-       public static void setHelpText(String hs_helpText) {
-               HandleServiceConfig.helpText = hs_helpText;
-       }
-
-       /**
-        * Gets the handleRepositoryImplementation.
-        * @return Returns a String
-        */
-       public static String getHandleRepositoryImplementation() {
-               return handleRepositoryImplementation;
-       }
-
-       /**
-        * Sets the handleRepositoryImplementation.
-        * @param handleRepositoryImplementation The handleRepositoryImplementation to set
-        */
-       public static void setHandleRepositoryImplementation(String handleRepositoryImplementation) {
-               HandleServiceConfig.handleRepositoryImplementation = handleRepositoryImplementation;
-       }
-
-       /**
-        * Gets the detailedHelpURL.
-        * @return Returns a String
-        */
-       public static String getDetailedHelpURL() {
-               return detailedHelpURL;
-       }
-
-       /**
-        * Sets the detailedHelpURL.
-        * @param detailedHelpURL The detailedHelpURL to set
-        */
-       public static void setDetailedHelpURL(String hs_detailedHelpURL) {
-               HandleServiceConfig.detailedHelpURL = hs_detailedHelpURL;
-       }
-
-       /**
-        * Gets the ticket.
-        * @return Returns a String
-        */
-       public static String getValidityPeriod() {
-               return validityPeriod;
-       }
-
-       /**
-        * Sets the ticket.
-        * @param ticket The ticket to set
-        */
-       public static void setValidityPeriod(String validityPeriod) {
-               HandleServiceConfig.validityPeriod = validityPeriod;
-       }
-
-       /**
-        * Gets the domain.
-        * @return Returns a String
-        */
-       public static String getDomain() {
-               return domain;
-       }
-
-       /**
-        * Sets the domain.
-        * @param domain The domain to set
-        */
-       public static void setDomain(String domain) {
-               HandleServiceConfig.domain = domain;
-       }
-
-       /**
-        * Gets the issuer.
-        * @return Returns a String
-        */
-       public static String getIssuer() {
-               return issuer;
-       }
-
-       /**
-        * Sets the issuer.
-        * @param issuer The issuer to set
-        */
-       public static void setIssuer(String issuer) {
-               HandleServiceConfig.issuer = issuer;
-       }
-
-       /**
-        * Gets the aaURL.
-        * @return Returns a String
-        */
-       public static String getAaURL() {
-               return aaURL;
-       }
-
-       /**
-        * Sets the aaURL.
-        * @param aaURL The aaURL to set
-        */
-       public static void setAaURL(String aaURL) {
-               HandleServiceConfig.aaURL = aaURL;
-       }
-
-       /**
-        * Gets the secretKey.  Can only be retrieved one time.
-        * @return Returns a String
-        */
-       public static String getSecretKey() {
-               String cacheKey = secretKey;
-               secretKey = null;
-               return cacheKey;
-       }
-
-       /**
-        * Sets the secretKey.
-        * @param secretKey The secretKey to set
-        */
-       public static void setSecretKey(String secretKey) {
-               HandleServiceConfig.secretKey = secretKey;
-       }
-
-}
\ No newline at end of file
diff --git a/src/edu/internet2/middleware/shibboleth/hs/HandleServiceException.java b/src/edu/internet2/middleware/shibboleth/hs/HandleServiceException.java
deleted file mode 100755 (executable)
index b7da299..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-package edu.internet2.middleware.shibboleth.hs;
-
-/**
- * 
- * Signals that an error has occurred while processing a 
- * Shibboleth AQHR (Attribute Query Handle Request)
- * 
- * @author Walter Hoehn wassa&#064;columbia.edu
- *
- */
-
-public class HandleServiceException extends Exception {
-
-       /**
-        * Constructs a <code>HandleServiceException</code> with the specified detail
-        * message. The error message string <code>s</code> can later be
-        * retrieved by the <code>{@link java.lang.Throwable#getMessage}</code>
-        * method of class <code>java.lang.Throwable</code>.
-        *
-        * @param s The detailed message.
-        */
-
-       public HandleServiceException(String message) {
-
-               super(message);
-       }
-
-}
\ No newline at end of file
diff --git a/src/edu/internet2/middleware/shibboleth/hs/HsConfigDigester.java b/src/edu/internet2/middleware/shibboleth/hs/HsConfigDigester.java
deleted file mode 100755 (executable)
index abd426d..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-package edu.internet2.middleware.shibboleth.hs;
-
-import javax.servlet.ServletContext;
-import javax.xml.parsers.SAXParser;
-
-import org.xml.sax.XMLReader;
-
-import edu.internet2.middleware.shibboleth.common.ServletDigester;
-
-/**
- * This class is a jakarta Digester style parser for the HS configuration file.  
- * It should populate the HandleServiceConfig object during HS initilization. NOTE: It is
- * assumed that the mutators of this class will only be called by a single thread during
- * servlet initilization only (NOT thread safe)
- * 
- * @author Walter Hoehn wassa&#064;columbia.edu
- */
-
-public class HsConfigDigester extends ServletDigester {
-
-       protected String hsConfigClass =
-               "edu.internet2.middleware.shibboleth.hs.HandleServiceConfig";
-       private boolean configured = false;
-
-       public HsConfigDigester() {
-               super();
-               configure();
-       }
-
-       public HsConfigDigester(SAXParser parser) {
-               super(parser);
-               configure();
-       }
-
-       public HsConfigDigester(ServletContext context) {
-               super(context);
-               configure();
-       }
-
-       public HsConfigDigester(XMLReader reader) {
-               super(reader);
-               configure();
-       }
-
-       protected void configure() {
-
-               if (configured == true) {
-                       return;
-               }
-               addObjectCreate("HandleServiceConfig", hsConfigClass);
-               addSetProperties("HandleServiceConfig");
-               addCallMethod("HandleServiceConfig/HelpText", "setHelpText", 0);
-               addCallMethod("HandleServiceConfig/SecretKey", "setSecretKey", 0);
-
-               configured = true;
-
-       }
-
-       /**
-        * Gets the wayfDataClass.
-        * @return Returns a String
-        */
-       public String getHsConfigClass() {
-               return hsConfigClass;
-       }
-
-       /**
-        * Sets the wayfDataClass.
-        * @param wayfDataClass The wayfDataClass to set
-        */
-       public void setHsConfigClass(String wayfDataClass) {
-               this.hsConfigClass = wayfDataClass;
-       }
-
-}
\ No newline at end of file