-
-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Manage JWTAlgorithmKMS lifecycle with Spring (#398) Makes it easier to use in unit tests * Move creation of token with JWK header to IJWTTokenGenerator (#398) Allows reuse in controller unit test * Replace String body type of GET-RequestEntities with Void (#398) * Add unit test for JWTVulnerability controller (#398) * Add unit test for JWTValidator (#398)
- Loading branch information
Showing
6 changed files
with
917 additions
and
73 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,22 +19,20 @@ | |
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.sasanlabs.internal.utility.JSONSerializationUtils; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* Singleton class parses SymmetricAlgoKeys.json from scripts/JWT and holds for entire Lifecycle of | ||
* Application Also this class is responsible to generate the Asymmetric Algorithm keys. | ||
* Parses SymmetricAlgoKeys.json from scripts/JWT. Initialization is costly, reuse of one instance | ||
* is recommended. Also this class is responsible to generate the Asymmetric Algorithm keys. | ||
* | ||
* @author KSASAN [email protected] | ||
*/ | ||
@Component | ||
public class JWTAlgorithmKMS { | ||
|
||
private static final Object MUTEX = new Object(); | ||
private Set<SymmetricAlgorithmKey> symmetricAlgorithmKeySet; | ||
|
||
private static volatile boolean initDone = false; | ||
|
||
private static Set<SymmetricAlgorithmKey> symmetricAlgorithmKeySet; | ||
|
||
public static Map<String, KeyPair> asymmetricAlgorithmKeyMap = new HashMap<String, KeyPair>(); | ||
public Map<String, KeyPair> asymmetricAlgorithmKeyMap = new HashMap<String, KeyPair>(); | ||
|
||
private static final String SYMMETRIC_KEYS_FILE = "/scripts/JWT/SymmetricAlgoKeys.json"; | ||
|
||
|
@@ -47,14 +45,16 @@ public class JWTAlgorithmKMS { | |
private static final transient Logger LOGGER = LogManager.getLogger(JWTAlgorithmKMS.class); | ||
|
||
public JWTAlgorithmKMS() { | ||
if (!initDone) { | ||
synchronized (MUTEX) { | ||
if (!initDone) { | ||
initialize(); | ||
initDone = true; | ||
} | ||
} | ||
try (InputStream jwtSymmetricKeyStream = | ||
this.getClass().getResourceAsStream(SYMMETRIC_KEYS_FILE)) { | ||
symmetricAlgorithmKeySet = | ||
JSONSerializationUtils.deserialize( | ||
jwtSymmetricKeyStream, | ||
new TypeReference<Set<SymmetricAlgorithmKey>>() {}); | ||
} catch (IOException e) { | ||
LOGGER.error("Following error occurred while parsing SymmetricAlgoKeys", e); | ||
} | ||
loadAsymmetricAlgorithmKeys(); | ||
} | ||
|
||
/** | ||
|
@@ -107,17 +107,4 @@ private void loadAsymmetricAlgorithmKeys() { | |
LOGGER.error(e); | ||
} | ||
} | ||
|
||
private void initialize() { | ||
try (InputStream jwtSymmetricKeyStream = | ||
this.getClass().getResourceAsStream(SYMMETRIC_KEYS_FILE)) { | ||
symmetricAlgorithmKeySet = | ||
JSONSerializationUtils.deserialize( | ||
jwtSymmetricKeyStream, | ||
new TypeReference<Set<SymmetricAlgorithmKey>>() {}); | ||
} catch (IOException e) { | ||
LOGGER.error("Following error occurred while parsing SymmetricAlgoKeys", e); | ||
} | ||
loadAsymmetricAlgorithmKeys(); | ||
} | ||
} |
Oops, something went wrong.