-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jans-auth-server): added jti to JWT tokens - both encoded into j…
…wt and as separate attribute in persistence #8512 (#8516) * feat(jans-auth-server): added short uuid with length = 22 #8512 Signed-off-by: YuriyZ <yzabrovarniy@gmail.com> * feat(jans-auth-server): added reference_id to token schema #8512 Signed-off-by: YuriyZ <yzabrovarniy@gmail.com> * feat(jans-auth-server): propagate reference_id to token and grant objects #8512 Signed-off-by: YuriyZ <yzabrovarniy@gmail.com> * feat(jans-auth-server): generate and keep jti in execution context #8512 Signed-off-by: YuriyZ <yzabrovarniy@gmail.com> --------- Signed-off-by: YuriyZ <yzabrovarniy@gmail.com>
- Loading branch information
Showing
12 changed files
with
168 additions
and
10 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
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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.jans.util; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.Base64; | ||
import java.util.Random; | ||
import java.util.UUID; | ||
|
||
/** | ||
* @author Yuriy Z | ||
*/ | ||
public class IdUtil { | ||
|
||
// we are ok to have not secured random | ||
private static final Random RANDOM = new Random(); | ||
|
||
private IdUtil() { | ||
} | ||
|
||
public static String randomShortUUID() { | ||
return toShortUUID(UUID.randomUUID()); | ||
} | ||
|
||
public static String toShortUUID(UUID uuid) { | ||
ByteBuffer byteBuffer = ByteBuffer.allocate(16); | ||
byteBuffer.putLong(uuid.getMostSignificantBits()); | ||
byteBuffer.putLong(uuid.getLeastSignificantBits()); | ||
return Base64.getEncoder().withoutPadding().encodeToString(byteBuffer.array()) | ||
.replace("/", randomChar()).replace("+", randomChar()); | ||
} | ||
|
||
private static String randomChar() { | ||
return (char) (RANDOM.nextInt(26) + 'a') + ""; | ||
} | ||
} |
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,24 @@ | ||
package io.jans.util; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import static org.testng.AssertJUnit.assertEquals; | ||
|
||
/** | ||
* @author Yuriy Z | ||
*/ | ||
public class IdUtilTest { | ||
|
||
@Test | ||
public void shortUuid_lenthMustBe22() { | ||
assertEquals(22, IdUtil.randomShortUUID().length()); | ||
} | ||
|
||
@Test(enabled = false) | ||
public void shortUuid_generateALotIdsAndPrintThem() { | ||
for (int i = 0; i < 100000; i++) { | ||
final String shortUUID = IdUtil.randomShortUUID(); | ||
System.out.println(shortUUID + " length: " + shortUUID.length()); | ||
}; | ||
} | ||
} |
Oops, something went wrong.