Book Image

Restful Java Web Services Security

By : René Enríquez
Book Image

Restful Java Web Services Security

By: René Enríquez

Overview of this book

Table of Contents (12 chapters)

OAuth token via Basic Auth


Now, let's explore and implement a short example of using tokens. In order to build this example, we will create a class. This class, as in the previous example, will simulate a database client. It will have the same method, getCompactDiscs(), but we will modify the internal function in this example. Also, it won't receive any parameter this time.

Alright, let's do it! First, create two static string fields in the class. The first field will hold the URL for authentication in the auth-server. The other field will have the URL showing the compact discs list; you can reuse the same web page from the previous example. Then, you should have your variables as shown:

private static String urlAuth = "https://localhost:8443/auth-server /j_oauth_token_grant";
private static String urlDiscs = "https://localhost:8443/discstore/discs";

After this, let's create our method to obtain the compact discs list. The following piece of code shows you exactly how the method is executed...