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