Basic Authentication with Glassfish Web Apps

Create a User on the Server

Log-in to the server administration (usually my-domain:4848) and go to Configurationsserver-configSecurityRealmsfile.

Click on Manage Users and create one or more users.


Define a User in your Web App

Create or modify WEB-INF/web.xml

<web-app xmlns=""

            <web-resource-name>Secure Application</web-resource-name>





Create or modify WEB-INF/sun-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD GlassFish Application Server 3.0 Servlet 3.0//EN" "">

security-role-mapping will map role-name from web.xml to the users know to the server. The value for role-name therefore is not important, as long as it is mapped to an existing user on the server.