public override async Task ServiceReady(ServiceSessionOperationMessage request, IMemoryChannel channel, DataTransferContext context) { try { if (string.IsNullOrEmpty(request.ResponderFor)) { CheckAuth(context, "ActAsService"); } else { CheckAuth(context, "ConnectAnyService", request.ResponderFor); } await base.ServiceReady(request, channel, context); } catch (Exception ex) { LogEnvironment.LogEvent(ex.OutlineException(), LogSeverity.Error); throw; } finally { TemporaryGrants.UnRegisterService(request.ServiceName); if (!string.IsNullOrEmpty(request.ResponderFor)) { TemporaryGrants.RevokeTemporaryPermission(request.ResponderFor, request.ServiceName); } } }
public override Task <RegisterServiceResponseMessage> RegisterService(RegisterServiceMessage request, DataTransferContext context) { try { if (string.IsNullOrEmpty(request.ResponderFor)) { CheckAuth(context, "ActAsService"); TemporaryGrants.RegisterService(request.ServiceName, context.Identity.Name); } else { CheckAuth(context, "ConnectAnyService", request.ResponderFor); TemporaryGrants.GrantTemporaryPermission(request.ResponderFor, request.ServiceName); } return(base.RegisterService(request, context)); } catch (Exception ex) { LogEnvironment.LogEvent(ex.OutlineException(), LogSeverity.Error); return(Task.FromResult(new RegisterServiceResponseMessage { Ok = false, Reason = ex.Message })); } }
/// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary> public void Dispose() { if (initialized && !string.IsNullOrEmpty(ServiceName)) { localProvider.Broker.UnRegisterService(this); if (!string.IsNullOrEmpty(consumedService) && !string.IsNullOrEmpty(ServiceName)) { TemporaryGrants.RevokeTemporaryPermission(consumedService, ServiceName); } } }
/// <summary> /// Initializes a new instance of the LocalServiceHubConsumer class /// </summary> /// <param name="serviceName">the local service name</param> /// <param name="localProvider">the local serviceHubProvider instance</param> public LocalServiceHubConsumer(string serviceName, IServiceHubProvider localProvider, string consumedService, ICustomServerSecurity serverSecurity) { this.localProvider = localProvider; ServiceName = serviceName; this.consumedService = consumedService; this.serverSecurity = serverSecurity; rnd = new Random(); if (!string.IsNullOrEmpty(serviceName) && !string.IsNullOrEmpty(consumedService)) { TemporaryGrants.GrantTemporaryPermission(consumedService, serviceName); } }
/// <summary> /// Gets an enumeration of Permissions for a set of user-labels that is appropriate for the given user /// </summary> /// <param name="userLabels">the labels that describe the current user</param> /// <param name="userAuthenticationType">the authentication-type that was used to authenticate current user</param> /// <returns>an enumerable of permissions for the given user-labels</returns> public IEnumerable <Permission> GetPermissions(string[] userLabels, string userAuthenticationType) { return((from ur in (from t in userLabels join u in HubConfiguration.Helper.HubUsers on new { UserName = t, AuthenticationType = userAuthenticationType } equals new { u.UserName, u.AuthenticationType } select u.Roles).SelectMany(r => r).Distinct() join hr in HubConfiguration.Helper.HubRoles on ur equals hr.RoleName select hr.Permissions).SelectMany(n => n).Distinct(StringComparer.OrdinalIgnoreCase) .Union(TemporaryGrants.GetTemporaryPermissions(userLabels)).Distinct(StringComparer.OrdinalIgnoreCase) .Select(p => new Permission { PermissionName = p })); }