Recently I had to test HTTP basic security for one of my web application
project, just to save my time I didn't want to use any standalone
server during development instead I tried to configure Maven Jetty
plug-in to support HTTP basic security. Here I have given the procedure
which I followed.
1.) Configure Maven Jetty plugin in project pom.xml file.
It's required to add a UserRealm under plug-in configuration section. Jetty provides number of in-built UserRealms, here I used HashUserRealm for simplicity which use in-memory HashMaps to store users and roles.
Then add a property file called jetty-users.properties which contains user names, passwords and user roles.
2.) Configure web.xml file of the web application.
In this example we allow users with ADMIN role to access any URL within the application.
1.) Configure Maven Jetty plugin in project pom.xml file.
It's required to add a UserRealm under plug-in configuration section. Jetty provides number of in-built UserRealms, here I used HashUserRealm for simplicity which use in-memory HashMaps to store users and roles.
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<scanIntervalSeconds>3</scanIntervalSeconds>
<webAppConfig>
<contextPath>/</contextPath>
</webAppConfig>
<userRealms>
<userRealm implementation="org.mortbay.jetty.security.HashUserRealm">
<name>basic security</name>
<config>jetty-users.properties</config>
</userRealm>
</userRealms>
</configuration>
</plugin>
</plugins>
Then add a property file called jetty-users.properties which contains user names, passwords and user roles.
sagara=sagara,ADMIN
2.) Configure web.xml file of the web application.
In this example we allow users with ADMIN role to access any URL within the application.
<security-constraint>
<display-name>authorizedUsers</display-name>
<web-resource-collection>
<web-resource-name>ALL URLs</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>ADMIN</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>basic security</realm-name>
</login-config>
<security-role>
<description>administrator access</description>
<role-name>ADMIN</role-name>
</security-role>


