2015-11-02 75 views
3

我在一個天藍色Web應用程序上託管了一個SOAP WCF。該服務將僅被服務器使用,並且不包含UI。我只需要一個服務帳戶來授權我的WCF。因爲它是SOAP,所以我不能使用oauth。我已經讀了一些關於ACS的文章,但對我而言似乎有點矯枉過正,因爲我只想使用一個帳戶來保護我的WCF。我的想法是,我打算利用Azure AD在那裏創建一個服務帳戶並使用它來保護該服務。在SOAP上添加簡單安全WCF在Azure webapp上承載

這是甚至可能在網絡應用程序或我需要託管它的網絡角色?無論如何,我如何基於我的前提在我的WCF上完成簡單的安全性?

+0

是的,這很有可能是因爲WCF服務涉及很多安全問題。他們可以在Azure網站中進行託管(限制在端口80/443)。通過安全,你究竟意味着什麼:識別客戶端,啼哭消息,識別服務器......? –

+1

我想使用某種類型的wcf安全性,以便WCF不會完全暴露給任何人使用。那麼,如果它的信任/持票人/信任或無關緊要。基本上我想知道哪些WS-安全方法應該用於我的用例,以及我應該如何驗證以及如何配置它。 – Aleve940

+0

您可以使用SWT和ACS作爲Auth提供程序創建一個非常簡單的ACS設置。你爲什麼覺得ACS過度殺傷? –

回答

5

詳細的解答例如

一般性討論之後,這裏是建立傳輸安全的詳細示例+簡單的密碼(在IIS中,在我剛剛測試過的場所或Azure上)

這是非常簡單的
- 沒有角色,沒有基於身份的聲明或程序控制。
- 身份是硬編碼的。
- 沒有使用更強大的消息安全性(中間人)。
- 傳輸安全性是最小的,因爲基本身份驗證沒有被證實。

該安全方案是短落實

1.傳輸安全性創建Web服務的

<system.serviceModel> 
<bindings> 
    <basicHttpBinding> 
    <binding name="BasicBindingConfiguration"> 
     <security mode="Transport"> 
     <transport clientCredentialType="None"/> 
     </security> 
    </binding> 
    </basicHttpBinding> 
</bindings> 
<services> 
    <service name="HelloServiceLibrary.HelloService" behaviorConfiguration="customIdentificationBehavior"> 
    <endpoint address="" 
       binding="basicHttpBinding" 
       contract ="HelloServiceLibrary.IHelloService" 
       name="basicEndpoint" 
       bindingConfiguration="BasicBindingConfiguration"> 
    </endpoint> 

2.模塊的聲明找到基本認證

<system.webServer> 
    <modules> 
    <add name="BasicAuthenticationModule" 
     type="Security.UserNameModuleAuthenticator,App_Code/Security" /> 
    </modules> 
</system.webServer> 

3.模塊的實現E:

public class UserNameModuleAuthenticator : IHttpModule{ 
    ... 
    public void OnAuthenticateRequest(object source, EventArgs eventArgs){ 
     HttpApplication app = (HttpApplication)source; 
     string authStr = app.Request.Headers["Authorization"]; 
     string username = ...; // from header 
     string password = ...; // from header 
     if (username == "gooduser" && password == "password") 
      { 
       app.Context.User = new GenericPrincipal(new GenericIdentity(username, "Custom Provider"), null); 
      } 
      else 
      { 
       DenyAccess(app); 
       return; 
      } 

4配置客戶端傳遞基本認證

<system.serviceModel> 
    <bindings> 
    <basicHttpBinding> 
     <binding name="basicEndpoint"> 
     <security mode="Transport" > 
      <transport clientCredentialType="Basic" 
        proxyCredentialType="None" 
        realm="" /> 
     </security> 
     </binding> 
    </basicHttpBinding> 
    </bindings> 
    <client> 
    <endpoint address="https://localhost/TransportUsernameService/HelloService.svc" 
     binding="basicHttpBinding" bindingConfiguration="basicEndpoint" 
     contract="SecureServiceReference.IHelloService" name="basicEndpoint" /> 
    </client> 
</system.serviceModel> 

5.在客戶端通**憑據服務器**

HelloServiceClient client = new HelloServiceClient("basicEndpoint", 
    new EndpointAddress("https://testsecurewebservice.azurewebsites.net/HelloService.svc")); 

client.ClientCredentials.UserName.UserName = userName; 
client.ClientCredentials.UserName.Password = password; 
String msg = client.SayHello(userName); 

可能擴展程序

  • 創建/(使用ASP.Net提供或定製基)
  • 有一定的作用
  • 把一些聲明權限對等的方法管理部分用戶在這裏
[PrincipalPermission(SecurityAction.Demand, Role = "Manager")] 

完整的解決方案:http://1drv.ms/1Q5j9w0

Regards

+0

非常感謝!嘗試用天藍色的webapp上的肥皂,它似乎工作!您能否解釋一下關於使用這種解決方案的安全性的缺點? – Aleve940

+0

我在另一條消息中解釋了它:「但強烈建議您也使用一些比傳輸安全性更高的消息安全性。 傳輸(Https/SSL)可能會受到中間人攻擊(控制路由器)。 –

+0

如果你怕中間人攻擊,你應該使用wsHttpBinding和消息安全。應該有一個用於加密的X509證書。 –

1

對於認證,你可以使用:

  • 用戶名身份驗證傳遞{登錄名,密碼}。
  • X509機制識別客戶端(需要部署在客戶端上ceritificates)
  • 定製認證

對於傳輸安全,你可以使用:使用

  • 信息安全安裝了證書在服務器端
  • 傳輸安全(HTTPS)

但強烈建議您也使用一些郵件安全性而不是傳輸安全性。 傳輸(Https/SSL)可以在中間受到攻擊(控制路由器)。

信息安全的缺點是,你已經得到了服務器上安裝證書:

這是很容易安裝在Web角色的證書,你可以設置在Role.OnStart方法

  • 如果你是熱衷於一個Web應用程序,這裏是提供運輸安全性的用戶名
    (你應該跳過部分的鏈接與ASP.NET成員資格/角色提供程序,因爲你需要一個單獨的用戶和數據庫是額外的工作):

https://msdn.microsoft.com/en-us/library/ff649647.aspx

  • 如果你是熱衷於信息安全,你應該去Web角色和使用證書進行消息安全。

與信息安全進行自定義驗證鏈接:
http://www.codeproject.com/Articles/33872/Custom-Authorization-in-WCF

問候