// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Security.Claims;
using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.Authentication.Cookies
{
///
/// Context object passed to the CookieAuthenticationEvents ValidatePrincipal method.
///
public class CookieValidatePrincipalContext : BaseCookieContext
{
///
/// Creates a new instance of the context object.
///
///
///
/// Contains the initial values for identity and extra data
///
public CookieValidatePrincipalContext(HttpContext context, AuthenticationScheme scheme, AuthenticationTicket ticket, CookieAuthenticationOptions options)
: base(context, scheme, options, ticket?.Properties)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (ticket == null)
{
throw new ArgumentNullException(nameof(ticket));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
Principal = ticket.Principal;
}
///
/// Contains the claims principal arriving with the request. May be altered to change the
/// details of the authenticated user.
///
public ClaimsPrincipal Principal { get; private set; }
///
/// If true, the cookie will be renewed
///
public bool ShouldRenew { get; set; }
///
/// Called to replace the claims principal. The supplied principal will replace the value of the
/// Principal property, which determines the identity of the authenticated request.
///
/// The used as the replacement
public void ReplacePrincipal(ClaimsPrincipal principal)
{
Principal = principal;
}
///
/// Called to reject the incoming principal. This may be done if the application has determined the
/// account is no longer active, and the request should be treated as if it was anonymous.
///
public void RejectPrincipal()
{
Principal = null;
}
}
}