Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Web-service enforced authentication

Web-service enforced authentication

Scheduled Pinned Locked Moved Web Development
csharpjavasecurityjsontutorial
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alabax
    wrote on last edited by
    #1

    Hello! I have large Java application, which is controlled through web-services. Some functions are available for anonymous users, it works ok. Some functions are only for authenticated users. The service expects login credentials in the http request. The following .net code using System; using System.Net; class Program { static void Main(string[] args) { WebServiceX.SomeAPI api = new WebServiceX.SomeAPI.SomeAPI(); api.Credentials = new NetworkCredential("MyUserName", "MyPassword"); api.PreAuthenticate = true; api.Url = "http://mysite/myapp/api"; api.SoapVersion = System.Web.Services.Protocols.SoapProtocolVersion.Soap11; api.someMethod(parameter); } } throws an exception: System.Web.Services.Protocols.SoapException: java.rmi.RemoteException: ---omitted---: CLQAHDEBUG: Permission Denied : User anonymous does not have permission ---internal method name--- in System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClien tMessage message, WebResponse response, Stream responseStream, Boolean asyncCall ) in System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodNa me, Object[] parameters) in WebServicesConsumer2.LMSRoster.LMSRosterAPI.unrosterUsers(String[] in0) in .\WebServicesConsumer2\Web References\LMSRoster\Reference.cs:line 1 31 in WebServicesConsumer2.Program.Main(String[] args) in .\WebService sConsumer2\Program.cs:line 19 Captured communication packets do not contain any credential data. Why? How to make it work?

    A 1 Reply Last reply
    0
    • A alabax

      Hello! I have large Java application, which is controlled through web-services. Some functions are available for anonymous users, it works ok. Some functions are only for authenticated users. The service expects login credentials in the http request. The following .net code using System; using System.Net; class Program { static void Main(string[] args) { WebServiceX.SomeAPI api = new WebServiceX.SomeAPI.SomeAPI(); api.Credentials = new NetworkCredential("MyUserName", "MyPassword"); api.PreAuthenticate = true; api.Url = "http://mysite/myapp/api"; api.SoapVersion = System.Web.Services.Protocols.SoapProtocolVersion.Soap11; api.someMethod(parameter); } } throws an exception: System.Web.Services.Protocols.SoapException: java.rmi.RemoteException: ---omitted---: CLQAHDEBUG: Permission Denied : User anonymous does not have permission ---internal method name--- in System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClien tMessage message, WebResponse response, Stream responseStream, Boolean asyncCall ) in System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodNa me, Object[] parameters) in WebServicesConsumer2.LMSRoster.LMSRosterAPI.unrosterUsers(String[] in0) in .\WebServicesConsumer2\Web References\LMSRoster\Reference.cs:line 1 31 in WebServicesConsumer2.Program.Main(String[] args) in .\WebService sConsumer2\Program.cs:line 19 Captured communication packets do not contain any credential data. Why? How to make it work?

      A Offline
      A Offline
      alabax
      wrote on last edited by
      #2

      To use the http authentication one has to override the GetWebRequest function and append http authorization header as follows: using System; using System.Collections.Generic; using System.Text; using System.Web.Services.Protocols; using System.Net; namespace WindowsApplication1.WebServiceAPI { public class WebServiceAPIAuth : WebServiceAPI { public string UserName; public string Password; private string S2Base(string s) { byte [] ba; ba=Encoding.ASCII.GetBytes(s); return Convert.ToBase64String(ba); } protected override System.Net.WebRequest GetWebRequest(Uri uri) { CredentialCache cc = new CredentialCache(); WebRequest wr = base.GetWebRequest(uri); wr.Headers.Add(HttpRequestHeader.Authorization, "Basic "+S2Base(UserName+':'+Password)); return wr; } } }

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups