The VMJ Authentication Library provides all the essential tools required for authentication and authorization in web applications. This includes APIs and functions, offering a comprehensive solution for securing and managing access.
This library offers a comprehensive set of APIs related to authentication and authorization, including functionalities for user registration, login, and CRUD operations for both users and roles. With this library, developers can quickly implement secure authentication and authorization features without the need to build them from scratch.
Register (/auth/register)The Register API is used to create a new user account in the system. It handles the process of validating user input, creating the user record in the database, and providing the necessary response based on the success or failure of the operation. This API is typically the first step for a user to gain access to the application.
Example of Request Body:
{
"email": "exampleuser@gmail.com",
"name": "Example User",
"password": "examplepassword"
}
Example of Response:
{
"data": {
"email": "exampleuser@gmail.com",
"name": "Example User",
"allowedPermissions": "",
"id": "12372338-2822-420d-8c06-cff0d411d771"
}
}
Forgot Password Token (/auth/forgot-password-token)The Forgot Password Token API is used to generate a token for resetting a user's password.
Example of Request Body:
{
"email": "exampleuser@gmail.com"
}
Example of Response:
{
"data": {
"forgotPasswordToken": "dCLmtf_NsIbgakaKFykw9BLk36TfD0Sg-MeFnvB4THDysZ3RcBhPGkKV9Tkc_i1u"
}
}
Forgot Password (/auth/forgot-password)The Forgot Password API allows users to reset their password using the token they received in the Forgot Password Token API.
Example of Request Body:
{
"forgotPasswordToken": "dCLmtf_NsIbgakaKFykw9BLk36TfD0Sg-MeFnvB4THDysZ3RcBhPGkKV9Tkc_i1u",
"password": "examplepassword"
}
Example of Response:
{
"data": {}
}
Login (/auth/login/pwd)The Login API is used to authenticate users by verifying their credentials, which typically include their email and password.
Example of Request Body:
{
"email": "exampleuser@gmail.com",
"password": "examplepassword"
}
Example of Response:
{
"data": {
"email": "exampleuser@gmail.com",
"name": "Example User",
"allowedPermissions": [],
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJmNzFkYTU1Zi0wZTgwLTQ3YjgtYmM2MS03ZWMyNzJhODVmY2Q6OnRlc3R1c2VyQGdtYWlsLmNvbSIsImlzcyI6ImFtYW5haC5jcy51aS5hYy5pZCIsImV4cCI6MTcyNzIwMTM5OSwiaWF0IjoxNzI3MTE0OTk5LCJlbWFpbCI6InRlc3R1c2VyQGdtYWlsLmNvbSJ9.O_RcjLd67faKwlFNBw9TqD4xD09-qNVai5W12Az8doQ",
"token_keep_login": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJmNzFkYTU1Zi0wZTgwLTQ3YjgtYmM2MS03ZWMyNzJhODVmY2Q6OnRlc3R1c2VyQGdtYWlsLmNvbSIsInBlcm1pc3Npb25zIjoiIiwiaXNzIjoiYW1hbmFoLmNzLnVpLmFjLmlkIiwiZXhwIjoxNzI3MjAxMzk5LCJpYXQiOjE3MjcxMTQ5OTksImVtYWlsIjoidGVzdHVzZXJAZ21haWwuY29tIn0.qrK_X-LYR21vi31hKqk7mQXPOKNVmv_8mKiuwy0Ww08"
}
}
CRUD RoleThis section covers the various APIs related to CRUD (Create, Read, Update, Delete) operations for roles in the system. These operations are essential for managing user roles, such as creating new roles, reading role details, updating existing roles, and deleting roles when necessary.
Create Role (/call/role/save)Example of Request Body:
{
"name": "Example Role",
"allowedPermissions": "CreateRole,ReadRole"
}
Example of Response:
{
"id": "12372338-2822-420d-8c06-cff0d411d771",
"name": "Example Role",
"allowedPermissions": "CreateRole,ReadRole"
}
Get Role Detail (/call/role/detail?id={id})Example of Response:
{
"data": {
"allowedPermissions": [
CreateRole,
ReadRole
],
"name": "Example Role",
"id": "12372338-2822-420d-8c06-cff0d411d771"
}
}
Get List of Role (/call/role/list)Example of Response:
{
"data": [
{
"allowedPermissions": [
CreateRole,
ReadRole
],
"name": "Example Role",
"id": "12372338-2822-420d-8c06-cff0d411d771"
},
// Other role objects
]
}
Update Role (/call/role/update)Example of Request Body:
{
"id": "12372338-2822-420d-8c06-cff0d411d771",
"name": "Example Role",
"allowedPermissions": "CreateRole,ReadRole"
}
Example of Response:
{
"id": "12372338-2822-420d-8c06-cff0d411d771",
"name": "Example Role",
"allowedPermissions": "CreateRole,ReadRole"
}
Delete Role (/call/role/delete)Example of Request Body:
{
"id": "12372338-2822-420d-8c06-cff0d411d771"
}
Example of Response:
{
"data": [
{
"allowedPermissions": [
ReadRole
],
"name": "Another Role",
"id": "53172742-2053-24fs-8c06-24s0d411sfw3"
},
// Other role objects
]
}
CRUD UserThis section covers the various APIs related to CRUD (Create, Read, Update, Delete) operations for users in the system. These operations are essential for managing users, such as creating new users, reading user details, updating existing users, and deleting users when necessary.
Create User (/call/user/save)Example of Request Body:
{
"15a9ff33-6dd2-4c0a-b113-a90ee32a01ca",
"name": "Example User",
"roleIds": "12372338-2822-420d-8c06-cff0d411d771",
"email": "exampleuser@gmail.com",
"password": "examplepassword",
"allowedPermissions": ""
}
Example of Response:
{
"data": [
{
"userRoles": [
{
"role": {
"allowedPermissions": "CreateRole,ReadRole",
"name": "Example Role",
"id": "12372338-2822-420d-8c06-cff0d411d771"
},
"id": "2a0859e2-e73f-4ebe-85c0-6a39d231bbbb"
}
],
"roleIds": "12372338-2822-420d-8c06-cff0d411d771",
"allowedPermissions": [
""
],
"name": "Example User",
"id": "15a9ff33-6dd2-4c0a-b113-a90ee32a01ca",
"userRolesName": [
"Example Role"
],
"email": "exampleuser@gmail.com"
},
// Other user objects
]
}
Get User Detail (/call/user/detail?id={id})Example of Response:
{
"data": {
"userRoles": [
{
"role": {
"allowedPermissions": "CreateRole,ReadRole",
"name": "Example Role",
"id": "12372338-2822-420d-8c06-cff0d411d771"
},
"id": "2a0859e2-e73f-4ebe-85c0-6a39d231bbbb"
}
],
"roleIds": "12372338-2822-420d-8c06-cff0d411d771",
"allowedPermissions": [
""
],
"name": "Example User",
"id": "15a9ff33-6dd2-4c0a-b113-a90ee32a01ca",
"userRolesName": [
"Example Role"
],
"email": "exampleuser@gmail.com"
}
}
Get List of User (/call/user/list)Example of Response:
{
"data": [
{
"userRoles": [
{
"role": {
"allowedPermissions": "CreateRole,ReadRole",
"name": "Example Role",
"id": "12372338-2822-420d-8c06-cff0d411d771"
},
"id": "2a0859e2-e73f-4ebe-85c0-6a39d231bbbb"
}
],
"roleIds": "12372338-2822-420d-8c06-cff0d411d771",
"allowedPermissions": [
""
],
"name": "Example User",
"id": "15a9ff33-6dd2-4c0a-b113-a90ee32a01ca",
"userRolesName": [
"Example Role"
],
"email": "exampleuser@gmail.com"
},
// Other user objects
]
}
Update User (/call/user/update)Example of Request Body:
{
"15a9ff33-6dd2-4c0a-b113-a90ee32a01ca",
"name": "Example User",
"roleIds": "12372338-2822-420d-8c06-cff0d411d771",
"email": "exampleuser@gmail.com",
"allowedPermissions": ""
}
Example of Response:
{
"data": {
"userRoles": [
{
"role": {
"allowedPermissions": "CreateRole,ReadRole",
"name": "Example Role",
"id": "12372338-2822-420d-8c06-cff0d411d771"
},
"id": "2a0859e2-e73f-4ebe-85c0-6a39d231bbbb"
}
],
"roleIds": "12372338-2822-420d-8c06-cff0d411d771",
"allowedPermissions": [
""
],
"name": "Example User",
"id": "15a9ff33-6dd2-4c0a-b113-a90ee32a01ca",
"userRolesName": [
"Example Role"
],
"email": "exampleuser@gmail.com"
}
}
Delete User (/call/user/delete)Example of Request Body:
{
"id": "15a9ff33-6dd2-4c0a-b113-a90ee32a01ca"
}
Example of Response:
{
"data": [
{
"userRoles": [
{
"role": {
"allowedPermissions": "CreateRole,ReadRole",
"name": "Example Role",
"id": "12372338-2822-420d-8c06-cff0d411d771"
},
"id": "2a0859e2-e73f-4ebe-85c0-6a39d231bbbb"
}
],
"roleIds": "12372338-2822-420d-8c06-cff0d411d771",
"allowedPermissions": [
""
],
"name": "Example User",
"id": "15a9ff33-6dd2-4c0a-b113-a90ee32a01ca",
"userRolesName": [
"Example Role"
],
"email": "exampleuser@gmail.com"
},
// Other user objects
]
}
Change User Role (/call/user/changerole)Example of Request Body:
{
"id": "15a9ff33-6dd2-4c0a-b113-a90ee32a01ca",
"roleIds": "12372338-2822-420d-8c06-cff0d411d771"
}
Example of Response:
{
"data": {
"userRoles": [
{
"role": {
"allowedPermissions": "CreateRole,ReadRole",
"name": "Example Role",
"id": "12372338-2822-420d-8c06-cff0d411d771"
},
"id": "2a0859e2-e73f-4ebe-85c0-6a39d231bbbb"
}
],
"roleIds": "12372338-2822-420d-8c06-cff0d411d771",
"allowedPermissions": [
""
],
"name": "Example User",
"id": "15a9ff33-6dd2-4c0a-b113-a90ee32a01ca",
"userRolesName": [
"Example Role"
],
"email": "exampleuser@gmail.com"
}
}
This library offers a comprehensive set of functions for authentication and authorization, including annotations to specify which user roles are allowed to access particular APIs.
@Restricted(permissionName)The Register API is used to create a new user account in the system. It handles the process of validating user input, creating the user record in the database, and providing the necessary response based on the success or failure of the operation. This API is typically the first step for a user to gain access to the application.
Example:
import id.ac.ui.cs.prices.winvmj.core.annotations.Post;
import id.ac.ui.cs.prices.winvmj.core.VMJExchange;
import id.ac.ui.cs.prices.winvmj.core.annotations.Restricted;
public class PaymentResourceImpl extends PaymentResourceComponent {
@Restricted(permissionName = "SavePayment")
@Post("call/payment/save")
public void savePayment(VMJExchange vmjExchange) {
// Handle POST request
}
}
v1.1.1:
v1.0.1: