Author: gtrasuk
Date: Fri Mar 30 21:11:53 2012
New Revision: 1307616
URL: http://svn.apache.org/viewvc?rev=1307616&view=rev
Log:
Security infrastructure mostly in place. VirtualFileSystemClassLoader get
access exceptions when loading the module's classes - should the load
operations be privileged?
Added:
river/jtsk/skunk/surrogate/src/org/apache/river/container/security/ContainerCodePolicy.java
river/jtsk/skunk/surrogate/src/org/apache/river/container/security/SecurityInitializer.java
Modified:
river/jtsk/skunk/surrogate/src/org/apache/river/container/Bootstrap.java
river/jtsk/skunk/surrogate/src/org/apache/river/container/MessageNames.java
river/jtsk/skunk/surrogate/src/org/apache/river/container/Messages.properties
river/jtsk/skunk/surrogate/src/org/apache/river/container/StarterServiceDeployer.java
river/jtsk/skunk/surrogate/src/org/apache/river/container/Strings.java
river/jtsk/skunk/surrogate/src/org/apache/river/container/core-config.xml
Modified:
river/jtsk/skunk/surrogate/src/org/apache/river/container/Bootstrap.java
URL:
http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/Bootstrap.java?rev=1307616&r1=1307615&r2=1307616&view=diff
==============================================================================
--- river/jtsk/skunk/surrogate/src/org/apache/river/container/Bootstrap.java
(original)
+++ river/jtsk/skunk/surrogate/src/org/apache/river/container/Bootstrap.java
Fri Mar 30 21:11:53 2012
@@ -92,6 +92,7 @@ public class Bootstrap {
private static Map<String, ClassLoader> createClassLoaders(ContainerConfig
config) throws MalformedURLException {
Map<String, ClassLoader> classLoaders = new HashMap<String,
ClassLoader>();
+ classLoaders.put(Strings.BOOTSTRAP_CLASS_LOADER,
Bootstrap.class.getClassLoader());
/*
Setup the classloaders according to the config file.
*/
Modified:
river/jtsk/skunk/surrogate/src/org/apache/river/container/MessageNames.java
URL:
http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/MessageNames.java?rev=1307616&r1=1307615&r2=1307616&view=diff
==============================================================================
--- river/jtsk/skunk/surrogate/src/org/apache/river/container/MessageNames.java
(original)
+++ river/jtsk/skunk/surrogate/src/org/apache/river/container/MessageNames.java
Fri Mar 30 21:11:53 2012
@@ -87,6 +87,7 @@ public class MessageNames {
MISSING_PROPERTY_ENTRY="missingPropertyEntry",
NO_DEPLOYMENT_DIRECTORY="noDeploymentDirectory",
PARENT_CLASS_LOADER_IS="parentClassLoaderIs",
+ POLICY_DECLINED="policyDeclined",
PROFILE_CONFIG_EXCEPTION="profileConfigurationException",
PROFILE_CONFIG_LOADING="profileConfigLoading",
READ_PROPERTIES="readProperties",
@@ -95,6 +96,9 @@ public class MessageNames {
READING_OBJECT_MEMBER_COUNT="readingObject.memberCount",
READING_OBJECT_ANNOTATED_MEMBER_FOUND="readingObject.annotatedMemberFound",
READING_OBJECT_NON_ANNOTATED_MEMBER_FOUND="readingObject.nonAnnotatedMemberFound",
+ SECURITY_INIT_FAILED="securityInitializationFailed",
+ SECURITY_INIT_SUCCEEDED="securityInitializationSucceeded",
+ SECURITY_INIT_WRONG_POLICY="securityInitializationWrongPolicy",
SHOW_COMMAND_LINE_ARGUMENTS="showCommandLineArguments",
SHUTDOWN_METHOD_HAS_PARAMETERS="shutdownMethodHasParameters",
SHUTDOWN_METHOD_NOT_VOID="shutdownMethodIsntVoid",
Modified:
river/jtsk/skunk/surrogate/src/org/apache/river/container/Messages.properties
URL:
http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/Messages.properties?rev=1307616&r1=1307615&r2=1307616&view=diff
==============================================================================
---
river/jtsk/skunk/surrogate/src/org/apache/river/container/Messages.properties
(original)
+++
river/jtsk/skunk/surrogate/src/org/apache/river/container/Messages.properties
Fri Mar 30 21:11:53 2012
@@ -69,6 +69,7 @@ missingPropertyEntry="Properties file ''
noDeploymentDirectory=No deployment directory called {0} found in {1}; \
skipping deployment.
parentClassLoaderIs=Parent class loader is {0}.
+policyDeclined=No permissions granted to protection domain with classloader
{0}.
profileConfigurationException=Failed to read the configuration for profile {0}.
profileConfigLoading=Loading the profile configuration with classloader {0}.
readProperties=...properties read were {0}.
@@ -77,6 +78,9 @@ readingObject=Reading instance of {1} na
readingObject.memberCount={0} members found.
readingObject.annotatedMemberFound=Member ''{0}'' is annotated @Injected.
readingObject.nonAnnotatedMemberFound=Member ''{0}'' is not annotated
@Injected.
+securityInitializationFailed=Failed to initialize security subsystem.
+securityInitializationSucceeded=Security Manager and Dynamic Policy
successfully installed.
+securityInitializationWrongPolicy=After security manager setup, the wrong
policy is installed: {0}.
showCommandLineArguments=Command line arguments were: {0}.
shutdownMethodHasParameters=A method flagged as @Shutdown must take no
parameters. \
Method ''{1}'' on class ''{0}'' has parameters.
Modified:
river/jtsk/skunk/surrogate/src/org/apache/river/container/StarterServiceDeployer.java
URL:
http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/StarterServiceDeployer.java?rev=1307616&r1=1307615&r2=1307616&view=diff
==============================================================================
---
river/jtsk/skunk/surrogate/src/org/apache/river/container/StarterServiceDeployer.java
(original)
+++
river/jtsk/skunk/surrogate/src/org/apache/river/container/StarterServiceDeployer.java
Fri Mar 30 21:11:53 2012
@@ -17,22 +17,26 @@
*/
/* TODO: - Complete deployment of items that are in the deployment
-directory.
+ directory.
*/
package org.apache.river.container;
import java.io.File;
+import java.io.FilePermission;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.security.CodeSource;
+import java.security.Permission;
+import java.security.Principal;
import java.security.cert.Certificate;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
+import net.jini.security.policy.DynamicPolicyProvider;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileType;
@@ -45,44 +49,42 @@ import org.apache.river.container.work.T
import org.apache.river.container.work.WorkManager;
/**
- *
- * @author trasukg
+
+ @author trasukg
*/
public class StarterServiceDeployer {
private int initCount = 0;
private static final Logger log =
Logger.getLogger(StarterServiceDeployer.class.getName(),
MessageNames.BUNDLE_NAME);
- @Injected(style=InjectionStyle.BY_TYPE)
+ @Injected(style = InjectionStyle.BY_TYPE)
private FileUtility fileUtility = null;
-
@Injected
private ClassLoader systemClassLoader = null;
-
@Name
private String myName = null;
- @Injected(style=InjectionStyle.BY_TYPE)
+ @Injected(style = InjectionStyle.BY_TYPE)
private CodebaseHandler codebaseHandler = null;
-
@Injected
private String deploymentDirectory = null;
-
@Injected(Strings.STARTER_SERVICE_DEPLOYER_PROPERTIES)
Properties configProperties = null;
-
private FileObject deploymentDirectoryFile = null;
-
- @Injected(style=InjectionStyle.BY_TYPE)
+ @Injected(style = InjectionStyle.BY_TYPE)
private PropertiesFileReader propertiesFileReader = null;
-
- @Injected(style=InjectionStyle.BY_TYPE)
+ @Injected(style = InjectionStyle.BY_TYPE)
private ArgsParser argsParser = null;
-
- @Injected(style=InjectionStyle.BY_TYPE)
- private WorkManager workManager=null;
+ @Injected(style = InjectionStyle.BY_TYPE)
+ private WorkManager workManager = null;
+ @Injected(style = InjectionStyle.BY_TYPE)
+ private DynamicPolicyProvider securityPolicy = null;
+
+ ;
public void addPlatformCodebaseJars(CodebaseContext codebaseContext)
throws IOException {
- /* Register the platform codebase jars with the codebase service. */
+ /*
+ Register the platform codebase jars with the codebase service.
+ */
String platformCodebaseSpec =
configProperties.getProperty(Strings.PLATFORM_CODEBASE);
String[] codebaseJars = Utils.splitOnWhitespace(platformCodebaseSpec);
for (String codebaseJar : codebaseJars) {
@@ -105,15 +107,19 @@ public class StarterServiceDeployer {
VirtualFileSystemClassLoader cl =
createChildOfSystemClassloader(codeSource);
- /* Include platform jars from the container's lib directory. */
+ /*
+ Include platform jars from the container's lib directory.
+ */
String platformJarSpec =
configProperties.getProperty(Strings.PLATFORM_JARS);
- addPlatformJarsToClassloader( platformJarSpec, cl);
+ addPlatformJarsToClassloader(platformJarSpec, cl);
addLibDirectoryJarsToClasspath(serviceRoot, cl);
return cl;
}
protected void addLibDirectoryJarsToClasspath(FileObject serviceRoot,
VirtualFileSystemClassLoader cl) throws FileSystemException {
- /* Add the jar files from the service's 'lib' directory. */
+ /*
+ Add the jar files from the service's 'lib' directory.
+ */
FileObject libDir = serviceRoot.resolveFile(Strings.LIB);
List<FileObject> jarFiles = Utils.findChildrenWithSuffix(libDir,
Strings.DOT_JAR);
@@ -123,26 +129,29 @@ public class StarterServiceDeployer {
}
protected void addPlatformJarsToClassloader(String platformJarSpec,
VirtualFileSystemClassLoader cl) throws IOException, LocalizedRuntimeException {
- if (platformJarSpec==null) {
+ if (platformJarSpec == null) {
throw new LocalizedRuntimeException(MessageNames.BUNDLE_NAME,
MessageNames.MISSING_PROPERTY_ENTRY,
- new Object[] {Strings.STARTER_SERVICE_DEPLOYER_PROPERTIES,
- Strings.PLATFORM_JARS }
- );
+ new Object[]{Strings.STARTER_SERVICE_DEPLOYER_PROPERTIES,
+ Strings.PLATFORM_JARS});
}
log.log(Level.FINE, MessageNames.ADDING_CLASSPATH_ENTRY, new
Object[]{platformJarSpec});
cl.addClassPathEntry(fileUtility.getLibDirectory(), platformJarSpec);
}
protected VirtualFileSystemClassLoader
createChildOfSystemClassloader(CodeSource codeSource) {
- /* Create the service classloader. */
+ /*
+ Create the service classloader.
+ */
VirtualFileSystemClassLoader cl =
new VirtualFileSystemClassLoader(null, systemClassLoader,
codeSource);
return cl;
}
public void exportServiceCodebaseJars(FileObject serviceRoot,
CodebaseContext codebaseContext) throws FileSystemException {
- /* Register the service's codebase jars with the codebase service. */
+ /*
+ Register the service's codebase jars with the codebase service.
+ */
FileObject libDlDir = serviceRoot.resolveFile(Strings.LIB_DL);
List<FileObject> dljarFiles = Utils.findChildrenWithSuffix(libDlDir,
Strings.DOT_JAR);
@@ -167,7 +176,9 @@ public class StarterServiceDeployer {
public void launchService(final ClassLoader cl, Properties startProps,
final String[] args) {
final String startClassName =
startProps.getProperty(Strings.START_CLASS);
- /* Launch the service. */
+ /*
+ Launch the service.
+ */
log.log(Level.FINE, MessageNames.CALLING_MAIN, new Object[]{
startClassName, Utils.format(args)
});
@@ -186,7 +197,9 @@ public class StarterServiceDeployer {
}
public Properties readStartProperties(FileObject serviceRoot) throws
FileSystemException, LocalizedRuntimeException, IOException {
- /* Read the start.properties file. */
+ /*
+ Read the start.properties file.
+ */
FileObject startProperties =
serviceRoot.resolveFile(Strings.START_PROPERTIES);
if (startProperties == null ||
!startProperties.getType().equals(FileType.FILE)
|| !startProperties.isReadable()) {
@@ -200,7 +213,9 @@ public class StarterServiceDeployer {
}
public void setupLiaisonConfiguration(FileObject serviceArchive,
FileObject serviceRoot, VirtualFileSystemClassLoader cl) throws
ConfigurationException {
- /* Setup the liaison configuration. */
+ /*
+ Setup the liaison configuration.
+ */
try {
File workingDir = null;
if (serviceArchive != null) {
@@ -209,8 +224,10 @@ public class StarterServiceDeployer {
workingDir = new File(serviceRoot.getURL().toURI());
}
+ grantPermissions(cl,
+ new Permission[] {new
FilePermission(workingDir.getAbsolutePath(), Strings.READ)});
Utils.logClassLoaderHierarchy(log, Level.FINE, this.getClass());
- String configName=VirtualFileSystemConfiguration.class.getName();
+ String configName = VirtualFileSystemConfiguration.class.getName();
invokeStatic(cl, configName,
Strings.SET_WORKING_DIRECTORY,
workingDir);
@@ -223,16 +240,21 @@ public class StarterServiceDeployer {
private void tryInitialize() throws IOException {
log.log(Level.FINE, MessageNames.STARTER_SERVICE_DEPLOYER_STARTING,
myName);
- /* Establish the deployment directory. */
+ /*
+ Establish the deployment directory.
+ */
deploymentDirectoryFile =
fileUtility.getProfileDirectory().resolveFile(deploymentDirectory);
if (deploymentDirectoryFile == null
|| deploymentDirectoryFile.getType() != FileType.FOLDER) {
log.log(Level.WARNING, MessageNames.NO_DEPLOYMENT_DIRECTORY,
new Object[]{deploymentDirectory,
fileUtility.getProfileDirectory()});
}
- /* Read the maximal policy file if there is one. */
+ /*
+ Read the maximal policy file if there is one.
+ */
readMaximalPolicy();
- /* Go through the deployment directory looking for services to deploy.
+ /*
+ Go through the deployment directory looking for services to deploy.
*/
List<FileObject> serviceArchives =
Utils.findChildrenWithSuffix(deploymentDirectoryFile,
@@ -254,7 +276,7 @@ public class StarterServiceDeployer {
private void deployServiceArchives(List<FileObject> serviceArchives) {
/*
- Deploy those services.
+ Deploy those services.
*/
for (FileObject archiveFile : serviceArchives) {
try {
@@ -294,16 +316,23 @@ public class StarterServiceDeployer {
log.log(Level.INFO, MessageNames.CODESOURCE_IS,
new Object[]{serviceName, serviceCodeSource});
VirtualFileSystemClassLoader cl =
createServiceClassloader(serviceRoot, serviceCodeSource);
- /* Create a codebase context. */
+ /*
+ Create a codebase context.
+ */
CodebaseContext codebaseContext =
codebaseHandler.createContext(serviceName);
addPlatformCodebaseJars(codebaseContext);
exportServiceCodebaseJars(serviceRoot, codebaseContext);
- /* Setup the classloader's codebase annotation. */
+ /*
+ Setup the classloader's codebase annotation.
+ */
cl.setCodebase(codebaseContext.getCodebaseAnnotation());
- /* Grant the appropriate permissions to the service's classloader and
- protection domain. */
+ /*
+ Grant the appropriate permissions to the service's classloader and
+ protection domain.
+ */
+
// TODO: Figure out how the protection domains, codesources, etc need
to work.
setupLiaisonConfiguration(serviceArchive, serviceRoot, cl);
Properties startProps = readStartProperties(serviceRoot);
@@ -324,30 +353,41 @@ public class StarterServiceDeployer {
Method method = clazz.getMethod(methodName, parameterTypes);
return method.invoke(null, parms);
}
-
- private Object instantiateService(ClassLoader cl, String className,
String[] parms)
+
+ private void grantPermissions(ClassLoader cl, Permission[] perms) {
+ try {
+ Class clazz =
Class.forName(VirtualFileSystemConfiguration.class.getName(), true, cl);
+ securityPolicy.grant(clazz, new Principal[0], perms);
+
+ } catch (Throwable t) {
+ throw new
ConfigurationException(MessageNames.FAILED_DEPLOY_SERVICE, t);
+ }
+ }
+
+ private Object instantiateService(ClassLoader cl, String className,
String[] parms)
throws ClassNotFoundException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException, NoSuchMethodException,
InstantiationException {
Class clazz = Class.forName(className, true, cl);
log.log(Level.FINE, MessageNames.CLASSLOADER_IS,
- new Object[] { clazz.getName(),
clazz.getClassLoader().toString()});
-
+ new Object[]{clazz.getName(),
clazz.getClassLoader().toString()});
+
// Get this through dynamic lookup becuase it won't be in the parent
// classloader!
- Class lifeCycleClass=Class.forName(Strings.LIFECYCLE_CLASS, true, cl);
- Constructor[] constructors=clazz.getDeclaredConstructors();
+ Class lifeCycleClass = Class.forName(Strings.LIFECYCLE_CLASS, true,
cl);
+ Constructor[] constructors = clazz.getDeclaredConstructors();
System.out.println("Class is " + clazz);
for (int i = 0; i < constructors.length; i++) {
Constructor constructor = constructors[i];
System.out.println("Found constructor " + constructor + " on " +
className);
}
- Constructor constructor = clazz.getDeclaredConstructor(new Class[]
{String[].class, lifeCycleClass});
+ Constructor constructor = clazz.getDeclaredConstructor(new
Class[]{String[].class, lifeCycleClass});
constructor.setAccessible(true);
- return constructor.newInstance(parms, null );
+ return constructor.newInstance(parms, null);
}
-
+
private void establishLiveDeploymentMonitoring() {
// TODO: Write this
}
+
private void readMaximalPolicy() {
// TODO: Write this.
}
Modified: river/jtsk/skunk/surrogate/src/org/apache/river/container/Strings.java
URL:
http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/Strings.java?rev=1307616&r1=1307615&r2=1307616&view=diff
==============================================================================
--- river/jtsk/skunk/surrogate/src/org/apache/river/container/Strings.java
(original)
+++ river/jtsk/skunk/surrogate/src/org/apache/river/container/Strings.java Fri
Mar 30 21:11:53 2012
@@ -25,6 +25,7 @@ public class Strings {
public static final String
ADD_URL="addURL",
+ BOOTSTRAP_CLASS_LOADER="bootstrapClassLoader",
CLASS_LOADERS="classLoaders",
COMMAND_LINE_ARGS = "commandLineArguments",
CONFIG_XML = "config.xml",
@@ -54,6 +55,8 @@ public class Strings {
PROFILE = "profile",
PROFILE_DIR="profileDirectory",
PUT = "put",
+ READ="read",
+ SECURITY_POLICY="securityPolicy",
SPACE=" ",
SSAR="ssar",
SET = "set",
Modified:
river/jtsk/skunk/surrogate/src/org/apache/river/container/core-config.xml
URL:
http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/core-config.xml?rev=1307616&r1=1307615&r2=1307616&view=diff
==============================================================================
--- river/jtsk/skunk/surrogate/src/org/apache/river/container/core-config.xml
(original)
+++ river/jtsk/skunk/surrogate/src/org/apache/river/container/core-config.xml
Fri Mar 30 21:11:53 2012
@@ -57,6 +57,8 @@
<!--cfg:component
class="org.apache.river.container.ShowContextToConsole"/-->
<cfg:component class="org.apache.river.container.AnnotatedClassDeployer"/>
+ <cfg:component
class="org.apache.river.container.security.SecurityInitializer"/>
+
<cfg:component class="org.apache.river.container.el.ArgsParserImpl"/>
<cfg:property name="deploymentDirectory" value="deploy"/>
Added:
river/jtsk/skunk/surrogate/src/org/apache/river/container/security/ContainerCodePolicy.java
URL:
http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/security/ContainerCodePolicy.java?rev=1307616&view=auto
==============================================================================
---
river/jtsk/skunk/surrogate/src/org/apache/river/container/security/ContainerCodePolicy.java
(added)
+++
river/jtsk/skunk/surrogate/src/org/apache/river/container/security/ContainerCodePolicy.java
Fri Mar 30 21:11:53 2012
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.river.container.security;
+
+import java.security.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.apache.river.container.MessageNames;
+
+/**
+ Implements the base policy for the container: Anything loaded by the same
+classloader (or one of its ancestors) as this policy has AllPermission.
+Anything loaded by a different classloader has no permissions (and will
+assumedly be granted appropriate permissions dynamically).
+ @author trasukg
+ */
+public class ContainerCodePolicy extends Policy {
+ private static final Logger log=
+ Logger.getLogger(ContainerCodePolicy.class.getName(),
+ MessageNames.BUNDLE_NAME);
+
+ List<ClassLoader> privilegedClassLoaders=new ArrayList<ClassLoader>();
+
+ public ContainerCodePolicy(ClassLoader bootstrapClassLoader) {
+ privilegedClassLoaders.add(bootstrapClassLoader);
+ ClassLoader cl=this.getClass().getClassLoader();
+ while (cl != null) {
+ privilegedClassLoaders.add(cl);
+ cl=cl.getParent();
+ }
+ allPermissions.add(new AllPermission());
+ allPermissions.setReadOnly();
+ noPermissions.setReadOnly();
+ }
+
+ private PermissionCollection allPermissions=new Permissions();
+ private PermissionCollection noPermissions=new Permissions();
+
+ @Override
+ public PermissionCollection getPermissions(ProtectionDomain domain) {
+ if (privilegedClassLoaders.contains(domain.getClassLoader()) ) {
+ return allPermissions;
+ } else {
+ log.log(Level.FINE, MessageNames.POLICY_DECLINED,
+ new Object[] { domain.getClassLoader() });
+ return noPermissions;
+ }
+ }
+
+
+}
Added:
river/jtsk/skunk/surrogate/src/org/apache/river/container/security/SecurityInitializer.java
URL:
http://svn.apache.org/viewvc/river/jtsk/skunk/surrogate/src/org/apache/river/container/security/SecurityInitializer.java?rev=1307616&view=auto
==============================================================================
---
river/jtsk/skunk/surrogate/src/org/apache/river/container/security/SecurityInitializer.java
(added)
+++
river/jtsk/skunk/surrogate/src/org/apache/river/container/security/SecurityInitializer.java
Fri Mar 30 21:11:53 2012
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.river.container.security;
+
+import java.security.Policy;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import net.jini.security.policy.DynamicPolicyProvider;
+import org.apache.river.container.ConfigurationException;
+import org.apache.river.container.Context;
+import org.apache.river.container.Init;
+import org.apache.river.container.Injected;
+import org.apache.river.container.InjectionStyle;
+import org.apache.river.container.MessageNames;
+
+/**
+ This class is the container component that sets up the security manager and
+ dynamic policy provider.
+
+ @author trasukg
+ */
+public class SecurityInitializer {
+
+ private static Logger log =
+ Logger.getLogger(SecurityInitializer.class.getName(),
+ MessageNames.BUNDLE_NAME);
+ @Injected(style = InjectionStyle.BY_TYPE)
+ private Context context;
+
+ @Injected
+ private ClassLoader bootstrapClassLoader;
+
+ @Init
+ public void initialize() {
+ Policy basePolicy = new ContainerCodePolicy(bootstrapClassLoader);
+ DynamicPolicyProvider policy = new DynamicPolicyProvider(basePolicy);
+ Policy.setPolicy(policy);
+
+ context.put(org.apache.river.container.Strings.SECURITY_POLICY,
policy);
+
+ System.setSecurityManager(new SecurityManager());
+
+ Policy installedPolicy = Policy.getPolicy();
+ if (installedPolicy != policy) {
+ throw new
ConfigurationException(MessageNames.SECURITY_INIT_WRONG_POLICY,
+ installedPolicy);
+ }
+
+ log.log(Level.INFO, MessageNames.SECURITY_INIT_SUCCEEDED);
+
+ }
+}