Megosztás a következőn keresztül:


Útmutató: A Windows Communication Foundation biztonsági eseményeinek naplózása

A Windows Communication Foundation (WCF) lehetővé teszi a biztonsági események naplózását a Windows eseménynaplójába, amely a Windows Eseménynapló használatával tekinthető meg. Ez a témakör azt ismerteti, hogyan állíthat be egy alkalmazást úgy, hogy naplózza a biztonsági eseményeket. A WCF-naplózással kapcsolatos további információkért lásd: Naplózás.

Biztonsági események naplózása kódban

  1. Adja meg a napló helyét. Ehhez állítsa az AuditLogLocationServiceSecurityAuditBehavior osztály tulajdonságát az AuditLogLocation enumerálási értékek egyikére az alábbi kódban látható módon.

    // Create a new auditing behavior and set the log location.
    ServiceSecurityAuditBehavior newAudit =
        new ServiceSecurityAuditBehavior();
    newAudit.AuditLogLocation =
        AuditLogLocation.Application;
    
    ' Create a new auditing behavior and set the log location.
    Dim newAudit As New ServiceSecurityAuditBehavior()
    newAudit.AuditLogLocation = AuditLogLocation.Application
    

    Az AuditLogLocation enumerálás három értékkel rendelkezik: Application, Securityvagy Default. Az érték a Eseménynapló látható naplók egyikét adja meg, a biztonsági naplót vagy az alkalmazásnaplót. Ha az Default értéket használja, a tényleges napló attól függ, hogy az alkalmazás melyik operációs rendszeren fut. Ha a naplózás engedélyezve van, és nincs megadva a napló helye, az alapértelmezett az olyan Security platformok naplója, amelyek támogatják a biztonsági naplóba való írást; ellenkező esetben a Application naplóba fog írni. Alapértelmezés szerint csak a Windows Server 2003 és a Windows Vista támogatja a biztonsági naplóba való írást.

  2. Állítsa be a naplózáshoz használt eseménytípusokat. Egyszerre naplózhatja a szolgáltatásszintű eseményeket vagy az üzenetszintű engedélyezési eseményeket. Ehhez állítsa a ServiceAuthorizationAuditLevel tulajdonságot vagy a MessageAuthenticationAuditLevel tulajdonságot az AuditLevel enumerálási értékek egyikére az alábbi kódban látható módon.

    // Create a new auditing behavior and set the log location.
    ServiceSecurityAuditBehavior newAudit =
        new ServiceSecurityAuditBehavior();
    newAudit.AuditLogLocation =
        AuditLogLocation.Application;
    newAudit.MessageAuthenticationAuditLevel =
        AuditLevel.SuccessOrFailure;
    newAudit.ServiceAuthorizationAuditLevel =
        AuditLevel.SuccessOrFailure;
    
    newAudit.MessageAuthenticationAuditLevel = _
        AuditLevel.SuccessOrFailure
    newAudit.ServiceAuthorizationAuditLevel = _
        AuditLevel.SuccessOrFailure
    
  3. Adja meg, hogy el szeretné-e tiltani vagy elérhetővé tenni az alkalmazásnak a naplónaplózási eseményekkel kapcsolatos hibákat. Állítsa be a SuppressAuditFailure tulajdonságot vagy falsetrue a következő kódban látható módon.

    // Create a new auditing behavior and set the log location.
    ServiceSecurityAuditBehavior newAudit =
        new ServiceSecurityAuditBehavior();
    newAudit.AuditLogLocation =
        AuditLogLocation.Application;
    newAudit.MessageAuthenticationAuditLevel =
        AuditLevel.SuccessOrFailure;
    newAudit.ServiceAuthorizationAuditLevel =
        AuditLevel.SuccessOrFailure;
    newAudit.SuppressAuditFailure = false;
    
    newAudit.SuppressAuditFailure = False
    

    Az alapértelmezett SuppressAuditFailure tulajdonság az true, hogy a naplózás sikertelensége ne befolyásolja az alkalmazást. Ellenkező esetben a rendszer kivételt jelez. Minden sikeres naplózáshoz részletes nyomkövetést kell írni. A naplózás sikertelensége esetén a nyomkövetés hibaszinten lesz megírva.

  4. Törölje a meglévőt ServiceSecurityAuditBehavior a leírásban található viselkedések gyűjteményéből ServiceHost. A viselkedésgyűjteményt a Behaviors tulajdonság éri el, amely viszont a Description tulajdonságból érhető el. Ezután adja hozzá az újat ServiceSecurityAuditBehavior ugyanahhoz a gyűjteményhez, ahogyan az az alábbi kódban is látható.

    // Remove the old behavior and add the new.
    serviceHost.Description.
        Behaviors.Remove<ServiceSecurityAuditBehavior>();
    serviceHost.Description.Behaviors.Add(newAudit);
    
    ' Remove the old behavior and add the new.
    serviceHost.Description.Behaviors.Remove(Of ServiceSecurityAuditBehavior)
    serviceHost.Description.Behaviors.Add(newAudit)
    

Naplózás beállítása konfigurációban

  1. A naplózás konfigurációban való beállításához adjon hozzá egy <viselkedési> elemet a <web.config fájl viselkedési> szakaszához. Ezután adjon hozzá egy <serviceSecurityAudit> elemet, és állítsa be a különböző attribútumokat az alábbi példában látható módon.

    <behaviors>  
       <behavior name="myAuditBehavior">  
          <serviceSecurityAudit auditLogLocation="Application"  
                suppressAuditFailure="false"
                serviceAuthorizationAuditLevel="None"
                messageAuthenticationAuditLevel="SuccessOrFailure" />  
          </behavior>  
    </behaviors>  
    
  2. Meg kell adnia a szolgáltatás viselkedését az alábbi példában látható módon.

    <services>  
        <service type="WCS.Samples.Service.Echo"
        behaviorConfiguration=" myAuditBehavior">  
           <endpoint address=""  
                    binding="wsHttpBinding"  
                    bindingConfiguration="CertificateDefault"
                    contract="WCS.Samples.Service.IEcho" />  
        </service>  
    </services>  
    

Példa

Az alábbi kód létrehozza az ServiceHost osztály egy példányát, és hozzáad egy újat ServiceSecurityAuditBehavior a viselkedésgyűjteményéhez.

public static void Main()
{
    // Get base address from appsettings in configuration.
    Uri baseAddress = new Uri(ConfigurationManager.
        AppSettings["baseAddress"]);

    // Create a ServiceHost for the CalculatorService type
    // and provide the base address.
    using (ServiceHost serviceHost = new
        ServiceHost(typeof(CalculatorService), baseAddress))
    {
        // Create a new auditing behavior and set the log location.
        ServiceSecurityAuditBehavior newAudit =
            new ServiceSecurityAuditBehavior();
        newAudit.AuditLogLocation =
            AuditLogLocation.Application;
        newAudit.MessageAuthenticationAuditLevel =
            AuditLevel.SuccessOrFailure;
        newAudit.ServiceAuthorizationAuditLevel =
            AuditLevel.SuccessOrFailure;
        newAudit.SuppressAuditFailure = false;
        // Remove the old behavior and add the new.
        serviceHost.Description.
            Behaviors.Remove<ServiceSecurityAuditBehavior>();
        serviceHost.Description.Behaviors.Add(newAudit);
        // Open the ServiceHostBase to create listeners
        // and start listening for messages.
        serviceHost.Open();

        // The service can now be accessed.
        Console.WriteLine("The service is ready.");
        Console.WriteLine("Press <ENTER> to terminate service.");
        Console.WriteLine();
        Console.ReadLine();

        // Close the ServiceHostBase to shutdown the service.
        serviceHost.Close();
    }
}
Public Shared Sub Main()
    ' Get base address from appsettings in configuration.
    Dim baseAddress As New Uri(ConfigurationManager.AppSettings("baseAddress"))

    ' Create a ServiceHost for the CalculatorService type 
    ' and provide the base address.
    Dim serviceHost As New ServiceHost(GetType(CalculatorService), baseAddress)
    Try
        ' Create a new auditing behavior and set the log location.
        Dim newAudit As New ServiceSecurityAuditBehavior()
        newAudit.AuditLogLocation = AuditLogLocation.Application
        newAudit.MessageAuthenticationAuditLevel = _
            AuditLevel.SuccessOrFailure
        newAudit.ServiceAuthorizationAuditLevel = _
            AuditLevel.SuccessOrFailure
        newAudit.SuppressAuditFailure = False
        ' Remove the old behavior and add the new.
        serviceHost.Description.Behaviors.Remove(Of ServiceSecurityAuditBehavior)
        serviceHost.Description.Behaviors.Add(newAudit)
        ' Open the ServiceHostBase to create listeners 
        ' and start listening for messages.
        serviceHost.Open()

        ' The service can now be accessed.
        Console.WriteLine("The service is ready.")
        Console.WriteLine("Press <ENTER> to terminate service.")
        Console.WriteLine()
        Console.ReadLine()

        ' Close the ServiceHostBase to shutdown the service.
        serviceHost.Close()
    Finally
    End Try

End Sub

.NET-keretrendszer Security

Ha a tulajdonságot trueúgy SuppressAuditFailure állítja be, hogy a rendszer letiltja a biztonsági auditok létrehozásának sikertelenségét (ha be van állítvafalse, kivétel keletkezik). Ha azonban engedélyezi a következő Windows helyi biztonsági beállítás tulajdonságot, a naplózási események generálásának sikertelensége miatt a Windows azonnal leáll:

Naplózás: A rendszer azonnali leállítása, ha nem lehet naplózni a biztonsági auditokat

A tulajdonság beállításához nyissa meg a Helyi biztonsági Gépház párbeszédpanelt. A Biztonsági Gépház területen kattintson a Helyi házirendek elemre. Ezután kattintson a Biztonsági beállítások gombra.

Ha a AuditLogLocation tulajdonság be van állítva, Security és az Objektumhozzáférés naplózása nincs beállítva a Helyi biztonsági házirendben, a naplózási események nem lesznek beírva a biztonsági naplóba. Vegye figyelembe, hogy a rendszer nem ad vissza hibát, de a naplóbejegyzések nem kerülnek a biztonsági naplóba.

Lásd még