Overview
ThePermissionService is responsible for ensuring that the connected Oracle database user has all necessary permissions to run OmniView successfully. This service:
- Deploys a temporary permission-checking package to Oracle
- Verifies required database privileges
- Validates Oracle Advanced Queuing (AQ) permissions
- Stores permission verification results in BoltDB
- Cleans up by dropping the temporary package after checks complete
Service Structure
Database repository for Oracle operations including package deployment and permission queries
Configuration repository for BoltDB operations to persist permission check results
Permission Entities
PermissionStatus
Oracle schema/username being verified
Permission to create sequences in the database
Permission to create stored procedures and packages
Permission to create custom Oracle types
Has the AQ_ADMINISTRATOR_ROLE granted (required for queue management)
Has the AQ_USER_ROLE granted (required for queue operations)
Has EXECUTE permission on DBMS_AQADM package (queue administration)
Has EXECUTE permission on DBMS_AQ package (queue operations)
True only if all of the above permissions are granted
DatabasePermissions
Constructor
NewPermissionService
Creates a new instance of PermissionService with injected dependencies.Database repository interface for Oracle database operations
Configuration repository interface for BoltDB operations
Returns a pointer to the newly created PermissionService instance
Methods
DeployAndCheck
The primary method that orchestrates the entire permission verification process. This method:- Checks if this is the first application run
- If first run:
- Deploys the TXEVENTQ_PERMISSION_CHECK_API package
- Executes permission checks
- Saves results to BoltDB
- Marks first run as complete
- Drops the temporary package
- If not first run: Returns immediately (cached results are used)
Oracle schema/username to verify permissions for (typically the connected user)
Returns true if all permissions are valid or if checks were previously completed
Returns error with detailed permission report if any checks fail, or if deployment/cleanup fails
Permission Package: Permission_Checks.sql
The service deploys a temporary Oracle package namedTXEVENTQ_PERMISSION_CHECK_API from the embedded asset file Permission_Checks.sql. This package contains:
Get_Permission_Report Function
- Queries Oracle system views (USER_SYS_PRIVS, USER_ROLE_PRIVS, USER_TAB_PRIVS)
- Checks for each required permission
- Returns a JSON object with permission status
Deployment Process
1. Package Existence Check
2. Package Deployment
3. Permission Verification
Executes theGet_Permission_Report function and unmarshals the JSON result into the PermissionStatus struct.
4. Result Storage
5. Package Cleanup
- Maintain a clean database state
- Improve security by removing diagnostic code
- Prevent namespace pollution
The package is dropped even if it doesn’t exist (SQLCODE -4043 is ignored) to ensure idempotency.
Error Handling
Permission Failures
IfAllValid is false, the service returns a detailed error with a formatted table showing which permissions are missing:
Deployment Errors
Errors during package deployment or dropping return immediately:- Package deployment failure: Returns error to caller
- Package drop failure: Returns error (prevents cleanup)
- BoltDB save failure: Returns error (prevents marking as complete)
First Run Detection
The service uses a “first run” flag stored in BoltDB to determine if permission checks need to be executed:- Permission checks only run once
- Faster subsequent startups
- Reduced database load
- Cached results available for auditing
Required Oracle Permissions
For OmniView to function correctly, the Oracle user must have:Object Creation Permissions
Object Creation Permissions
- CREATE SEQUENCE: Required for generating unique IDs
- CREATE PROCEDURE: Required for deploying OmniView packages
- CREATE TYPE: Required for defining queue payload types
Oracle AQ Roles
Oracle AQ Roles
- AQ_ADMINISTRATOR_ROLE: Required for:
- Creating queues and queue tables
- Managing subscriptions
- Administering AQ objects
- AQ_USER_ROLE: Required for:
- Enqueuing messages
- Dequeuing messages
- Basic queue operations
DBMS Package Execution
DBMS Package Execution
- EXECUTE on DBMS_AQADM: Required for:
- Queue administration procedures
- Subscription management
- Queue table operations
- EXECUTE on DBMS_AQ: Required for:
- Enqueue operations
- Dequeue operations
- Message handling
Granting Permissions
If permission checks fail, a DBA must grant the required permissions:Architecture Pattern
PermissionService follows the hexagonal architecture (ports and adapters) pattern:- Core Service (internal/service/permissions): Contains permission verification logic
- Ports (internal/core/ports): Define repository interfaces
- Adapters:
internal/adapter/storage/oracle: Implements DatabaseRepository for Oracleinternal/adapter/storage/boltdb: Implements ConfigRepository for BoltDB
- Separation of concerns
- Testability with mock repositories
- Database-agnostic business logic
- Easy addition of permission checks
Usage Flow
Security Considerations
- Temporary Package: The permission check package is deployed, used, and immediately dropped to minimize security exposure
- Read-Only Checks: The package only reads from system views, never modifies data
- Cached Results: Permission status is cached to prevent repeated diagnostic queries
- Error Details: Permission failures provide detailed output to help DBAs grant correct permissions
Related Documentation
- TracerService - Requires permissions to deploy and run
- SubscriberService - Requires AQ permissions for subscriptions
- Architecture Overview - Learn about the hexagonal pattern
- Oracle Integration - Oracle-specific configuration