NullSecurityContext.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #region Apache License
  2. //
  3. // Licensed to the Apache Software Foundation (ASF) under one or more
  4. // contributor license agreements. See the NOTICE file distributed with
  5. // this work for additional information regarding copyright ownership.
  6. // The ASF licenses this file to you under the Apache License, Version 2.0
  7. // (the "License"); you may not use this file except in compliance with
  8. // the License. You may obtain a copy of the License at
  9. //
  10. // http://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // Unless required by applicable law or agreed to in writing, software
  13. // distributed under the License is distributed on an "AS IS" BASIS,
  14. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. // See the License for the specific language governing permissions and
  16. // limitations under the License.
  17. //
  18. #endregion
  19. using System;
  20. using log4net.Core;
  21. namespace log4net.Util
  22. {
  23. /// <summary>
  24. /// A SecurityContext used when a SecurityContext is not required
  25. /// </summary>
  26. /// <remarks>
  27. /// <para>
  28. /// The <see cref="NullSecurityContext"/> is a no-op implementation of the
  29. /// <see cref="SecurityContext"/> base class. It is used where a <see cref="SecurityContext"/>
  30. /// is required but one has not been provided.
  31. /// </para>
  32. /// </remarks>
  33. /// <author>Nicko Cadell</author>
  34. public sealed class NullSecurityContext : SecurityContext
  35. {
  36. /// <summary>
  37. /// Singleton instance of <see cref="NullSecurityContext"/>
  38. /// </summary>
  39. /// <remarks>
  40. /// <para>
  41. /// Singleton instance of <see cref="NullSecurityContext"/>
  42. /// </para>
  43. /// </remarks>
  44. public static readonly NullSecurityContext Instance = new NullSecurityContext();
  45. /// <summary>
  46. /// Private constructor
  47. /// </summary>
  48. /// <remarks>
  49. /// <para>
  50. /// Private constructor for singleton pattern.
  51. /// </para>
  52. /// </remarks>
  53. private NullSecurityContext()
  54. {
  55. }
  56. /// <summary>
  57. /// Impersonate this SecurityContext
  58. /// </summary>
  59. /// <param name="state">State supplied by the caller</param>
  60. /// <returns><c>null</c></returns>
  61. /// <remarks>
  62. /// <para>
  63. /// No impersonation is done and <c>null</c> is always returned.
  64. /// </para>
  65. /// </remarks>
  66. public override IDisposable Impersonate(object state)
  67. {
  68. return null;
  69. }
  70. }
  71. }