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;
/**
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 {
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()) {
* 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("")) {
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())
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.
}
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;
*/
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);
* @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())) {
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 */
if (!initialized) { return defaultMapping; }
- return (NameIdentifierMapping) byFormat.get(format);
+ return byFormat.get(format);
}
/**
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)