Checkpoint

Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
This commit is contained in:
Georg Pfuetzenreuter 2022-05-06 21:56:06 +02:00
parent 20d049ea10
commit fc9f4b56b5
Signed by: Georg
GPG Key ID: 1ED2F138E7E6FF57
3 changed files with 17 additions and 11 deletions

View File

@ -32,6 +32,7 @@ public class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception
{
http.csrf().disable();
super.configure(http); //.anonymous().disable()
http
.authorizeRequests()

View File

@ -26,13 +26,15 @@ import org.springframework.web.bind.annotation.ModelAttribute;
//import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.github.dockerjava.api.model.Container;
import com.github.dockerjava.api.model.Image;
import java.util.Random;
//@SessionAttributes("osChoice")
@SpringBootApplication
@Controller
public class WebApplication {
@ -93,9 +95,7 @@ public class WebApplication {
availableOs.add("opensuse-tumbleweed");
availableOs.add("ubuntu");
model.addAttribute("availableOs", availableOs);
model.addAttribute("osChoice", new String());
//model.addAttribute("osChoice", new String());
return("portal");
}
@ -119,16 +119,19 @@ public class WebApplication {
}
@PostMapping("/frontend/container/add")
public static String addContainer(@PathVariable String osChoice, HttpServletRequest request, Model model) {
//public static String addContainer(@PathVariable HttpServletRequest request, Model model) {
public static String addContainer(@RequestBody String osChoice, Model model,HttpServletRequest request) {
KeycloakAuthenticationToken principal = (KeycloakAuthenticationToken) request.getUserPrincipal();
String username= null;
String userid = principal.getName();
IDToken token = principal.getAccount().getKeycloakSecurityContext().getIdToken();
Map<String, Object> customClaims = token.getOtherClaims();
username = String.valueOf(customClaims.get("username"));
model.addAttribute("osChoice", osChoice);
//String osChoice = null;
//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);

View File

@ -17,15 +17,17 @@
</table>
<h2>Generate new throw-away shell:</h2>
<select th:field="*{availableOs}" class="form-control" id="osChoice" name="osChoice">
<select th:field="*{availableOs}" class="form-control" th:id="osChoice" th:name="osChoice">
<option value="">Select operating system ...</option>
<option
th:each="osoption : ${availableOs}"
th:value="${osoption}"
th:text="${osoption}"></option>
</select>
<form th:object="${osChoice}" 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.');">
<button class="btn btn-primary" id="request_submission" type="submit">Generate</button>
<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>
</form>