Repository navigation
Expand file tree
/
Copy pathSecurityHelper.cs
More file actions
40 lines (38 loc) · 1.56 KB
/
Copy pathSecurityHelper.cs
File metadata and controls
40 lines (38 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (c) Microsoft Open Technologies, Inc. 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.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Authentication
{
/// <summary>
/// Helper code used when implementing authentication middleware
/// </summary>
public static class SecurityHelper
{
/// <summary>
/// Add all ClaimsIdenities from an additional ClaimPrincipal to the ClaimsPrincipal
/// </summary>
/// <param name="identity"></param>
public static void AddUserPrincipal([NotNull] HttpContext context, [NotNull] ClaimsPrincipal principal)
{
ClaimsPrincipal existingPrincipal = context.User;
if (existingPrincipal != null)
{
foreach (var existingClaimsIdentity in existingPrincipal.Identities)
{
// REVIEW: No longer use auth type for anything, so we could remove this check, except for the default one HttpContext.user creates
// REVIEW: Need to ignore any identities that did not come from an authentication scheme?
if (existingClaimsIdentity.IsAuthenticated)
{
principal.AddIdentity(existingClaimsIdentity);
}
}
}
context.User = principal;
}
}
}