2015-11-19 29 views
0

在我使用角度js構建的ASP.Net MVC SPA中,我想根據用戶是否在特定安全組中顯示或隱藏鏈接或不。我打算在html頁面中使用ng-if指令來顯示或隱藏。如何獲得用戶使用的安全組列表

在我以前的純MVC.net應用程序的項目中,我有下面的方法讓我看到這個安全組列表。

但我該如何在angularjs應用程序中做到這一點?目前,我的應用程序位於雲端,它根據Azure Active Directory對用戶進行身份驗證。

internal static IEnumerable<string> GetSecurityGroups() 
    { 
     try 
     { 
      ClaimsPrincipal claimsPrincipal = null; 
      claimsPrincipal = Thread.CurrentPrincipal as ClaimsPrincipal; 
      claimsPrincipal = ((claimsPrincipal == null) && (HttpContext.Current.User != null)) 
       ? HttpContext.Current.User as ClaimsPrincipal 
       : claimsPrincipal; 
      if (claimsPrincipal != null) 
      { 
       return ((ClaimsIdentity)claimsPrincipal.Identity).Claims 
        .Where(
         claim => 
          "group".Equals(claim.Type.Replace("http://sts.tmft.net/user/", ""), 
           StringComparison.InvariantCultureIgnoreCase)) 
        .Select(c => c.Value).ToList(); 
      } 
     } 
     catch (Exception exception) 
     { 
      Log.Error(exception); 
     } 
     return new[] { "No rights" }; 
    } 

回答

1

你可以露出上述(GetSecurityGroups)爲web服務,則有角度使用所得到的權限對象顯示/隱藏部分。

請注意,您仍然需要限制訪問功能(即Web服務調用隱藏的部分暴露)在服務器端,因爲你不能真正相信這種客戶端安全上應該比任何東西更如果有用戶決定使用未經授權的功能,那麼這是一個小的障礙。

相關問題