Skip to content

Commit 2bb5ceb

Browse files
author
Manish Baxi
committed
2 parents c40e925 + 1a41e5d commit 2bb5ceb

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

README.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ This prevents information leakage and malicious use of the application by intern
99
external users.
1010

1111
Spring Security is a flexible framework for implementing security requirements for web
12-
based applications. It is therefore not uncommon for developers to use Spring Security to
13-
enforce security restrictions on REST API endpoints. One of the challenges encountered
12+
based applications. It is therefore not uncommon for developers to use Spring Security for
13+
enforcing security restrictions on REST API endpoints. One of the challenges encountered
1414
when using Spring Security to secure REST API endpoints stems from the requirement to
1515
support stateless REST clients. In this context, *stateless* means that the client does
1616
not provide any information with REST requests that would allow the server to determine the
@@ -56,7 +56,9 @@ With this configuration, Spring Security uses HTTP sessions to store user creden
5656
between requests.
5757

5858
The *API* layer cannot use the default configuration because all communication between this
59-
layer and its clients has been assumed to be stateless. Spring Security configuration for
59+
layer and its clients has been assumed to be stateless, which means that HTTP Sessions
60+
cannot be relied upon for determining the application users' identity but the default Spring
61+
Security configuration makes use of HTTP Sessions. Spring Security configuration for
6062
this layer is therefore slightly more involved and is shown below.
6163

6264
<bean class="org.example.api.security.APIAuthenticationEntryPoint" id="apiAuthenticationEntryPoint" />
@@ -75,24 +77,26 @@ Spring Security interface `SecurityContextRepository`, whose other implementatio
7577
Of course, it is not mandatory to use Ehcache. Any other caching solution could be used to
7678
store user credentials in between REST calls.
7779

80+
In essence, theHTTP Session has been replaced with an expirable cache. Provided the cache is
81+
configured correctly, it provides exactly the same semantics as the HTTP Session for storing
82+
Spring Security authentication tokens, such as, sliding expiration, idle timeout and replication.
83+
7884
#4. Running the application
7985
The following pre-requisites apply to this application.
8086

8187
1. Java Development Kit (JDK) 6.0 or higher;
8288
1. Apache Maven 3.0.4 or higher.
8389

8490
Once these have been installed and the code checked out, the `web` application can be run
85-
as `mvn clean package tomcat7:run -pl common,data,domain,service,transfer,web`. This starts an
86-
embedded Tomcat instance on local port `8888`. The application can then be accessed using
87-
any web browser on [http://localhost:8888](http://localhost:8888). When accessed for the first
88-
time, the application will present a login screen with instructions on logging in.
89-
Successfully logging in as an *Admin* user provides access to a list of users for the system.
90-
This functionality is not accessible to normal users (try accessing it as a normal user).
91-
92-
Similarly, the `api` application can be run as
93-
`mvn clean package tomcat7:run -pl api,common,data,domain,service,transfer`. This starts
94-
an embedded Tomcat instance on local port `9999`. The application can then be accessed
95-
using a REST client, such as the *Postman* extension for Google Chrome on
91+
as `mvn clean package tomcat7:run -am -pl web`. This starts an embedded Tomcat instance on
92+
local port `8888`. The application can then be accessed using any web browser on [http://localhost:8888](http://localhost:8888). When accessed for the first time, the
93+
application will present a login screen with instructions on logging in. Successfully logging
94+
in as an *Admin* user provides access to a list of users for the system. This functionality
95+
is not accessible to normal users (try accessing it as a normal user).
96+
97+
Similarly, the `api` application can be run as `mvn clean package tomcat7:run -am -pl api`.
98+
This starts an embedded Tomcat instance on local port `9999`. The application can then be
99+
accessed using a REST client, such as the *Postman* extension for Google Chrome on
96100
`http://localhost:9999`. There are two REST endpoints - `http://localhost:9999/authenticate`
97101
to authenticate clients and `http://localhost:9999/users` to access the user list.
98102
First, make a *POST* request to `http://localhost:9999/authenticate` with two form parameters

0 commit comments

Comments
 (0)