Skip to content

Commit

Permalink
添加获取用户Id和名称的扩展方法
Browse files Browse the repository at this point in the history
  • Loading branch information
Kation committed Sep 30, 2017
1 parent 060d1d7 commit 9e8d4a4
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Wodsoft.ComBoost.Security/Security/PrincipalExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,16 @@ public static bool IsInRole(this IPrincipal principal, object role)
if (authentication.IsInStaticRole(role))
return true;
return authentication.IsInDynamicRole(role);
}

public static string GetUserId(this IPrincipal principal)
{
if (principal == null)
throw new ArgumentNullException(nameof(principal));
IAuthentication authentication = principal as IAuthentication;
if (authentication == null)
return null;
return authentication.GetUserId();
}
}
}

0 comments on commit 9e8d4a4

Please sign in to comment.