I am having trouble getting BASIC authentication to work with Glassfish. I am developing an application and I need to be prompted for a username and password. I have gotten the application to prompt me for a password when I attempt to access the application, but after entering the correct login information, I get HTTP Status 403 - Access to the requested resource has been denied.
I have gone into the Glassfish Admin Console and created a few sample users in the file realm and enabled the Security Manager.
Next, in my web.xml file, I have added the following:
<security-constraint>
<web-resource-collection>
<web-resource-name>Secure Application</web-resource-name>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>User</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>file</realm-name>
</login-config>
<security-role>
<role-name>User</role-name>
</security-role>
I'm not exactly sure what to do next. I have searched for several hours with no luck. The authentication works because if I enter incorrect login information, it prompts again, but after successfully authenticating, I get the access denied message shown above.
If it helps, I am running Glassfish Open Source 3.0.1 and using Netbeans 6.9 for development.
I'm not sure if defaults apply but you may need to create sun-web.xml and set a mapping for role "User":
<sun-web-app error-url="">
...
<security-role-mapping>
<role-name>User</role-name>
<group-name>filerealm-group-name</group-name>
</security-role-mapping>
...
</sun-web-app>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With