/// <summary> /// Get protected object by name /// </summary> /// <param name="objectName"></param> /// <returns></returns> public async Task <PermissionedObjectDto> GetByObjectNameAsync(string objectName) { return(await _permissionedObjectManager.GetAsync(objectName)); }
public virtual async Task AuthorizeAsync(MethodInfo methodInfo, Type type) { if (!_authConfiguration.IsEnabled) { return; } var shaServiceType = typeof(ApplicationService); var controllerType = typeof(ControllerBase); if (type == null || !shaServiceType.IsAssignableFrom(type) && !controllerType.IsAssignableFrom(type)) { return; } /*if (!AbpSession.UserId.HasValue) * { * throw new AbpAuthorizationException( * LocalizationManager.GetString(AbpConsts.LocalizationSourceName, "CurrentUserDidNotLoginToTheApplication") * ); * }*/ var isDynamic = type.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IDynamicCrudAppService <, ,>)); // ToDo: move to a provider/manager var typeName = type.FullName; if (isDynamic) { var entityType = type.FindBaseGenericType(typeof(AbpAsyncCrudAppService <, , , , , , ,>))?.GetGenericArguments()[0]; typeName = $"{entityType?.Namespace}.Dynamic{entityType?.Name}CrudAppService"; } var permission = await _permissionedObjectManager.GetAsync($"{typeName}@{methodInfo.Name}"); if (permission != null && ( permission.ActualAccess == (int)RefListPermissionedAccess.Disable || permission.ActualAccess == (int)RefListPermissionedAccess.AnyAuthenticated && AbpSession.UserId == null || permission.ActualAccess == (int)RefListPermissionedAccess.RequiresPermissions && (permission.ActualPermissions == null || !permission.ActualPermissions.Any()) )) { throw new AbpAuthorizationException( LocalizationManager.GetString(SheshaConsts.LocalizationSourceName, "AccessDenied") ); } if (permission == null || permission.ActualAccess == (int)RefListPermissionedAccess.AllowAnonymous || permission.ActualAccess == (int)RefListPermissionedAccess.AnyAuthenticated && AbpSession.UserId != null || permission.ActualPermissions == null || !permission.ActualPermissions.Any()) { return; } // ToDo: add RequireAll flag await PermissionChecker.AuthorizeAsync(false, permission.ActualPermissions.ToArray()); }