Permalink
Show file tree
Hide file tree
23 changes: 8 additions & 15 deletions
23
hawtio-karaf-terminal/src/main/java/io/hawt/web/plugin/karaf/terminal/TerminalServlet.java
59 changes: 54 additions & 5 deletions
59
hawtio-karaf-terminal/src/main/webapp/app/js/gogoPlugin.js
44 changes: 20 additions & 24 deletions
44
hawtio-system/src/main/java/io/hawt/web/LoginServlet.java
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
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); | ||
| } | ||
|
|
||
| } |