This package, com.medjay.authenticatehelper, provides a robust authentication helper for a Spring Boot application. It includes JWT-based authentication, Redis integration for storing permissions, and a custom security configuration.
- Java 11+
- Spring Boot
- Redis Server
-
Clone the repository:
git clone https://github.com/your-repo/authenticatehelper.git
-
Navigate to the project directory:
cd authenticatehelper -
Build the project:
mvn clean install
-
Run the Spring Boot application:
mvn spring-boot:run
- AuthenticateHelperApplication: The entry point of the Spring Boot application.
- AuthTestController: A simple controller to test the authentication process.
- SecurityConfiguration: Configures the Spring Security settings, including public URLs and JWT filter integration.
- JwtFilter: Custom filter to process JWT tokens in incoming requests.
- JwtService: Handles JWT token operations like extraction and validation.
- RedisService: Manages Redis operations, particularly fetching user permissions.
- UserAuthenticationToken: Custom implementation of
AbstractAuthenticationTokenfor security context management.
- AuthErrorCodes: Enum defining various authentication error codes and messages.
- AuthErrorResponse: Record for structuring authentication error responses.
- DefaultAuthException: Custom exception for authentication errors.
Ensure the following properties are set in application.properties:
# JWT secret key
authentication.secret-key=your-secret-key
# Header acronym for JWT
authentication.header-acronym=Bearer
# Public URLs that do not require authentication
authentication.open-urls=/public/**
# Redis configuration
authentication.redis.host-name=localhost
authentication.redis.port=6379
I made this to ease my pain in spinning up new microservices in our env that will have token authentication and get permission from a redis cache.
You can simply copy all other classes other than the main class or simply package this and use it as a dependency in your application.