Error handling for AQH creation.
authorwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Tue, 11 Feb 2003 22:59:18 +0000 (22:59 +0000)
committerwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Tue, 11 Feb 2003 22:59:18 +0000 (22:59 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@459 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/hs/HandleRepository.java
src/edu/internet2/middleware/shibboleth/hs/HandleServlet.java
src/edu/internet2/middleware/shibboleth/hs/provider/CryptoHandleRepository.java
src/edu/internet2/middleware/shibboleth/hs/provider/MemoryHandleRepository.java

index 4ef63f0..f3c69fc 100644 (file)
@@ -62,8 +62,9 @@ public interface HandleRepository {
        /**
         * Creates an opaque identifier that may be shared with target sites and subsequently 
         * used in attribute requests for the given <code>AuthNPrincipal</code>.
+        * @throws HandleRepositoryException if a Attribute Query Handle could not be created.
         */
-       public String getHandle(AuthNPrincipal principal);
+       public String getHandle(AuthNPrincipal principal) throws HandleRepositoryException;
 
        /**
         * Finds the <code>AuthNPrincipal</code> associated with a given opaque identifier.
index 59eda1b..1a33e6d 100644 (file)
@@ -236,11 +236,14 @@ public class HandleServlet extends HttpServlet {
                        String handle = handleRepository.getHandle(new AuthNPrincipal(req.getRemoteUser()));
                        log.info("Issued Handle (" + handle + ") to (" + req.getRemoteUser() + ")");
 
-                       byte[] buf =
-                               generateAssertion(handle, req.getParameter("shire"), req.getRemoteAddr(), req.getAuthType());
+                       byte[] buf = generateAssertion(handle, req.getParameter("shire"), req.getRemoteAddr(), req.getAuthType());
 
                        createForm(req, res, buf);
 
+               } catch (HandleRepositoryException ex) {
+                       log.error(ex);
+                       handleError(req, res, ex);
+                       return;
                } catch (HandleException ex) {
                        log.error(ex);
                        handleError(req, res, ex);
index 79f52a5..0751e6b 100644 (file)
@@ -56,6 +56,8 @@ import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutput;
 import java.io.ObjectOutputStream;
+import java.security.GeneralSecurityException;
+import java.security.KeyException;
 import java.security.KeyStore;
 import java.security.KeyStoreException;
 import java.security.NoSuchAlgorithmException;
@@ -69,7 +71,6 @@ import javax.crypto.Cipher;
 import javax.crypto.SecretKey;
 
 import org.apache.log4j.Logger;
-
 import sun.misc.BASE64Decoder;
 import sun.misc.BASE64Encoder;
 
@@ -95,8 +96,8 @@ public class CryptoHandleRepository extends BaseHandleRepository implements Hand
 
                        keyStore.load(
                                new FileInputStream(
-                                       properties
-                                               .getProperty("edu.internet2.middleware.shibboleth.hs.provider.CryptoHandleRepository.keyStorePath")),
+                                       properties.getProperty(
+                                               "edu.internet2.middleware.shibboleth.hs.provider.CryptoHandleRepository.keyStorePath")),
                                properties
                                        .getProperty("edu.internet2.middleware.shibboleth.hs.provider.CryptoHandleRepository.keyStorePassword")
                                        .toCharArray());
@@ -138,8 +139,13 @@ public class CryptoHandleRepository extends BaseHandleRepository implements Hand
        /**
         * @see edu.internet2.middleware.shibboleth.hs.HandleRepository#getHandle(Principal)
         */
-       public String getHandle(AuthNPrincipal principal) {
+       public String getHandle(AuthNPrincipal principal) throws HandleRepositoryException {
                try {
+                       if (principal == null) {
+                               log.error("A principal must be supplied for Attribute Query Handle creation.");
+                               throw new IllegalArgumentException("A principal must be supplied for Attribute Query Handle creation.");
+                       }
+
                        HandleEntry handleEntry = createHandleEntry(principal);
                        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
                        GZIPOutputStream zipStream = new GZIPOutputStream(outStream);
@@ -155,9 +161,15 @@ public class CryptoHandleRepository extends BaseHandleRepository implements Hand
                        String handle = new BASE64Encoder().encode(cipherTextHandle);
                        return handle.replaceAll(System.getProperty("line.separator"), "");
 
-               } catch (Exception e) {
-                       System.err.println(e);
-                       return null;
+               } catch (KeyException e) {
+                       log.error("Could not use the supplied secret key for Triple DES encryption: " + e);
+                       throw new HandleRepositoryException("Could not use the supplied secret key for Triple DES encryption.");
+               } catch (GeneralSecurityException e) {
+                       log.error("Appropriate JCE provider not found in the java environment.  Could not load Cipher: " + e);
+                       throw new HandleRepositoryException("Appropriate JCE provider not found in the java environment.  Could not load Cipher.");
+               } catch (IOException e) {
+                       log.error("Could not serialize Principal for handle creation: " + e);
+                       throw new HandleRepositoryException("Could not serialize Principal for Attribute Query Handle creation.");
                }
        }
 
index 1f4fcdb..ee5b1d2 100644 (file)
@@ -82,7 +82,13 @@ public class MemoryHandleRepository extends BaseHandleRepository implements Hand
        /**
         * @see edu.internet2.middleware.shibboleth.hs.HandleRepository#getHandle(Principal)
         */
-       public String getHandle(AuthNPrincipal principal) {
+       public String getHandle(AuthNPrincipal principal) throws HandleRepositoryException {
+
+               if (principal == null) {
+                       log.error("A principal must be supplied for Attribute Query Handle creation.");
+                       throw new IllegalArgumentException("A principal must be supplied for Attribute Query Handle creation.");
+               }
+
                String handle = UUIDGenerator.getInstance().generateRandomBasedUUID().toString();
                log.debug("Assigning handle (" + handle + ") to principal (" + principal.getName() + ").");
                synchronized (cache.handleEntries) {