Wednesday, December 14, 2011

JBoss and Basic Authentication

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
< description>
/services/*

< auth-constraint>
< role-name>user


< security-role>
< role-name>user

< security-role>
< role-name>operator

< security-role>
< role-name>admin


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


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 name="rolesProperties">props/rk-roles.properties




Create two new files in the conf/props.

One file with the users called rk-users.properties

Add the following user

admin=adminpwd


One file with the roles called rk-roles.properties

Add the following roles

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


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

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

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


0 comments:

Post a Comment