You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by mu...@apache.org on 2011/11/18 17:47:01 UTC
svn commit: r1203738 - in
/santuario/xml-security-java/trunk/src/main/java/javax/xml/crypto/dsig:
TransformService.java XMLDSigSecurity.java XMLSignatureFactory.java
Author: mullan
Date: Fri Nov 18 16:47:00 2011
New Revision: 1203738
URL: http://svn.apache.org/viewvc?rev=1203738&view=rev
Log:
Remove dependency on XMLDSigSecurity for finding providers. Use new JDK 1.5
Provider.Service API instead.
Removed:
santuario/xml-security-java/trunk/src/main/java/javax/xml/crypto/dsig/XMLDSigSecurity.java
Modified:
santuario/xml-security-java/trunk/src/main/java/javax/xml/crypto/dsig/TransformService.java
santuario/xml-security-java/trunk/src/main/java/javax/xml/crypto/dsig/XMLSignatureFactory.java
Modified: santuario/xml-security-java/trunk/src/main/java/javax/xml/crypto/dsig/TransformService.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/javax/xml/crypto/dsig/TransformService.java?rev=1203738&r1=1203737&r2=1203738&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/javax/xml/crypto/dsig/TransformService.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/javax/xml/crypto/dsig/TransformService.java Fri Nov 18 16:47:00 2011
@@ -219,47 +219,44 @@ public abstract class TransformService i
String mechanismType, Provider provider)
throws NoSuchAlgorithmException {
- Object[] objs = (Object[]) XMLDSigSecurity.getImpl
- (algorithm, new MechanismMapEntry(algorithm, mechanismType),
- "TransformService", provider);
-
- TransformService spi = (TransformService) objs[0];
- spi.mechanism = mechanismType;
- spi.algorithm = algorithm;
- spi.provider = (Provider) objs[1];
- return spi;
+ if (provider == null) {
+ provider = getProvider("TransformService", algorithm,
+ mechanismType);
+ }
+ Provider.Service ps = provider.getService("TransformService",
+ algorithm);
+ if (ps == null) {
+ throw new NoSuchAlgorithmException("no such algorithm: " +
+ algorithm + " for provider " +
+ provider.getName());
+ }
+ TransformService ts = (TransformService)ps.newInstance(null);
+ ts.algorithm = algorithm;
+ ts.mechanism = mechanismType;
+ ts.provider = provider;
+ return ts;
}
- private static class MechanismMapEntry implements Map.Entry {
- private final String mechanism;
- private final String key;
- MechanismMapEntry(String algorithm, String mechanism) {
- this.mechanism = mechanism;
- this.key = "TransformService." + algorithm + " MechanismType";
- }
- public boolean equals(Object o) {
- if (!(o instanceof Map.Entry)) {
- return false;
+ private static Provider getProvider(String engine, String alg, String mech)
+ throws NoSuchAlgorithmException
+ {
+ Map<String, String> map = new HashMap<String, String>();
+ map.put(engine + "." + alg, "");
+ map.put(engine + "." + alg + " " + "MechanismType", mech);
+ Provider[] providers = Security.getProviders(map);
+ if (providers == null) {
+ if (mech.equals("DOM")) {
+ // look for providers without MechanismType specified
+ map.clear();
+ map.put(engine + "." + alg, "");
+ providers = Security.getProviders(map);
+ if (providers != null)
+ return providers[0];
}
- Map.Entry e = (Map.Entry) o;
- return (getKey()==null ?
- e.getKey()==null : getKey().equals(e.getKey())) &&
- (getValue()==null ?
- e.getValue()==null : getValue().equals(e.getValue()));
- }
- public Object getKey() {
- return key;
- }
- public Object getValue() {
- return mechanism;
- }
- public Object setValue(Object value) {
- throw new UnsupportedOperationException();
- }
- public int hashCode() {
- return (getKey()==null ? 0 : getKey().hashCode()) ^
- (getValue()==null ? 0 : getValue().hashCode());
+ throw new NoSuchAlgorithmException("Algorithm type " + alg +
+ " not available");
}
+ return providers[0];
}
/**
Modified: santuario/xml-security-java/trunk/src/main/java/javax/xml/crypto/dsig/XMLSignatureFactory.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/javax/xml/crypto/dsig/XMLSignatureFactory.java?rev=1203738&r1=1203737&r2=1203738&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/javax/xml/crypto/dsig/XMLSignatureFactory.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/javax/xml/crypto/dsig/XMLSignatureFactory.java Fri Nov 18 16:47:00 2011
@@ -189,19 +189,33 @@ public abstract class XMLSignatureFactor
private static XMLSignatureFactory findInstance(String mechanismType,
Provider provider) {
- Object[] objs = null;
+ if (provider == null) {
+ provider = getProvider("XMLSignatureFactory", mechanismType);
+ }
+ Provider.Service ps = provider.getService("XMLSignatureFactory",
+ mechanismType);
+ if (ps == null) {
+ throw new NoSuchMechanismException("Cannot find " + mechanismType +
+ " mechanism type");
+ }
try {
- objs = (Object[]) XMLDSigSecurity.getImpl
- (mechanismType, "XMLSignatureFactory", provider);
+ XMLSignatureFactory fac = (XMLSignatureFactory)ps.newInstance(null);
+ fac.mechanismType = mechanismType;
+ fac.provider = provider;
+ return fac;
} catch (NoSuchAlgorithmException nsae) {
- throw new NoSuchMechanismException
- ("Cannot find " + mechanismType + " mechanism type", nsae);
+ throw new NoSuchMechanismException("Cannot find " + mechanismType +
+ " mechanism type", nsae);
}
+ }
- XMLSignatureFactory factory = (XMLSignatureFactory) objs[0];
- factory.mechanismType = mechanismType;
- factory.provider = (Provider) objs[1];
- return factory;
+ private static Provider getProvider(String engine, String mech) {
+ Provider[] providers = Security.getProviders(engine + "." + mech);
+ if (providers == null) {
+ throw new NoSuchMechanismException("Mechanism type " + mech +
+ " not available");
+ }
+ return providers[0];
}
/**