Authentication Developer Guide¶
This guide explains the authentication mechanisms used in the geOrchestra Gateway and how to extend or customize them.
Authentication Architecture¶
The geOrchestra Gateway uses Spring Security's WebFlux-based security framework, with a reactive architecture. The main authentication components are:
- Authentication Providers: Handle different authentication methods
- User Mappers: Convert authentication results to GeorchestraUser objects
- User Customizers: Enhance user information after authentication
- Global Filters: Process authentication in the request pipeline
Authentication Methods¶
LDAP Authentication¶
LDAP authentication is implemented in the org.georchestra.gateway.security.ldap
package with two implementations:
- Basic LDAP: Simple username/password binding with minimal user attributes
- Extended LDAP: Full geOrchestra LDAP schema support with roles and organization information
Key classes:
LdapAuthenticationConfiguration
: Spring configuration for LDAPGeorchestraLdapAuthenticationProvider
: Authentication provider implementationGeorchestraLdapAuthenticatedUserMapper
: Maps LDAP users to GeorchestraUser objects
To customize LDAP authentication, implement a custom LdapAuthenticatedUserMapper
.
OAuth2/OpenID Connect¶
OAuth2 and OpenID Connect are implemented in the org.georchestra.gateway.security.oauth2
package.
Key classes:
OAuth2Configuration
: Spring configuration for OAuth2OpenIdConnectUserMapper
: Maps OAuth2 authentication to GeorchestraUser objectsOpenIdConnectCustomConfig
: Customization for specific providers
To customize OAuth2 authentication:
1. Implement a custom OAuth2UserMapper
2. Configure custom claim mappings in application properties
Header Pre-Authentication¶
Header-based pre-authentication is implemented in the org.georchestra.gateway.security.preauth
package.
Key classes:
HeaderPreAuthenticationConfiguration
: Spring configuration for pre-authenticationPreauthAuthenticationManager
: Validates pre-authentication headersPreauthenticatedUserMapperExtension
: Maps header values to GeorchestraUser objects
To customize header pre-authentication:
1. Implement a custom PreauthenticatedUserMapperExtension
2. Configure custom header mappings in application properties
The GeorchestraUser Model¶
The GeorchestraUser
class is the core user model used throughout the application. It contains:
- Basic user information (username, email, etc.)
- Roles and organization details
- Extended attributes
public class GeorchestraUser implements UserDetails {
private String username;
private String organization;
private String email;
private Set<String> roles;
private Map<String, String> attributes;
// methods omitted for brevity
}
User Customizers¶
The GeorchestraUserCustomizerExtension
interface allows customizing user information after authentication:
public interface GeorchestraUserCustomizerExtension {
Mono<GeorchestraUser> customize(GeorchestraUser user);
}
Implementations include:
RolesMappingsUserCustomizer
: Applies role mappings based on configurationCreateAccountUserCustomizer
: Handles user creation through login
To implement a custom user customizer:
1. Create a class implementing GeorchestraUserCustomizerExtension
2. Register it as a Spring bean
@Component
public class MyCustomUserCustomizer implements GeorchestraUserCustomizerExtension {
@Override
public Mono<GeorchestraUser> customize(GeorchestraUser user) {
// Customize user here
return Mono.just(user);
}
}
Authentication Flow¶
- A request arrives at the gateway
- Spring Security filter chain processes the request
- Authentication is performed via the appropriate provider
- User information is mapped to a GeorchestraUser object
- User customizers are applied
- Authorization decisions are made based on user roles
- User information is added to request headers for backend services
Security Context Propagation¶
In a reactive environment, the security context is propagated via the Reactor Context:
public Mono<ServerResponse> handleRequest(ServerRequest request) {
return ReactiveSecurityContextHolder.getContext()
.map(SecurityContext::getAuthentication)
.flatMap(auth -> {
GeorchestraUser user = (GeorchestraUser) auth.getPrincipal();
// Use user information
return ServerResponse.ok().build();
});
}
Adding a New Authentication Method¶
To add a new authentication method:
- Create an authentication configuration class
- Implement a user mapper for the new authentication method
- Register the configuration with Spring Boot auto-configuration
- Add configuration properties for the new method
Example structure:
org.georchestra.gateway.security.newauth
├── NewAuthConfiguration.java
├── NewAuthProvider.java
├── NewAuthUserMapper.java
└── NewAuthProperties.java
Debugging Authentication¶
For debugging authentication issues:
- Enable debug logging for security components:
logging:
level:
org.springframework.security: DEBUG
org.georchestra.gateway.security: DEBUG
-
Use the
/whoami
endpoint to check the authenticated user information -
Monitor the authentication flow in logs
Security Considerations¶
- Password Security: LDAP passwords should be one-way hashed
- HTTPS: Always use HTTPS in production
- OAuth2 Client Secrets: Keep client secrets secure
- Header Security: Validate and sanitize pre-authentication headers
- Role Validation: Validate role assignments for security-critical operations