简体   繁体   中英

How to add basic authentication to a Axis2 service?

I created a service with wsdl2java from Axis2 and I want to add HTTP basic authentication.

I read this document and this document from Axis2 home page but it doesn't seem to explain the server configuration. How can I configure basic authentication on server side?

I would normally host my webservices using a web server (nginx/apache) and/or a app server (tomcat) and configure the basic authentication there. You get better control, logging and monitoring options this way. Specially if you want to authenticate against a database, LDAP or active directory.

I use embeded Jetty and I deployed Axis2 war.

I added basic authentication to Jetty using the example from here with 2 small changes:

  • user and password are passed directly in the code like this:

loginService.putUser("username", Credential.getCredential("password"), new String[] {"user"});

  • the line

mapping.setPathSpec("/*");

is changed to match only my service web path so user and password will not be required for the rest of the axis interface.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM