1 package org.eclipse.jetty.policy.loader;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.InputStream;
23 import java.io.InputStreamReader;
24 import java.security.KeyStore;
25 import java.security.ProtectionDomain;
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.HashMap;
29 import java.util.Iterator;
30 import java.util.List;
31 import java.util.Map;
32
33 import org.eclipse.jetty.policy.PolicyContext;
34 import org.eclipse.jetty.policy.PolicyBlock;
35 import org.eclipse.jetty.policy.PolicyException;
36 import org.eclipse.jetty.policy.entry.GrantEntry;
37 import org.eclipse.jetty.policy.entry.KeystoreEntry;
38
39
40
41
42
43 public class DefaultPolicyLoader
44 {
45
46 public static Map<ProtectionDomain, PolicyBlock> load( InputStream policyStream, PolicyContext context ) throws PolicyException
47 {
48 Map<ProtectionDomain, PolicyBlock> policies = new HashMap<ProtectionDomain, PolicyBlock>();
49 KeyStore keystore = null;
50
51 try
52 {
53 PolicyFileScanner loader = new PolicyFileScanner();
54
55 Collection<GrantEntry> grantEntries = new ArrayList<GrantEntry>();
56 List<KeystoreEntry> keystoreEntries = new ArrayList<KeystoreEntry>();
57
58 loader.scanStream( new InputStreamReader(policyStream), grantEntries, keystoreEntries );
59
60 for ( Iterator<KeystoreEntry> i = keystoreEntries.iterator(); i.hasNext();)
61 {
62 KeystoreEntry node = i.next();
63 node.expand( context );
64
65 keystore = node.toKeyStore();
66
67 if ( keystore != null )
68 {
69
70 context.setKeystore( keystore );
71 break;
72 }
73 }
74
75 for ( Iterator<GrantEntry> i = grantEntries.iterator(); i.hasNext(); )
76 {
77 GrantEntry grant = i.next();
78 grant.expand( context );
79
80 PolicyBlock policy = new PolicyBlock();
81
82 policy.setCodeSource( grant.getCodeSource() );
83 policy.setPrincipals( grant.getPrincipals() );
84 policy.setPermissions( grant.getPermissions() );
85
86 policies.put( policy.toProtectionDomain(), policy );
87 }
88
89 return policies;
90 }
91 catch ( Exception e )
92 {
93 throw new PolicyException( e );
94 }
95 }
96 }
97
98
99
100
101