/// <summary> /// Install the capability on the port /// </summary> /// <param name="capability">The capability to install</param> /// <param name="targetPort">The port on which to install</param> /// <returns>If the install succeeded</returns> private bool RemoteInstallCapability(Capability capability, VPort targetPort) { VModule targetModule = null; lock (this) { if (registeredPorts.ContainsKey(targetPort)) { targetModule = registeredPorts[targetPort]; } } if (targetModule == null) { logger.Log("Platform could not find the target module for port {0}", targetPort.ToString()); return false; } ResultCode result = (ResultCode) targetModule.InstallCapability(capability, targetPort); if (result == ResultCode.Success) { return true; } else { logger.Log("RemoteCapabilityInstall failed: {0}", result.ToString()); return false; } }
/// <summary> /// Issues a capability /// </summary> /// <param name="module">The module that is asking for the capability</param> /// <param name="targetPort">The port for which the capability is being requested</param> /// <param name="userName">The name of the user on behalf of which the capability is being requested</param> /// <param name="password">The password of the user</param> /// <returns>The issued capability</returns> public VCapability GetCapability(VModule requestingModule, VPort targetPort, string username, string password) { // .... //check if the user is valid, the module exists, and the port is registered // .... if (!username.Equals(Constants.UserSystem.Name) && config.ValidUserUntil(username, password) < DateTime.Now) return null; if (!runningModules.ContainsKey(requestingModule)) return null; //if (!config.allPorts.ContainsKey(targetPort.GetInfo())) // return null; if (!registeredPorts.ContainsKey(targetPort)) return null; string portName = targetPort.GetInfo().GetFriendlyName(); DateTime allowedUntil = (Settings.EnforcePolicies) ? policyEngine.AllowAccess(portName, requestingModule.GetInfo().FriendlyName(), username) : DateTime.MaxValue; if (allowedUntil < DateTime.Now) { return null; } Capability capability = new Capability("platform", allowedUntil); if (RemoteInstallCapability(capability, targetPort)) { return capability; } else { return null; } }