2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: CSenWsSecurityHeader represents security header functionality
15 * according to oasis wss spesifications (2004/01)
27 #ifndef SEN_WS_SECURITY_HEADER_H
28 #define SEN_WS_SECURITY_HEADER_H
31 #include <SenBaseFragment.h>
32 #include <SenSoapConstants.h>
35 // FORWARD DECLARATIONS
36 class CSenIdentityProvider;
41 * CSenWsSecurityHeader represents security header functionality according to
42 * oasis web services security (WSS) specifications (2004/01) or older (2003/06)
46 class CSenWsSecurityHeader : public CSenBaseFragment
48 public: // Constructors and destructor
51 * PasswordType Enumeration
55 EText = 1, // default, wsse:PasswordText
56 EDigest // wsse:Digest
62 * @return a pointer to new CSenWsSecurityHeader class instance.
64 IMPORT_C static CSenWsSecurityHeader* NewL();
68 * @return a new CSenWsSecurityHeader class instance, which pointer
69 * is left on cleanup stack.
71 IMPORT_C static CSenWsSecurityHeader* NewLC();
76 * @param aData Data to be set as header's content.
77 * @return a pointer to new CSenWsSecurityHeader class instance.
79 IMPORT_C static CSenWsSecurityHeader* NewL(const TDesC8& aData);
83 * @param aData Data to be set as header's content.
84 * @return a new CSenWsSecurityHeader class instance, which pointer
85 * is left on cleanup stack.
87 IMPORT_C static CSenWsSecurityHeader* NewLC(const TDesC8& aData);
91 * @param aData Data to be set as header's content.
92 * @param aSecurityNs A namespace to be set to the header.
93 * @return a pointer to new CSenWsSecurityHeader class instance.
95 IMPORT_C static CSenWsSecurityHeader* NewL(const TDesC8& aData, const TDesC8& aSecurityNs);
99 * @param aData Data to be set as header's content.
100 * @param aSecurityNs A namespace to be set to the header.
101 * @return a new CSenWsSecurityHeader class instance, which pointer
102 * is left on cleanup stack.
104 IMPORT_C static CSenWsSecurityHeader* NewLC(const TDesC8& aData, const TDesC8& aSecurityNs);
109 IMPORT_C virtual ~CSenWsSecurityHeader();
114 * Constructs a username token.
115 * @since Series60 3.0
116 * @param aIdentityProvider Identity provider which is used to get
117 * the authorization ID used in username token. Method takes the
118 * AuthzID out from aIdentityProvider, and uses it as username for
120 * Format of the token is as follows:
122 * <wsse:UsernameToken>
126 * </wsse:UsernameToken>"
128 * The above token assumes, that wsse namespace is declared in
129 * top level of the security header.
130 * @return a pointer to buffer containing the username token. Does not
131 * return NULL. Ownership is transferred to the caller. Method leaves
132 * with value KErrNotSupported, if a password type is not supported.
134 IMPORT_C HBufC8* UsernameTokenL(CSenIdentityProvider &aIdentityProvider);
137 * Constructs a username token.
138 * @since Series60 3.0
139 * @param aIdentityProvider Identity provider which is used to get
140 * the authorization ID used in username token. Method takes the
141 * AuthzID out from aIdentityProvider, and uses it as username for
142 * this token. Password is also fetched from aIdentityProvider via
143 * calling Password() getter, which must return a Base64 [XML-Schema]
144 * encoded, SHA-1 hash value, of the UTF8 encoded password.
145 * @param aType Specifies the type of the password, either
146 * wsse:PasswordText or wsse:PasswordDigest
148 * Format of the token is as follows (if password type is wsse:PasswordText):
150 * <wsse:UsernameToken>
157 * </wsse:UsernameToken>"
159 * If the password type is wsse:Password:Digest, then the password element
160 * will be declared as follows:
162 * <wsse:Password Type="wsse:PasswordDigest">
164 * The above token assumes, that wsse namespace is declared in
165 * top level of the security header.
166 * @return a pointer to buffer containing the username token. Does not
167 * return NULL. Ownership is transferred to the caller. Method leaves
168 * with value KErrNotSupported, if a password type is not supported.
170 IMPORT_C HBufC8* UsernameTokenL(CSenIdentityProvider &aIdentityProvider,
171 CSenWsSecurityHeader::TPasswordType aType);
176 * Constructs a username token. This method does not add the <Password>
177 * element, since it is optional for basic username tokens.
178 * @since Series60 3.0
179 * @param aUsername User name which is used in the username
181 * @param aToken Ref-to-pointer where the token will be
182 * allocated. Shouldn't contain any data when
183 * called, or that data will be lost.
184 * @return KErrNone or some system-wide Symbian error code.
186 IMPORT_C static TInt UsernameTokenL(const TDesC8& aUsername,
190 * Constructs a username token using a password, too.
191 * @since Series60 5.0
192 * @param aUsername User name which is to be used in new token.
193 * @param aPassword Password which is to be use in new token.
194 * The type will be set to default: wsse:PasswordDigest,
195 * defined in KSecurityAttrTypeText. This is
196 * a Base64 [XML-Schema] encoded, SHA-1 hash value,
197 * of the UTF8 encoded password.
198 * @param aToken Ref-to-pointer in which the token will be
199 * allocated. Shouldn't contain any data when
200 * called, or that data will be lost.
201 * @return KErrNone or some system-wide Symbian error code.
203 IMPORT_C static TInt UsernameTokenL(const TDesC8& aUsername,
204 const TDesC8& aPassword,
208 * Constructs a username token using a password, too.
209 * @since Series60 5.0
210 * @param aUsername User name which is to be used in new token.
211 * @param aPassword Password which is to be use in new token
212 * This is a Base64 [XML-Schema] encoded, SHA-1
213 * hash value, of the UTF8 encoded password.
214 * @param aType Specifies the type of the password:
215 * - EText, being default refers to wsse:PasswordText,
216 * but this method does not add this, since it can
218 * - EDigest: will add wsse:PasswordDigest attribute
219 * to the <Password> -element, as in here:
221 * <wsse:UsernameToken>
225 * <wsse:Password Type="wsse:PasswordDigest">
228 * </wsse:UsernameToken>"
230 * @param aToken Ref-to-pointer where the token will be
231 * allocated. Shouldn't contain any data when
232 * called, or that data will be lost.
233 * @return KErrNone or some system-wide Symbian error code.
235 IMPORT_C static TInt UsernameTokenL(const TDesC8& aUsername,
236 const TDesC8& aPassword,
237 CSenWsSecurityHeader::TPasswordType aType,
242 * Constructs a BinarySecurityToken.
243 * @since Series60 5.0
245 * @param aContent Encoded EncryptedData which is to be used in token.
246 * @param aToken Ref-to-pointer where the token will be
247 * allocated. Shouldn't contain any data when
248 * called, or that data will be lost.
249 * @return KErrNone or some system-wide Symbian error code.
251 IMPORT_C static TInt BinarySecurityTokenL(const TDesC8& aContent,
254 * Constructs a BinarySecurityToken.
255 * @since Series60 5.0
257 * @param aContent Encoded EncryptedData which is to be used in token.
258 * @param aValueType Indicates what the security token is
259 * @param aToken Ref-to-pointer where the token will be
260 * allocated. Shouldn't contain any data when
261 * called, or that data will be lost.
262 * @return KErrNone or some system-wide Symbian error code.
264 IMPORT_C static TInt BinarySecurityTokenL(const TDesC8& aContent,
265 const TDesC8& aValueType,
269 * Constructs a timestamp.
270 * @since Series60 5.0
271 * Format of the timestamp is as follows:
272 * <wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
273 * <wsu:Created>2001-09-13T08:42:00Z</wsu:Created>
274 * <wsu:Expires>2002-09-13T08:42:00Z</wsu:Expires>
276 * The wsu namespace is declared inside this element.
277 * Based on chapter 10 from WS-Security 2004
278 * @param aCreated - creation time of token
279 * @param aExpires - end of validation time for token
280 * @param aTimestamp - a pointer to buffer containing the timestamp. Does not
281 * return NULL. Ownership is transferred to the caller.
282 * @return KErrNone or some system-wide Symbian error code.
284 IMPORT_C static TInt TimestampL(const TDesC8& aCreated, const TDesC8& aExpires, HBufC8*& aTimestamp);
287 * Constructs a timestamp.
288 * @since Series60 5.0
289 * Format of the timestamp is as follows:
290 * <wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
291 * <wsu:Created>2001-09-13T08:42:00Z</wsu:Created>
293 * The wsu namespace is declared inside this element.
294 * Based on chapter 10 from WS-Security 2004
295 * @param aCreated - creation time of token
296 * @param aTimestamp - a pointer to buffer containing the timestamp. Does not
297 * return NULL. Ownership is transferred to the caller.
298 * @return KErrNone or some system-wide Symbian error code.
300 IMPORT_C static TInt TimestampL(const TDesC8& aCreated, HBufC8*& aTimestamp);
303 * Constructs a security token reference.
304 * @since Series60 5.0
305 * Format of the token reference is as follows:
306 * <wsse:SecurityTokenReference wsu:Id="...">
307 * <wsse:Reference URI="..."/>
308 * </wsse:SecurityTokenReference>
310 * The above token assumes, that wsse namespace is declared in
311 * top level of the security header.
313 * @param aSTR - a pointer to buffer containing the token reference. Does not
314 * return NULL. Ownership is transferred to the caller.
315 * @return KErrNone or some system-wide Symbian error code.
317 // IMPORT_C static TInt SecurityTokenReferenceL(const TDesC8& aURI, HBufC8*& aSTR);
322 /** Basic getter for XML namespace of the WS security header.
323 * Subclasses should override this to use different namespace
324 * @since Series60 3.0
325 * @return the WS security header namespace as string
327 IMPORT_C virtual TPtrC8 XmlNs();
330 * Basic getter for XML namespace prefix of the WS security header.
331 * Subclasses should override this to use different namespace prefix
332 * @since Series60 3.0
333 * @return the WS security header namespace prefix as string
335 IMPORT_C virtual TPtrC8 XmlNsPrefix();
340 * C++ default constructor
342 IMPORT_C CSenWsSecurityHeader();
345 * Basic BaseConstructL function
347 IMPORT_C void BaseConstructL();
349 // Functions from base classes
352 * From CSenBaseFragment Basic BaseConstructL function
353 * @since Series60 3.0
354 * @param aData will be used as current token (content) of this security
357 IMPORT_C void BaseConstructL(const TDesC8& aData);
358 IMPORT_C void BaseConstructL(const TDesC8& aData, const TDesC8& aSecurityNs);
361 #endif // SEN_WS_SECURITY_HEADER_H