[rule]
id = "java-custom-authz-call"
languages = ["java"]
category = "custom"
confidence = "medium"
description = "Custom authorization-style method call (heuristic: name suggests role/membership/permission check)"
query = """
(method_invocation
name: (identifier) @method_name @method_name_excl
) @match
"""
[rule.predicates.method_name]
match = "^(is|has|can)\\w*?(Admin|Manager|Member|Recruiter|Viewer|Editor|Owner|Access|Permission|Privilege|Role|Authority|Authorized)(?:[A-Z]\\w*)?$"
[rule.predicates.method_name_excl]
not_match = "^(hasRole|hasAnyRole|hasAuthority|hasAnyAuthority|isUserInRole)$"
[[rule.tests]]
input = """
public class OrgController {
public void delete(Account account, Org org) {
if (!privService.isOrgAdmin(account.getId(), org.getId())) {
throw new ForbiddenException();
}
}
}
"""
expect_match = true
[[rule.tests]]
input = """
public class CandidateController {
public void view(Account account, Candidate c) {
if (!privService.isCandidateViewer(account.getId(), c.getOrgId())) {
throw new ForbiddenException();
}
}
}
"""
expect_match = true
[[rule.tests]]
input = """
public class AdminController {
public void edit(Account actor, Org org, Account subject) {
if (!privService.isAdminForAccount(actor, org, subject)) {
throw new ForbiddenException();
}
}
}
"""
expect_match = true
[[rule.tests]]
input = """
public class ReportController {
public Report build(Account actor, Long orgId) {
if (!privService.hasFullOrganizationAccess(actor, orgId)) {
return Report.empty();
}
return Report.full();
}
}
"""
expect_match = true
[[rule.tests]]
input = """
public class RoleController {
public void edit(Account actor, Org org, Role role) {
if (!privService.canEditRole(actor, org, role)) {
throw new ForbiddenException();
}
}
}
"""
expect_match = true
[[rule.tests]]
input = """
public class PermissionController {
public void update(Account actor, Permission p) {
if (!privService.canManagePermission(actor, p)) {
throw new ForbiddenException();
}
}
}
"""
expect_match = true
[[rule.tests]]
input = """
public class RoleController {
public void assign(Account actor, Role role, User target) {
if (!privService.canAssignAdminRole(actor, role, target)) {
throw new ForbiddenException();
}
}
}
"""
expect_match = true
[[rule.tests]]
input = """
public class Service {
public void doWork(Note note) {
if (note.isArchived()) { return; }
process(note);
}
}
"""
expect_match = false
[[rule.tests]]
input = """
public class Service {
public void doWork(String s) {
if (s.isEmpty()) { return; }
if (str.hasLength(s)) { process(s); }
}
}
"""
expect_match = false
[[rule.tests]]
input = """
public class SecurityConfig {
public void configure(HttpSecurity http) {
http.authorizeRequests().antMatchers("/admin/**").hasRole("ADMIN");
}
}
"""
expect_match = false
[[rule.tests]]
input = """
public class SecurityConfig {
public void configure(HttpSecurity http) {
http.authorizeRequests().antMatchers("/admin/**").hasAnyRole("ADMIN", "MANAGER");
}
}
"""
expect_match = false
[[rule.tests]]
input = """
public class SecurityConfig {
public void configure(HttpSecurity http) {
http.authorizeRequests().antMatchers("/api/**").hasAnyAuthority("SCOPE_read", "SCOPE_write");
}
}
"""
expect_match = false
[[rule.tests]]
input = """
public class Servlet {
public void doGet() {
if (request.isUserInRole("admin")) { allow(); }
}
}
"""
expect_match = false
[[rule.tests]]
input = """
public class Filter {
public boolean accept(SearchRequest req) {
return req.isIncludeAdmins() || req.isIncludeEmployees();
}
}
"""
expect_match = false