Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

Here's how to add basic HTTP authentication to a Weblogic web service. I've had to do this recently at work and was a little confused at how the role-name, principal-name, etc were related so decided to add this as a note for the future and for anyone else who may be interested.

There are two deployment descriptor files that need modification to add authentication. These are web.xml and weblogic.xml.

The web.xml defines the majority of the configuration. Simply add something like this to it:
 web.xml
...
<security-constraint>
<web-resource-collection>
<web-resource-name>Access to the entire application</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>MyUsers</role-name>
</auth-constraint>
<user-data-constraint>
<description>SSL not required</description>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>default</realm-name>
</login-config>
<security-role>
<role-name>MyUsers</role-name>
</security-role>
...




This sets up authentication for the entire web app without requiring SSL. The role name used is MyUsers, this is just a reference to the actual role that is defined inside the weblogic.xml file.

The next bit of configuration is inside the weblogic.xml file. This is where the role name is connected to the actual principal that may be used to authenticate the web service.
 weblogic.xml
...
<security-role-assignment>
<role-name>MyUsers</role-name>
<principal-name>weblogicuser</principal-name>
</security-role-assignment>
...


This connects the MyUsers role defined in the web.xml to the Weblogic user named weblogicuser. In place of a user, a group can be used too.

The users/groups are defined inside Weblogic under your realm configuration:
wlssecroles.png


That's all there is to it. The web service will now require authentication before any requests are served.

-i

A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
Hi! You can search my blog here ⤵
NOTE: (2022) This Blog is no longer maintained and I will not be answering any emails or comments.

I am now focusing on Atari Gamer.