-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cherry pick branch 'genexuslabs:gamutils_eo' into beta
- Loading branch information
Showing
6 changed files
with
170 additions
and
70 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
72 changes: 72 additions & 0 deletions
72
gamutils/src/main/java/com/genexus/gam/utils/json/JWTAlgorithm.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,72 @@ | ||
package com.genexus.gam.utils.json; | ||
|
||
import com.nimbusds.jose.JWSAlgorithm; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
public enum JWTAlgorithm { | ||
|
||
HS256, HS512, HS384, RS256, RS512; | ||
|
||
private static final Logger logger = LogManager.getLogger(JWTAlgorithm.class); | ||
|
||
public static JWSAlgorithm getJWSAlgorithm(JWTAlgorithm alg) | ||
{ | ||
logger.debug("getJWSAlgorithm"); | ||
switch (alg) | ||
{ | ||
case HS256: | ||
return JWSAlgorithm.HS256; | ||
case HS512: | ||
return JWSAlgorithm.HS512; | ||
case HS384: | ||
return JWSAlgorithm.HS384; | ||
case RS256: | ||
return JWSAlgorithm.RS256; | ||
case RS512: | ||
return JWSAlgorithm.RS512; | ||
default: | ||
logger.error("getJWSAlgorithm - not implemented algorithm"); | ||
return null; | ||
} | ||
} | ||
|
||
public static JWTAlgorithm getJWTAlgoritm(String alg) | ||
{ | ||
logger.debug("getJWTAlgoritm"); | ||
switch (alg.trim().toUpperCase()) | ||
{ | ||
case "HS256": | ||
return JWTAlgorithm.HS256; | ||
case "HS512": | ||
return JWTAlgorithm.HS512; | ||
case "HS384": | ||
return JWTAlgorithm.HS384; | ||
case "RS256": | ||
return JWTAlgorithm.RS256; | ||
case "RS512": | ||
return JWTAlgorithm.RS512; | ||
default: | ||
logger.error("getJWTAlgoritm- not implemented algorithm"); | ||
return null; | ||
} | ||
} | ||
|
||
public static boolean isSymmetric(JWTAlgorithm alg) | ||
{ | ||
logger.debug("isSymmetric"); | ||
switch (alg) | ||
{ | ||
case HS256: | ||
case HS384: | ||
case HS512: | ||
return true; | ||
case RS256: | ||
case RS512: | ||
return false; | ||
default: | ||
logger.error("isSymmetric - not implemented algorithm"); | ||
return false; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.