Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:APIJSON APIJSON AbstractVerifier verifyAccess

From Leeroopedia
Knowledge Sources
Domains Security, Access_Control, Authorization
Last Updated 2026-10-11 00:00 GMT

Overview

Concrete role-based access control gate that verifies the requesting user's role is permitted to perform the requested method on the requested table, provided by the APIJSON ORM framework.

Description

The verifyAccess method on AbstractVerifier is the authorization check that runs after authentication but before SQL execution. It:

  1. Checks if role verification is enabled (ENABLE_VERIFY_ROLE)
  2. Validates the role is a known role (UNKNOWN, LOGIN, CONTACT, CIRCLE, OWNER, ADMIN) via ROLE_MAP
  3. Triggers verifyLogin() for any non-UNKNOWN role
  4. Delegates to verifyRole() which calls:
    1. verifyAllowRole() - checks ACCESS_MAP for allowed roles on this table+method
    2. verifyUseRole() - validates that the role's conditions are met (e.g., OWNER must own the data)

The ACCESS_MAP is populated from two sources:

  • SYSTEM_ACCESS_MAP - built from @MethodAccess annotations on model classes
  • Runtime access rules loaded from the Access database table

If the table is not in ACCESS_MAP or the role is not in the allowed list for the method, an IllegalAccessException is thrown.

Usage

Called internally by ObjectParser during setSQLConfig(). Override verifyUseRole in a subclass to add custom role validation logic (e.g., checking that a CONTACT role user is actually in the data owner's contact list).

Code Reference

Source Location

  • Repository: APIJSON
  • File: src/main/java/apijson/orm/AbstractVerifier.java

Signature

public boolean verifyAccess(SQLConfig<T, M, L> config) throws Exception

public void verifyRole(SQLConfig<T, M, L> config, String table, RequestMethod method, String role) throws Exception

public void verifyAllowRole(SQLConfig<T, M, L> config, String table, RequestMethod method, String role) throws Exception

public void verifyUseRole(@NotNull SQLConfig<T, M, L> config, String table, RequestMethod method, String role) throws Exception

Parameters:

  • config - SQLConfig containing table name, method, and role
  • table - Table name to check access for
  • method - HTTP method (GET/POST/PUT/DELETE)
  • role - Role name (UNKNOWN/LOGIN/CONTACT/CIRCLE/OWNER/ADMIN)

Import

import apijson.orm.AbstractVerifier;

I/O Contract

Inputs

Name Type Required Description
config SQLConfig<T,M,L> Yes Contains table, method, role
table String Yes Table name
method RequestMethod Yes HTTP method
role String Yes Role name
ACCESS_MAP Map<String,Map<RequestMethod,String[]>> Yes Runtime access rules

Outputs

Name Type Description
return (verifyAccess) boolean true if access granted
return (verifyRole/verifyAllowRole/verifyUseRole) void Throws IllegalAccessException if denied

Usage Examples

Access Check Flow

// During request processing:
// config.setRole("OWNER");  // from @role directive
// config.setTable("Moment");
// config.setMethod(RequestMethod.PUT);

boolean allowed = verifier.verifyAccess(config);
// 1. Role "OWNER" found in ROLE_MAP
// 2. verifyLogin() called (user must be authenticated)
// 3. verifyAllowRole: checks ACCESS_MAP["Moment"]["PUT"] contains "OWNER"
// 4. verifyUseRole: checks user owns the Moment being updated

Custom Role Validation

public class MyVerifier extends AbstractVerifier<Long, JSONObject, JSONArray> {
    @Override
    public void verifyUseRole(SQLConfig<Long, JSONObject, JSONArray> config,
            String table, RequestMethod method, String role) throws Exception {
        super.verifyUseRole(config, table, method, role);
        
        if ("OWNER".equals(role) && "Moment".equals(table)) {
            Long userId = getVisitor().getId();
            Long momentUserId = config.getWhere().get("userId");
            if (!userId.equals(momentUserId)) {
                throw new IllegalAccessException("Not the owner of this Moment!");
            }
        }
    }
}

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment