View Javadoc

1   /*
2    * The MIT License
3    *
4    * Original work sponsored and donated by National Board of e-Health (NSI), Denmark (http://www.nsi.dk)
5    *
6    * Copyright (C) 2011 National Board of e-Health (NSI), Denmark (http://www.nsi.dk)
7    *
8    * Permission is hereby granted, free of charge, to any person obtaining a copy of
9    * this software and associated documentation files (the "Software"), to deal in
10   * the Software without restriction, including without limitation the rights to
11   * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12   * of the Software, and to permit persons to whom the Software is furnished to do
13   * so, subject to the following conditions:
14   *
15   * The above copyright notice and this permission notice shall be included in all
16   * copies or substantial portions of the Software.
17   *
18   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24   * SOFTWARE.
25   *
26   * $HeadURL: https://svn.softwareborsen.dk/sosi/trunk/modules/seal/src/main/java/dk/sosi/seal/pki/CRLCache.java $
27   * $Id: CRLCache.java 8697 2011-09-02 10:33:55Z chg@lakeside.dk $
28   */
29  package dk.sosi.seal.pki;
30  
31  import java.security.cert.X509CRL;
32  import java.util.Date;
33  import java.util.Map;
34  import java.util.Set;
35  
36  /**
37   * Cache for CRLs based on the retrieval url.
38   * <p/>
39   * Any implementation should be thread-safe.
40   *
41   * @author ht@arosii.dk
42   * @since 2.0
43   */
44  public interface CRLCache {
45  
46      /**
47       * A carrier entity to hold the CRL and associated timestamps.
48       */
49      public static class CRLInfo {
50  
51          private final X509CRL crl;
52          private final long lastModified;
53          private final long created;
54  
55          public CRLInfo(final X509CRL crl, final long lastModified) {
56              this.crl = crl;
57              this.lastModified = lastModified;
58              this.created = new Date().getTime();
59          }
60  
61          CRLInfo(CRLInfo other) {
62              this.crl = other.crl;
63              this.lastModified = other.lastModified;
64              this.created = other.created;
65          }
66  
67          /**
68           * The actual revocation list.
69           */
70          public X509CRL getCrl() {
71              return crl;
72          }
73  
74          /**
75           * The time for which the latest version is from; should be identical
76           * to time when the CRL was created.
77           */
78          public long getLastModified() {
79              return lastModified;
80          }
81  
82          /**
83           * The time (absolute time) this was created, should be updated
84           * each time a check is made against the endpoint
85           */
86          public long getCreated() {
87              return created;
88          }
89      }
90  
91      /**
92       * Retrieves the CRL information from the cache.
93       *
94       * @param url the location for the CRL
95       * @return the combined information containing the CRL.
96       */
97      CRLInfo get(String url);
98  
99      /**
100      * Updates the cache for the url with the supplied CRL.
101      * <p/>
102      * if crl is null the cache entry for url will be removed.
103      *
104      * @param url the location of the CRL.
105      * @param crl the CRL.
106      * @return the combined information saved in the cache.
107      */
108     CRLInfo update(String url, X509CRL crl);
109 
110     /**
111      * Update the cache with the info.
112      * <p/>
113      * if the info is null the cache entry for url will be removed.
114      *
115      * @param url  the location of the CRL.
116      * @param info the cache entry.
117      * @return the info supplied.
118      */
119     CRLInfo update(String url, CRLInfo info);
120 
121     /**
122      * Returns all entries in the cache. Should not be considered
123      * mutable.
124      *
125      * @return all entries in the cache.
126      */
127     Set<Map.Entry<String, CRLInfo>> entries();
128 
129     /**
130      * Clears the cache. No entries should be available after
131      * this operation is performed.
132      */
133     void clear();
134 }