View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
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.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.policy.entry;
20  
21  import java.io.InputStream;
22  import java.net.URL;
23  import java.security.KeyStore;
24  
25  import org.eclipse.jetty.policy.PolicyContext;
26  import org.eclipse.jetty.policy.PolicyException;
27  import org.eclipse.jetty.util.resource.Resource;
28  
29  public class KeystoreEntry extends AbstractEntry
30  {
31      /**
32       * The URL part of keystore clause.
33       */
34      private String url;
35  
36      /**
37       * The typename part of keystore clause.
38       */
39      private String type;
40      
41      // cached value
42      private KeyStore keystore;
43  
44      public KeyStore toKeyStore() throws PolicyException
45      { 
46          if ( keystore != null && !isDirty() )
47          {
48              return keystore;
49          }
50          
51          try 
52          {           
53              keystore = KeyStore.getInstance( type );
54              
55              URL keyStoreLocation = new URL ( url );
56              Resource r = Resource.newResource(keyStoreLocation);
57              InputStream istream = r.getInputStream();
58              
59              keystore.load( istream, null );
60              
61              
62          }
63          catch ( Exception e )
64          {
65              throw new PolicyException( e );
66          }
67          
68          return keystore; 
69      }
70      
71      @Override
72      public void expand( PolicyContext context ) throws PolicyException
73      {
74          url = context.evaluate( url );
75          
76          setExpanded( true );
77      }
78  
79      public String getUrl()
80      {
81          return url;
82      }
83  
84      public void setUrl( String url )
85      {
86          this.url = url;
87      }
88  
89      public String getType()
90      {
91          return type;
92      }
93  
94      public void setType( String type )
95      {
96          this.type = type;
97      }    
98  }