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.HelloWorldResourceThe 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 4.0 (installed at AS_HOME=<install_dir>/glassfish4):
myRealm"$AS_HOME/bin/asadmin start-domainConfigurations -> server-config -> Security -> Realms,
click on "New..."
| Name | myRealm |
|---|---|
| Class Name | com.sun.enterprise.security.auth.realm.file.FileRealm |
| JAAS context | fileRealm |
| Key File | ${com.sun.aas.instanceRoot}/config/myRealm-keyfile |
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 fields
joeUser (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 fields
web.xml and sun-web.xml to understand how role mappings are configured.
This blog is also helpful
in helping to clarify role mappings.
https-server-glassfish.war as a Web ApplicationApplications, click on "Deploy...". Select file
./target/https-server-glassfish.war
$AS_HOME/bin/asadmin deploy ./target/https-server-glassfish.warFrom a web browser, visit:
https://localhost:8181/https-server-glassfish-webapp/helloworld
(you have to add security exception for GlassFish server certificate / ignore all warnings about security)
myUser and Password myPass or, Username
joeUser and Password joePassmyUser and Password myPass, verify that expected
output: Sending "Hello World" to user "myUser" was displayed
joeUser and Password joePass, verify that expected
output: Sending "Hello World" to user "joeUser" was displayed
Run the example as follows:
Create war package
mvn clean package
setup GlassFish 4.0 (installed at AS_HOME=<install_dir>/glassfish4):
joeUser" to the
"Group List:" of "Users" set "Group List:" for this user to
"OtherUsers"
From a web browser, visit:
https://localhost:8181/https-server-glassfish-webapp/helloworld
(you have to add security exception for GlassFish server certificate / ignore all warnings about security)
joeUser and Password joePass, verify that expected
output looks like: HTTP Status 403 - Access to the requested resource has been denied