public AuthorizationBehavior(IAuthorizationNode authorization, IFubuRequestContext context, IAuthorizationFailureHandler failureHandler, SecuritySettings settings) { _authorization = authorization; _context = context; _failureHandler = failureHandler; _settings = settings; }
public IMedia <T> SelectMedia(CurrentMimeType mimeTypes, IFubuRequestContext context) { foreach (var acceptType in mimeTypes.AcceptTypes) { var candidates = Media.Where(x => x.Mimetypes.Contains(acceptType)); if (candidates.Any()) { var writer = candidates.FirstOrDefault(x => x.MatchesRequest(context)); if (writer != null) { context.Logger.DebugMessage(() => new WriterChoice(acceptType, writer, writer.Condition)); return(writer); } context.Logger.DebugMessage(() => NoWritersMatch.For(acceptType, candidates)); } } if (mimeTypes.AcceptsAny()) { var media = Media.FirstOrDefault(x => x.MatchesRequest(context)); context.Logger.DebugMessage(() => new WriterChoice(MimeType.Any.Value, media, media.Condition)); return(media); } return(null); }
public T Read(string mimeType, IFubuRequestContext context) { var json = context.Services.GetInstance <NewtonSoftJsonReader>().GetInputText(); var values = new JObjectValues(json); return((T)context.Services.GetInstance <IObjectResolver>().BindModel(typeof(T), values).Value); }
public AuthorizationBehavior(IAuthorizationNode authorization, IFubuRequestContext context, IAuthorizationFailureHandler failureHandler) { _authorization = authorization; _context = context; _failureHandler = failureHandler; }
public T Read <T>(IFubuRequestContext context) { var serializer = new XmlSerializer(typeof(T)); var reader = new StreamReader(context.Request.Input, true); return((T)serializer.Deserialize(reader)); }
public void Write(string mimeType, IFubuRequestContext context, T resource) { var serializer = context.Services.GetInstance <IJsonSerializer>(); var json = serializer.Serialize(resource.ToDictionary()); context.Writer.Write(mimeType, json); }
protected static string serializeData <T>(IFubuRequestContext context, T target) { var serializer = context.Services.GetInstance <IJsonSerializer>(); var text = serializer.Serialize(target); return(text); }
public T Read <T>(IFubuRequestContext context) { var serializer = new JavaScriptSerializer { MaxJsonLength = int.MaxValue }; return(serializer.Deserialize <T>(context.Request.InputText())); }
public virtual AuthorizationRight IsAuthorized(IFubuRequestContext context, IEnumerable<IAuthorizationPolicy> policies) { var result = DetermineRights(context, policies); _logger.DebugMessage(() => new AuthorizationResult(result)); return result; }
public Task <InputMessage> Read(string mimeType, IFubuRequestContext context) { // read the body of the http request from IHttpRequest // read header information and route information from // IHttpRequest return(new InputMessage().ToCompletionTask()); }
public void Write(string mimeType, IFubuRequestContext context, T resource) { var view = BuildView(context); view.Page.ServiceLocator = context.Services; view.Page.As <IFubuPage <T> >().Model = resource; view.Render(context); }
public T Read(string mimeType, IFubuRequestContext context) { var model = _formatter.Read <T>(context); context.Services.GetInstance <IBindingContext>().BindProperties(model); return(model); }
public async Task <T> Read(string mimeType, IFubuRequestContext context) { var model = await _formatter.Read <T>(context).ConfigureAwait(false); context.Services.GetInstance <IBindingContext>().BindProperties(model); return(model); }
public virtual AuthorizationRight IsAuthorized(IFubuRequestContext context, IEnumerable <IAuthorizationPolicy> policies) { var result = DetermineRights(context, policies); _logger.DebugMessage(() => new AuthorizationResult(result)); return(result); }
public virtual void Write <T>(IFubuRequestContext context, T resource, string mimeType) { var serializer = new JavaScriptSerializer { MaxJsonLength = int.MaxValue }; var text = serializer.Serialize(resource); context.Writer.Write(mimeType, text); }
public AuthorizationRight IsAuthorized(IFubuRequestContext context) { if (!_policies.Any()) { return(AuthorizationRight.Allow); } return(AuthorizationRight.Combine(_policies.Select(x => x.RightsFor(context)))); }
public async Task <T> Read <T>(IFubuRequestContext context) { var serializer = new XmlSerializer(typeof(T)); var reader = new StreamReader(context.Request.Input, true); var xml = await reader.ReadToEndAsync().ConfigureAwait(false); return((T)serializer.Deserialize(new XmlTextReader(new StringReader(xml)))); }
public Task Write(string mimeType, IFubuRequestContext context, T resource) { var stringWriter = new StringWriter(); var writer = new JsonTextWriter(stringWriter); _serializer.Serialize(writer, resource); return(context.Writer.Write(mimeType, stringWriter.ToString())); }
public IRenderableView BuildView(IFubuRequestContext context) { if (context.Request.IsAjaxRequest() || context.Services.GetInstance <ICurrentChain>().IsInPartial()) { return(_view.GetPartialView()); } return(_view.GetView()); }
public ConditionalService(IServiceLocator services, IFubuRequestContext context) { _conditions = new Cache <Type, bool>(type => { var condition = services.GetInstance(type).As <IConditional>(); return(condition.ShouldExecute(context)); }); }
public void SetUp() { ClassUnderTest = new JsonSerializer(); theFubuRequestContext = MockRepository.GenerateMock<IFubuRequestContext>(); theHttpRequest = MockRepository.GenerateMock<IHttpRequest>(); theOutputWriter = new InMemoryOutputWriter(); theFubuRequestContext.Stub(x => x.Request).Return(theHttpRequest); theFubuRequestContext.Stub(x => x.Writer).Return(theOutputWriter); }
public void SetUp() { ClassUnderTest = new JsonSerializer(); theFubuRequestContext = MockRepository.GenerateMock <IFubuRequestContext>(); theHttpRequest = MockRepository.GenerateMock <IHttpRequest>(); theOutputWriter = new InMemoryOutputWriter(); theFubuRequestContext.Stub(x => x.Request).Return(theHttpRequest); theFubuRequestContext.Stub(x => x.Writer).Return(theOutputWriter); }
void IMediaWriter <T> .Write(string mimeType, IFubuRequestContext request, T resource) { var node = new DictionaryMediaNode(); var context = new ProjectionContext <T>(request.Services, new SimpleValues <T>(resource)); write(context, node); request.Writer.Write(mimeType, JsonUtil.ToJson(node.Values)); }
public async Task <T> Read <T>(IFubuRequestContext context) { var serializer = context.Services.GetInstance <IJsonSerializer>(); var reader = new StreamReader(context.Request.Input); var json = await reader.ReadToEndAsync().ConfigureAwait(false); return(serializer.Deserialize <T>(json)); }
public ConditionalService(IServiceLocator services, IFubuRequestContext context) { _conditions = new Cache<Type, bool>(type => { var condition = services.GetInstance(type).As<IConditional>(); return condition.ShouldExecute(context); }); }
public AggregatedQuery Read(string mimeType, IFubuRequestContext context) { var messageTypes = context.Service <IClientMessageCache>(); var serializer = context.Service <NewtonSoftJsonSerializer>().InnerSerializer(); var json = context.Request.Input.ReadAllText(); return(Read(serializer, messageTypes, json)); }
public async Task <AggregatedQuery> Read(string mimeType, IFubuRequestContext context) { var messageTypes = context.Service <IClientMessageCache>(); var serializer = context.Service <NewtonSoftJsonSerializer>().InnerSerializer(); var reader = new StreamReader(context.Request.Input); var json = await reader.ReadToEndAsync().ConfigureAwait(false); return(Read(serializer, messageTypes, json)); }
public AuthorizationRight RightsFor(IFubuRequestContext request) { var customerId = request.Models.Get<Customer>().Id; var productId = request.Models.Get<Product>().Id; var hasPurchasedProduct = request.Service<IRepository>().Get<IPurchaseHistory>(customerId) .Any(x => x.ContainsProduct(productId)); return !hasPurchasedProduct ? AuthorizationRight.Deny : AuthorizationRight.Allow; }
public AuthorizationRight RightsFor(IFubuRequestContext request) { var customerId = request.Models.Get <Customer>().Id; var productId = request.Models.Get <Product>().Id; var hasPurchasedProduct = request.Service <IRepository>().Get <IPurchaseHistory>(customerId) .Any(x => x.ContainsProduct(productId)); return(!hasPurchasedProduct ? AuthorizationRight.Deny : AuthorizationRight.Allow); }
public async Task <T> Read(string mimeType, IFubuRequestContext context) { var json = await context.Services.GetInstance <NewtonSoftJsonReader>().GetInputText().ConfigureAwait(false); var values = new JObjectValues(json); var value = context.Services.GetInstance <IObjectResolver>().BindModel(typeof(T), values).Value.As <T>(); return(value); }
// This signature is necessary because we are assuming // that some Writer's will be able to produce representations // for multiple mimetype's public void Write(string mimeType, IFubuRequestContext context, SomeResource resource) { if (mimeType == "special/format") { writeSpecial(resource); } else { writeJson(resource); } }
// This signature is necessary because we are assuming // that some Writer's will be able to produce representations // for multiple mimetype's public Task Write(string mimeType, IFubuRequestContext context, SomeResource resource) { if (mimeType == "special/format") { return(writeSpecial(resource)); } else { return(writeJson(resource)); } }
Task IMediaWriter <T> .Write(string mimeType, IFubuRequestContext request, T resource) { var node = new DictionaryMediaNode(); var context = new ProjectionContext <T>(request.Services, new SimpleValues <T>(resource)); write(context, node); var serializer = request.Services.GetInstance <IJsonSerializer>(); return(request.Writer.Write(mimeType, serializer.Serialize(node.Values, false))); }
public void Write <T>(IFubuRequestContext context, T target, string mimeType) { var serializer = new XmlSerializer(typeof(T)); context.Writer.Write(mimeType, stream => { var xmlWriter = new XmlTextWriter(stream, Encoding.Unicode) { Formatting = Formatting.None }; serializer.Serialize(xmlWriter, target); }); }
public AuthorizationRight DetermineRights(IFubuRequestContext context, IEnumerable<IAuthorizationPolicy> policies) { // Check every authorization policy for this endpoint var rights = policies.Select(policy => { var policyRights = policy.RightsFor(context); _logger.DebugMessage(() => new AuthorizationPolicyResult(policy, policyRights)); return policyRights; }); // Combine the results var result = AuthorizationRight.Combine(rights); return result; }
public AuthorizationRight DetermineRights(IFubuRequestContext context, IEnumerable <IAuthorizationPolicy> policies) { // Check every authorization policy for this endpoint var rights = policies.Select(policy => { var policyRights = policy.RightsFor(context); _logger.DebugMessage(() => new AuthorizationPolicyResult(policy, policyRights)); return(policyRights); }); // Combine the results var result = AuthorizationRight.Combine(rights); return(result); }
public AuthorizationRight RightsFor(IFubuRequestContext request) { var currentSdkUser = request.Service<ICurrentSDKUser>(); var tokenRepository = request.Service<IAuthenticationTokenRepository>(); var logger = request.Service<ILogger>(); var authToken = request.Models.Get<AuthenticationTokenRequest>(); //Workaround: RightsFor is getting called multiple times because of a Fubu bug if (request.Models.Has<IAuthenticationToken>()) return AuthorizationRight.Allow; var token = authToken.authToken; if (token.IsEmpty()) { if (currentSdkUser.IsAuthenticated) { logger.LogDebug("No AuthToken was found in this request but a user is already authenticated. Using the current user's credentials."); return AuthorizationRight.Allow; } return AuthorizationRight.Deny; } logger.LogDebug("Authentication token {0} found.", token); var authenticationToken = tokenRepository.RetrieveByToken(token); if (authenticationToken == null) { return AuthorizationRight.Deny; } logger.LogDebug("Authentication token {0} found and validated for user {1}.", authenticationToken, authenticationToken); request.Models.Set(authenticationToken); currentSdkUser.SetUser(authenticationToken.Username); return AuthorizationRight.Allow; }
public bool ShouldExecute(IFubuRequestContext context) { throw new NotImplementedException(); }
public bool ShouldExecute(IFubuRequestContext context) { return true; }
public AuthorizationRight RightsFor(IFubuRequestContext request) { var principal = Thread.CurrentPrincipal; return DetermineRights(principal); }
public AuthorizationRight RightsFor(IFubuRequestContext request) { return PrincipalRoles.IsInRole(_role) ? AuthorizationRight.Allow : AuthorizationRight.None; }
public bool ShouldExecute(IFubuRequestContext context) { return _condition(); }
public ChainAuthorizor(IFubuRequestContext context, ITypeResolver types) { _context = context; _types = types; }
public AuthorizationRight RightsFor(IFubuRequestContext request) { return AuthorizationRight.Deny; }
public AuthorizationRight RightsFor(IFubuRequestContext request) { throw new NotImplementedException(); }
public AuthorizationRight RightsFor(IFubuRequestContext request) { return AuthorizationCheck.IsAuthorized ? AuthorizationRight.Allow : AuthorizationRight.Deny; }