milani_lucie
asked on
Authorization using custom roles from DB - WCF
SecurityLib.dll
Public Class MyCustomValidator
Inherits UserNamePasswordValidator
Public Shared _roles As New List(Of String)
Public Overrides Sub Validate(ByVal userName As String, ByVal password As String)
If (userName <> "Mike" OrElse password <> "Sam") Then
Throw New FaultException("Invalid Credentials !")
Else
Dim str As String = "User,Admin"
_roles.AddRange(str.Split( ",").ToLis t())
End If
End Sub
End Class
ServiceLib.dll
Public Class AddClass
Implements IAdd
Public Function AddFunc(ByVal value1 As Integer, ByVal value2 As Integer) As Integer Implements IAdd.AddFunc
If SecurityLib.MyCustomValida tor._roles .Contains( "Admin") Then
Return (value1 + value2)
End If
End Function
End Class
Client
Sub Main()
Dim client As New AddProxy.AddClient
client.ClientCredentials.U serName.Us erName = "Mike"
client.ClientCredentials.U serName.Pa ssword = "Sam"
Console.WriteLine("Additio n of two numbers = " & client.AddFunc(10, 20))
client.Close()
Console.ReadLine()
End Sub
My problem here is: I have delcared the variable (_roles) as SHARED in SECURITYLIB.dll. So it will be shared among ALL instances as it belongs to CLASS not to an instance. Now if two or more users are working on the same application, then i will lose the previous user roles values. If it is NOT a SHARED variable (_roles), then i need to create an instance of SECURITYLIB.dll which will make the variable (_roles) as "" (Empty String) or may be NULL. Also please note that in WCF security using UserName and Password
Public Overrides Sub Validate(ByVal userName As String, ByVal password As String)
will be called first before
Public Function AddFunc(ByVal value1 As Integer, ByVal value2 As Integer) As Integer Implements IAdd.AddFunc
Can you please let me know, how can i tackle this situation ?
Thanks
Public Class MyCustomValidator
Inherits UserNamePasswordValidator
Public Shared _roles As New List(Of String)
Public Overrides Sub Validate(ByVal userName As String, ByVal password As String)
If (userName <> "Mike" OrElse password <> "Sam") Then
Throw New FaultException("Invalid Credentials !")
Else
Dim str As String = "User,Admin"
_roles.AddRange(str.Split(
End If
End Sub
End Class
ServiceLib.dll
Public Class AddClass
Implements IAdd
Public Function AddFunc(ByVal value1 As Integer, ByVal value2 As Integer) As Integer Implements IAdd.AddFunc
If SecurityLib.MyCustomValida
Return (value1 + value2)
End If
End Function
End Class
Client
Sub Main()
Dim client As New AddProxy.AddClient
client.ClientCredentials.U
client.ClientCredentials.U
Console.WriteLine("Additio
client.Close()
Console.ReadLine()
End Sub
My problem here is: I have delcared the variable (_roles) as SHARED in SECURITYLIB.dll. So it will be shared among ALL instances as it belongs to CLASS not to an instance. Now if two or more users are working on the same application, then i will lose the previous user roles values. If it is NOT a SHARED variable (_roles), then i need to create an instance of SECURITYLIB.dll which will make the variable (_roles) as "" (Empty String) or may be NULL. Also please note that in WCF security using UserName and Password
Public Overrides Sub Validate(ByVal userName As String, ByVal password As String)
will be called first before
Public Function AddFunc(ByVal value1 As Integer, ByVal value2 As Integer) As Integer Implements IAdd.AddFunc
Can you please let me know, how can i tackle this situation ?
Thanks
ASKER
I am working on Console Application - Both Host and Client. Does the above URL helps :( ? BTW: I hate MSDN. You can provide me any article which can be easily understandable on this for implementation !!
Thanks
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Nope...That will not work. Can you please provide me another way of doing this ?
Thanks
Thanks
ASKER
Provided solution will not work.
http://msdn.microsoft.com/en-us/library/ff647040.aspx
Cheers,
Darren