|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
DefaultPolicy.java | 0% | 0% | 0% | 0% |
|
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.spice.xmlpolicy.runtime;
|
|
9 |
|
|
10 |
import java.security.CodeSource;
|
|
11 |
import java.security.Permission;
|
|
12 |
import java.security.Permissions;
|
|
13 |
import java.util.Iterator;
|
|
14 |
import java.util.Map;
|
|
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 | 0 |
public DefaultPolicy( final Map grants )
|
36 |
throws Exception
|
|
37 |
{ |
|
38 | 0 |
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 | 0 |
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 | 0 |
protected final void processGrants( final Map grants ) |
57 |
throws Exception
|
|
58 |
{ |
|
59 | 0 |
final Iterator iterator = grants.keySet().iterator(); |
60 | 0 |
while( iterator.hasNext() )
|
61 |
{ |
|
62 | 0 |
final CodeSource codeSource = (CodeSource)iterator.next(); |
63 | 0 |
final Permission[] permissions = (Permission[])grants.get( codeSource ); |
64 | 0 |
final Permissions permissionSet = createPermissionSetFor( codeSource ); |
65 |
|
|
66 | 0 |
for( int i = 0; i < permissions.length; i++ ) |
67 |
{ |
|
68 | 0 |
final Permission permission = permissions[ i ]; |
69 | 0 |
permissionSet.add( permission ); |
70 |
} |
|
71 |
} |
|
72 |
} |
|
73 |
} |
|
74 |
|
|