Cleanups, fix admin role
Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
This commit is contained in:
parent
cbec25cd6b
commit
8b21823002
@ -36,7 +36,7 @@ public class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
|
|||||||
http
|
http
|
||||||
.authorizeRequests()
|
.authorizeRequests()
|
||||||
.antMatchers("/portal").hasAuthority("devel-user")
|
.antMatchers("/portal").hasAuthority("devel-user")
|
||||||
.antMatchers("/admin").hasAuthority("devel-admins")
|
.antMatchers("/admin").hasAuthority("devel-admin")
|
||||||
.anyRequest().permitAll();
|
.anyRequest().permitAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,13 @@ import com.github.dockerjava.api.model.Image;
|
|||||||
public class WebApplication {
|
public class WebApplication {
|
||||||
|
|
||||||
static ArrayList<String> availableOs = new ArrayList<String>();
|
static ArrayList<String> availableOs = new ArrayList<String>();
|
||||||
|
|
||||||
|
private void genOsList() {
|
||||||
|
availableOs.add("archlinux");
|
||||||
|
availableOs.add("opensuse-leap");
|
||||||
|
availableOs.add("opensuse-tumbleweed");
|
||||||
|
availableOs.add("ubuntu");
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(WebApplication.class, args);
|
SpringApplication.run(WebApplication.class, args);
|
||||||
@ -49,7 +56,6 @@ public class WebApplication {
|
|||||||
public String portal(Model model) throws pubshError {
|
public String portal(Model model) throws pubshError {
|
||||||
KeycloakAuthenticationToken authentication = (KeycloakAuthenticationToken)
|
KeycloakAuthenticationToken authentication = (KeycloakAuthenticationToken)
|
||||||
SecurityContextHolder.getContext().getAuthentication();
|
SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
|
||||||
Principal principal = (Principal) authentication.getPrincipal();
|
Principal principal = (Principal) authentication.getPrincipal();
|
||||||
String username="";
|
String username="";
|
||||||
String email="";
|
String email="";
|
||||||
@ -62,8 +68,6 @@ public class WebApplication {
|
|||||||
if (principal instanceof KeycloakPrincipal) {
|
if (principal instanceof KeycloakPrincipal) {
|
||||||
KeycloakPrincipal<?> kPrincipal = (KeycloakPrincipal<?>) principal;
|
KeycloakPrincipal<?> kPrincipal = (KeycloakPrincipal<?>) principal;
|
||||||
IDToken token = kPrincipal.getKeycloakSecurityContext().getIdToken();
|
IDToken token = kPrincipal.getKeycloakSecurityContext().getIdToken();
|
||||||
//System.out.println("Token: " + token);
|
|
||||||
|
|
||||||
Map<String, Object> customClaims = token.getOtherClaims();
|
Map<String, Object> customClaims = token.getOtherClaims();
|
||||||
if (! customClaims.containsKey("username")) {
|
if (! customClaims.containsKey("username")) {
|
||||||
System.out.println("Fatal: received logon without username.");
|
System.out.println("Fatal: received logon without username.");
|
||||||
@ -85,21 +89,13 @@ public class WebApplication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<Image> images = Docker.getImages(null);
|
List<Image> images = Docker.getImages(null);
|
||||||
|
|
||||||
//System.out.println(images);
|
|
||||||
List<Container> containers = Docker.getContainers(null);
|
List<Container> containers = Docker.getContainers(null);
|
||||||
//System.out.println(containers);
|
|
||||||
|
|
||||||
model.addAttribute("docker_images", images);
|
model.addAttribute("docker_images", images);
|
||||||
model.addAttribute("docker_containers", containers);
|
model.addAttribute("docker_containers", containers);
|
||||||
|
|
||||||
ArrayList<String> availableOs = new ArrayList<String>();
|
genOsList();
|
||||||
availableOs.add("archlinux");
|
|
||||||
availableOs.add("opensuse-leap");
|
|
||||||
availableOs.add("opensuse-tumbleweed");
|
|
||||||
availableOs.add("ubuntu");
|
|
||||||
model.addAttribute("availableOs", availableOs);
|
model.addAttribute("availableOs", availableOs);
|
||||||
//model.addAttribute("osChoice", new String());
|
|
||||||
|
|
||||||
return("admin");
|
return("admin");
|
||||||
}
|
}
|
||||||
@ -139,11 +135,13 @@ public class WebApplication {
|
|||||||
model.addAttribute("attribute01", attribute01);
|
model.addAttribute("attribute01", attribute01);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Image> images = Docker.getImages(username);
|
List<Image> images = Docker.getImages(username);
|
||||||
List<Container> containers = Docker.getContainers(username);
|
List<Container> containers = Docker.getContainers(username);
|
||||||
|
|
||||||
model.addAttribute("docker_images", images);
|
model.addAttribute("docker_images", images);
|
||||||
model.addAttribute("docker_containers", containers);
|
model.addAttribute("docker_containers", containers);
|
||||||
|
|
||||||
|
genOsList();
|
||||||
model.addAttribute("availableOs", availableOs);
|
model.addAttribute("availableOs", availableOs);
|
||||||
|
|
||||||
return("portal");
|
return("portal");
|
||||||
|
@ -5,12 +5,25 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="container">
|
<div id="container">
|
||||||
<div th:if="${message}" th:text="${message}" th:class="${'alert ' + alertClass}"/></div>
|
<div th:if="${message}" th:text="${message}" th:class="${'alert ' + alertClass}"/></div>
|
||||||
<h1>
|
<h2>
|
||||||
Hello, <span th:text="${username}"></span>.
|
Hello, <span th:text="${username}"></span>.
|
||||||
</h1>
|
</h2>
|
||||||
|
<h3>Generate new throw-away shell:</h3>
|
||||||
|
<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('osoption') + ' - 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
|
||||||
|
th:each="osoption : ${availableOs}"
|
||||||
|
th:value="${osoption}"
|
||||||
|
th:attr="value=${osoption}"
|
||||||
|
th:text="${osoption}"></option>
|
||||||
|
</select>
|
||||||
|
<button class="btn btn-primary" th:id="request_submission" th:type="submit">Generate</button>
|
||||||
|
</form>
|
||||||
<div th:if="${attribute01 != null}" th:text="${attribute01}"></div>
|
<div th:if="${attribute01 != null}" th:text="${attribute01}"></div>
|
||||||
<h2>Available images:</h2>
|
|
||||||
<table>
|
<h3>Available images:</h3>
|
||||||
|
<table th:if="${docker_images!=null and !docker_images.empty}">
|
||||||
<tr th:each="image: ${docker_images}" th:if="${image.repoTags[0] != '<none>:<none>'}">
|
<tr th:each="image: ${docker_images}" th:if="${image.repoTags[0] != '<none>:<none>'}">
|
||||||
<td>
|
<td>
|
||||||
<table>
|
<table>
|
||||||
@ -27,22 +40,10 @@
|
|||||||
<td th:text="${image.created}" />
|
<td th:text="${image.created}" />
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
<div th:if="${docker_images.empty}"><p>None yet!</p></div>
|
||||||
<h2>Generate new throw-away shell:</h2>
|
|
||||||
<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('osoption') + ' - please be patient after you confirm, as the generation may take a short while.');">
|
<h3>Existing containers:</h3>
|
||||||
<select class="form-control" th:object="${osChoice}" name="osChoice">
|
<table th:if="${docker_containers!=null and !docker_containers.empty}">
|
||||||
<option value="">Select operating system ...</option>
|
|
||||||
<option
|
|
||||||
th:each="osoption : ${availableOs}"
|
|
||||||
th:value="${osoption}"
|
|
||||||
th:attr="value=${osoption}"
|
|
||||||
th:text="${osoption}"></option>
|
|
||||||
</select>
|
|
||||||
<button class="btn btn-primary" th:id="request_submission" th:type="submit">Generate</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<h2>Existing containers:</h2>
|
|
||||||
<table>
|
|
||||||
<tr th:each="container: ${docker_containers}">
|
<tr th:each="container: ${docker_containers}">
|
||||||
<td th:text="${container.names[0]}" />
|
<td th:text="${container.names[0]}" />
|
||||||
<td th:text="${container.image}" />
|
<td th:text="${container.image}" />
|
||||||
@ -54,9 +55,14 @@
|
|||||||
</form>
|
</form>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
<div th:if="${docker_containers.empty}"><p>None yet!</p></div>
|
||||||
<p></p>
|
<p></p>
|
||||||
<a href="/logout">Logout</a>
|
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
<footer>
|
||||||
|
|
||||||
|
<p><a href="/logout">SSO Logout</a></p>
|
||||||
|
</footer>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user