KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > loom > xmlpolicy > runtime > DefaultPolicy


1 /*
2  * Copyright (C) The Spice Group. All rights reserved.
3  *
4  * This software is published under the terms of the Spice
5  * Software License version 1.1, a copy of which has been included
6  * with this distribution in the LICENSE.txt file.
7  */

8 package org.codehaus.loom.xmlpolicy.runtime;
9
10 import java.security.CodeSource JavaDoc;
11 import java.security.Permission JavaDoc;
12 import java.security.Permissions JavaDoc;
13 import java.util.Iterator JavaDoc;
14 import java.util.Map JavaDoc;
15
16 /**
17  * A policy implementation that accepts policys details from a map.
18  * The map is between a codebase and a array of permissions.
19  * Note that it was a deliberate decision to limit the time at which you can
20  * specify policy data for security reasons.
21  *
22  * @author Peter Donald
23  */

24 public class DefaultPolicy
25     extends AbstractPolicy
26 {
27     /**
28      * Create a Policy that applies specified grants.
29      * Each entry in map maps a CodeSource to an array
30      * of Permissions.
31      *
32      * @param grants the grant map
33      * @throws Exception if unable to construct Policy
34      */

35     public DefaultPolicy( final Map JavaDoc grants )
36         throws Exception JavaDoc
37     {
38         processGrants( grants );
39     }
40
41     /**
42      * Create a policy with zero entrys.
43      * Sub-classes usually use this constructor then
44      * invoke processGrants separately.
45      */

46     public DefaultPolicy()
47     {
48     }
49
50     /**
51      * Process map of grants and configure Policy appropriately.
52      *
53      * @param grants the grants map
54      * @throws Exception if unable to perform configuration
55      */

56     protected final void processGrants( final Map JavaDoc grants )
57         throws Exception JavaDoc
58     {
59         final Iterator JavaDoc iterator = grants.keySet().iterator();
60         while( iterator.hasNext() )
61         {
62             final CodeSource JavaDoc codeSource = (CodeSource JavaDoc)iterator.next();
63             final Permission JavaDoc[] permissions = (Permission JavaDoc[])grants.get( codeSource );
64             final Permissions JavaDoc permissionSet = createPermissionSetFor( codeSource );
65
66             for( int i = 0; i < permissions.length; i++ )
67             {
68                 final Permission JavaDoc permission = permissions[ i ];
69                 permissionSet.add( permission );
70             }
71         }
72     }
73 }
74
Popular Tags