-
Notifications
You must be signed in to change notification settings - Fork 541
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a LoginTokenServlet that plugins can use to fetch a token, and le…
…t's use it in hawtio-karaf-terminal. Also handle cases where the terminal scope gets created a couple times.
- Loading branch information
Showing
6 changed files
with
149 additions
and
48 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
42 changes: 42 additions & 0 deletions
42
hawtio-system/src/main/java/io/hawt/web/LoginTokenServlet.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,42 @@ | ||
| package io.hawt.web; | ||
|
|
||
| import org.apache.commons.codec.binary.Base64; | ||
|
|
||
| import javax.security.auth.Subject; | ||
| import javax.servlet.http.HttpSession; | ||
| import java.io.PrintWriter; | ||
| import java.security.SecureRandom; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
|
|
||
| /** | ||
| * @author Stan Lewis | ||
| */ | ||
| public class LoginTokenServlet extends LoginServlet { | ||
|
|
||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| public static final String LOGIN_TOKEN = "LoginToken"; | ||
|
|
||
| @Override | ||
| protected void sendResponse(HttpSession session, Subject subject, PrintWriter out) { | ||
|
|
||
| String token = (String) session.getAttribute(LOGIN_TOKEN); | ||
|
|
||
| if ( token == null) { | ||
| byte[] seed = (subject.toString() + new Long(System.currentTimeMillis()).toString()).getBytes(); | ||
| SecureRandom random = new SecureRandom(seed); | ||
| byte[] tokenBytes = new byte[128]; | ||
| random.nextBytes(tokenBytes); | ||
| token = Base64.encodeBase64String(tokenBytes); | ||
| session.setAttribute(LOGIN_TOKEN, token); | ||
| } | ||
|
|
||
| Map<String, String> answer = new HashMap<String, String>(); | ||
| answer.put("token", token); | ||
|
|
||
| ServletHelpers.writeObject(converters, options, out, answer); | ||
| } | ||
|
|
||
| } |