top of page

API - Document - User Service

  • Writer: everyone testing4
    everyone testing4
  • Jun 21, 2022
  • 1 min read

Updated: Jun 26, 2022

Here is the API document for User Service. Source Code: https://github.com/josdoaitran/example_user_service_spring_boot_jwt


User Service is the simple Java Spring Boot with Security JWT.


ree

Business Context of User Service:

- The users can login by their user name and password information.

- Each user type will have the several permission as below:



​Role

​Permission

​User

​login

Manager

​login, getUsers

​Admin

​​login, getUsers, createUsers

​Super Admin

Example users:


username & password

roles

​john

​ROLE_USER

jim

​ROLE_MANAGER

​will

​ROLE_ADMIN

arnold

​ROLE_SUPER_ADMIN; ROLE_ADMIN, ROLE_USER

Authentication:


​​Path:

​/api/login

​​Method:

Post

Header:

Content-Type: Application/json

​​Body:

​form-data

username: userName

password: password

Response

​​Success: 200

​​{ "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ3aWxsIiwicm9sZXMiOlsiUk9MRV9NQU5BR0VSIl0sImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6ODA4MC9hcGkvdG9rZW4vcmVmcmVzaCIsImV4cCI6MTY1NTk3NjMzNn0.T22TxqAXlCsojJjL9Cyzvp7hTK9jk0U2t74JwC-GcLk", "refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ3aWxsIiwicm9sZXMiOlsiUk9MRV9NQU5BR0VSIl0sImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6ODA4MC9hcGkvbG9naW4iLCJleHAiOjE2NTU5NzU3NTB9.3z-4PrCeSLdKkfZckHmpC9CDks0ICx7iuB8NPZrxr4A" }



RefresherToken

Request:


Path:

​/api/token/fresher

Method:

​Get

Header:

​ Content-Type: Application/json Authorization: Bearer {{accessToken}}


Body:

None

Response


​Success: 200

​{ "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ3aWxsIiwicm9sZXMiOlsiUk9MRV9NQU5BR0VSIl0sImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6ODA4MC9hcGkvdG9rZW4vcmVmcmVzaCIsImV4cCI6MTY1NTk3NjMzNn0.T22TxqAXlCsojJjL9Cyzvp7hTK9jk0U2t74JwC-GcLk", "refresh_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ3aWxsIiwicm9sZXMiOlsiUk9MRV9NQU5BR0VSIl0sImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6ODA4MC9hcGkvbG9naW4iLCJleHAiOjE2NTU5NzU3NTB9.3z-4PrCeSLdKkfZckHmpC9CDks0ICx7iuB8NPZrxr4A" }




GetUsers

Request

​Path:

​/api/getusers

Method:

Get

Headers

​Content-Type: Application/json Authorization: Bearer {{accessToken}}

Body

​None

Response

​Success: 200

​[ { "id": 5, "name": "John Travolta", "username": "john", "password": "$2a$10$/NTH2cd.9eePyyr8MENXyu/TNUOcOjv0TnNNIiq2JBe6p0caV69kq", "roles": [ { "id": 1, "name": "ROLE_USER" } ] }, { "id": 6, "name": "Will Smith", "username": "will", "password": "$2a$10$M8p7EpHwS5b63iUP16D0g.JiwX.zB4uwMPkuk1FqDUVmzw1NNSleG", "roles": [ { "id": 2, "name": "ROLE_MANAGER" } ] }, { "id": 7, "name": "Jim Carry", "username": "jim", "password": "$2a$10$ZqiAhQyGqavlS2ITO6MsUu7siNCcU9jzxUxT7d4r9WybMz7gSFbxC", "roles": [ { "id": 3, "name": "ROLE_ADMIN" } ] }, { "id": 8, "name": "Arnold Schwarzenegger", "username": "arnold", "password": "$2a$10$ysCham3ff4ywD.IaVk0Cyu3kx2NrnbAOALUfS85bEk4VP6YLqwWxy", "roles": [ { "id": 1, "name": "ROLE_USER" }, { "id": 3, "name": "ROLE_ADMIN" }, { "id": 4, "name": "ROLE_SUPER_ADMIN" } ] } ]

Add a new user

Request

​Path:

​/api/user/save

Method:

Post

Headers

​Content-Type: Application/json Authorization: Bearer {{accessToken}}

Body

{ "name":"TestUser1", "username": "testuser1", "password": "testpassword" }

Response


​Created: 201

​{ "id": 10, "name": "TestUser1", "username": "testuser1", "password": "$2a$10$3xfFBwjHFbj1eTsQQcFISeoJaopFGQNbEBe.derx6ggTeqsvDJBZm", "roles": [] }

Add a role to a user

Request

​Path:

/api/role/addtouser

Method:

Put

Headers

​Content-Type: Application/json Authorization: Bearer {{accessToken}}

Body

{ "username":"testuser1", "roleName": "ROLE_SUPPERVISOR" }

Response


​Created: 201

​{ "id": 10, "name": "TestUser1", "username": "testuser1", "password": "$2a$10$3xfFBwjHFbj1eTsQQcFISeoJaopFGQNbEBe.derx6ggTeqsvDJBZm", "roles": [] }


 
 
 

Comments


logo.png

Hi, We're Testing4Everyone

We are building up QA/QC community to share technical skills about software testing to everyone. 

  • Facebook
  • Twitter
  • LinkedIn
  • Instagram

Software Testing:

+ Testing concepts

+ Manual testing tips and skills

+ Automation test for Web/ Mobile / Win App.
+ Performance testing for Web/Mobile app.
+ Security testing for QA and QC.

Subscribe

Thanks for submitting!

©2023 by Jeff Sherman. Proudly created with Wix.com

bottom of page