IdAuthenticationManager.pas 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. { $HDR$}
  2. {**********************************************************************}
  3. { Unit archived using Team Coherence }
  4. { Team Coherence is Copyright 2002 by Quality Software Components }
  5. { }
  6. { For further information / comments, visit our WEB site at }
  7. { http://www.TeamCoherence.com }
  8. {**********************************************************************}
  9. {}
  10. { $Log: 10075: IdAuthenticationManager.pas
  11. {
  12. { Rev 1.0 2002.11.12 10:30:58 PM czhower
  13. }
  14. unit IdAuthenticationManager;
  15. interface
  16. Uses
  17. Classes, SysUtils, IdAuthentication, IdURI, IdGlobal, IdBaseComponent;
  18. Type
  19. TIdAuthenticationItem = class(TCollectionItem)
  20. protected
  21. FURI: TIdURI;
  22. FParams: TStringList;
  23. procedure SetParams(const Value: TStringList);
  24. procedure SetURI(const Value: TIdURI);
  25. public
  26. constructor Create(ACollection: TCOllection); override;
  27. destructor Destroy; override;
  28. property URL: TIdURI read FURI write SetURI;
  29. property Params: TStringList read FParams write SetParams;
  30. end;
  31. TIdAuthenticationCollection = class(TOwnedCollection)
  32. protected
  33. function GetAuthItem(AIndex: Integer): TIdAuthenticationItem;
  34. procedure SetAuthItem(AIndex: Integer;
  35. const Value: TIdAuthenticationItem);
  36. public
  37. constructor Create(AOwner: Tpersistent);
  38. function Add: TIdAuthenticationItem;
  39. property Items[AIndex: Integer]: TIdAuthenticationItem read GetAuthItem write SetAuthItem;
  40. end;
  41. TIdAuthenticationManager = class(TIdBaseComponent)
  42. protected
  43. FAuthentications: TIdAuthenticationCollection;
  44. public
  45. constructor Create(AOwner: TComponent); override;
  46. destructor Destroy; override;
  47. procedure AddAuthentication(AAuthtetication: TIdAuthentication; AURL: TIdURI);
  48. property Authentications: TIdAuthenticationCollection read FAuthentications;
  49. end;
  50. implementation
  51. { TIdAuthenticationManager }
  52. function TIdAuthenticationCollection.Add: TIdAuthenticationItem;
  53. begin
  54. result := TIdAuthenticationItem.Create(self);
  55. end;
  56. constructor TIdAuthenticationCollection.Create(AOwner: Tpersistent);
  57. begin
  58. inherited Create(AOwner, TIdAuthenticationItem);
  59. end;
  60. function TIdAuthenticationCollection.GetAuthItem(
  61. AIndex: Integer): TIdAuthenticationItem;
  62. begin
  63. result := TIdAuthenticationItem(inherited Items[AIndex]);
  64. end;
  65. procedure TIdAuthenticationCollection.SetAuthItem(AIndex: Integer;
  66. const Value: TIdAuthenticationItem);
  67. begin
  68. if Items[AIndex] <> nil then begin
  69. Items[AIndex].Assign(Value);
  70. end;
  71. end;
  72. { TIdAuthenticationManager }
  73. procedure TIdAuthenticationManager.AddAuthentication(
  74. AAuthtetication: TIdAuthentication; AURL: TIdURI);
  75. begin
  76. with Authentications.Add do begin
  77. URL.URI := AURL.URI;
  78. Params.Assign(AAuthtetication.Params);
  79. end;
  80. end;
  81. constructor TIdAuthenticationManager.Create(AOwner: TComponent);
  82. begin
  83. inherited Create(AOwner);
  84. FAuthentications := TIdAuthenticationCollection.Create(self);
  85. end;
  86. destructor TIdAuthenticationManager.Destroy;
  87. begin
  88. FreeAndNil(FAuthentications);
  89. inherited Destroy;
  90. end;
  91. { TIdAuthenticationItem }
  92. constructor TIdAuthenticationItem.Create(ACollection: TCOllection);
  93. begin
  94. inherited Create(ACollection);
  95. FURI := TIdURI.Create;
  96. FParams := TStringList.Create;
  97. end;
  98. destructor TIdAuthenticationItem.Destroy;
  99. begin
  100. FreeAndNil(FURI);
  101. FreeAndNil(FParams);
  102. inherited Destroy;
  103. end;
  104. procedure TIdAuthenticationItem.SetParams(const Value: TStringList);
  105. begin
  106. FParams.Assign(Value);
  107. end;
  108. procedure TIdAuthenticationItem.SetURI(const Value: TIdURI);
  109. begin
  110. FURI.URI := Value.URI;
  111. end;
  112. end.