This document objectively describes the permission interfaces and functions. It is strictly based on the typings and the existing code.
- Permissions are organized into groups, persisted as Java classes with
@IgrpPermissionannotations inside the project structure. - Flow: define permission group → persist Java class → read and extract permissions into JSON.
- Purpose: export envelope containing all permission groups read from disk.
- Shape:
permissionGroups: GroupPermissionDef[].
- Purpose: represents a group (class) aggregating multiple permissions.
- Fields:
name: string,permissions: PermissionDef[],module?: string.
- Purpose: describes a single permission extracted/annotated.
- Fields:
name: string,description: string,enabled?: boolean.
- Purpose: defines, at controller/action level, the set of required permissions.
- Fields:
items: string[],operator?: 'AND' | 'OR'(defaultOR).
- Purpose: defines an HTTP action of a controller, including the associated permissions configuration.
- Relevant fields for permissions:
permission?: PermissionsConfig,roles?: string[]. Also includesactionName,method,path, and other metadata.
- Goal: persist a
GroupPermissionDefas the Java class representing the permission group. - Parameters:
basePath: string— project base path. Required.groupConfig: GroupPermissionDef— group definition and its permissions.moduleName?: string— module name to resolve the output directory. Optional.
- Behavior:
- Validates
basePathand capitalizesgroupConfig.name. - Loads the application base config to resolve paths.
- Sets
groupConfig.module = moduleName(or'shared'if not provided). - Renders and saves the group
.javafile via template.
- Validates
- Storage (output path resolved by
saveGroupPermissionDef):- DDD structure:
<basePath>/<main>/<module|shared>/infrastructure/authorization/permission/<GroupName>.java(src/modules/permission/saveGroupPermissionDefinition.ts:10–24). - Classic structure:
<basePath>/<main>/authorization/permission/<GroupName>.java(src/modules/permission/saveGroupPermissionDefinition.ts:20–24).
- DDD structure:
- Goal: read permission groups from
.javafiles and export asAppExportsConfig. - Parameters:
basePath: string— project base path.moduleName?: string— module to inspect; defaults to'shared'.
- Behavior:
- Resolves
<basePath>/<main>/<module|shared>/infrastructure/authorization/permission/. - Lists all
.javafiles and builds aGroupPermissionDeffor each class found. - Permission extraction parses
@IgrpPermissionannotations in class content (src/utils/permissionParser.ts:6–22).
- Resolves
- Return:
AppExportsConfigwithpermissionGroups: GroupPermissionDef[].
- Create: build
GroupPermissionDefwith group name andPermissionDef[]. - Store: call
addPermissionConfig(...)to render and save the Java class into the module’s permission directory. - Read: call
loadConfigs(...)to scan the directory and obtainAppExportsConfigas JSON.
import { GroupPermissionDef } from './src/interfaces/types';
const group: GroupPermissionDef = {
name: 'AppPermissionThree',
permissions: [
{ name: 'hr.employee.view', description: 'Permission to view employee', enabled: false },
{ name: 'hr.employee.edit', description: 'Permission to edit employee' },
{ name: 'hr.leave.approve', description: 'Permission to approve leave requests' }
]
};import { addPermissionConfig } from './src';
await addPermissionConfig('C:/projects/my-api', group, 'shared');
// Without moduleName: await addPermissionConfig('C:/projects/my-api', group);Expected disk output (DDD):
C:/projects/my-api/<main>/shared/infrastructure/authorization/permission/AppPermissionThree.java
Note: the class contains one @IgrpPermission(name, description, enabled?) annotation per permission.
import { loadConfigs } from './src';
const result = await loadConfigs('C:/projects/my-api', 'shared');
console.log(JSON.stringify(result, null, 2));Example output (AppExportsConfig):
{
"permissionGroups": [
{
"name": "AppPermissionThree",
"permissions": [
{ "name": "hr.employee.view", "description": "Permission to view employee", "enabled": false },
{ "name": "hr.employee.edit", "description": "Permission to edit employee" },
{ "name": "hr.leave.approve", "description": "Permission to approve leave requests" }
]
}
]
}PermissionsConfigfor an action with defaultORoperator:
{
"items": ["permission_action_one", "permission_action_two"],
"operator": "OR"
}ControllerActionwith associated permissions:
{
"actionName": "updateAnimal",
"path": "update-animal",
"method": "PUT",
"roles": ["role_one", "role_two"],
"permission": {
"items": ["permission_action_one", "permission_action_two"],
"operator": "OR"
}
}moduleNameonly controls the storage directory; groups returned byloadConfigsdo not set themodulefield by default.- If the permission directory does not exist,
loadConfigsreturns{ "permissionGroups": [] }(src/index.ts:1398–1400).