Basic authentication in Glassfish

I'm having trouble getting BASIC authentication to work with Glassfish. I am developing an application and I need to provide a username and password. I received the application to ask me for the password when trying 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 went into the Glassfish Admin Console and created some sample users in the area fileand enabled Security Manager.

Then, in my web.xmlfile, I 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>

, . . , , , , , .

, Glassfish Open Source 3.0.1 Netbeans 6.9 .

+3
2

, , sun-web.xml "":

<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>
+6

, Glassfish http://download.oracle.com/javaee/6/tutorial/doc/bnbxj.html .

, , , . , glassfish-web.xml, ,

WEB-INF/glassfish-web-app.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app>
    <security-role-mapping>
        <role-name>User</role-name>
        <group-name>User</group-name>
    </security-role-mapping>
</glassfish-web-app>
+1

Source: https://habr.com/ru/post/1768659/


All Articles