This example demonstrates how to develop secure RESTful “Hello world” web service with a Servlet 2.5 container.
The example consists of just one Java class:
org.glassfish.jersey.examples.https.glassfish.resources.HelloWorldResource
A resource class that produces a textual response to an HTTP GET request.
The mapping of the URI path space is presented in the following table:
| URI path | Resource class | HTTP methods |
|---|---|---|
| /helloworld | HelloWorldResource | GET |
Run the example as follows:
Create war package
mvn clean package
Setup GlassFish 6.0 (installed at AS_HOME=<install_dir>/glassfish4):
Add new security realm called “myRealm”
$AS_HOME/bin/asadmin start-domainConfigurations -> server-config -> Security -> Realms, click on “New...”myUser (click on “myRealm” -> “Manage Users” -> “New...”);User ID:” set to “myUser” and “Group List:” set to “Users”myPass in “New Password:” and “Confirm New Password:” text fieldsjoeUser (click on “myRealm” -> “Manage Users” -> “New...”);User ID:” set to “joeUser” and “Group List:” set to “Users”joePass in “New Password:” and “Confirm New Password:” text fieldsCheck web.xml and sun-web.xml to understand how role mappings are configured. This blog is also helpful in helping to clarify role mappings. Deploy https-server-glassfish.war as a Web Application
Applications, click on “Deploy...”. Select file ./target/https-server-glassfish.war$AS_HOME/bin/asadmin deploy ./target/https-server-glassfish.warFrom a web browser, visit:
myUser and Password myPass or, Username joeUser and Password joePassmyUser and Password myPass, verify that expected output: Sending "Hello World" to user "myUser" was displayedjoeUser and Password joePass, verify that expected output: Sending "Hello World" to user "joeUser" was displayedRun the example as follows:
Create war package
mvn clean package
setup GlassFish 6.0 (installed at AS_HOME=<install_dir>/glassfish6):
joeUser” to the “Group List:” of “Users” set “Group List:” for this user to “OtherUsers”From a web browser, visit:
joeUser and Password joePass, verify that expected output looks like: HTTP Status 403 - Access to the requested resource has been denied