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(",").ToList())
        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.MyCustomValidator._roles.Contains("Admin") Then
            Return (value1 + value2)
        End If
    End Function

End Class

Client

Sub Main()
       Dim client As New AddProxy.AddClient
       client.ClientCredentials.UserName.UserName = "Mike"
       client.ClientCredentials.UserName.Password = "Sam"
       Console.WriteLine("Addition 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
milani_lucieAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DarrenSenior Software EngineerCommented:
Have you looked into using SQL Server Role Provider instead.

http://msdn.microsoft.com/en-us/library/ff647040.aspx

Cheers,

Darren
0
milani_lucieAuthor Commented:
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
0
DarrenSenior Software EngineerCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
milani_lucieAuthor Commented:
Nope...That will not work. Can you please provide me another way of doing this ?

Thanks
0
milani_lucieAuthor Commented:
Provided solution will not work.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
WCF

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.