HttpContext.User.Identity.Name
HttpContext.User.IsInRole(...)
ãŸãã¯
Thread.CurrentPrincipal.Identity.Name
Thread.CurrentPrincipal.IsInRole(...)
ãããã®åŒã³åºãã®ç®çã¯ãäœããã®é¢æ°ãŸãã¯ã¡ãœãããžã®åŒã³åºãã®èš±å¯ã«é¢ãã決å®ãçŸåšã®ãŠãŒã¶ãŒã«é¢ããæ å ±ã®è¡šç€ºãªã©ãè¡ãå¿ èŠãããå ŽåããããŸãã
ãããã®ã¯ã©ã¹ã«ã¯ãããŒã¿ããŒã¹ããã®ããŒã¿ã®èªã¿åãããã©ãŒã èªèšŒãNTLMããŒã¯ã³ãKerberosããŒã¯ã³ãªã©ãããŸããŸãªæ¹æ³ã§ãŠãŒã¶ãŒæ å ±ã衚瀺ãããŸããã ãããã®å ŽåãããŠãŒã¶ãŒã«é¢ããæ å ±ããŠãŒã¶ãŒã®èªèšŒãããã³è¿œå æ å ±ã®ååŸãšããã¿ã¹ã¯ã解決ãããŸããã
ãæãåãã§ã¯ãã»ãšãã©ã®ã¢ããªã±ãŒã·ã§ã³ã§ããã§ååã§ããã ããã§ååã§ãªãå Žåã¯ãããŸããŸãªçš®é¡ã®ç¬èªã®ãã¬ãŒã ã¯ãŒã¯ãäœæãããŸããããäž»ãªè³ªåã¯å€ãã®å Žåãäž»ãªè³ªåã§ããããŠãŒã¶ãŒã«ã¯ç¹å®ã®åœ¹å²ããããŸããã ããæç¹ãŸã§ã¯ããŠãŒã¶ãŒãªããžããªã1ã€ã«ãªããŸã§ããã§ååã§ãããããžãã¹ããŒãããŒãªã©ãšå¯Ÿè©±ããå¿ èŠã¯ãããŸããã§ããã ã¯ã©ãŠããåæ£ã·ã¹ãã ãSaaSã¢ããªã±ãŒã·ã§ã³ãããã³çŸä»£ã®Webãæ³åããã®ãé£ããä»ã®å©ç¹ã®åºçŸã«ãããããšãã°ãããŒãããŒã®åŸæ¥å¡ãCRMã®ç¹å®ã®æ©èœã«ã¢ã¯ã»ã¹ã§ããããã«ãããå Žåããã®ã¢ãã«ã¯ååã§ã¯ãããŸããã§ããã ã¢ããªã±ãŒã·ã§ã³ã®éçºãšé²åã®åé¡ããã°ãã°çºçããŸããããšãã°ãæåã¯ãŠãŒã¶ãŒãšç®¡çè ã®2ã€ã®ãŠãŒã¶ãŒã°ã«ãŒãã䜿çšããã³ãŒãå ã§å¯å€§ã«æ¿èªãèšå®ããããšãèšç»ããŠããŸããã
ãã¥ãŒå±æ§ïŒ
[Authorize("Administrators")]
public ActionResult DoSomeHardcoreAdminStuff()
{
...
}
ãããŠã1幎åŸãããžãã¹ã¯ãç°ãªãã¬ãã«ã®ã¢ã¯ã»ã¹æš©ãæã€è€æ°ã®ç°ãªããŠãŒã¶ãŒã°ã«ãŒããæã¡ãä»ã®ãã¹ãŠã®ãã®ïŒãã®ç¶æ³ã®ãã©ãå šäœãç解ããããïŒãSystemAdministratorãšSecurityAdministratorã«å¯Ÿãã管çè ã®æš©å©ãåºå¥ããã®ãè¯ããšå€æããŸããã ãããã®èŠä»¶ã¯ããžãã¹ã®æ³ååã«ãã£ãŠã®ã¿å¶éããããããããã¯å¶éã§ã¯ãããŸããã
éçºè ã®èŠ³ç¹ããèŠããšãããããã¹ãŠããã¯ãããžãŒãšæŸèæã®åç©åããããããŸããã åã¢ããªã±ãŒã·ã§ã³ã¯ãç¬èªã®æ¹æ³ã§ãŠãŒã¶ãŒãèªèšŒããŸããã ãŠãŒã¶ãŒã¯ãOAuthãFormsãWindowsãªã©ã䜿çšããŠèªèšŒã§ããŸãã ç¹å®ã®ã±ãŒã¹ããšã«ãç§ã¯ç¬èªã®èªèšŒããã³æ¿èªããžãã¯ãäœæããå¿ èŠããããŸãããApiãããå Žåã¯ãèªè»¢è»ãåæ§ã«æç»ããŸãã
ããã«å¯Ÿå¿ããŠã2008幎ã«ãWindows Identity FoundationïŒWIFïŒã®æåã®ãªãªãŒã¹ããã€ã¯ããœããã®æ·±éšãããªãªãŒã¹ãããã¯ã¬ãŒã ããŒã¹ã®IDã®æŠå¿µãå°å ¥ãããŸããã ãã®ãã¬ãŒã ã¯ãŒã¯ã®ç®æšã¯ããããã©ã®ããã«æ©èœãããã®è©³çŽ°ã«å ¥ãããšãªãããŠãŒã¶ãŒã®èŠä»¶ãè¡šçŸããããã®æœè±¡çãªã¡ã«ããºã ãæäŸããããšã§ãã
èŠããã«ãWIFã®ã¢ã€ãã¢ã¯ãããªãåçŽãªå®äŸã§èª¬æã§ããŸãã
ããªãã¯18æ³ã«ãªããæ ç»é€šã«è¡ãããšã«ããŸããã ã¢ãã«ãæ ç»ã ããããæ®å¿µãªããã圌ãã¯ãããŸã§ãã¹ããŒããŸãã¯ä»ã®èº«å蚌ææžãååŸããããšãã§ããŸããã§ããïŒãŸãããŸãã¯ããŸãã«ãæ zyã§ããïŒã ãã¹ããŒããåãåãããã°ããããŠãã¹ããŒããæ瀺ãããã¹ããŒããæ瀺ãããããæ°è»œã«å€§åãªãã±ãããè³Œå ¥ããŠã»ãã·ã§ã³ã«è¡ã£ãŠãã ããã ãããŠãããã§ã¯WIFã®èŠ³ç¹ããèŠãŸãïŒ
件åãã€ãŸããIDãããã€ããŒïŒãã¹ããŒããªãã£ã¹ïŒã«ç§»åããBirth CertificateTokenã«åºã¥ããŠPassportTokenãååŸããŸãã 次ã«ããã®PassportTokenã䜿çšããŠã蚌ææžå©çšè ïŒæ ç»ïŒã«ã¢ã¯ã»ã¹ãã幎霢ã確èªããŠãããµãŒãã¹ã«ã¢ã¯ã»ã¹ããŸãã
ãã®äŸããåŒãåºããäž»ãªã¢ã€ãã¢ïŒ
1.ã¢ãã«ãã»ãã·ã§ã³ãžã®èšªåè ãšããŠããªããæ¿èªããããã«ãæ ç»é€šã¯é¡§å®¢ããŒã¹ãç¶æããããã©ãã«è¡ã£ããããå¿ èŠã¯ãããŸããã 圌ãå¿ èŠãšããã®ã¯ãèªåãä¿¡é Œãã身å蚌ææžïŒãã¹ããŒããè»äºIDãæš©å©ïŒã ãã§ãã
2.ãã¹ããŒããªãã£ã¹ã§ã¯ããã¹ããŒãã®æç€ºå ŽæãããããŸããã ïŒWIFã®èŠ³ç¹ãããç§ã¯ãŸã å°ãç¥ãå¿ èŠããããŸãããããã¯å¿ èŠã§ã¯ãããŸããïŒã
3.ãã¹ããŒãã䜿çšãããšãæ ç»é€šã«è¡ã£ãŠãããŠã€ã¹ããŒãè³Œå ¥ããããå·ãçºè¡ããæžé¡ãä¿¡é Œããæ©é¢ã§äœå® ããŒã³ãªã©ãè³Œå ¥ãããã§ããŸãã æ©é¢ã
OAuthãWS-TrustãWS-FedãSAML-Pãªã©ã®ãããã³ã«ããã§ã«äœ¿çšããŠãã人ãããããããã®çžäºäœçšã¹ããŒã ã¯ããªãã¿ã®ãã®ã§ãã èŠããã«ãç¹å®ã®åœ¢åŒã®ããŒã¯ã³ã®åœ¢ã§ä¿¡é Œã§ããIDãããã€ããŒãããŠãŒã¶ãŒã«é¢ããæ å ±ãååŸããããã䜿çšããŠã¢ããªã±ãŒã·ã§ã³ã§æ±ºå®ãäžããŸãã éåããå Žåãããšãã°ãã©ãŒã èªèšŒã§ã¯ãããªãèªèº«ããã®èªèšŒæ©é¢ã§ããããã®æ å ±ã䜿çšããŸãã WIFã¯ãã®ãããªã·ããªãªãèš±å¯ããŸãã WIFã¯ãããããçš®é¡ã®ã·ããªãªããµããŒãããã®ã«ååãªæè»æ§ãåããŠããŸãã
WIFã䜿çšãããšãèªèšŒããã»ã¹ãä¿¡é Œã§ããåœäºè ã«ãå€éšå§èšãã§ããèªèšŒããã³æ¿èªããã»ã¹ã§éçºè ãä»å ¥ããå¿ èŠæ§ãæå°éã«æããŸãã ã¢ããªã±ãŒã·ã§ã³ã«æ瀺ããããã¹ãŠã®IDã¯ãClaimsPrincipalããã³ClaimsIdentityã¿ã€ãã«ãã£ã¹ããããŸãã ãããã®ã¿ã€ãã¯ãæšæºã®* Principalããã³* Identityã«éåžžã«äŒŒãŠããŸãããIPrincipalããã³IIdentityã€ã³ã¿ãŒãã§ã€ã¹ãå®è£ ããŸãããè¿œå ã®ããããã£ããããŸããããã¯ãçŸåšã®ãŠãŒã¶ãŒã«é¢ããŠå©çšå¯èœãªãã¹ãŠã®ã¹ããŒãã¡ã³ãã®ã³ã¬ã¯ã·ã§ã³ã§ãã ããã«ãäºææ§ã®ããã«ãIIdentityããã³IClaimsPrincipalã䜿çšããããŸããŸãªæ¢åã®æ¹æ³ããµããŒããããŠããŸããããšãã°ã
[PrincipalPermission(SecurityAction.Demand, Role = "Administrators")]
static void CheckAdministrator()
{
Console.WriteLine("User is an administrator");
}
ãããè¡ãã«ã¯ããŠãŒã¶ãŒããAdministratorsããšããå€ãæã€ããŒã«ã¿ã€ãã®ã¹ããŒãã¡ã³ãïŒããŒã«ãšããŠäœ¿çšãããã¹ããŒãã¡ã³ãã®ã¿ã€ããèšå®ã§ããŸãïŒãæã£ãŠããã ãã§ååã§ãã
ASP.NET MVCã¢ããªã±ãŒã·ã§ã³ã§ã¯ãããã¯æ¬¡ã®ããã«ãªããŸãã
[ClaimsAuthorize(ClaimTypes.Role, "Administrators")]
public ActionResult DoSomeHardcoreAdminStuff()
{
...
}
ãŸãã¯ïŒ
[ClaimsAuthorize(ClaimTypes.Permission, "DoSomeHardcoreAdminStuff")]
public ActionResult DoSomeHardcoreAdminStuff()
{
...
}
ç¹å®ã®ãªãœãŒã¹ãžã®ã¢ã¯ã»ã¹ã確èªãããããŠãŒã¶ãŒã®å¹Žéœ¢ãäœæãèªå® ã®é»è©±çªå·ãååŸãããããããã®ããè€éãªã·ããªãªããããŸãã
ãããã®ãã¹ãŠã®å€æã®çµæãšããŠãããŒã«ããŒã¹ã®ã»ãã¥ãªãã£ã¢ãããŒãã¯ã¢ããªã±ãŒã·ã§ã³ã«èª²ããããªããªããå¿ èŠãªãã§ãã¯ãå®è¡ããæ¹æ³ãããŒã¹ãå Žæãèªç±ã«éžæã§ããå Žåã«ãã£ãŠã¯ãã¢ããªã±ãŒã·ã§ã³å ã«ãŠãŒã¶ãŒæ å ±ãä¿åããã¡ã«ããºã ãå®å šã«åé€ã§ããŸãã ãšãããããŠãŒã¶ãŒãã©ã®ããã«èªèšŒããããã¯æ°ã«ããŸãããããã¯ãæšæºã®ãã°ã€ã³ãšãã¹ã¯ãŒãã®ãã¢ã§ããããšãã¹ããŒãã¹ããŒãã«ãŒãã§ããããšã§ãã ããã¯ãIDãããã€ããŒã®ã¿ã¹ã¯ã§ãã
çŸåšãMicrosoftãã©ãããã©ãŒã ã§ã®ãã®ãããªã¢ãããŒãã«ã¯ãADFSïŒActive Directory Federation ServicesïŒãšAzure ACSã®2ã€ã®äž»èŠãªãœãªã¥ãŒã·ã§ã³ããããŸãã ã©ã¡ããèªåã«åããªãå Žåã¯ããµã³ãã«ãå«ããã³ãã¬ãŒããããã«ã¹ã¿ãžãªã«å ¥ããããã®ã§ãèªåã§ãµãŒãã¹ãèªç±ã«äœæã§ããŸãã ãŸããç¬èªã®è£œåãéçºã§ãããªãŒãã³ãœãŒã¹ã®IdentityServerãµãŒããŒããããŸãã
ããã€ãã®äºå®ïŒ
ããã«äœ¿çšã§ããWIFã¯ã次ã®ãããã³ã«ããµããŒãããŠããŸãã
1. WSãã§ãã¬ãŒã·ã§ã³
2. WS-Trust
3. WS-Security
4. WS-SecurityPolicy
5. WS-Addressing
SAML-Pãããã³ã«ã®ãµããŒãã¯CTPç¶æ ã§ãã RTMããŒãžã§ã³ã«é¢ããæ å ±ã¯ãŸã ãããŸããã OAuth2æ¡åŒµæ©èœããããŸãã
SAML1.1ããã³SAML2è³æ Œæ å ±ãæšæºã§ãµããŒããããŠããŸãã ãã ããSWTããã³JWTïŒJson Web TokenïŒã®ãµããŒããè¿œå ããã©ã€ãã©ãªã¯æ¢ã«ããªãéçºãããŠããŸãã
ããã¯ãSystem.Securityåå空éã§äœãèµ·ãã£ãŠãããã«ã€ããŠã®ããããããªäœè«ã§ããã å ¥éèšäºã®äžéšãšããŠã詳现ã«ç«ã¡å ¥ããããªã
ãšããã§ã.Net 4.5ã§ã¯ãã¯ã¬ãŒã ããŒã¹ã®IDãšWIFãå±±ã®çã«ãªããŸããã ãã¹ãŠã®ã¿ã€ã*ããªã³ã·ãã«ã¯ClaimsPrincipalããç¶æ¿ãããå éšã®KerberosããŒã¯ã³ã«ã¯äžé£ã®ã¹ããŒãã¡ã³ããªã©ãå«ãŸããŸãã 誰ãããã®ãããã¯ã«èå³ãæã£ãŠãããªããã³ã¡ã³ãã«ããªãã®åžæãæžããŠãã ãããç§ã¯ãã£ãšæéãæžããŸãã
䟿å©ãªãªã³ã¯ïŒ
1. msdn.microsoft.com/en-us/security/aa570351.aspx-MSDNã®ããŒãžã
2. claimid.codeplex.com-ã³ãŒãäŸãšç¡æã®æ¬ã
3. leastprivilege.com -Dominick Baierããã°ã
4.github.com/thinktecture/Thinktecture.IdentityServer-ãªãŒãã³ãœãŒã¹ã®Identity Serverã
PSã ã¬ãã¥ãŒãæäŸããŠãããXaocCPSã«æè¬ããŸãã