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  import org.eclipse.jetty.util.resource.Resource;
25  
26  public class KeystoreEntry extends AbstractEntry
27  {
28      /**
29       * The URL part of keystore clause.
30       */
31      private String url;
32  
33      /**
34       * The typename part of keystore clause.
35       */
36      private String type;
37      
38      // cached value
39      private KeyStore keystore;
40  
41      public KeyStore toKeyStore() throws PolicyException
42      { 
43          if ( keystore != null && !isDirty() )
44          {
45              return keystore;
46          }
47          
48          try 
49          {           
50              keystore = KeyStore.getInstance( type );
51              
52              URL keyStoreLocation = new URL ( url );
53              Resource r = Resource.newResource(keyStoreLocation);
54              InputStream istream = r.getInputStream();
55              
56              keystore.load( istream, null );
57              
58              
59          }
60          catch ( Exception e )
61          {
62              throw new PolicyException( e );
63          }
64          
65          return keystore; 
66      }
67      
68      @Override
69      public void expand( PolicyContext context ) throws PolicyException
70      {
71          url = context.evaluate( url );
72          
73          setExpanded( true );
74      }
75  
76      public String getUrl()
77      {
78          return url;
79      }
80  
81      public void setUrl( String url )
82      {
83          this.url = url;
84      }
85  
86      public String getType()
87      {
88          return type;
89      }
90  
91      public void setType( String type )
92      {
93          this.type = type;
94      }    
95  }