Overview
The Secure Link API maintains a comprehensive audit trail of every link access attempt, regardless of success or failure. This provides visibility into link usage patterns, security events, and potential abuse.Why Audit Tracking?
Security Monitoring
Detect unauthorized access attempts and potential security threats
Usage Analytics
Analyze link performance, popular content, and access patterns
Compliance
Maintain records for regulatory requirements and data governance
Troubleshooting
Diagnose access issues and validate security configuration
What Gets Tracked
Every access attempt generates an audit record with the following information:Audit Record Structure
LinkAccessAudit.java:21-48
Field Descriptions
The unique identifier of the link being accessed
The outcome of the access attempt (see AccessResult enum below)
Client IP address (supports both IPv4 and IPv6, max 45 characters)
Client user agent string (browser, app, bot identifier)
Timestamp when the access attempt occurred (timezone-aware)
AccessResult Enum
TheAccessResult enum captures the outcome of every access validation:
Result Values
SUCCESS
SUCCESS
Access granted - All validation checks passed.Details:
- Link exists and is ACTIVE
- Not expired by time or view limit
- Password validated (if required)
- View count incremented
- Content returned to client
NOT_FOUND
NOT_FOUND
Link does not exist - No link found with the provided shortCode.Details:
- shortCode not in database
- Could indicate deleted link, typo, or enumeration attempt
- Most common for expired/cleaned-up links
REVOKED
REVOKED
Link manually disabled - Administrator revoked the link.Details:
- Link exists but status is REVOKED
- Permanent denial (cannot be un-revoked)
- Typically used for compromised or abused links
EXPIRED
EXPIRED
Time-based expiration - Link exceeded its expiresAt timestamp.Details:
- Current time > expiresAt
- Link status automatically updated to EXPIRED
- Expected outcome for time-limited sharing
ResolveLinkServiceImpl.java:74-77
VIEW_LIMIT_REACHED
VIEW_LIMIT_REACHED
Usage limit exceeded - Link has been accessed maxViews times.Details:
- viewCount >= maxViews
- Link status automatically updated to EXPIRED
- Used for one-time or limited-distribution content
ResolveLinkServiceImpl.java:78-82
PASSWORD_REQUIRED
PASSWORD_REQUIRED
Missing password - Link requires password but none provided.Details:
- Link has passwordProtected = true
- Client did not provide password parameter
- Informational denial (not necessarily malicious)
ResolveLinkServiceImpl.java:88-90
INVALID_PASSWORD
INVALID_PASSWORD
Password mismatch - Provided password does not match stored hash.Details:
- Password provided but BCrypt validation failed
- Could indicate legitimate user error or attack attempt
- Multiple failures may indicate brute-force attack
ResolveLinkServiceImpl.java:91-93
UNEXPECTED_STATE
UNEXPECTED_STATE
Invalid link state - Link exists but is not ACTIVE (edge case).Details:
- Link passed existence check but isActive() returned false
- Should be rare; indicates potential data consistency issue
- May occur during concurrent status transitions
ResolveLinkServiceImpl.java:83-85
Audit Recording Process
Audit records are created automatically for every access attempt, using a separate transaction to ensure records are preserved even if the main request fails.Implementation
LinkAccesAuditServiceImpl.java:22-34
The
REQUIRES_NEW transaction propagation ensures audit records are committed even if the parent transaction rolls back. This guarantees no access attempt goes unrecorded.Audit Points in Resolution Flow
Audit records are created at multiple points during link resolution:ResolveLinkServiceImpl.java:57-105
Access Context
Client information is captured from the HTTP request:AccessContextDto.java
- IP Address:
X-Forwarded-Forheader or direct connection IP - User Agent:
User-AgentHTTP header
Analytics and Reporting
The audit data powers various analytics endpoints:Access Summary
- Total access attempts
- Successful accesses
- Failed accesses by reason
Daily/Hourly Access Trends
Access by Result
Security Exceptions
Security Monitoring Use Cases
Detecting Brute Force Attacks
Monitor for multipleINVALID_PASSWORD results from the same IP:
Link Enumeration Detection
Identify potential shortCode enumeration attempts:Popular Link Analysis
Best Practices
Retention Policy
Implement audit log retention policies based on compliance requirements (e.g., 90 days, 1 year).
Alerting
Set up automated alerts for:
- Sudden spikes in
NOT_FOUNDresults (enumeration) - High volumes of
INVALID_PASSWORDfrom single IP (brute force) - Unusual access patterns outside business hours
Metrics Integration
The audit system integrates with Micrometer for real-time metrics:ResolveLinkServiceImpl.java:53-55
ResolveLinkServiceImpl.java:61-64
/actuator/prometheus for monitoring systems.
Next Steps
Statistics API
Explore the complete statistics and analytics API
Access Control
Learn about validation flow and security constraints
