Esempio n. 1
0
 public UserSecurityContext(
     UserContext userContext,
     SystemPermissionManager systemPermissionManager,
     DependencyInjectionContainer dependencyInjectionContainer,
     EntitySecurityConfigurationRegister entityConfigurationRegister,
     ObjectSecurityConfigurationRegister objectSecurityConfigurationRegister)
 {
     this.UserContext                         = userContext;
     this.systemPermissionManager             = systemPermissionManager;
     this.dependencyInjectionContainer        = dependencyInjectionContainer;
     this.entityConfigurationRegister         = entityConfigurationRegister;
     this.objectSecurityConfigurationRegister = objectSecurityConfigurationRegister;
 }
Esempio n. 2
0
        public RequestHandlerGuard(Type type, EntitySecurityConfigurationRegister entitySecurityConfigurationRegister)
        {
            // If child implements ISecureHandler<,,>.
            this.ContextCommand = type.GetTypeInfo().GetInterfaces()
                                  .SingleOrDefault(t =>
            {
                if (!t.GetTypeInfo().IsGenericType)
                {
                    return(false);
                }

                var genericTypeDefinition = t.GetGenericTypeDefinition();
                return
                (genericTypeDefinition == typeof(ISecureHandler <, ,>) ||
                 genericTypeDefinition == typeof(IAsyncSecureHandler <, ,>));
            });

            this.GetPermission = type.GetTypeInfo().GetMethod(nameof(ISecureHandler.GetPermission));

            if (this.ContextCommand != null)
            {
                // Get T from ISecureHandler<TContext,TRequest>
                var contextType = this.ContextCommand.GenericTypeArguments[0];

                if (!entitySecurityConfigurationRegister.Guards.TryGetValue(contextType, out var guard))
                {
                    throw new BusinessException($"Context of type `{contextType.Name}` was not registered with the `SecurityGuard`.");
                }

                this.EntitySecurityConfiguration = guard;
                this.EnforceContextPermission    =
                    this.EntitySecurityConfiguration.PermissionManager.GetTypeInfo().GetMethod(nameof(SystemPermissionManager.EnforceCanDo));
            }

            // If child implements ISecureHandler.
            this.SystemCommand = type.GetTypeInfo().GetInterfaces().SingleOrDefault(t => t == typeof(ISecureHandler));
        }
Esempio n. 3
0
 public RequestHandlerGuardRegister(EntitySecurityConfigurationRegister entitySecurityConfigurationRegister)
 {
     this.entitySecurityConfigurationRegister = entitySecurityConfigurationRegister;
 }