KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > osgi > service > condpermadmin > BundleSignerCondition


1 /*
2  * $Header: /cvsroot/eclipse/org.eclipse.osgi/osgi/src/org/osgi/service/condpermadmin/BundleSignerCondition.java,v 1.9 2006/09/14 22:06:52 twatson Exp $
3  *
4  * Copyright (c) OSGi Alliance (2005, 2006). All Rights Reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 package org.osgi.service.condpermadmin;
20
21 import org.eclipse.osgi.framework.internal.core.AbstractBundle;
22 import org.osgi.framework.Bundle;
23
24 /**
25  * Condition to test if the signer of a bundle matches a pattern. Since the bundle's signer can
26  * only change when the bundle is updated, this condition is immutable.
27  * <p>
28  * The condition expressed using a single String that specifies a Distinguished
29  * Name (DN) chain to match bundle signers against. DN's are encoded using IETF
30  * RFC 2253. Usually signers use certificates that are issued by certificate
31  * authorities, which also have a corresponding DN and certificate. The
32  * certificate authorities can form a chain of trust where the last DN and
33  * certificate is known by the framework. The signer of a bundle is expressed as
34  * signers DN followed by the DN of its issuer followed by the DN of the next
35  * issuer until the DN of the root certificate authority. Each DN is separated
36  * by a semicolon.
37  * <p>
38  * A bundle can satisfy this condition if one of its signers has a DN chain that
39  * matches the DN chain used to construct this condition. Wildcards (`*') can be
40  * used to allow greater flexibility in specifying the DN chains. Wildcards can
41  * be used in place of DNs, RDNs, or the value in an RDN. If a wildcard is used
42  * for a value of an RDN, the value must be exactly "*" and will match any value
43  * for the corresponding type in that RDN. If a wildcard is used for a RDN, it
44  * must be the first RDN and will match any number of RDNs (including zero
45  * RDNs).
46  *
47  * @version $Revision: 1.9 $
48  */

49 public class BundleSignerCondition {
50     private static final String JavaDoc CONDITION_TYPE = "org.osgi.service.condpermadmin.BundleSignerCondition";
51     /**
52      * Constructs a Condition that tries to match the passed Bundle's location
53      * to the location pattern.
54      *
55      * @param bundle The Bundle being evaluated.
56      * @param info The ConditionInfo to construct the condition for. The args of
57      * the ConditionInfo specify a single String specifying the chain of
58      * distinguished names pattern to match against the signer of the
59      * Bundle.
60      * @return A Condition which checks the signers of the specified bundle.
61      */

62     static public Condition getCondition(Bundle bundle, ConditionInfo info) {
63         if (!CONDITION_TYPE.equals(info.getType()))
64             throw new IllegalArgumentException JavaDoc("ConditionInfo must be of type \"" + CONDITION_TYPE + "\"");
65         String JavaDoc[] args = info.getArgs();
66         if (args.length != 1)
67             throw new IllegalArgumentException JavaDoc("Illegal number of args: " + args.length);
68         // implementation specific code used here
69
AbstractBundle ab = (AbstractBundle) bundle;
70         return ab.getBundleData().matchDNChain(args[0]) ? Condition.TRUE : Condition.FALSE;
71     }
72
73     private BundleSignerCondition() {
74         // private constructor to prevent objects of this type
75
}
76 }
77
Popular Tags