-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CONLUZ-37] Implemented a validation class to stop the app bootstrap …
…if required config parameters are not present (#39)
- Loading branch information
1 parent
754678e
commit 95f0e2e
Showing
9 changed files
with
82 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.lucoenergia.conluz; | ||
|
||
import org.lucoenergia.conluz.infrastructure.shared.security.auth.JwtConfiguration; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.ApplicationArguments; | ||
import org.springframework.boot.ApplicationRunner; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class AppConfigCheck implements ApplicationRunner { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(AppConfigCheck.class); | ||
|
||
private final JwtConfiguration jwtConfiguration; | ||
|
||
public AppConfigCheck(JwtConfiguration jwtConfiguration) { | ||
this.jwtConfiguration = jwtConfiguration; | ||
} | ||
|
||
@Override | ||
public void run(ApplicationArguments args) { | ||
isSecretKeyPresent(); | ||
} | ||
|
||
private void isSecretKeyPresent() { | ||
// Secret key must be present | ||
String secretKey = jwtConfiguration.getSecretKey(); | ||
if (secretKey == null || secretKey.isBlank()) { | ||
LOGGER.error("Secret key not found. You must provide a secret key using the parameter {}", | ||
JwtConfiguration.CONLUZ_JWT_SECRET_KEY); | ||
System.exit(1); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...rg/lucoenergia/conluz/infrastructure/shared/security/auth/SecretKeyNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package org.lucoenergia.conluz.infrastructure.shared.security.auth; | ||
|
||
public class SecretKeyNotFoundException extends RuntimeException { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters