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          catch ( Exception e )
57          {
58              throw new PolicyException( e );
59          }
60          
61          return keystore; 
62      }
63      
64      @Override
65      public void expand( PolicyContext context ) throws PolicyException
66      {
67          url = context.evaluate( url );
68          
69          setExpanded( true );
70      }
71  
72      public String getUrl()
73      {
74          return url;
75      }
76  
77      public void setUrl( String url )
78      {
79          this.url = url;
80      }
81  
82      public String getType()
83      {
84          return type;
85      }
86  
87      public void setType( String type )
88      {
89          this.type = type;
90      }    
91  }