Checkpoint: Working OS-picker
Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
This commit is contained in:
parent
fc9f4b56b5
commit
e37ec4083a
@ -16,9 +16,11 @@ import org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken;
|
|||||||
import org.keycloak.representations.IDToken;
|
import org.keycloak.representations.IDToken;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.util.MultiValueMap;
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
//import org.springframework.web.bind.annotation.DeleteMapping;
|
//import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@ -118,20 +120,15 @@ public class WebApplication {
|
|||||||
return("redirect:/portal");
|
return("redirect:/portal");
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/frontend/container/add")
|
@PostMapping(path="/frontend/container/add",consumes=MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||||
//public static String addContainer(@PathVariable HttpServletRequest request, Model model) {
|
public static String addContainer(@RequestBody MultiValueMap<String, String> body, HttpServletRequest request) {
|
||||||
public static String addContainer(@RequestBody String osChoice, Model model,HttpServletRequest request) {
|
|
||||||
KeycloakAuthenticationToken principal = (KeycloakAuthenticationToken) request.getUserPrincipal();
|
KeycloakAuthenticationToken principal = (KeycloakAuthenticationToken) request.getUserPrincipal();
|
||||||
String username= null;
|
String username= null;
|
||||||
String userid = principal.getName();
|
String userid = principal.getName();
|
||||||
IDToken token = principal.getAccount().getKeycloakSecurityContext().getIdToken();
|
IDToken token = principal.getAccount().getKeycloakSecurityContext().getIdToken();
|
||||||
Map<String, Object> customClaims = token.getOtherClaims();
|
Map<String, Object> customClaims = token.getOtherClaims();
|
||||||
username = String.valueOf(customClaims.get("username"));
|
username = String.valueOf(customClaims.get("username"));
|
||||||
//String osChoice = null;
|
String osChoice = (String) body.getFirst("osChoice");
|
||||||
//model.addAttribute("osChoice", osChoice);
|
|
||||||
//Map<String, Object> allAttributes = null;
|
|
||||||
//model.addAllAttributes(allAttributes);
|
|
||||||
//System.out.println(allAttributes);
|
|
||||||
|
|
||||||
System.out.printf("New container with OS %s requested by %s (%s)", osChoice, userid, username);
|
System.out.printf("New container with OS %s requested by %s (%s)", osChoice, userid, username);
|
||||||
|
|
||||||
@ -141,7 +138,6 @@ public class WebApplication {
|
|||||||
|
|
||||||
//Docker.buildImage(username, osChoice, count);
|
//Docker.buildImage(username, osChoice, count);
|
||||||
|
|
||||||
|
|
||||||
return("redirect:/portal");
|
return("redirect:/portal");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,16 +17,16 @@
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<h2>Generate new throw-away shell:</h2>
|
<h2>Generate new throw-away shell:</h2>
|
||||||
<select th:field="*{availableOs}" class="form-control" th:id="osChoice" th:name="osChoice">
|
<form th:object="${osChoice}" th:id="request_pseudoform" action="#" th:action="@{'/frontend/container/add'}" th:method="post" th:os="${osoption}" th:onsubmit="return confirm('You are about to generate a shell with the OS ' + this.getAttribute('os') + ' - please be patient after you confirm, as the generation may take a short while.');">
|
||||||
|
<select class="form-control" th:object="${osChoice}" name="osChoice">
|
||||||
<option value="">Select operating system ...</option>
|
<option value="">Select operating system ...</option>
|
||||||
<option
|
<option
|
||||||
th:each="osoption : ${availableOs}"
|
th:each="osoption : ${availableOs}"
|
||||||
th:value="${osoption}"
|
th:value="${osoption}"
|
||||||
|
th:attr="value=${osoption}"
|
||||||
th:text="${osoption}"></option>
|
th:text="${osoption}"></option>
|
||||||
</select>
|
</select>
|
||||||
|
<p><span th:text="${osChoice}"></span></p>
|
||||||
<form th:object="${osChoice}" th:id="request_pseudoform" action="#" th:action="@{'/frontend/container/add'}" th:method="post" th:os="${osChoice}" th:onsubmit="return confirm('You are about to generate a shell with the OS ' + this.getAttribute('os') + ' - please be patient after you confirm, as the generation may take a short while.');">
|
|
||||||
<input th:type="hidden" th:method="post" th:name="osChoice" th:value="osChoice" th:attr="value = ${osChoice}" />
|
|
||||||
<button class="btn btn-primary" th:id="request_submission" th:type="submit">Generate</button>
|
<button class="btn btn-primary" th:id="request_submission" th:type="submit">Generate</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user