This class describes the support needed to implement security.
This class describes the support needed to implement security.

Three main pieces of functionality are required to implement security for JavaScript. First, it must be possible to define classes with an associated security domain. (This security domain may be any object incorporating notion of access restrictions that has meaning to an embedding; for a client-side JavaScript embedding this would typically be java.security.ProtectionDomain or similar object depending on an origin URL and/or a digital certificate.) Next it must be possible to get a security domain object that allows a particular action only if all security domains associated with code on the current Java stack allows it. And finally, it must be possible to execute script code with associated security domain injected into Java stack.

These three pieces of functionality are encapsulated in the SecurityController class.

Esempio n. 1
0
		/// <summary>
		/// Initialize global controller that will be used for all
		/// security-related operations.
		/// </summary>
		/// <remarks>
		/// Initialize global controller that will be used for all
		/// security-related operations. The global controller takes precedence
		/// over already installed
		/// <see cref="Context">Context</see>
		/// -specific controllers and cause
		/// any subsequent call to
		/// <see cref="Context.SetSecurityController(SecurityController)">Context.SetSecurityController(SecurityController)</see>
		/// to throw an exception.
		/// <p>
		/// The method can only be called once.
		/// </remarks>
		/// <seealso cref="HasGlobal()">HasGlobal()</seealso>
		public static void InitGlobal(SecurityController controller)
		{
			if (controller == null)
			{
				throw new ArgumentException();
			}
			if (global != null)
			{
				throw new SecurityException("Cannot overwrite already installed global SecurityController");
			}
			global = controller;
		}
Esempio n. 2
0
		private InterpretedFunction(InterpreterData idata, object staticSecurityDomain)
		{
			this.idata = idata;
			// Always get Context from the current thread to
			// avoid security breaches via passing mangled Context instances
			// with bogus SecurityController
			Context cx = Context.GetContext();
			SecurityController sc = cx.GetSecurityController();
			object dynamicDomain;
			if (sc != null)
			{
				dynamicDomain = sc.GetDynamicSecurityDomain(staticSecurityDomain);
			}
			else
			{
				if (staticSecurityDomain != null)
				{
					throw new ArgumentException();
				}
				dynamicDomain = null;
			}
			this.securityController = sc;
			this.securityDomain = dynamicDomain;
		}
Esempio n. 3
0
		private InterpretedFunction(Rhino.InterpretedFunction parent, int index)
		{
			this.idata = parent.idata.itsNestedFunctions[index];
			this.securityController = parent.securityController;
			this.securityDomain = parent.securityDomain;
		}
Esempio n. 4
0
		/// <summary>Set the security controller for this context.</summary>
		/// <remarks>
		/// Set the security controller for this context.
		/// <p> SecurityController may only be set if it is currently null
		/// and
		/// <see cref="SecurityController.HasGlobal()">SecurityController.HasGlobal()</see>
		/// is <tt>false</tt>.
		/// Otherwise a SecurityException is thrown.
		/// </remarks>
		/// <param name="controller">a SecurityController object</param>
		/// <exception cref="System.Security.SecurityException">
		/// if there is already a SecurityController
		/// object for this Context or globally installed.
		/// </exception>
		/// <seealso cref="SecurityController.InitGlobal(SecurityController)">SecurityController.InitGlobal(SecurityController)</seealso>
		/// <seealso cref="SecurityController.HasGlobal()">SecurityController.HasGlobal()</seealso>
		public void SetSecurityController(SecurityController controller)
		{
			if (@sealed)
			{
				OnSealedMutation();
			}
			if (controller == null)
			{
				throw new ArgumentException();
			}
			if (securityController != null)
			{
				throw new SecurityException("Can not overwrite existing SecurityController object");
			}
			if (SecurityController.HasGlobal())
			{
				throw new SecurityException("Can not overwrite existing global SecurityController object");
			}
			securityController = controller;
		}