下面列出了org.osgi.framework.Bundle#getSignerCertificates ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Constructs a Condition that tries to match the passed Bundle's location
* to the location pattern.
*
* @param bundle The Bundle being evaluated.
* @param info The ConditionInfo from which to construct the condition. The
* ConditionInfo must specify one or two arguments. The first
* argument of the ConditionInfo specifies the chain of distinguished
* names pattern to match against the signer of the bundle. The
* Condition is satisfied if the signer of the bundle matches the
* pattern. The second argument of the ConditionInfo is optional. If
* a second argument is present and equal to "!", then the
* satisfaction of the Condition is negated. That is, the Condition
* is satisfied if the signer of the bundle does NOT match the
* pattern. If the second argument is present but does not equal "!",
* then the second argument is ignored.
* @return A Condition which checks the signers of the specified bundle.
*/
public static Condition getCondition(final Bundle bundle, final ConditionInfo info) {
if (!CONDITION_TYPE.equals(info.getType()))
throw new IllegalArgumentException("ConditionInfo must be of type \"" + CONDITION_TYPE + "\"");
String[] args = info.getArgs();
if (args.length != 1 && args.length != 2)
throw new IllegalArgumentException("Illegal number of args: " + args.length);
Map<X509Certificate, List<X509Certificate>> signers = bundle.getSignerCertificates(Bundle.SIGNERS_TRUSTED);
boolean match = false;
for (List<X509Certificate> signerCerts : signers.values()) {
List<String> dnChain = new ArrayList<String>(signerCerts.size());
for (X509Certificate signer : signerCerts) {
dnChain.add(signer.getSubjectDN().getName());
}
if (FrameworkUtil.matchDistinguishedNameChain(args[0], dnChain)) {
match = true;
break;
}
}
boolean negate = (args.length == 2) ? "!".equals(args[1]) : false;
return negate ^ match ? Condition.TRUE : Condition.FALSE;
}
/**
* Constructs a Condition that tries to match the passed Bundle's location
* to the location pattern.
*
* @param bundle The Bundle being evaluated.
* @param info The ConditionInfo from which to construct the condition. The
* ConditionInfo must specify one or two arguments. The first
* argument of the ConditionInfo specifies the chain of distinguished
* names pattern to match against the signer of the bundle. The
* Condition is satisfied if the signer of the bundle matches the
* pattern. The second argument of the ConditionInfo is optional. If
* a second argument is present and equal to "!", then the
* satisfaction of the Condition is negated. That is, the Condition
* is satisfied if the signer of the bundle does NOT match the
* pattern. If the second argument is present but does not equal "!",
* then the second argument is ignored.
* @return A Condition which checks the signers of the specified bundle.
*/
public static Condition getCondition(final Bundle bundle, final ConditionInfo info) {
if (!CONDITION_TYPE.equals(info.getType()))
throw new IllegalArgumentException("ConditionInfo must be of type \"" + CONDITION_TYPE + "\"");
String[] args = info.getArgs();
if (args.length != 1 && args.length != 2)
throw new IllegalArgumentException("Illegal number of args: " + args.length);
Map<X509Certificate, List<X509Certificate>> signers = bundle.getSignerCertificates(Bundle.SIGNERS_TRUSTED);
boolean match = false;
for (List<X509Certificate> signerCerts : signers.values()) {
List<String> dnChain = new ArrayList<String>(signerCerts.size());
for (X509Certificate signer : signerCerts) {
dnChain.add(signer.getSubjectDN().getName());
}
if (FrameworkUtil.matchDistinguishedNameChain(args[0], dnChain)) {
match = true;
break;
}
}
boolean negate = (args.length == 2) ? "!".equals(args[1]) : false;
return negate ^ match ? Condition.TRUE : Condition.FALSE;
}
/**
* Used by the filter matching algorithm. This methods does NOT satisfy the
* normal equals contract. Since the class is only used in filter expression
* evaluations, it only needs to support comparing an instance created with
* a Bundle to an instance created with a pattern string from the filter
* expression.
*
* @param o SignerProperty to compare against.
* @return true if the DN name chain matches the pattern.
*/
@Override
public boolean equals(Object o) {
if (!(o instanceof SignerProperty))
return false;
SignerProperty other = (SignerProperty) o;
Bundle matchBundle = bundle != null ? bundle : other.bundle;
String matchPattern = bundle != null ? other.pattern : pattern;
Map<X509Certificate, List<X509Certificate>> signers = matchBundle.getSignerCertificates(Bundle.SIGNERS_TRUSTED);
for (List<X509Certificate> signerCerts : signers.values()) {
List<String> dnChain = new ArrayList<String>(signerCerts.size());
for (X509Certificate signerCert : signerCerts) {
dnChain.add(signerCert.getSubjectDN().getName());
}
try {
if (FrameworkUtil.matchDistinguishedNameChain(matchPattern, dnChain)) {
return true;
}
} catch (IllegalArgumentException e) {
continue; // bad pattern
}
}
return false;
}
/**
* Constructs a Condition that tries to match the passed Bundle's location
* to the location pattern.
*
* @param bundle The Bundle being evaluated.
* @param info The ConditionInfo from which to construct the condition. The
* ConditionInfo must specify one or two arguments. The first
* argument of the ConditionInfo specifies the chain of distinguished
* names pattern to match against the signer of the bundle. The
* Condition is satisfied if the signer of the bundle matches the
* pattern. The second argument of the ConditionInfo is optional. If
* a second argument is present and equal to "!", then the
* satisfaction of the Condition is negated. That is, the Condition
* is satisfied if the signer of the bundle does NOT match the
* pattern. If the second argument is present but does not equal "!",
* then the second argument is ignored.
* @return A Condition which checks the signers of the specified bundle.
*/
public static Condition getCondition(final Bundle bundle, final ConditionInfo info) {
if (!CONDITION_TYPE.equals(info.getType()))
throw new IllegalArgumentException("ConditionInfo must be of type \"" + CONDITION_TYPE + "\"");
String[] args = info.getArgs();
if (args.length != 1 && args.length != 2)
throw new IllegalArgumentException("Illegal number of args: " + args.length);
Map<X509Certificate, List<X509Certificate>> signers = bundle.getSignerCertificates(Bundle.SIGNERS_TRUSTED);
boolean match = false;
for (List<X509Certificate> signerCerts : signers.values()) {
List<String> dnChain = new ArrayList<String>(signerCerts.size());
for (X509Certificate signer : signerCerts) {
dnChain.add(signer.getSubjectDN().getName());
}
if (FrameworkUtil.matchDistinguishedNameChain(args[0], dnChain)) {
match = true;
break;
}
}
boolean negate = (args.length == 2) ? "!".equals(args[1]) : false;
return negate ^ match ? Condition.TRUE : Condition.FALSE;
}