Project exemplifies the use of the following resources:
- It was used SOLID, DRY, KISS, FIRST and other useful principles.
- Design Patterns when reasonable to do so.
- Different environment profiles with different sets of configurations for
the Spring Security, Authenticated routes and databases.
- Custom database table to store and manage the system's users, which I
called Members in the system.
- HATEOAS
- Content Negotiation (JSON, XML and YML)
- CORS for origin filtering.
- Automatic Code Coverage generation (maven-surefire-plugin and JaCoCo).
- Spring Boot Security 6.4
- Authentication based on JWT tokens
- JWT tokens generation and validation through filters.
- Authentication events capture.
- Authentication/Authorization filters.
- Lombok
- Mapstruct
- OpenAPI
- H2 database in "file-mode", having the generated persistence
files store on the 'data' folder at the root of the project.
- Flyway to apply migrations to H2
- Using yaml files for the application properties.
- Tests and mocks:
Junit, Assertj, Rest Assured, Mockito, BDDMockito, Hamcrest...
- The project evolved from a basic and simplistic implementation to a more complex yet minimalistic monolithic implementation, utilizing the latest versions of common Java resources and dependencies.
- The objective was to test the new versions of the dependencies mentioned earlier by applying them to a micro-monolithic application. This test did not take into account concurrent or parallel access to the application's resources, particularly the database.
- The decision to use the H2 database was based on its practicality. H2 is a relatively simple database, primarily used for testing. However, for a micro application like this, it allows us to complete tasks without the need to configure or run additional services or containers. It is portable and easy to manage.
- The system creates database structures for different profiles (test, dev, prod) using Flyway migrations and an H2 (file-mode) database.
- In the pom.xml file, the maven-surefire-plugin has been configured to work in conjunction with JaCoCo, generating automatic reports whenever 'mvn test' is executed.
- MapStruct and Lombok working together, with the integration of Lombok’s MapStruct binding features.
http://localhost:8080/swagger-ui/index.html
http://localhost:8080/v3/api-docs
http://localhost:8080/h2
H2 persistence base on environment profiles:
- DEV : jdbc:h2:file:./data/test_dev_db
- TEST : jdbc:h2:file:./data/testdb
- PROD : jdbc:h2:file:./data/test_prod_db
[GET] /api/member/v1/token
- This route requires basic authentication, and the accepted media type response can be JSON (default), XML or YAML.
- The response carries the JWT token on its header, in the 'Authorization' attribute, and also in the body, through the property (or tag) 'token'.
# ------------- JSON --------------
curl -s -u 'ayrton.senna@bravo.com:ayrton_pass' \
-L -X GET 'http://localhost:8080/api/member/v1/token' | jq
# Base64 encoded credentials:
curl -s -u 'YXlydG9uLnNlbm5hQGJyYXZvLmNvbTpheXJ0b25fcGFzcw=='
-L -X GET 'http://localhost:8080/api/member/v1/token' | jq
# ------------- XML --------------
curl -s -u 'ayrton.senna@bravo.com:ayrton_pass' -H 'Accept: application/xml' \
-L -X GET 'http://localhost:8080/api/member/v1/token' | xmllint --format -
# ------------- YAML --------------
curl -s -u 'ayrton.senna@bravo.com:ayrton_pass' -H 'Accept: application/x-yaml' \
-L -X GET 'http://localhost:8080/api/member/v1/token' | yq
# ------------- CORS --------------
curl -s -u 'ayrton.senna@bravo.com:ayrton_pass' -H 'Origin: http://localhost:3000' \
-L -X GET 'http://localhost:8080/api/member/v1/token' | yq
-- JSON response --
{
"token": [your-jwt-token]
}
curl -s -I -u 'ayrton.senna@bravo.com:ayrton_pass' -L -X GET 'http://localhost:8080/api/member/v1/token'
-- response --
HTTP/1.1 200
Authorization: [your-jwt-toke]
Set-Cookie: JSESSIONID=598F62A04F9B40A6D85ECCF8F853F024; Path=/; HttpOnly
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
X-Content-Type-Options: nosniff
X-XSS-Protection: 0
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
Content-Type: application/json
Transfer-Encoding: chunked
Date: Sun, 23 Feb 2025 15:43:44 GMT
# BASH:
# get the JWT token and stores it in a bash variable:
myJWTToken=`curl -s -u 'ayrton.senna@bravo.com:ayrton_pass' \
-L -X GET 'http://localhost:8080/api/member/v1/token' | jq -r '.token'`
# run cURL using the variable as the authorization token:
curl -s -H "Authorization: $myJWTToken" \
-L -X GET 'http://localhost:8080/api/member/v1/member-details/ayrton.senna@bravo.com' | jq
This controller implements 3 actions:
[GET] /api/corporation/v1 - unautenticated route
[GET] /api/corporation/v1/info - unautenticated route
[GET] /api/corporation/v1/info-corp - authenticated route
- This controller implements 3 routes.
- Only Web layer tests.
- HATEOAS - regardless of the selected Response data format, Responses include HATEOAS links to make it a RESTful API.
- Content Negotiation allow for Responses and Requests in JSON, XML and YML data formats (JSON by default).
ROUTES:
/api/corporation/v1
# JSON response:
curl -s -L -X GET 'http://localhost:8080/api/corporation/v1' | jq
# XML response:
curl -s -H 'Accept: application/xml' \
-L -X GET 'http://localhost:8080/api/corporation/v1' | xmllint --format -
# YAML response:
curl -s -H 'Accept: application/x-yaml' \
-L -X GET 'http://localhost:8080/api/corporation/v1' | yq
/api/corporation/v1/info
# JSON response:
curl -s -L -X GET 'http://localhost:8080/api/corporation/v1/info' | jq
# XML response:
curl -s -H 'Accept: application/xml' \
-L -X GET 'http://localhost:8080/api/corporation/v1/info' | xmllint --format -
# YAML response:
curl -s -H 'Accept: application/x-yaml' \
-L -X GET 'http://localhost:8080/api/corporation/v1/info' | yq
/api/corporation/v1/info-corp
# BASH:
# get the JWT token and stores it in a bash variable:
myJWTToken=`curl -s -u 'ayrton.senna@bravo.com:ayrton_pass' \
-L -X GET 'http://localhost:8080/api/member/v1/token' | jq -r '.token'`
# run cURL using the variable as the authorization token:
# ------------- JSON --------------
curl -s -H "Authorization: $myJWTToken" \
-L -X GET 'http://localhost:8080/api/corporation/v1/info-corp' | jq
# ------------- XML ---------------
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/xml' \
-L -X GET 'http://localhost:8080/api/corporation/v1/info-corp' | xmllint --format -
# ------------- YAML --------------
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/x-yaml' \
-L -X GET 'http://localhost:8080/api/corporation/v1/info-corp' | yq
# ------------- CORS --------------
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/json' -H 'Origin: http://localhost:3000' \
-L -X GET 'http://localhost:8080/api/corporation/v1/info-corp' | jq
This controller implements routes to manage Members (Users), and also the action to generate the JWT tokens:
-
HATEOAS - regardless of the selected Response data format, Responses include 'links' to make it a RESTful API.
-
Content Negotiation allow for Responses and Requests in JSON, XML and YML data formats (JSON by default).
-
Pagination - paginated list of members on /api/member/v1/list, with page number, size (quantity), and sorting direction
[GET] /api/member/v1/token
[POST] /api/member/v1/member-create
[GET] /api/member/v1/list
[GET] /api/member/v1/member-full-details/{username}
[GET] /api/member/v1/member-details/{username}
[GET] /api/member/v1/me
[PUT] /api/member/v1/member-update
[PATCH] /api/member/v1/member-password
[PATCH] /api/member/v1/manage-member-password
[PATCH] /api/member/v1/member-disable/{id}
[PATCH] /api/member/v1/member-enable/{id}
[PATCH] /api/member/v1/member-lock/{id}
[PATCH] /api/member/v1/member-unlock/{id}
# Requesting the JWT token and storing it in a bash variable
myJWTToken=`curl -s -u 'ayrton.senna@bravo.com:ayrton_pass' \
-L -X GET 'http://localhost:8080/api/member/v1/token' | jq -r '.token'`
# JSON request and response:
curl -s -H "Authorization: $myJWTToken" -H 'Content-Type: application/json' \
-L -X POST 'http://localhost:8080/api/member/v1/member-create' \
-d '{
"memberName":"Rubens Barrichello",
"memberEmail":"rubens.barrichello@bravo.com",
"memberMobileNumber":"(11) 98765-4321",
"memberPassword": "barrichello_pass",
"memberAuthorities": [
"ROLE_ADMIN"
]
}' | jq
# XML request and response:
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/xml' -H 'Content-Type: application/xml' \
-L -X POST 'http://localhost:8080/api/member/v1/member-create' \
-d '<MemberCreateRequest>
<memberName>Emerson Fittipaldi</memberName>
<memberEmail>emerson.fittipaldi@bravo.com</memberEmail>
<memberMobileNumber>(11) 98765-4321</memberMobileNumber>
<memberPassword>fittipaldi_pass</memberPassword>
<memberAuthorities>
<memberAuthorities>ROLE_ADMIN</memberAuthorities>
</memberAuthorities>
</MemberCreateRequest>' | xmllint --format -
# YAML request and response:
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/x-yaml' -H 'Content-Type: application/x-yaml' \
-L -X POST 'http://localhost:8080/api/member/v1/member-create' \
-d '---
memberName: "Nelson Piquet"
memberEmail: "nelson.piquet@bravo.com"
memberMobileNumber: "(11) 98765-4321"
memberPassword: "piquet_pass"
memberAuthorities:
- "ROLE_ADMIN"' | yq
# CORS - origin filter and JSON request / response
curl -s -H "Authorization: $myJWTToken" -H 'Origin: http://localhost:3000' \
-H 'Content-Type: application/json' \
-L -X POST 'http://localhost:8080/api/member/v1/member-create' \
-d '{
"memberName":"Felipe Massa",
"memberEmail":"felipe.massa@bravo.com",
"memberMobileNumber":"(11) 98765-4321",
"memberPassword": "massa_pass",
"memberAuthorities": [
"ROLE_ADMIN"
]
}' | jq
Paginated params for this request:
- page: (default: 0) the page number to be shown (determined by the quantity of members in the database divided by the value of the 'size' param, which is explained bellow)
- size: (default: 8) the quantity of members to be showed per page
- sortDir: (default: asc) the sorting direction, if asc or desc.
- sortBy: (default: memberEmail) the data wich the sorting must be based (memberEmail, memberId, and so on..)
sortDir: It selects 'asc' (ascending) sort direction, in case an invalid sorting direction is received.
sortBy: It throws a custom exception (InvalidSortByException) in case the value is not a member data, which would make it an unsortable data.
# Requesting the JWT token and storing it in a bash variable
myJWTToken=`curl -s -u 'ayrton.senna@bravo.com:ayrton_pass' \
-L -X GET 'http://localhost:8080/api/member/v1/token' | jq -r '.token'`
# run cURL using the variable as the authorization token:
# ------------- JSON - PAGINATED --------------
curl -s -H "Authorization: $myJWTToken"
-L -X GET 'http://localhost:8080/api/member/v1/list?page=0&size=8&sortDir=desc&sortBy=memberId' | jq
curl -s -H "Authorization: $myJWTToken"
-L -X GET 'http://localhost:8080/api/member/v1/list?page=0&size=8&sortDir=desc' | jq
curl -s -H "Authorization: $myJWTToken"
-L -X GET 'http://localhost:8080/api/member/v1/list?page=0&size=8' | jq
curl -s -H "Authorization: $myJWTToken"
-L -X GET 'http://localhost:8080/api/member/v1/list?page=0' | jq
curl -s -H "Authorization: $myJWTToken"
-L -X GET 'http://localhost:8080/api/member/v1/list' | jq
# -------------- XML - PAGINATED --------------
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/xml' \
-L -X GET 'http://localhost:8080/api/member/v1/list?page=0&size=8&sortDir=desc&sortBy=memberId' | xmllint --format -
# ------------- YAML - PAGINATED --------------
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/x-yaml' \
-L -X GET 'http://localhost:8080/api/member/v1/list?page=0&size=8&sortDir=desc&sortBy=memberId' | yq
# ------------- CORS - PAGINATED --------------
curl -s -H "Authorization: $myJWTToken" -H 'Origin: http://localhost:3000' \
-L -X GET 'http://localhost:8080/api/member/v1/list?page=0&size=8&sortDir=desc&sortBy=memberId' | jq
# Requesting the JWT token and storing it in a bash variable
myJWTToken=`curl -s -u 'ayrton.senna@bravo.com:ayrton_pass' \
-L -X GET 'http://localhost:8080/api/member/v1/token' | jq -r '.token'`
# run cURL using the variable as the authorization token:
# ------------- JSON --------------
curl -s -H "Authorization: $myJWTToken" \
-L -X GET 'http://localhost:8080/api/member/v1/member-full-details/ayrton.senna@bravo.com' | jq
# ------------- XML --------------
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/xml' \
-L -X GET 'http://localhost:8080/api/member/v1/member-full-details/ayrton.senna@bravo.com' \
| xmllint --format -
# ------------- YAML --------------
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/x-yaml' \
-L -X GET 'http://localhost:8080/api/member/v1/member-full-details/ayrton.senna@bravo.com' | yq
# ------------- CORS --------------
curl -s -H "Authorization: $myJWTToken" -H 'Origin: http://localhost:3000' \
-L -X GET 'http://localhost:8080/api/member/v1/member-full-details/ayrton.senna@bravo.com' | jq
# Requesting the JWT token and storing it in a bash variable
myJWTToken=`curl -s -u 'ayrton.senna@bravo.com:ayrton_pass' \
-L -X GET 'http://localhost:8080/api/member/v1/token' | jq -r '.token'`
# run cURL using the variable as the authorization token:
# ------------- JSON --------------
curl -s -H "Authorization: $myJWTToken" \
-L -X GET 'http://localhost:8080/api/member/v1/member-details/ayrton.senna@bravo.com' | jq
# ------------- XML --------------
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/xml' \
-L -X GET 'http://localhost:8080/api/member/v1/member-details/ayrton.senna@bravo.com' \
| xmllint --format -
# ------------- YAML --------------
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/x-yaml' \
-L -X GET 'http://localhost:8080/api/member/v1/member-details/ayrton.senna@bravo.com' | yq
# ------------- CORS --------------
curl -s -H "Authorization: $myJWTToken" -H 'Origin: http://localhost:3000' \
-L -X GET 'http://localhost:8080/api/member/v1/member-details/ayrton.senna@bravo.com' | jq
# Requesting the JWT token and storing it in a bash variable
myJWTToken=`curl -s -u 'ayrton.senna@bravo.com:ayrton_pass' \
-L -X GET 'http://localhost:8080/api/member/v1/token' | jq -r '.token'`
# run cURL using the variable as the authorization token:
# ------------- JSON --------------
curl -s -H "Authorization: $myJWTToken" \
-L -X GET 'http://localhost:8080/api/member/v1/me' | jq
# ------------- XML --------------
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/xml' \
-L -X GET 'http://localhost:8080/api/member/v1/me' | xmllint --format -
# ------------- YAML --------------
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/x-yaml' \
-L -X GET 'http://localhost:8080/api/member/v1/me' | yq
# ------------- CORS --------------
curl -s -H "Authorization: $myJWTToken" -H 'Origin: http://localhost:3000' \
-L -X GET 'http://localhost:8080/api/member/v1/me' | jq
# Requesting the JWT token and storing it in a bash variable
myJWTToken=`curl -s -u 'ayrton.senna@bravo.com:ayrton_pass' \
-L -X GET 'http://localhost:8080/api/member/v1/token' | jq -r '.token'`
# ------------- JSON (request and response) --------------
curl -s -H "Authorization: $myJWTToken" -H 'Content-Type: application/json' \
-L -X PUT 'http://localhost:8080/api/member/v1/member-update' \
-d '{
"membrerId": 51,
"memberName":"Rubens Barrichello",
"memberEmail":"rubens.barrichello@bravo.com",
"memberMobileNumber":"(11) 98765-4321",
"memberPassword": "barrichello_pass",
"memberAuthorities": [
"ROLE_ADMIN"
]
}' | jq
# -------------- XML (request and response) --------------
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/xml' \
-H 'Content-Type: application/xml' \
-L -X PUT 'http://localhost:8080/api/member/v1/member-update' \
-d '<MemberCreateRequest>
<memberId>52</memberId>
<memberName>Emerson Fittipaldi</memberName>
<memberEmail>emerson.fittipaldi@bravo.com</memberEmail>
<memberMobileNumber>(11) 98765-4321</memberMobileNumber>
<memberPassword>fittipaldi_pass</memberPassword>
<memberAuthorities>
<memberAuthorities>ROLE_ADMIN</memberAuthorities>
</memberAuthorities>
</MemberCreateRequest>' | xmllint --format -
# ------------- YAML (request and response) --------------
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/x-yaml' \
-H 'Content-Type: application/x-yaml' \
-L -X PUT 'http://localhost:8080/api/member/v1/member-update' \
-d '---
memberId: 53
memberName: "Nelson Piquet"
memberEmail: "nelson.piquet@bravo.com"
memberMobileNumber: "(11) 98765-4321"
memberPassword: "piquet_pass"
memberAuthorities:
- "ROLE_ADMIN"' | yq
# ------------- CORS - origin filter and JSON request / response -------------
curl -s -H "Authorization: $myJWTToken" -H 'Origin: http://localhost:3000' \
-H 'Content-Type: application/json' \
-L -X PUT 'http://localhost:8080/api/member/v1/member-update' \
-d '{
"memberId": 54,
"memberName":"Felipe Massa",
"memberEmail":"felipe.massa@bravo.com",
"memberMobileNumber":"(11) 98765-4321",
"memberPassword": "massa_pass",
"memberAuthorities": [
"ROLE_ADMIN"
]
}' | jq
# Requesting the JWT token and storing it in a bash variable
myJWTToken=`curl -s -u 'ayrton.senna@bravo.com:ayrton_pass' \
-L -X GET 'http://localhost:8080/api/member/v1/token' | jq -r '.token'`
curl -s -H "Authorization: $myJWTToken" \
-L -X PATCH 'http://localhost:8080/api/member/v1/member-password' \
-d '{"newPassword": "mynewpassword"}' | jq
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/xml' -H 'Content-Type: application/xml' \
-L -X PATCH 'http://localhost:8080/api/member/v1/member-password' \
-d '<MemberUpdatePasswordRequest>
<newPassword>mynewpassword</newPassword>
</MemberUpdatePasswordRequest>' | xmllint --format -
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/x-yaml' -H 'Content-Type: application/x-yaml' \
-L -X PATCH 'http://localhost:8080/api/member/v1/member-password' \
-d '--- newPassword: "mynewpassword"' | yq
curl -s -H "Authorization: $myJWTToken" -H 'Origin: http://localhost:3000' \
-L -X PATCH 'http://localhost:8080/api/member/v1/member-password' \
-d '{"newPassword": "mynewpassword"}' | jq
# Requesting the JWT token and storing it in a bash variable
myJWTToken=`curl -s -u 'ayrton.senna@bravo.com:ayrton_pass' \
-L -X GET 'http://localhost:8080/api/member/v1/token' | jq -r '.token'`
curl -s -H "Authorization: $myJWTToken" \
-L -X PATCH 'http://localhost:8080/api/member/v1/manage-member-password' \
-d '{"memberUsername": "mfredson2@amazon.com", "memberPassword": "newpassword"}' | jq
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/xml' \
-H 'Content-Type: application/xml' \
-L -X PATCH 'http://localhost:8080/api/member/v1/manage-member-password' \
-d '<MemberManagePasswordRequest>
<memberUsername>mfredson2@amazon.com</memberUsername>
<memberPassword>newpassword</memberPassword>
</MemberManagePasswordRequest>' | xmllint --format -
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/x-yaml' \
-H 'Content-Type: application/x-yaml' \
-L -X PATCH 'http://localhost:8080/api/member/v1/manage-member-password' \
-d '---
memberUsername: "Nelson Piquet"
memberPassword: "newpassword"' | yq
curl -s -H "Authorization: $myJWTToken" -H 'Origin: http://localhost:3000' \
-L -X GET 'http://localhost:8080/api/member/v1/manage-member-password' \
-d '{"memberUsername": "mfredson2@amazon.com", "memberPassword": "newpassword"}' \
| jq
# Requesting the JWT token and storing it in a bash variable
myJWTToken=`curl -s -u 'ayrton.senna@bravo.com:ayrton_pass' \
-L -X GET 'http://localhost:8080/api/member/v1/token' | jq -r '.token'`
# run cURL using the variable as the authorization token:
# ------------- JSON --------------
curl -s -H "Authorization: $myJWTToken" \
-L -X PATCH 'http://localhost:8080/api/member/v1/member-disable/3' | jq
# ------------- XML --------------
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/xml' \
-L -X PATCH 'http://localhost:8080/api/member/v1/member-disable/3' | xmllint --format -
# ------------- YAML --------------
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/x-yaml' \
-L -X PATCH 'http://localhost:8080/api/member/v1/member-disable/3' | yq
# ------------- CORS --------------
curl -s -H "Authorization: $myJWTToken" -H 'Origin: http://localhost:3000' \
-L -X PATCH 'http://localhost:8080/api/member/v1/member-disable/3' | jq
# Requesting the JWT token and storing it in a bash variable
myJWTToken=`curl -s -u 'ayrton.senna@bravo.com:ayrton_pass' \
-L -X GET 'http://localhost:8080/api/member/v1/token' | jq -r '.token'`
# ------------- JSON --------------
curl -s -H "Authorization: $myJWTToken" \
-L -X PATCH 'http://localhost:8080/api/member/v1/member-enable/3' | jq
# -------------- XML --------------
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/xml' \
-L -X PATCH 'http://localhost:8080/api/member/v1/member-enable/3' | xmllint --format -
# ------------- YAML --------------
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/x-yaml' \
-L -X PATCH 'http://localhost:8080/api/member/v1/member-enable/3' | yq
# ------------- CORS --------------
curl -s -H "Authorization: $myJWTToken" -H 'Origin: http://localhost:3000' \
-L -X PATCH 'http://localhost:8080/api/member/v1/member-enable/3' | jq
# Requesting the JWT token and storing it in a bash variable
myJWTToken=`curl -s -u 'ayrton.senna@bravo.com:ayrton_pass' \
-L -X GET 'http://localhost:8080/api/member/v1/token' | jq -r '.token'`
# ------------- JSON --------------
curl -s -H "Authorization: $myJWTToken" \
-L -X PATCH 'http://localhost:8080/api/member/v1/member-lock/3' | jq
# -------------- XML --------------
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/xml' \
-L -X PATCH 'http://localhost:8080/api/member/v1/member-lock/3' | xmllint --format -
# ------------- YAML --------------
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/x-yaml' \
-L -X PATCH 'http://localhost:8080/api/member/v1/member-lock/3' | yq
# ------------- CORS --------------
curl -s -H "Authorization: $myJWTToken" \
-H 'Origin: http://localhost:3000' \
-L -X PATCH 'http://localhost:8080/api/member/v1/member-lock/3' | jq
# Requesting the JWT token and storing it in a bash variable
myJWTToken=`curl -s -u 'ayrton.senna@bravo.com:ayrton_pass' \
-L -X GET 'http://localhost:8080/api/member/v1/token' | jq -r '.token'`
# ------------- JSON --------------
curl -s -H "Authorization: $myJWTToken" \
-L -X PATCH 'http://localhost:8080/api/member/v1/member-unlock/3' | jq
# -------------- XML --------------
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/xml' \
-L -X PATCH 'http://localhost:8080/api/member/v1/member-unlock/3' | xmllint --format -
# ------------- YAML --------------
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/x-yaml' \
-L -X PATCH 'http://localhost:8080/api/member/v1/member-unlock/3' | yq
# ------------- CORS --------------
curl -s -H "Authorization: $myJWTToken" \
-H 'Origin: http://localhost:3000' \
-L -X PATCH 'http://localhost:8080/api/member/v1/member-unlock/3' | jq
This controller implements routes to manage Members (Users), and also the action to generate the JWT tokens:
-
HATEOAS - regardless of the selected Response data format, Responses include 'links' to make it a RESTful API.
-
Content Negotiation allow for Responses and Requests in JSON, XML and YML data formats (JSON by default).
-
Pagination - paginated list of members on /api/authentication-failure/v1/member/{username}, with page number, size (quantity), and sorting direction
[GET] /api/authentication-failure/v1/member/{username}
[GET] /api/authentication-failure/v1/log/{id}
Paginated params for this request:
- page: (default: 0) the page number to be shown (determined by the quantity of a member's logs in the database divided by the value of the 'size' param, which is explained bellow)
- size: (default: 8) the quantity of a member's authentication failure logs to be showed per page
- sortDir: (default: asc) the sorting direction, if asc or desc.
- sortBy: (default: memberEmail) the data wich the sorting must be based (memberEmail, memberId, and so on..)
sortDir: It selects 'asc' (ascending) sort direction, in case an invalid sorting direction is received.
sortBy: It throws a custom exception (InvalidSortByException) in case the value is not a member's log data, which would make it an unsortable data.
# Requesting the JWT token and storing it in a bash variable
myJWTToken=`curl -s -u 'ayrton.senna@bravo.com:ayrton_pass' \
-L -X GET 'http://localhost:8080/api/member/v1/token' | jq -r '.token'`
# run cURL using the variable as the authorization token:
# ------------- JSON - PAGINATED --------------
curl -s -H "Authorization: $myJWTToken" \
-L -X GET 'http://localhost:8080/api/authentication-failure/v1/member/ayrton.senna@bravo.com?page=0&size=8&sortDir=desc&sortBy=logAuthTime' | jq
curl -s -H "Authorization: $myJWTToken" \
-L -X GET 'http://localhost:8080/api/authentication-failure/v1/member/ayrton.senna@bravo.com?page=0&size=8&sortDir=desc' | jq
curl -s -H "Authorization: $myJWTToken" \
-L -X GET 'http://localhost:8080/api/authentication-failure/v1/member/ayrton.senna@bravo.com?page=0&size=8' | jq
curl -s -H "Authorization: $myJWTToken" \
-L -X GET 'http://localhost:8080/api/authentication-failure/v1/member/ayrton.senna@bravo.com?page=0' | jq
curl -s -H "Authorization: $myJWTToken" \
-L -X GET 'http://localhost:8080/api/authentication-failure/v1/member/ayrton.senna@bravo.com' | jq
# -------------- XML - PAGINATED --------------
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/xml' \
-L -X GET 'http://localhost:8080/api/authentication-failure/v1/member/ayrton.senna@bravo.com?page=0&size=8&sortDir=desc&sortBy=logAuthTime' \
| xmllint --format -
# ------------- YAML - PAGINATED --------------
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/x-yaml' \
-L -X GET 'http://localhost:8080/api/authentication-failure/v1/member/ayrton.senna@bravo.com?page=0&size=8&sortDir=desc&sortBy=logAuthTime' \
| yq
# ------------- CORS - PAGINATED --------------
curl -s -H "Authorization: $myJWTToken" -H 'Origin: http://localhost:3000' \
-L -X GET 'http://localhost:8080/api/authentication-failure/v1/member/ayrton.senna@bravo.com?page=0&size=8&sortDir=desc&sortBy=logAuthTime' \
| jq
# Requesting the JWT token and storing it in a bash variable
myJWTToken=`curl -s -u 'ayrton.senna@bravo.com:ayrton_pass' \
-L -X GET 'http://localhost:8080/api/member/v1/token' | jq -r '.token'`
# run cURL using the variable as the authorization token:
# ------------- JSON --------------
curl -s -H "Authorization: $myJWTToken" \
-L -X GET 'http://localhost:8080/api/authentication-failure/v1/log/1' | jq
# -------------- XML --------------
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/xml' \
-L -X GET 'http://localhost:8080/api/authentication-failure/v1/log/1' | xmllint --format -
# ------------- YAML --------------
curl -s -H "Authorization: $myJWTToken" -H 'Accept: application/x-yaml' \
-L -X GET 'http://localhost:8080/api/authentication-failure/v1/log/1' | yq
# ------------- CORS --------------
curl -s -H "Authorization: $myJWTToken" -H 'Origin: http://localhost:3000' \
-L -X GET 'http://localhost:8080/api/authentication-failure/v1/log/1' | jq
If you want to be a lion, you must train with lions. -- Carlos Gracie, Sr