Miscellaneous code cleanups.
authorwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Tue, 25 Jul 2006 18:57:53 +0000 (18:57 +0000)
committerwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Tue, 25 Jul 2006 18:57:53 +0000 (18:57 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@1976 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/aa/arp/provider/BaseArpRepository.java
src/edu/internet2/middleware/shibboleth/common/Credentials.java
src/edu/internet2/middleware/shibboleth/common/NameMapper.java
src/edu/internet2/middleware/shibboleth/common/ServiceProviderMapper.java
src/edu/internet2/middleware/shibboleth/common/Trust.java

index afc76ae..d772dfa 100755 (executable)
@@ -70,7 +70,7 @@ public abstract class BaseArpRepository implements ArpRepository {
        public Arp[] getAllPolicies(Principal principal) throws ArpRepositoryException {
 
                log.debug("Received a query for all policies applicable to principal: (" + principal.getName() + ").");
-               Set allPolicies = new HashSet();
+               Set<Arp> allPolicies = new HashSet<Arp>();
                Arp sitePolicy = getSitePolicy();
                if (sitePolicy != null) {
                        log.debug("Returning site policy.");
@@ -188,7 +188,7 @@ class ArpCache {
        private static ArpCache instance = null;
        /** Time in seconds for which ARPs should be cached. */
        private long cacheLength;
-       private Map cache = new HashMap();
+       private Map<Principal, CachedArp> cache = new HashMap<Principal, CachedArp>();
        private static Logger log = Logger.getLogger(ArpCache.class.getName());
        private ArpCacheCleaner cleaner = new ArpCacheCleaner();
 
@@ -343,11 +343,11 @@ class ArpCache {
                                                return;
                                        }
                                        log.debug("ArpCache cleanup thread searching for stale entries.");
-                                       Set needsDeleting = new HashSet();
+                                       Set<CachedArp> needsDeleting = new HashSet<CachedArp>();
                                        synchronized (cache) {
-                                               Iterator iterator = cache.values().iterator();
+                                               Iterator<CachedArp> iterator = cache.values().iterator();
                                                while (iterator.hasNext()) {
-                                                       CachedArp cachedArp = (CachedArp) iterator.next();
+                                                       CachedArp cachedArp = iterator.next();
                                                        if ((System.currentTimeMillis() - cachedArp.creationTimeMillis) > (cacheLength * 1000)) {
                                                                needsDeleting.add(cachedArp);
                                                        }
index 1a0e023..83122db 100644 (file)
@@ -83,7 +83,7 @@ public class Credentials {
        public static final String credentialsNamespace = "urn:mace:shibboleth:credentials:1.0";
 
        private static Logger log = Logger.getLogger(Credentials.class.getName());
-       private Hashtable data = new Hashtable();
+       private Hashtable<String, Credential> data = new Hashtable<String, Credential>();
        private boolean singleMode = false;
 
        /**
@@ -144,12 +144,12 @@ public class Credentials {
                if ((identifier == null || identifier.equals("")) && data.size() == 1) { return (Credential) data.values()
                                .iterator().next(); }
 
-               return (Credential) data.get(identifier);
+               return data.get(identifier);
        }
 
        public Credential getCredential() {
 
-               return (Credential) data.values().iterator().next();
+               return data.values().iterator().next();
        }
 
        static class CredentialFactory {
@@ -226,7 +226,7 @@ class FileCredentialResolver implements CredentialResolver {
                        throw new CredentialFactoryException("Failed to load private key.");
                }
 
-               List certChain = getCertificateChain(e, key);
+               List<Certificate> certChain = getCertificateChain(e, key);
 
                Credential credential = new Credential(((X509Certificate[]) certChain.toArray(new X509Certificate[0])), key);
                if (log.isDebugEnabled()) {
@@ -307,9 +307,10 @@ class FileCredentialResolver implements CredentialResolver {
         *             thrown if the certificate files is not found, can not be parsed, or an IOException occurs whils
         *             reading the file
         */
-       private List getCertificateChain(Element credentialConfigElement, PrivateKey key) throws CredentialFactoryException {
+       private List<Certificate> getCertificateChain(Element credentialConfigElement, PrivateKey key)
+                       throws CredentialFactoryException {
 
-               List certChain = new ArrayList();
+               List<Certificate> certChain = new ArrayList<Certificate>();
                String certPath = getCertPath(credentialConfigElement);
 
                if (certPath == null || certPath.equals("")) {
@@ -331,7 +332,7 @@ class FileCredentialResolver implements CredentialResolver {
                                throw new CredentialFactoryException("Only X.509 certificates are supported");
                        }
 
-                       ArrayList allCerts = new ArrayList();
+                       ArrayList<Certificate> allCerts = new ArrayList<Certificate>();
 
                        try {
                                Certificate[] certsFromPath = loadCertificates(new ShibResource(certPath, this.getClass())
@@ -440,64 +441,68 @@ class FileCredentialResolver implements CredentialResolver {
 
                return certChain;
        }
-    
-    /**
-     * Determines whether the key is PEM or DER encoded.
-     * 
-     * @param e the file credential resolver configuration element
-     * @param keyStream an input stream reading the private key
-     * 
-     * @return the encoding format of the key
-     * 
-     * @throws CredentialFactoryException thrown if the key format can not be determined or the key can not be read
-     */
-    private int getKeyEncodingFormat(Element e, InputStream keyStream) throws CredentialFactoryException {
-        NodeList keyElements = e.getElementsByTagNameNS(Credentials.credentialsNamespace, "Key");
-        if (keyElements.getLength() < 1) {
-            log.error("No private key specified in file credential resolver");
-            throw new CredentialFactoryException("File Credential Resolver requires a <Key> specification.");
-        }
-
-        if (keyElements.getLength() > 1) {
-            log.error("Multiple Key path specifications, using first.");
-        }
-
-        String formatStr = ((Element) keyElements.item(0)).getAttribute("format");
-        
-        if(formatStr != null && formatStr.length() > 0) {
-            if(formatStr.equals("PEM")) {
-                return EncodedKey.PEM_ENCODING;
-            }else if(formatStr.equals("DER")) {
-                return EncodedKey.DER_ENCODING;
-            }else if(formatStr.equals("PKCS12")) {
-                log.error("PKCS12 private keys are not yet supported");
-                return -1;
-            }
-        }
-        
-        if(log.isInfoEnabled()) {
-            log.info("Private key format was not specified in file credential resolver configuration, attempting to auto-detect it.");
-        }
-        try {
-            // Need to mark the stream and then reset it, after getting the
-            // first byte so that the private key decoder starts reading at
-            // the correct position
-            keyStream.mark(2);
-            int firstByte = keyStream.read();
-            keyStream.reset();
-
-            // PEM encoded keys must start with a "-", a decimal value of 45
-            if (firstByte == 45) { return EncodedKey.PEM_ENCODING; }
-
-            // DER encoded keys must start with a decimal value of 48
-            if (firstByte == 48) { return EncodedKey.DER_ENCODING; }
-
-            // Can not determine type
-            return -1;
-        }catch (IOException ioe) {
-            throw new CredentialFactoryException("Could not determine the type of private key for file credential resolver.");
-        }
-    }
+
+       /**
+        * Determines whether the key is PEM or DER encoded.
+        * 
+        * @param e
+        *            the file credential resolver configuration element
+        * @param keyStream
+        *            an input stream reading the private key
+        * @return the encoding format of the key
+        * @throws CredentialFactoryException
+        *             thrown if the key format can not be determined or the key can not be read
+        */
+       private int getKeyEncodingFormat(Element e, InputStream keyStream) throws CredentialFactoryException {
+
+               NodeList keyElements = e.getElementsByTagNameNS(Credentials.credentialsNamespace, "Key");
+               if (keyElements.getLength() < 1) {
+                       log.error("No private key specified in file credential resolver");
+                       throw new CredentialFactoryException("File Credential Resolver requires a <Key> specification.");
+               }
+
+               if (keyElements.getLength() > 1) {
+                       log.error("Multiple Key path specifications, using first.");
+               }
+
+               String formatStr = ((Element) keyElements.item(0)).getAttribute("format");
+
+               if (formatStr != null && formatStr.length() > 0) {
+                       if (formatStr.equals("PEM")) {
+                               return EncodedKey.PEM_ENCODING;
+                       } else if (formatStr.equals("DER")) {
+                               return EncodedKey.DER_ENCODING;
+                       } else if (formatStr.equals("PKCS12")) {
+                               log.error("PKCS12 private keys are not yet supported");
+                               return -1;
+                       }
+               }
+
+               if (log.isInfoEnabled()) {
+                       log
+                                       .info("Private key format was not specified in file credential resolver configuration, attempting to auto-detect it.");
+               }
+               try {
+                       // Need to mark the stream and then reset it, after getting the
+                       // first byte so that the private key decoder starts reading at
+                       // the correct position
+                       keyStream.mark(2);
+                       int firstByte = keyStream.read();
+                       keyStream.reset();
+
+                       // PEM encoded keys must start with a "-", a decimal value of 45
+                       if (firstByte == 45) { return EncodedKey.PEM_ENCODING; }
+
+                       // DER encoded keys must start with a decimal value of 48
+                       if (firstByte == 48) { return EncodedKey.DER_ENCODING; }
+
+                       // Can not determine type
+                       return -1;
+               } catch (IOException ioe) {
+                       throw new CredentialFactoryException(
+                                       "Could not determine the type of private key for file credential resolver.");
+               }
+       }
 
        /**
         * Gets the private key password from the Credentials configuration element if one exists.
@@ -602,7 +607,7 @@ class FileCredentialResolver implements CredentialResolver {
                        }
                        return null;
                }
-               ArrayList paths = new ArrayList();
+               ArrayList<String> paths = new ArrayList<String>();
                for (int i = 0; i < pathElements.getLength(); i++) {
                        Node tnode = pathElements.item(i).getFirstChild();
                        String path = null;
@@ -672,7 +677,7 @@ class FileCredentialResolver implements CredentialResolver {
         */
        private Certificate[] loadCertificates(InputStream inStream, String certType) throws CredentialFactoryException {
 
-               ArrayList certificates = new ArrayList();
+               ArrayList<Certificate> certificates = new ArrayList<Certificate>();
 
                try {
                        CertificateFactory certFactory = CertificateFactory.getInstance(certType);
@@ -733,7 +738,8 @@ class FileCredentialResolver implements CredentialResolver {
         * @throws InvalidCertificateChainException
         *             thrown if a chain cannot be constructed from the specified elements
         */
-       protected void walkChain(X509Certificate[] chainSource, List chainDest) throws CredentialFactoryException {
+       protected void walkChain(X509Certificate[] chainSource, List<Certificate> chainDest)
+                       throws CredentialFactoryException {
 
                X509Certificate currentCert = (X509Certificate) chainDest.get(chainDest.size() - 1);
                if (currentCert.getSubjectDN().equals(currentCert.getIssuerDN())) {
index e035d3a..bf288ee 100644 (file)
@@ -45,9 +45,10 @@ import edu.internet2.middleware.shibboleth.xml.Parser;
 public class NameMapper {
 
        private static Logger log = Logger.getLogger(NameMapper.class.getName());
-       private Map byFormat = new HashMap();
-       private Map byId = new HashMap();
-       private static Map registeredMappingTypes = Collections.synchronizedMap(new HashMap());
+       private Map<URI, NameIdentifierMapping> byFormat = new HashMap<URI, NameIdentifierMapping>();
+       private Map<String, NameIdentifierMapping> byId = new HashMap<String, NameIdentifierMapping>();
+       private static Map<String, Class> registeredMappingTypes = Collections
+                       .synchronizedMap(new HashMap<String, Class>());
        /** true if mappings have been added */
        protected boolean initialized = false;
        /** Mapping to use if no other mappings have been added */
@@ -180,7 +181,7 @@ public class NameMapper {
 
                if (!initialized) { return defaultMapping; }
 
-               return (NameIdentifierMapping) byFormat.get(format);
+               return byFormat.get(format);
        }
 
        /**
@@ -196,13 +197,13 @@ public class NameMapper {
                        if (!initialized) { return defaultMapping; }
 
                        if (byFormat.size() == 1) {
-                               Iterator values = byFormat.values().iterator();
-                               Object mapping = values.next();
-                               return (NameIdentifierMapping) mapping;
+                               Iterator<NameIdentifierMapping> values = byFormat.values().iterator();
+                               NameIdentifierMapping mapping = values.next();
+                               return mapping;
                        }
                }
 
-               return (NameIdentifierMapping) byId.get(id);
+               return byId.get(id);
        }
 
        protected NameIdentifierMapping loadNameIdentifierMapping(Class implementation, Element config)
index 9bbd101..add4a87 100644 (file)
@@ -46,7 +46,7 @@ import edu.internet2.middleware.shibboleth.idp.IdPConfig;
 public class ServiceProviderMapper {
 
        private static Logger log = Logger.getLogger(ServiceProviderMapper.class.getName());
-       protected Map relyingParties = new HashMap();
+       protected Map<String, RelyingParty> relyingParties = new HashMap<String, RelyingParty>();
        private MetadataProvider metaData;
        private IdPConfig configuration;
        private Credentials credentials;
@@ -222,7 +222,7 @@ public class ServiceProviderMapper {
                private String overridenIdPProviderId;
                private URL overridenAAUrl;
                private URI overridenDefaultAuthMethod;
-               private List mappingIds = new ArrayList();
+               private List<String> mappingIds = new ArrayList<String>();
                private IdPConfig configuration;
                private boolean overridenPassThruErrors = false;
                private boolean passThruIsOverriden = false;
index c7293aa..dfb5196 100644 (file)
@@ -19,8 +19,8 @@ package edu.internet2.middleware.shibboleth.common;
 import java.security.cert.X509Certificate;
 
 import org.opensaml.SAMLSignedObject;
+import org.opensaml.saml2.metadata.RoleDescriptor;
 
-import edu.internet2.middleware.shibboleth.metadata.RoleDescriptor;
 
 /**
  * Defines methodology for determing whether or not a system entity should trust the messages issued by another.