View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    * 
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   * 
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.river.tool.envcheck.plugins;
19  
20  import org.apache.river.tool.envcheck.AbstractPlugin;
21  import org.apache.river.tool.envcheck.Plugin;
22  import org.apache.river.tool.envcheck.EnvCheck;
23  import org.apache.river.tool.envcheck.Reporter;
24  import org.apache.river.tool.envcheck.Reporter.Message;
25  import org.apache.river.tool.envcheck.SubVMTask;
26  import org.apache.river.tool.envcheck.Util;
27  import org.apache.river.start.SharedActivationGroupDescriptor;
28  
29  /**
30   * Check whether <code>jsk-policy.jar</code> is installed in the extensions
31   * directory. For both the current VM and for the group VM (if any) load
32   * <code>net.jini.security.policy.DynamicPolicyProvider</code> and verify that
33   * it was loaded with the extension classloader by verifying that the parent
34   * loader is the bootstrap loader (<code>null</code>).  The group VM is checked
35   * only if the descriptors <code>getServerCommand()</code> method returns
36   * non-<code>null</code>
37   */
38  public class CheckJSKPolicy extends AbstractPlugin {
39  
40      private EnvCheck envCheck;
41      private String codebase;
42      private static String provider = 
43  	"net.jini.security.policy.DynamicPolicyProvider";
44  
45      /**
46       * Perform the check both for the current VM, and for the group VM if a
47       * <code>SharedActivationGroupDescriptor</code> is available from the plugin
48       * container.
49       */
50      public void run(EnvCheck envCheck) {
51  	this.envCheck = envCheck;
52  	checkPolicy(null);
53  	SharedActivationGroupDescriptor gd = envCheck.getGroupDescriptor();
54  	if (gd != null) {
55  	    checkPolicy(gd);
56  	}
57      }
58  
59      /**
60       * Check the policy for the command line or group. If <code>gd</code>
61       * is <code>null</code>, the policy of the command line being analyzed
62       * is checked.
63       *
64       * @param gd the group descriptor, or <code>null</code>
65       */
66      private void checkPolicy(SharedActivationGroupDescriptor gd) {
67  	String source = 
68  	    gd == null ? getString("vmsource")
69  	               : getString("groupsource", gd.getServerCommand());
70  	Object o = envCheck.launch(null, gd, taskName("JSKPolicyTask"));
71  	if (o instanceof Boolean) {
72  	    Message message;
73  	    if (((Boolean) o).booleanValue()) {
74  		message = new Message(Reporter.INFO,
75  				      getString("policyOK"),
76  				      getString("policyExp"));
77  	    } else {
78  		message = new Message(Reporter.ERROR,
79  				      getString("policyBad"),
80  				      getString("missingPolicyExp"));
81  	    }
82  	    Reporter.print(message, source);
83  	} else {
84  	    handleUnexpectedSubtaskReturn(o, source);
85  	}
86      }
87  
88      /**
89       * The task which checks the group VM.
90       */
91      public static class JSKPolicyTask implements SubVMTask {
92  	
93  	public Object run(String[] args) {
94  	    try {
95  		Class c = Class.forName(provider);
96  		if (c.getClassLoader().getParent() == null) {
97  		    return new Boolean(true);
98  		} else {
99  		    return new Boolean(false);
100 		}
101 	    } catch (ClassNotFoundException e) {
102 		return new Boolean(false);
103 	    }
104 	}
105     }
106 }
107