Unit 3
Unit 3
Purpose: Prevents users from overwhelming the API with too many
requests.
Why it's important: Ensures the API remains available and responsive,
protecting against denial-of-service attacks where attackers flood the API
with requests to disrupt service.
Encryption:
Purpose: Secures data when it's transmitted over the network or stored
on disk.
Why it's important: Prevents unauthorized access to sensitive
information by encoding data in a way that only authorized parties can
decrypt, ensuring confidentiality and integrity of data.
Authentication:
Audit Logging:
Purpose: Rate limiting restricts the number of requests a client can make
to prevent API overload.
Benefits: Ensures that resources are allocated efficiently, reducing the
impact of excessive traffic.
Implementation: Should be the first defense mechanism applied to
incoming requests to mitigate potential DoS effects.
3. ENCRYPTION
Importance of Encryption
Process:
o Alice encrypts plaintext ("Hello") using an encryption algorithm
and a key.
o The ciphertext ("Jgnnq") is transmitted or stored securely.
o Bob, possessing the decryption key, decrypts the ciphertext back to
the original plaintext.
4. AUDIT LOGGING
Key Points:
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
private void logAudit(long auditId, String method, String path, String userId)
{
now.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME),
auditId, method, path, userId);
writeLogToFile(logMessage);
private void logAudit(long auditId, String method, String path, int status,
String userId) {
now.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME),
auditId, method, path, status, userId);
writeLogToFile(logMessage);
}
public static void main(String[] args) {
Key Concepts
OAuth 2.0 defines several grant types to accommodate different use cases:
API KEYS
API keys play a crucial role in securing access to APIs and controlling how
applications interact with sensitive data. Here’s a simplified overview
highlighting their importance, use cases, advantages, types, and best practices:
API keys are unique identifiers (usually alphanumeric strings) that authorize
applications to access APIs. They serve as a form of authentication and
authorization mechanism between the Client (application) and the API server.
1. Public API Keys: Used for read-only access to public data and are
typically embedded in client-side applications.
2. Secret API Keys: Used for accessing sensitive data, including write
operations, and must be kept confidential in server-side applications.
3. JWT-based API Keys: Use JSON Web Tokens for authentication and
authorization, commonly used in modern web applications.
4. Session-based API Keys: Temporary keys issued for short-term access
that expire after a session ends.
5. Scoped API Keys: Used to restrict access to specific features or
resources of an API.
API keys are typically generated through the API provider’s developer
portal or admin dashboard.
Choose the appropriate type of key based on your application’s needs
(e.g., public vs. secret) and securely manage and store them.