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