Autenticación y autorización
Implemente mecanismos sólidos de autenticación y autorización para controlar el acceso a los recursos del sistema.
Autenticación y autorización es una lección gratuita de System Design Basics for Backend Developers en CoddyKit. Esta es la lección 1 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de System Design Basics for Backend Developers, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de System Design Basics for Backend Developers incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
Auth vs. Auth: The Basics
In system design, authentication and authorization are critical for security. They control who can access your system and what they can do.
- Authentication (AuthN) verifies who you are.
- Authorization (AuthZ) determines what you're allowed to do.
Think of it like a club: authentication is checking your ID at the door, authorization is seeing if you have a VIP pass to enter special areas.
What is Authentication?
Authentication is the process of proving your identity to a system. This confirms that you are who you claim to be.
Common authentication methods include:
- Password-based: Username and password.
- Multi-factor: Combining passwords with codes from an app or SMS.
- Biometric: Fingerprints or facial recognition.
- Token-based: Using a cryptographic token after initial login.
Token-Based Authentication
Token-based authentication is popular for web and mobile apps. After a user logs in (authenticates) with credentials, the server issues a token.
This token is then sent with every subsequent request to prove the user's identity without sending credentials repeatedly. A common type is the JSON Web Token (JWT).
Understanding JWTs
A JWT (JSON Web Token) is a compact, URL-safe means of representing claims to be transferred between two parties. It's often used to authenticate users.
JWTs consist of three parts, separated by dots:
- Header: Type of token and signing algorithm.
- Payload: Claims (user ID, roles, expiration).
- Signature: Used to verify the token hasn't been tampered with.
It looks something like this:
eyJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiIxMjMiLCJyb2xlIjoiYWRtaW4ifQ.SFLS...Simple Token Check Demo
When a client sends a request with a token, the server must validate it. This often involves checking the signature and expiration.
Here's a very simplified conceptual example of how a server might check if a token is known, representing a basic validation step:
public class TokenChecker {
public static void main(String[] args) {
String userToken = "validUserToken123";
String adminToken = "adminSecretToken456";
String invalidToken = "badToken";
System.out.println("User Token Check: " + isValid(userToken));
System.out.println("Admin Token Check: " + isValid(adminToken));
System.out.println("Invalid Token Check: " + isValid(invalidToken));
}
// A very simplified conceptual token validation
public static boolean isValid(String token) {
if (token.equals("validUserToken123") || token.equals("adminSecretToken456")) {
return true; // Token is conceptually 'valid'
}
return false; // Token is not recognized
}
}What is Authorization?
Authorization is the process of determining what an authenticated user or system is permitted to do.
For example, a regular user might be able to view their own profile, but only an administrator can delete user accounts. Authorization answers the question: "Are you allowed to do that?"
Role-Based Access Control (RBAC)
One common authorization model is Role-Based Access Control (RBAC). In RBAC, permissions are associated with roles, and users are assigned to roles.
- Users: Individuals or systems.
- Roles: Collections of permissions (e.g., 'Admin', 'Editor', 'Viewer').
- Permissions: Specific actions on resources (e.g., 'read_post', 'edit_user').
This simplifies managing access, as you assign users to roles rather than individual permissions.
Policy-Based Authorization
For more complex scenarios, Policy-Based Authorization (like Attribute-Based Access Control or ABAC) allows for very fine-grained control.
Instead of just roles, access decisions are based on attributes of the user, the resource, the environment, and the action itself. This offers greater flexibility but can be more complex to manage.
AuthN and AuthZ Together
Authentication and authorization work hand-in-hand in a typical request flow:
- A user tries to access a resource.
- The system authenticates the user (e.g., validates their token). If invalid, access is denied.
- If authenticated, the system then authorizes the user: it checks if the user's role or attributes grant them permission for that specific action on that resource.
- If authorized, access is granted. Otherwise, it's denied.
Identify the Concepts
Which of the following statements correctly describe the concepts of Authentication and Authorization?
Recap: Securing Access
We've explored the crucial difference between authentication (who you are) and authorization (what you can do).
You learned about token-based authentication with JWTs and authorization models like RBAC. Understanding these concepts is fundamental to designing secure and robust systems.
Keep practicing these distinctions as you design systems that need to control access effectively!
Preguntas frecuentes
¿La lección «Autenticación y autorización» es gratis?
Sí — el texto completo de «Autenticación y autorización» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de System Design Basics for Backend Developers, actualiza a CoddyKit PRO. El curso de System Design Basics for Backend Developers incluye 4 lecciones en total.
¿Qué aprenderé en «Autenticación y autorización»?
Implemente mecanismos sólidos de autenticación y autorización para controlar el acceso a los recursos del sistema. Practicas System Design Basics for Backend Developers con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar System Design Basics for Backend Developers?
No se requiere experiencia previa. System Design Basics for Backend Developers en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 1 de 4.
¿Cuánto tiempo toma la lección «Autenticación y autorización»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de System Design Basics for Backend Developers?
Sí. Cada lección de System Design Basics for Backend Developers incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Autenticación y autorización
- Cifrado y privacidad de datos
- Protección contra DDoS y firewalls
- Limitación y regulación de la velocidad