|
JBoss and Basic Authentication |
|
Written by Administrator
Saturday, 07 March 2009 18:25 |
|
|
|
|
|
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");
|