Hi Brook,
You should add an authorization assertion to the policy assigned to the web
service.
Something like this:
<policy name="usernameTokenSecurity">
<authorization>
<allow role="SomeRole"/>
</authorization>
<usernameForCertificateSecurity establishSecurityContext="true"
renewExpiredSecurityContext="false" requireSignatureConfirmation="false"
messageProtectionOrder="SignBeforeEncryptAndEncryptSignature"
requireDerivedKeys="true" ttlInSeconds="60">
<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 />
</policy>
In this case, only the users assigned to the role "SomeRole" will able to
execute the service. The authorization assertion also supports user names
instead of roles.
Regards,
Pablo Cibraro
http://weblogs.asp.net/cibrax [quoted text, click to view] "BrookHeat" <BrookHeat@discussions.microsoft.com> wrote in message
news:075A421C-C80A-4472-A24C-A383EED83377@microsoft.com...
> Hello,
>
> I want to restrict access to an ASP.NET web service using a WS-Security
> Username and password. I'm *not* using SSL, ceretificates, Kerberos,
> Windows
> accounts, or anything of the kind. I simply want to 1) detect whether or
> not
> the <wsse:UsernameToken> element is present. If not, automatically reject
> the request. If so, check for an acceptable password.
>
> To accomplish this, I've written a custom UsernameTokenManager, which
> looks
> like this:
>
> Imports Microsoft.VisualBasic
> Imports Microsoft.Web.Services3.Security.Tokens
>
> Namespace Brook
>
> Public Class MyUserNameTokenManager
> Inherits UsernameTokenManager
> Protected Overrides Function AuthenticateToken(ByVal token As
> UsernameToken) As String
> Dim blah As String
> blah = ""
> If token.Username = "brook" Then
> blah = "monkey"
> End If
> Return blah
> End Function
> End Class
>
> End Namespace
>
> Furthermore, I have updated my web.config file with the following:
>
> <security>
> <securityTokenManager>
> <add type="Brook.MyUserNameTokenManager"
> namespace="
http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" > localName="UsernameToken" qname="wsse:UsernameToken" />
> </securityTokenManager>
> </security>
>
> Now, the good news is that this works flawlessly- a client sending a
> request
> to the service with an incorrect username/password is returned an error.
> The
> problem is that clients sending requests with *no* WS-Security information
> (just a plain old SOAP message) are allowed through.
>
> How do I configure my service to reject messages that are missing the
> <wsse:UsernameToken> security information in the soap header? I'm
> thinking
> the answer might be in the use of a policy file, but I haven't had any
> success on this front.
>
> Thanks
>
> Brook