/// <summary> /// Set up the <paramref name="policyBuilder"/> to require an administrator. /// </summary> /// <param name="policyBuilder">Used for building policies during application startup.</param> public static AuthorizationPolicyBuilder RequireAdmin(this AuthorizationPolicyBuilder policyBuilder) { policyBuilder.RequireAuthenticatedUser(); policyBuilder.RequireAssertion(context => { if (context.HasFailed) { return(true); } return(context.User.IsAdmin()); }); return(policyBuilder); }
/// <summary> /// Require nothing /// </summary> /// <param name="builder"></param> /// <returns></returns> public static AuthorizationPolicyBuilder RequireNothing( this AuthorizationPolicyBuilder builder) => builder.RequireAssertion(ctx => true);
/// <summary> /// Require assertion /// </summary> /// <param name="builder"></param> /// <param name="handler"></param> public static AuthorizationPolicyBuilder Require( this AuthorizationPolicyBuilder builder, Func <AuthorizationHandlerContext, bool> handler) => builder.RequireAssertion(ctx => handler(ctx));
/// <summary> /// Adds an <see cref="Infrastructure.AssertionRequirement"/> to the current instance. /// </summary> /// <param name="handler">The handler to evaluate during authorization.</param> /// <returns>A reference to this instance after the operation has completed.</returns> public AcceptancePolicyBuilder RequireAssertion(Func <AuthorizationHandlerContext, bool> handler) { _builder.RequireAssertion(handler); return(this); }