Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@

/**
* The Spring Boot 3 app for the token server
*
*
* @author Jared Hatfield (UnitVectorY Labs)
*/
@SpringBootApplication
@ComponentScan(basePackages = { "com.unitvectory.lockservicecentral" })
public class App {
/**
* The main entry point for the application.
*
* @param args command-line arguments
*/
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

/**
* Custom logic to validate the aud claim in the JWT
*
*
* @author Jared Hatfield (UnitVectorY Labs)
*/
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@

/**
* The Time Configuration
*
*
* @author Jared Hatfield (UnitVectorY Labs)
*/
@Configuration
@Profile("!time-disabled")
public class EpochTimeProviderConfiguration {

/**
* Creates the EpochTimeProvider bean.
*
* @return the EpochTimeProvider instance
*/
@Bean
public EpochTimeProvider epochTimeProvider() {
return SystemEpochTimeProvider.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

/**
* The JSON validation configuration
*
*
* @author Jared Hatfield (UnitVectorY Labs)
*/
@Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@

/**
* Security Configuration
*
*
* Configures JWT validation based on `jwt.issuer` and `jwt.jwks` settings.
* If neither is set, no authentication is required.
*
*
* If either is set, JWT authentication is required.
* JWKS is prioritized, but OpenID Connect discovery is used if only the issuer
* is set.
*
*
* If `jwt.issue` is set, the issuer claim is validated.
* If `jwt.audience` is set, the audience claim is validated.
*
*
* @author Jared Hatfield (UnitVectorY Labs)
*/
@Configuration
Expand All @@ -61,6 +61,13 @@ public class MyCustomSecurityConfiguration {
@Value("${jwt.audience:#{null}}")
private String audience;

/**
* Creates the SecurityFilterChain bean.
*
* @param http the HttpSecurity to configure
* @return the configured SecurityFilterChain
* @throws Exception if an error occurs during configuration
*/
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
if (this.issuer != null || this.jwks != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@

/**
* The UUID Generator Configuration
*
*
* @author Jared Hatfield (UnitVectorY Labs)
*/
@Configuration
@Profile("!uuid-disabled")
public class UuidGeneratorConfiguration {

/**
* Creates the UuidGenerator bean.
*
* @return the UuidGenerator instance
*/
@Bean
public UuidGenerator uuidGenerator() {
return RandomUuidGenerator.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

/**
* Web MVC configuration to register the canonical emit interceptor.
*
*
* @author Jared Hatfield (UnitVectorY Labs)
*/
@Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

/**
* The Lock Controller
*
*
* @author Jared Hatfield (UnitVectorY Labs)
*/
@RestController
Expand All @@ -51,11 +51,11 @@ public class LockController {

/**
* Gets the status of a lock.
*
*
* The status of the lock is always returned, even if the lock does not exist as
* that is just an available lock. The locks that are unavailable are the ones
* that include the `owner` and `expiry` fields.
*
*
* @param namespace the lock namespace
* @param lockName the lock name
* @return the lock status
Expand All @@ -74,7 +74,7 @@ public ResponseEntity<Lock> getLock(

/**
* Acquire a lock.
*
*
* @param namespace the lock namespace
* @param lockName the lock name
* @param lock the lock request
Expand All @@ -99,7 +99,7 @@ public ResponseEntity<Lock> acquireLock(

/**
* Renew a lock.
*
*
* @param namespace the lock namespace
* @param lockName the lock name
* @param lock the lock request
Expand All @@ -124,7 +124,7 @@ public ResponseEntity<Lock> renewLock(

/**
* Release a lock.
*
*
* @param namespace the lock namespace
* @param lockName the lock name
* @param lock the lock request
Expand All @@ -149,7 +149,7 @@ public ResponseEntity<Lock> releaseLock(

/**
* Sets the lock attributes.
*
*
* @param lock the lock
* @param namespace the namespace
* @param lockName the lock name
Expand All @@ -167,7 +167,7 @@ private void setLockAttributes(@NonNull Lock lock, @NonNull String namespace, @N

/**
* Enriches the canonical log context with lock operation details.
*
*
* @param namespace the lock namespace
* @param lockName the lock name
* @param operation the lock operation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

/**
* The internal error response
*
*
* @author Jared Hatfield (UnitVectorY Labs)
*/
@Getter
Expand All @@ -35,7 +35,7 @@ public class InternalErrorResponse {

/**
* Create a new internal error response
*
*
* @param errorId the error ID
*/
public InternalErrorResponse(String errorId) {
Expand All @@ -45,7 +45,7 @@ public InternalErrorResponse(String errorId) {

/**
* Create a new internal error response
*
*
* @param errorId the error ID
* @param message the message
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

/**
* The validation error response
*
*
* @author Jared Hatfield (UnitVectorY Labs)
*/
@Getter
Expand All @@ -44,7 +44,7 @@ public class ValidationErrorResponse {

/**
* Create a new validation error response from a handler method validation
*
*
* @param ex the handler method validation exception
*/
public ValidationErrorResponse(HandlerMethodValidationException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

/**
* The global exception handler
*
*
* @author Jared Hatfield (UnitVectorY Labs)
*/
@ControllerAdvice
Expand All @@ -47,20 +47,38 @@ public class GlobalExceptionHandler {
@Autowired
private ObjectProvider<CanonicalLogContext> canonicalLogContextProvider;

/**
* Handles ValidateJsonSchemaException.
*
* @param ex the exception
* @return the error response
*/
@ExceptionHandler(ValidateJsonSchemaException.class)
public ResponseEntity<ValidateJsonSchemaFailedResponse> onValidateJsonSchemaException(
ValidateJsonSchemaException ex) {
enrichCanonicalContextForValidationError();
return ResponseEntity.badRequest().body(new ValidateJsonSchemaFailedResponse(ex));
}

/**
* Handles HandlerMethodValidationException.
*
* @param ex the exception
* @return the error response
*/
@ExceptionHandler(HandlerMethodValidationException.class)
public ResponseEntity<ValidationErrorResponse> onHandlerMethodValidationException(
HandlerMethodValidationException ex) {
enrichCanonicalContextForValidationError();
return ResponseEntity.badRequest().body(new ValidationErrorResponse(ex));
}

/**
* Handles HttpRequestMethodNotSupportedException.
*
* @param ex the exception
* @return the error response
*/
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public ResponseEntity<InternalErrorResponse> onHttpRequestMethodNotSupportedException(
HttpRequestMethodNotSupportedException ex) {
Expand All @@ -69,13 +87,25 @@ public ResponseEntity<InternalErrorResponse> onHttpRequestMethodNotSupportedExce
.body(new InternalErrorResponse(this.uuidGenerator.generateUuid(), "Method not allowed"));
}

/**
* Handles NoResourceFoundException.
*
* @param ex the exception
* @return the error response
*/
@ExceptionHandler(NoResourceFoundException.class)
public ResponseEntity<InternalErrorResponse> onNoResourceFoundException(NoResourceFoundException ex) {
// Don't log stack trace for client errors like 404
return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body(new InternalErrorResponse(this.uuidGenerator.generateUuid(), "Resource not found"));
}

/**
* Handles all other exceptions.
*
* @param ex the exception
* @return the error response
*/
@ExceptionHandler(Exception.class)
public ResponseEntity<InternalErrorResponse> onException(Exception ex) {
// This will generate a unique error ID for each error
Expand Down Expand Up @@ -105,7 +135,7 @@ private void enrichCanonicalContextForValidationError() {

/**
* Enriches the canonical log context for unhandled exceptions.
*
*
* @param ex the exception
* @param errorId the error ID for correlation
*/
Expand Down
Loading
Loading