all groups > dotnet web services enhancements > february 2006 >
You're in the

dotnet web services enhancements

group:

who can give me a e.g using Customer UsernameToken


who can give me a e.g using Customer UsernameToken Alan
2/21/2006 6:49:27 AM
dotnet web services enhancements:
I just wanna use Customer UsernameToken to verify the username in my SQL
Re: who can give me a e.g using Customer UsernameToken Pablo Cibraro
2/21/2006 2:41:52 PM
Hi Alan,

The WSSP project in GDN contains some samples that show how to do that.
http://www.gotdotnet.com/codegallery/codegallery.aspx?id=67f659f6-9457-4860-80ff-0535dffed5e6
Take a look the sample called "DirectAuthentication - Database".

Regards,
Pablo Cibraro
http://weblogs.asp.net/cibrax

[quoted text, click to view]

Re: who can give me a e.g using Customer UsernameToken Alan
2/21/2006 3:53:27 PM
Pablo ,
if i wanna not direct authentication, what should i do?
I just take a try write a customerUserNameTokenManager base on the demo
of Hands-on WSE3.0 "Security\CS\Basic\Part3" . I want to authorize the user
from the client through the username and check it's role in my own App.
so, the CustomUsernameTokenManager.cs is:
public class CustomUsernameTokenManager : UsernameTokenManager
{
/// <summary>
/// Constructs an instance of this security token manager.
/// </summary>
public CustomUsernameTokenManager()
{
}
protected override string AuthenticateToken( UsernameToken token )
{
bool valid = MyApp.ValidateUser(token.Username, token.Password);
if (!valid)
{
throw new ApplicationException("Invalid user");
}
....
return token.Password;
}
}

is it right?
can you give me a demo about it , especialy the policy config, thanks
[quoted text, click to view]
Re: who can give me a e.g using Customer UsernameToken Alan
2/22/2006 6:31:28 AM
sorry, I am just a beginner in WSE
after i follow your step my wse3policyCache.config is
....
<policy name="MyClientPolicy">
<usernameOverTransportSecurity />
<usernameForCertificateSecurity establishSecurityContext="false"
renewExpiredSecurityContext="true" requireSignatureConfirmation="false"
messageProtectionOrder="SignBeforeEncrypt" requireDerivedKeys="true"
ttlInSeconds="300">
<serviceToken>
<x509 storeLocation="CurrentUser" storeName="AddressBook"
findValue="CN=WSE2QuickStartServer" findType="FindBySubjectDistinguishedName"
/>
</serviceToken>
<protection>
<request signatureOptions="IncludeAddressing, IncludeTimestamp,
IncludeSoapBody" encryptBody="true" />
<response signatureOptions="IncludeAddressing, IncludeTimestamp,
IncludeSoapBody" encryptBody="true" />
<fault signatureOptions="IncludeAddressing, IncludeTimestamp,
IncludeSoapBody" encryptBody="false" />
</protection>
</usernameForCertificateSecurity>
<requireActionHeader />
</policy>
.....
and the Web.config
.....
<microsoft.web.services3>
<diagnostics>
<trace enabled="true" input="InputTrace.webinfo"
output="OutputTrace.webinfo" />
</diagnostics>
<tokenIssuer>
<statefulSecurityContextToken enabled="true" />
</tokenIssuer>
<security>
<securityTokenManager>
<add
type="Microsoft.Web.Services3.QuickStart.CustomUsernameTokenManager"
namespace="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" localName="UsernameToken" />
</securityTokenManager>

<x509 allowTestRoot="true" />
</security>
<policy fileName="wse3policyCache.config" />
</microsoft.web.services3>
.....
then i get a fault:
<faultstring>Microsoft.Web.Services3.Security.SecurityFault: Security
requirements are not satisfied because the security header is not present in
the incoming message.
at
Microsoft.Web.Services3.Design.UsernameOverTransportAssertion.ServiceInputFilter.ValidateMessageSecurity(SoapEnvelope envelope, Security security)
at
Microsoft.Web.Services3.Security.ReceiveSecurityFilter.ProcessMessage(SoapEnvelope envelope)
......
how can i do? help me please
[quoted text, click to view]
Re: who can give me a e.g using Customer UsernameToken Pablo Cibraro
2/22/2006 10:21:52 AM
Yes, it is right. Then, you have to configure a policy assertion and your
CustomUsernameTokenManager for the service.

The Policy should look like this (UsernameOverTransport):

<policies xmlns="http://schemas.microsoft.com/wse/2005/06/policy">
<policy name="MyServicePolicy">
<usernameOverTransportSecurity />
</policy>
</policies>

Configuration for the custom username token manager (Web.config):

<microsoft.web.services3>
<security>
<securityTokenManager>
<add
type="Microsoft.Web.Services3.Security.Tokens.UsernameTokenManager,
Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"
namespace="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
localName="UsernameToken" />
</securityTokenManager>
</security>
<policy fileName="wse3policyCache.config" />
</microsoft.web.services3>

Finally, you have to assign the policy to your service:

[Policy("MyServicePolicy")]
public class MyWebService : WebService
{
//Web service code
}

Does this answer your question ?.

Regards,
Pablo Cibraro
http://weblogs.asp.net/cibrax

[quoted text, click to view]

Re: who can give me a e.g using Customer UsernameToken Pablo Cibraro
2/22/2006 1:18:22 PM
Hi Alan,

The error is happening because you are using different policies on the
client and the service.

You should use the policies below on the client and the service

Client (wse3policyCache.config )

<policies xmlns="http://schemas.microsoft.com/wse/2005/06/policy">
<policy name="ClientPolicy">
<usernameOverTransportSecurity />
</policy>
</policies>

Service (wse3policyCache.config )

<policies xmlns="http://schemas.microsoft.com/wse/2005/06/policy">
<policy name="ServicePolicy">
<usernameOverTransportSecurity />
</policy>
</policies>

Your web.config file is ok.

Remember to assign the policy in the service and the proxy by means of the
"Policy" attribute.

Code for the client application:

UsernameToken token = new UsernameToken("MyUser", "MyPass");
WsProxy proxy = new WsProxy();

proxy.SetPolicy("ClientPolicy");
proxy.SetClientCredential(token);

proxy.SomeMethod();

Code for the service

[Policy("ServicePolicy")]
public class MyService : WebService
{
[WebMethod()]
public void SomeMethod()
{
}
}

Regards,
Pablo.

[quoted text, click to view]

Re: who can give me a e.g using Customer UsernameToken Alan
2/22/2006 7:24:26 PM
thanks Pablo
if i only use the customerUsernameToken, it worked well
but i have a problem
[quoted text, click to view]
other policy
in the server policy:

<policy name="ServicePolicy">
<usernameForCertificateSecurity establishSecurityContext="false"
renewExpiredSecurityContext="true" requireSignatureConfirmation="false"
messageProtectionOrder="SignBeforeEncrypt" requireDerivedKeys="true"
ttlInSeconds="300">
<serviceToken>
<x509 storeLocation="LocalMachine" storeName="My"
findValue="CN=WSE2QuickStartServer" findType="FindBySubjectDistinguishedName"
/>
</serviceToken>
<protection>
<request signatureOptions="IncludeAddressing, IncludeTimestamp,
IncludeSoapBody" encryptBody="true" />
<response signatureOptions="IncludeAddressing, IncludeTimestamp,
IncludeSoapBody" encryptBody="true" />
<fault signatureOptions="IncludeAddressing, IncludeTimestamp,
IncludeSoapBody" encryptBody="false" />
</protection>
</usernameForCertificateSecurity>
<requireActionHeader />
<usernameOverTransportSecurity />
</policy>
and the client is
<policy name="ClientPolicy">
<usernameForCertificateSecurity establishSecurityContext="false"
renewExpiredSecurityContext="true" requireSignatureConfirmation="false"
messageProtectionOrder="SignBeforeEncrypt" requireDerivedKeys="true"
ttlInSeconds="300">
<serviceToken>
<x509 storeLocation="CurrentUser" storeName="AddressBook"
findValue="CN=WSE2QuickStartServer" findType="FindBySubjectDistinguishedName"
/>
</serviceToken>
<protection>
<request signatureOptions="IncludeAddressing, IncludeTimestamp,
IncludeSoapBody" encryptBody="true" />
<response signatureOptions="IncludeAddressing, IncludeTimestamp,
IncludeSoapBody" encryptBody="true" />
<fault signatureOptions="IncludeAddressing, IncludeTimestamp,
IncludeSoapBody" encryptBody="false" />
</protection>
</usernameForCertificateSecurity>
<requireActionHeader />
<usernameOverTransportSecurity />
</policy>
and then i got a mistake:
<faultcode
xmlns:q0="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">q0:InvalidSecurity</faultcode>
<faultstring>Microsoft.Web.Services3.Security.SecurityFault: An
error was discovered processing the <Security> header --->
System.Security.Cryptography.CryptographicException: WSE009: The input was
not a valid SOAP message because it had more than one element with the
following ID value: SecurityToken-385d18a3-1c78-49c4-b152-d90cd4fcae79.
at
Microsoft.Web.Services3.Security.MessageSignature.FindIdElements(XmlElement
element)
at
Microsoft.Web.Services3.Security.MessageSignature.FindIdElements(XmlElement
element)
...
how to solve this problem or can i use other method to encrypt with
Re: who can give me a e.g using Customer UsernameToken Hans
3/6/2006 11:16:27 PM
Hi Pablo,

its working fine for me,
but my doubt is, how is it possible to set the policy if the client is other
than .NET application or .NET applicaion having framework which is less than
2.0?

Give me some suggestion since in my case the consumer of my web service can
be anybody.


[quoted text, click to view]
AddThis Social Bookmark Button