In this post I will explain how you can configure Glassfish instance (server) with basic authentication. If you deploy any java application or ADF application or web service in the Glassfish instance the user who will use this application or web service will be prompted to enter username and password.
To do so follow this following steps:
1- Open Glassfish admin console then go to:
2- Enter "USERS" in Assign Groups
3- Press in "Manage Users" button
4- Press New to create new user and set Group List to "USERS"
5- In your web application add this in web.xml
6- In your web application create file "sun-web.xml" in the same place of web.xml and write this:
7- Now deploy the web application (Java, ADF ,Web Service,...) to the Glassfish and when you try to call the application you have to enter username / password
To do so follow this following steps:
1- Open Glassfish admin console then go to:
Configurations --> Server-config -->
Security --> Realms --> file
2- Enter "USERS" in Assign Groups
3- Press in "Manage Users" button
4- Press New to create new user and set Group List to "USERS"
5- In your web application add this in web.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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>USERS</role-name> | |
</auth-constraint> | |
</security-constraint> | |
<login-config> | |
<auth-method>BASIC</auth-method> | |
<realm-name>file</realm-name> | |
</login-config> | |
<security-role> | |
<role-name>USERS</role-name> | |
</security-role> |
6- In your web application create file "sun-web.xml" in the same place of web.xml and write this:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version = '1.0' encoding = 'UTF-8'?> | |
<sun-web-app error-url=""> | |
<security-role-mapping> | |
<role-name>USERS</role-name> | |
<group-name>USERS</group-name> | |
</security-role-mapping> | |
</sun-web-app> |
7- Now deploy the web application (Java, ADF ,Web Service,...) to the Glassfish and when you try to call the application you have to enter username / password
Thanks
ReplyDelete