View Javadoc

1   package org.eclipse.jetty.policy.entry;
2   //========================================================================
3   //Copyright (c) Webtide LLC
4   //------------------------------------------------------------------------
5   //All rights reserved. This program and the accompanying materials
6   //are made available under the terms of the Eclipse Public License v1.0
7   //and Apache License v2.0 which accompanies this distribution.
8   //
9   //The Eclipse Public License is available at
10  //http://www.eclipse.org/legal/epl-v10.html
11  //
12  //The Apache License v2.0 is available at
13  //http://www.apache.org/licenses/LICENSE-2.0.txt
14  //
15  //You may elect to redistribute this code under either of these licenses.
16  //========================================================================
17  
18  import java.io.InputStream;
19  import java.net.URL;
20  import java.security.KeyStore;
21  
22  import org.eclipse.jetty.policy.PolicyContext;
23  import org.eclipse.jetty.policy.PolicyException;
24  
25  public class KeystoreEntry extends AbstractEntry
26  {
27      /**
28       * The URL part of keystore clause.
29       */
30      private String url;
31  
32      /**
33       * The typename part of keystore clause.
34       */
35      private String type;
36      
37      // cached value
38      private KeyStore keystore;
39  
40      public KeyStore toKeyStore() throws PolicyException
41      { 
42          if ( keystore != null && !isDirty() )
43          {
44              return keystore;
45          }
46          
47          try 
48          {           
49              keystore = KeyStore.getInstance( type );
50              
51              URL keyStoreLocation = new URL ( url );
52              InputStream istream = keyStoreLocation.openStream();
53              
54              keystore.load( istream, null );
55              
56              
57          }
58          catch ( Exception e )
59          {
60              throw new PolicyException( e );
61          }
62          
63          return keystore; 
64      }
65      
66      @Override
67      public void expand( PolicyContext context ) throws PolicyException
68      {
69          url = context.evaluate( url );
70          
71          setExpanded( true );
72      }
73  
74      public String getUrl()
75      {
76          return url;
77      }
78  
79      public void setUrl( String url )
80      {
81          this.url = url;
82      }
83  
84      public String getType()
85      {
86          return type;
87      }
88  
89      public void setType( String type )
90      {
91          this.type = type;
92      }    
93  }