This project focuses on Spring Security in Spring Boot. The goal of this project is to show API restrictions to various users and their functionality.
Below are APIs with their restrictions according to user's role. (Example, if a user is "ADMINISTRATOR", then he can can access certain APIs as below table shows).
Anonymous | User | Accountant | Administrator | |
---|---|---|---|---|
POST api/auth/signup | + | + | + | + |
POST api/auth/changepass | + | + | + | |
GET api/empl/payment | - | + | + | - |
POST api/acct/payments | - | - | + | - |
PUT api/acct/payments | - | - | + | - |
GET api/admin/user | - | - | - | + |
DELETE api/admin/user/{email} | - | - | - | + |
PUT api/admin/user/role | - | - | - | + |
- POST
api/auth/signup
for registration of a user. - POST
api/auth/changepass
for updating password - GET
api/empl/payment
to view payments of employees (if there is any). - POST
api/acct/payments
to upload payment of employee (for particular period if there is no such). - PUT
api/acct/payments
to change a salary of employee in particular period (if there is such period). - GET
api/admin/user
to view all users in database with their role. (e.g. "ROLE_USER", "ROLE_ADMINISTRATOR", etc.) - DELETE
api/admin/user/{email}
to delete a user from database. - PUT
api/admin/user/role
to grant or remove any role from user.
-
POST
api/auth/signup
:{ "name":"Rahman", "lastname":"Rejepov", "email":"rahman@acme.com", "password":"rahmanGaziUniversity" }
In example above, sent JSON data will be processed for verification.
i. If email has already been registered before, it will throw exception.
ii. If password does not support all the conditions in PasswordAuthentication.java, it will throw exception. -
POST
api/auth/changepass
:{ "new_password": "your new Password" (for updating your password, you must be authenticated, first) }
- GET
api/empl/payment
:
GET request for api/empl/payment with the correct authentication for johndoe@acme.com :
In case of successful authentication, application will return all the payrolls of that employee:
[ { "name": "John", "lastname": "Doe", "period": "March-2021", "salary": "1234 dollar(s) 56 cent(s)" }, { "name": "John", "lastname": "Doe", "period": "February-2021", "salary": "1234 dollar(s) 56 cent(s)" }, { "name": "John", "lastname": "Doe", "period": "January-2021", "salary": "1234 dollar(s) 56 cent(s)" } ]
- POST
api/acct/payments
:
If a user wants to upload employee payrolls, then JSON data should be like this:
[ { "employee": "johndoe@acme.com", "period": "01-2021", "salary": 123456 }, { "employee": "johndoe@acme.com", "period": "01-2021", "salary": 123456 } ]
-
PUT
api/acct/payments
:
If there is an employee with uploaded payment such as:{ "employee": "johndoe@acme.com", "period": "01-2021", (period existing in database) "salary": 123457 (updated salary for that period) }
Then, in case of successful update, the response will be like:
{ "status": "Updated successfully!" }
-
GET
api/admin/user
:
Shows all the users in database with their granted roles (for example):[ { "id": 1, "name": "John", "lastname": "Doe", "email": "johndoe@acme.com", "roles": [ "ROLE_ADMINISTRATOR" ] }, { "id": 2, "name": "Ivan", "lastname": "Ivanov", "email": "ivanivanov@acme.com", "roles": [ "ROLE_ACCOUNTANT", "ROLE_USER" ] } ]
In example above, in order to get user list, user must be authenticated and authorized as ADMINISTRATOR.
-
DELETE
api/admin/user/{email}
:
In {email} , there must be existing user email to be able to delete that user as ADMINISTRATOR :
Example: Requested DELETEapi/admin/user/johndoe@acme.com
to delete a user with email johndoe@acme.com :
Response: (in case of successful deletion):{ "user": "ivanivanov@acme.com", "status": "Deleted successfully!" }
-
PUT
api/admin/user/role
:
In case of successful authentication and authorization as ADMINISTRATOR of a user, a user can grant or remove role of requested user:{ "user": "ivanivanov@acme.com", "role": "ACCOUNTANT", "operation": "REMOVE" }
In case of successful romoval of a role from the user, the response will be like:
{ "id": 2, "name": "Ivan", "lastname": "Ivanov", "email": "ivanivanov@acme.com", "roles": [ "ROLE_USER" ] }
The same process is applied for grant operation.