-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use local file to keep token and use it in daemon.
- Loading branch information
1 parent
b9fcb15
commit d3a92ff
Showing
3 changed files
with
97 additions
and
29 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
24 changes: 24 additions & 0 deletions
24
jgrab-runner/src/main/java/com/athaydes/jgrab/daemon/Authorizer.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,24 @@ | ||
package com.athaydes.jgrab.daemon; | ||
|
||
import com.athaydes.jgrab.JGrabHome; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.util.UUID; | ||
|
||
final class Authorizer { | ||
private static final String tokenFile = "token"; | ||
|
||
public static String generateRandomToken() throws IOException { | ||
var token = generateToken(); | ||
Files.writeString( new File( JGrabHome.getDir(), tokenFile ).toPath(), | ||
token, StandardCharsets.US_ASCII ); | ||
return token; | ||
} | ||
|
||
private static String generateToken() { | ||
return UUID.randomUUID().toString(); | ||
} | ||
} |
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