powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Delphi [игнор отключен] [закрыт для гостей] / SOAP WS-Security
7 сообщений из 7, страница 1 из 1
SOAP WS-Security
    #39522048
rgreat
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Как заставить это работать?

Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
<soapenv:Envelope xmlns:ser="http://service.dao.kasant_cusi.kasant.niias.org/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Header>
    <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"  xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <wsse:UsernameToken wsu:Id="UsernameToken-3F862F7046BBBE999E15054850043811">
    <wsse:Username>xxxx</wsse:Username>
    <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">xxxx</wsse:Password>
    <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">CxAcZvjTCNo+6e3Syc8E5w==</wsse:Nonce>
    <wsu:Created>2017-09-15T14:16:44.380Z</wsu:Created>
    </wsse:UsernameToken></wsse:Security>
   </soapenv:Header>
   <soapenv:Body>
      <ser:getDataViol>
         <date>2017-07-07</date>
      </ser:getDataViol>
   </soapenv:Body>
</soapenv:Envelope>"


Через SoapUI работает.

Как попробую на дельфях (что с помощью левого WSSE.pas что просто подменой траффика) - хрен там.
Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
  <soap:Fault>
    <faultcode xmlns:ns1="http://ws.apache.org/wss4j">ns1:SecurityError</faultcode>
      <faultstring>A security error was encountered when verifying the message</faultstring>
    </soap:Fault>
  </soap:Body>
</soap:Envelope>
...
Рейтинг: 0 / 0
SOAP WS-Security
    #39522084
sql2012
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
rgreat,

ошибка в 17 строке
...
Рейтинг: 0 / 0
SOAP WS-Security
    #39522116
rgreat
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Вот и я вижу что в 17-й.... :(
...
Рейтинг: 0 / 0
SOAP WS-Security
    #39522193
Фотография _Vasilisk_
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
rgreat,

Отправляешь одно и тоже сообщение? Идентичные, с точностью до байта?
...
Рейтинг: 0 / 0
SOAP WS-Security
    #39526035
Фотография X-Cite
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
http://www.sql.ru/forum/1244434/klient-web-servisa-s-avtorizaciey

Для soap header`ов надо самому писать классы сериализации в soap
Например уже есть готовый WSSE
...
Рейтинг: 0 / 0
SOAP WS-Security
    #39526036
Фотография X-Cite
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
HTTPRIO имеет событие Before где передается Stream, который сохранив в файл увидите что у вас передается.
...
Рейтинг: 0 / 0
SOAP WS-Security
    #39527285
rgreat
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
В общем кое-как разобрался.

Юнит WSSE.pas.
Код: pascal
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
unit WSSE;

interface

uses
  System.SysUtils,
  Soap.InvokeRegistry,
  Soap.SOAPHTTPClient,
  System.Types,
  Soap.XSBuiltIns,
  Xml.XMLIntf;

const
  IS_OPTN=$0001;
  IS_ATTR=$0010;
  IS_TEXT=$0020;
  IS_REF =$0080;
  IS_QUAL=$0100;

  NS_SECEXT = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
  NS_UTILITY = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';

type
  tTimestampFault=(wsu_MessageExpired);

  Id = type WideString;

  Created=class(TXSDateTime)
  end;

  Expires=class(TXSDateTime)
  end;

  Timestamp=class(TRemotable)
  private
    FCreated:Created;
    FExpires:Expires;
    FId: Id;
  public
    destructor Destroy; override;
  published
    property Created:Created Index (IS_OPTN) read FCreated write FCreated;
    property Expires:Expires Index (IS_OPTN) read FExpires write FExpires;
    property Id:Id Index (IS_ATTR or IS_QUAL) read FId write FId;
  end;

  AttributedString=class(TRemotable)
  private
    FText:WideString;
    FId:Id;
    FId_Specified:boolean;
    procedure SetId(Index:Integer; const AId:Id);
    function Id_Specified(Index:Integer):boolean;
  published
    property Text:WideString Index (IS_TEXT) read FText write FText;
    property Id:Id Index (IS_ATTR or IS_OPTN or IS_QUAL) read FId write SetId stored Id_Specified;
  end;

  Nonce=class(AttributedString)
  private
    FEncodingType: WideString;
    FEncodingType_Specified:boolean;
    procedure SetEncodingType(Index:Integer; const AWideString:WideString);
    function EncodingType_Specified(Index:Integer):boolean;
  published
    property EncodingType:WideString Index (IS_ATTR or IS_OPTN) read FEncodingType write SetEncodingType stored EncodingType_Specified;
  end;

  Password=class(AttributedString)
  private
    FType_:WideString;
    FType__Specified:boolean;
    procedure SetType_(Index:Integer; const AWideString:WideString);
    function Type__Specified(Index:Integer):boolean;
  published
    property Type_:WideString Index (IS_ATTR or IS_OPTN) read FType_ write SetType_ stored Type__Specified;
  end;

  UsernameToken=class(TRemotable)
  private
    FUserName:string;
    FCreated:Created;
    FPassword:Password;
    FNonce: Nonce;
    FId: Id;
  public
    destructor Destroy; override;
    function   ObjectToSOAP(RootNode, ParentNode: IXMLNode;
                            const ObjConverter: IObjConverter;
                            const NodeName, NodeNamespace, ChildNamespace: InvString; ObjConvOpts: TObjectConvertOptions;
                            out RefID: InvString): IXMLNode; override;
    property Id:Id Index (IS_ATTR or IS_QUAL) read FId write FId;
  published
    property Username:String read FUsername write FUsername;
    property Password:Password read FPassword write FPassword;
//    property Nonce: Nonce read FNonce write FNonce;
//    property Created:Created index (IS_REF) read FCreated write FCreated;
  end;

  Security=class(TSOAPHeader)
  private
    FTimestamp:Timestamp;
    FUserNameToken:UserNameToken;
  public
    destructor Destroy; override;
  published
    property Timestamp:TimeStamp index (IS_REF) read FTimestamp write FTimestamp;
    property UsernameToken:UsernameToken index (IS_REF) read FUserNameToken write FUserNameToken;
  end;

procedure AddSoapHeaderSecurity(aService: IInvokable; aUserName, aPassword: string);


implementation


procedure AddSoapHeaderSecurity(aService: IInvokable; aUserName, aPassword: string);
var
  Wsse: Security;
  Headers: ISOAPHeaders;
begin
  Wsse:=Security.Create;
  Wsse.MustUnderstand:=True;
  Wsse.UsernameToken:=UsernameToken.Create;
  Wsse.UsernameToken.Id:=TGuid.NewGuid.ToString;
  Wsse.UsernameToken.Username:=aUserName;
  Wsse.UsernameToken.Password:=Password.Create;
  Wsse.UsernameToken.Password.Type_:='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText';
  Wsse.UsernameToken.Password.Text:=aPassword;
  Wsse.Timestamp:=Timestamp.Create;
  Wsse.Timestamp.Created:=Created.Create;
  Wsse.Timestamp.Created.AsDateTime:=Now-1/24/60;
  Wsse.Timestamp.Expires:=Expires.Create;
  Wsse.Timestamp.Expires.AsDateTime:=Now+5/24/60;

  Headers:=aService as ISOAPHeaders;
  Headers.OwnsSentHeaders:=True;
  Headers.Send(Wsse);
end;

destructor Timestamp.Destroy;
begin
  FreeAndNIL(FCreated);
  FreeAndNIL(FExpires);
  inherited Destroy;
end;

destructor UsernameToken.Destroy;
begin
  FreeAndNil(FCreated);
  FreeAndNil(FPassword);
  FreeAndNil(FNonce);
  inherited Destroy;
end;

function UsernameToken.ObjectToSOAP(RootNode, ParentNode: IXMLNode;
  const ObjConverter: IObjConverter; const NodeName, NodeNamespace,
  ChildNamespace: InvString; ObjConvOpts: TObjectConvertOptions;
  out RefID: InvString): IXMLNode;
begin
  Result := inherited;
  if (Result <> nil) and (Length(FId) > 0) then
  begin
    Result.DeclareNamespace('wsu', NS_UTILITY);
    Result.SetAttributeNS('Id', NS_UTILITY, FId);
  end;
end;

procedure AttributedString.SetId(Index:Integer; const AId:Id);
begin
  FId:=AId;
  FId_Specified:=True;
end;

function AttributedString.Id_Specified(Index:Integer):boolean;
begin
  Result:=FId_Specified;
end;

procedure Password.SetType_(Index:Integer; const AWideString:WideString);
begin
  FType_:=AWideString;
  FType__Specified:=True;
end;

function Password.Type__Specified(Index:Integer):boolean;
begin
  Result:=FType__Specified;
end;

procedure Nonce.SetEncodingType(Index:Integer; const AWideString:WideString);
begin
  FEncodingType:=AWideString;
  FEncodingType_Specified:=True;
end;

function Nonce.EncodingType_Specified(Index:Integer):boolean;
begin
  Result:=FEncodingType_Specified;
end;

destructor Security.Destroy;
begin
  FreeAndNIL(FTimestamp);
  FreeAndNIL(FUserNameToken);
  inherited Destroy;
end;

initialization
  RemClassRegistry.RegisterXSClass(Security, NS_SECEXT, 'Security');
  RemClassRegistry.RegisterXSClass(Timestamp, NS_UTILITY, 'Timestamp');
  RemClassRegistry.RegisterXSClass(Created, NS_UTILITY, 'Created');
  RemClassRegistry.RegisterXSClass(Expires, NS_UTILITY, 'Expires');
  RemClassRegistry.RegisterXSClass(UsernameToken, NS_SECEXT, 'UsernameToken');
  RemClassRegistry.RegisterXSClass(Password, NS_SECEXT, 'Password');
  RemClassRegistry.RegisterXSInfo(TypeInfo(Nonce), NS_SECEXT, 'Nonce');
  RemClassRegistry.RegisterXSInfo(TypeInfo(tTimestampFault), NS_UTILITY, 'tTimestampFault');
  RemClassRegistry.RegisterExternalPropName(TypeInfo(tTimestampFault), 'wsu_MessageExpired', 'wsu:MessageExpired');
  RemClassRegistry.RegisterXSInfo(TypeInfo(Id), NS_UTILITY, 'Id');
  RemClassRegistry.RegisterXSClass(AttributedString, NS_SECEXT, 'AttributedString');
  RemClassRegistry.RegisterExternalPropName(TypeInfo(Password), 'Type_', 'Type');
end.



Использование:
Код: pascal
1.
2.
3.
4.
5.
6.
7.
uses WSSE;

var
  WS: MyWebService;
begin
  WS:=GetMyWebService;
  AddSoapHeaderSecurity(WS,'user','password');

...
Рейтинг: 0 / 0
7 сообщений из 7, страница 1 из 1
Форумы / Delphi [игнор отключен] [закрыт для гостей] / SOAP WS-Security
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]