Authentication & Authorization
Admin endpoints use a role-based access control (RBAC) system built on Spring Security and JWT authentication.Role Requirements
Admin endpoints require:- Valid JWT token in the
Authorizationheader - User account with
ROLE_ADMINauthority assigned
Security Implementation
Authorization Header Format:/api/admin/** routes are protected by the hasAuthority("ROLE_ADMIN") security rule defined in SecurityConfig.java:52.
Session Management: Stateless JWT-based authentication (no server-side sessions).
Available Endpoints
Toggle TKOH Collaborator Status
Path Parameters
The unique identifier of the profile to update
Response
Indicates whether the operation completed successfully
Human-readable message describing the result (e.g., “Estado de colaborador actualizado”)
ISO 8601 timestamp of when the response was generated
The updated profile information
Profile unique identifier
URL-friendly profile identifier
User’s full name
Professional headline or tagline
Profile biography or description
Public contact email address
Geographic location
URL to the profile avatar image
URL to the user’s resume document
Response Example
Error Responses
403 Forbidden - User lacks admin privilegesAccess Control Details
User Roles
The system uses a simple role-based model stored in theroles field of the User entity:
- ROLE_USER: Standard user with access to their own profile management
- ROLE_ADMIN: Administrator with access to all admin endpoints
JWT Token Claims
Admin authentication tokens include the following claims:Subject - the user’s email address
The user’s database identifier
The associated profile identifier
Issued at timestamp (Unix time)
Expiration timestamp (Unix time)
Security Filter Chain
The admin endpoints are protected by the following security mechanisms:- JWT Authentication Filter: Validates the JWT token and extracts user details
- Authorization Check: Verifies the user has
ROLE_ADMINauthority - Stateless Sessions: No server-side session management required
CORS Configuration
Admin endpoints respect the same CORS configuration as other API endpoints:- Allowed Methods: GET, POST, PUT, DELETE, OPTIONS, PATCH
- Allowed Headers: Authorization, Content-Type, Cache-Control
- Credentials: Supported for authenticated requests
Best Practices
- Token Expiration: Admin tokens expire based on the
application.security.jwt.expirationconfiguration (typically 60 minutes) - Token Refresh: Implement token refresh logic before expiration to maintain admin sessions
- Error Handling: Always check the
successfield in responses and handle errors appropriately - Audit Logging: Consider logging all admin actions for compliance and security auditing
- Rate Limiting: Implement rate limiting on admin endpoints to prevent abuse
Source Code Reference
- Controller:
studios/tkoh/portfolio/controller/AdminController.java:20 - Security Config:
studios/tkoh/portfolio/config/SecurityConfig.java:52 - User Model:
studios/tkoh/portfolio/model/User.java:51 - JWT Service:
studios/tkoh/portfolio/security/JwtService.java