How to implement Web Application Basic Authentication in Weblogic

You can easily setup the Basic Authentication in Weblogic by using this post. I assume you are having basic knowledge about JEE. If yes, then you just need to configure Group and User in Weblogic Admin console, and modify the web.xml and weblogic.xml files in WEB-INF folder. That's it. You are done and your application resources are secured.
Lets perform the two activities - Weblogic Configuration and Web Application Configuration:
  1. Weblogic Configuration (You may use existing users and groups and move to next activity)
    • Use the following steps:
    1. Login to Weblogic Admin console and go to Security Realms > [myrealm] >Users and Groups (tab) 
    2. Select Groups tab in second tab row
    3. Click on new button
    4. Fill the required fields (Group: testGroup etc) and click on Ok to create the group. (Keep the DefaultAuthenticator as provider)
    5. Now similarly, create the test user by clicking the new button on Users tab. (Keep the DefaultAuthenticator as provider)
    6. Now we need to associate the test user with newly created group testGroup. Go to the users list on Users tab.
    7. Click on the newly created user test
    8. Click on Groups tab.
    9. Select the testGroup and click on Save to complete the steps.
  2. Web Application Configuration
    • In Web.xml
    • <security-constraint>
            <web-resource-name>Secure Page</web-resource-name>
      • security-constraint tag contains the resource information like Name and URL patterns and which role can access that information using auth-constraint tag. As you can see I have given name Secure Page and secured all the pages under /securepages directory/context. You can give any name to the role that would have the access to resources defined in URL patterns. This name is an identifier only nothing to do with group we created in above activity. But later we need to map it with actual weblogic group.
      • login-config tag describes what method we are going to use for authentication or how the login form would appear. Here we are using the BASIC, similarly for form-authentication you can use FORM. In Admin console you can check or config which realm you want to use. Same we need to set in realm-name tag
      • You know we have given role in auth-constaint, same we need to declare in web.xml. So in short, we use security-role tag for role declaration.
    • In weblogic.xml
    • <security-role-assignment>
      • weblogic.xml is also part of WEB-INF directory. Since we have defined the resources to be secured, role that can access them, BASIC authentication method and role declaration the only part remains to map the declared role with weblogic group or individual user. That is done using setting weblogic group in principal-name and declared role in role-name tag.

Now, after performing all the above mentioned activities, basic authentication is up and running. You can test it by accessing the secure page on browser.

Note: Above steps will setup the basic authentication and the browser would provide the login window and it cannot be customized. If you want a custom Login page then please refer the Form Authentication.

Visit Weblogic Tips & Tricks for more such tips.
Do you enjoy this article? please help spread the word. Your views are valuable.
Post your view


Write comments