code_junkie

Securing a remote ajax method call

Nov 14th, 2011
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. Imports System.Web.Services.Protocols
  2. Public Class ServiceCredentials
  3.  
  4. Inherits SoapHeader
  5.  
  6. Private _userName As String
  7. Public Property UserName() As String
  8. Get
  9. Return _userName
  10. End Get
  11. Set(ByVal value As String)
  12. _userName = value
  13. End Set
  14. End Property
  15.  
  16.  
  17. Private _password As String
  18. Public Property Password() As String
  19. Get
  20. Return _password
  21. End Get
  22. Set(ByVal value As String)
  23. _password = value
  24. End Set
  25. End Property
  26.  
  27. Public Sub New()
  28.  
  29. End Sub
  30.  
  31. Public Sub NewUserInfo(ByVal ServiceUser As String, ByVal ServicePassword As String)
  32. Me.UserName = ServiceUser
  33. Me.Password = ServicePassword
  34.  
  35. End Sub
  36.  
  37. <WebMethod()> _
  38. <SoapHeader("CredentialsHeader")> _
  39. Function MyWebMethod(ByVal paremetersPassed as String)
  40. 'check permissions here
  41. If PermissionsValid(CredentialsHeader) then
  42. 'ok!
  43. .......
  44. else
  45. 'throw a permission error
  46. end if
  47. End Function
  48.  
  49. Function PermissionsValid(byval Credentials as ServiceCredentials) as boolean
  50.  
  51. 'check Credentials.Username and Credentials.Password here and return a boolean
  52. End Function
  53.  
  54. if User.IsAuthenticated
  55.  
  56. Browser <-(1)-> ASP/.NET App (`https://123.com/app`) <-(2)-> Web Service (`https://456.com/ws`)
Add Comment
Please, Sign In to add comment