JBoss and Basic Authentication
Written by Administrator    Saturday, 07 March 2009 18:25    PDF Print E-mail

This is a short how to enable basic auth on a JBoss server and a small test client.

This example is run on Java5, Ubuntu Edgy Eft and JBoss 4.5. It assumes you are working with a web application.

Step 1 Add a jboss-web.xml file to your webapps WEB-INF directory.
Add the following content

< jboss>
   < jboss-web>
   < security-domain>java:/jaas/myapplication
   < /security-domain>
   < /jboss-web>
   < /jboss>

Change your web.xml file and add the following rows.
    < security-constraint>
        < web-resource-collection>
    < web-resource-name>UserResources</web-resource-name>
    < description></description>
    </url-pattern>/services/*</url-pattern>
    </web-resource-collection>
        < auth-constraint>
        < role-name>user</role-name>
        </auth-constraint>
        </security-constraint>
        < security-role>
        < role-name>user</role-name>
    </security-role>
    < security-role>
    < role-name>operator</role-name>
    </security-role>
    < security-role>
    < role-name>admin</role-name>
    </security-role>

    < login-config>
    < auth-method>BASIC</auth-method>
    < realm-name>MyApplicationRealm</realm-name>
    </login-config>

Change some files on your JBoss application server files.
Change the file login-config.xml in the conf directory.
< application-policy name="myapplication">
       < authentication>
          < login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"
             flag = "required">
           < module-option name="usersProperties">props/rk-users.properties</module-option>
           < module-option name="rolesProperties">props/rk-roles.properties</module-option>
          </login-module>
       </authentication>
    </application-policy>

Create two new files in the conf/props.<br>
One file with the users called rk-users.properties<br>
Add the following user<br>
admin=adminpwd<br>

One file with the roles called rk-roles.properties<br>
Add the following roles<br>
admin=sysadmin,user

I made a xfire client calling my xfire web services. see xfire codehaus for an examle on a web client.

Then add these lines of code<br>

org.codehaus.xfire.client.Client client = org.codehaus.xfire.client.Client.getInstance(service);

client.setProperty(Channel.USERNAME, "admin");

client.setProperty(Channel.PASSWORD, "adminpwd");

 

Your are currently browsing this site with Internet Explorer 6 (IE6).

Your current web browser must be updated to version 7 of Internet Explorer (IE7) to take advantage of all of template's capabilities.

Why should I upgrade to Internet Explorer 7? Microsoft has redesigned Internet Explorer from the ground up, with better security, new capabilities, and a whole new interface. Many changes resulted from the feedback of millions of users who tested prerelease versions of the new browser. The most compelling reason to upgrade is the improved security. The Internet of today is not the Internet of five years ago. There are dangers that simply didn't exist back in 2001, when Internet Explorer 6 was released to the world. Internet Explorer 7 makes surfing the web fundamentally safer by offering greater protection against viruses, spyware, and other online risks.

Get free downloads for Internet Explorer 7, including recommended updates as they become available. To download Internet Explorer 7 in the language of your choice, please visit the Internet Explorer 7 worldwide page.