diff --git a/src/main/java/de/jottyfan/camporganizer/config/SecurityConfig.java b/src/main/java/de/jottyfan/camporganizer/config/SecurityConfig.java index 4f392ba..4004168 100644 --- a/src/main/java/de/jottyfan/camporganizer/config/SecurityConfig.java +++ b/src/main/java/de/jottyfan/camporganizer/config/SecurityConfig.java @@ -55,8 +55,12 @@ public class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { super.configure(http); - http.authorizeRequests().antMatchers("/**").permitAll(); - http.anonymous().disable(); + http.authorizeRequests() + // @formatter:off + .antMatchers("/user/**", "/business/**").authenticated() + .anyRequest().permitAll(); + // @formatter:on +// http.anonymous().disable(); http.csrf().disable(); } } \ No newline at end of file diff --git a/src/main/java/de/jottyfan/camporganizer/module/common/CommonController.java b/src/main/java/de/jottyfan/camporganizer/module/common/CommonController.java new file mode 100644 index 0000000..a6c4be8 --- /dev/null +++ b/src/main/java/de/jottyfan/camporganizer/module/common/CommonController.java @@ -0,0 +1,37 @@ +package de.jottyfan.camporganizer.module.common; + +import javax.servlet.http.HttpServletRequest; + +import org.jooq.exception.DataAccessException; +import org.keycloak.KeycloakSecurityContext; +import org.springframework.ui.Model; + +/** + * + * @author jotty + * + */ +public abstract class CommonController { + + /** + * try to get current keycloak user + * + * @param request the request + * @return the preferred username or null + */ + private String getCurrentUser(HttpServletRequest request) { + KeycloakSecurityContext ksc = (KeycloakSecurityContext) request + .getAttribute(KeycloakSecurityContext.class.getName()); + return ksc == null ? null : ksc.getIdToken().getPreferredUsername(); + } + + /** + * setup the session for the template + * @param model the model + * @param request the request + */ + public void setupSession(Model model, HttpServletRequest request) { + String username = getCurrentUser(request); + model.addAttribute("currentUser", username); + } +} diff --git a/src/main/java/de/jottyfan/camporganizer/module/common/IndexController.java b/src/main/java/de/jottyfan/camporganizer/module/common/IndexController.java index 5d1dbc9..d87a6f3 100644 --- a/src/main/java/de/jottyfan/camporganizer/module/common/IndexController.java +++ b/src/main/java/de/jottyfan/camporganizer/module/common/IndexController.java @@ -7,6 +7,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; /** @@ -15,18 +16,27 @@ import org.springframework.web.bind.annotation.GetMapping; * */ @Controller -public class IndexController { +public class IndexController extends CommonController { private static final Logger LOGGER = LogManager.getLogger(IndexController.class); @Autowired private HttpServletRequest request; + @Autowired + private IndexService service; + @GetMapping("/") - public String index() { - if (request == null) { - LOGGER.error("request is null"); - } - return "/"; + public String index(Model model) { + super.setupSession(model, request); + model.addAttribute("camps", service.getAllCamps()); + return "/index"; + } + + @GetMapping("/user") + public String user(Model model) { + super.setupSession(model, request); + model.addAttribute("camps", service.getAllCamps()); + return "/user/index"; } @GetMapping("/logout") diff --git a/src/main/java/de/jottyfan/camporganizer/module/common/IndexService.java b/src/main/java/de/jottyfan/camporganizer/module/common/IndexService.java new file mode 100644 index 0000000..84ba436 --- /dev/null +++ b/src/main/java/de/jottyfan/camporganizer/module/common/IndexService.java @@ -0,0 +1,33 @@ +package de.jottyfan.camporganizer.module.common; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import de.jottyfan.camporganizer.db.jooq.tables.records.VCampRecord; + +/** + * + * @author jotty + * + */ +@Service +public class IndexService { + @Autowired + private IndexGateway gateway; + + /** + * get all camps from the database and prepare them for the view + * + * @return the list of found camps + */ + public List getAllCamps() { + Stream stream = gateway.getAllCamps(); + List list = new ArrayList<>(); + stream.forEach(o -> list.add(o)); + return list; + } +} diff --git a/src/main/java/de/jottyfan/camporganizer/module/common/ManifestBean.java b/src/main/java/de/jottyfan/camporganizer/module/common/ManifestBean.java new file mode 100644 index 0000000..4cb2ba9 --- /dev/null +++ b/src/main/java/de/jottyfan/camporganizer/module/common/ManifestBean.java @@ -0,0 +1,25 @@ +package de.jottyfan.camporganizer.module.common; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.info.BuildProperties; +import org.springframework.stereotype.Component; + +/** + * + * @author jotty + * + */ +@Component +public class ManifestBean { + + @Autowired(required = false) + private BuildProperties buildProperties; + + /** + * @return the version of this project + */ + public String getVersion() { + return buildProperties != null ? buildProperties.getVersion() + : this.getClass().getPackage().getImplementationVersion(); + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index ccb29ee..59d3a65 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -7,7 +7,7 @@ spring.datasource.password=jooq # application server.port = 8081 -server.servlet.context-path=/COBusiness +server.servlet.context-path=/CampOrganizer2 # keycloak keycloak.auth-server-url = http://localhost:8080/ @@ -15,7 +15,7 @@ keycloak.realm = ow keycloak.resource = biblecamp keycloak.public-client = true keycloak.security-constraints[0].authRoles[0] = business -keycloak.security-constraints[0].securityCollections[0].patterns[0] = /* +keycloak.security-constraints[0].securityCollections[0].patterns[0] = /business/* #keycloak.credentia keycloak.use-resource-role-mappings=true #keycloak.bearer-only=true diff --git a/src/main/resources/static/css/style.css b/src/main/resources/static/css/style.css new file mode 100644 index 0000000..e6fa006 --- /dev/null +++ b/src/main/resources/static/css/style.css @@ -0,0 +1,100 @@ +html { + width: 100vw; + height: 100vh; +} + +body { + background-image: linear-gradient(to bottom right, rgb(255, 190, 111), rgb(198, 70, 0)); +} + +.mainpage { + background-color: rgba(255, 255, 255, 0.4); + padding: 8px; + overflow: auto; + width: 100%; + height: calc(100vh - 60px); /* 60 px is the current height of the headline; TODO: calculate it */ +} + +.middlecenter { + margin: auto; + top: 40vh; + bottom: 40vh; + position: fixed; + left: 40vw; + right: 40vw; +} + +.myheadline { + margin: 8px; +} + +.bottomdist16 { + margin-bottom: 16px; +} + +.topright { + position: fixed; + right: 8px; + top: 8px; +} + +.tablelink { + cursor: pointer; + text-decoration: none; + color: black; +} + +.tablelink:hover { + text-decoration: underline; + color: darkcyan; +} + +.deletelink { + padding: 4px; + border: 1px solid rgba(0, 0, 0, 0.0); + border-radius: 4px; +} + +.deletelink:hover { + color: red; + border: 1px solid red; + text-decoration-line: line-through; +} + +.linkbtn { + background: transparent; + border: 2px solid transparent; + padding: 8px; +} + +.linkbtn:hover { + background-color: white; + border: 2px solid silver; + border-radius: 4px; +} + +.btn-icon-silent { + background: transparent; + border: 2px solid transparent; + padding: 8px; + color: silver; +} + +.btn-icon-silent:hover { + background-color: white; + border: 2px solid silver; + border-radius: 4px; + color: darkcyan; +} + +.mytoggle_collapsed { + display: none; +} + +.mytoggle_btn { + cursor: pointer; +} + +.mytoggle_btn:hover { + background-color: #abcdef; +} diff --git a/src/main/resources/static/js/mytoggle.js b/src/main/resources/static/js/mytoggle.js new file mode 100644 index 0000000..9420db1 --- /dev/null +++ b/src/main/resources/static/js/mytoggle.js @@ -0,0 +1,8 @@ +class MyToggle { + constructor() { + } + + toggle(divid) { + $("[id='" + divid + "']").toggle(); + } +} \ No newline at end of file diff --git a/src/main/resources/templates/error.html b/src/main/resources/templates/error.html new file mode 100644 index 0000000..3bc2ce5 --- /dev/null +++ b/src/main/resources/templates/error.html @@ -0,0 +1,20 @@ + + + + +Fehler + + + + + + +
+ +
+ + + \ No newline at end of file diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html new file mode 100644 index 0000000..6d3f21c --- /dev/null +++ b/src/main/resources/templates/index.html @@ -0,0 +1,61 @@ + + + +Camp Organizer 2 + + + + +
+ + Das Buchungsportal dess Onkel Werner Freizeiten e.V. +
+ +
+ +

Unsere Freizeiten

+
+
+   +
+
+
+
+
Ort
+
+ +
+
+
+
Jungen und Mädchen
+
+
+
+
Zeit
+
+ +
+
+
+
Preis
+
+
+
+
Ferien
+
+
+
+
+
+ +
+
+
+
+
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/template.html b/src/main/resources/templates/template.html new file mode 100644 index 0000000..46a6c1d --- /dev/null +++ b/src/main/resources/templates/template.html @@ -0,0 +1,33 @@ + + + +Camp Organizer Business + + + + + + + + + + + + + + + +
+
+ + [[${currentUser}]] aus Version ausloggen + + + einloggen + +
+ Layout header +
+
Layout content
+ + \ No newline at end of file diff --git a/src/main/resources/templates/user/index.html b/src/main/resources/templates/user/index.html new file mode 100644 index 0000000..6d3f21c --- /dev/null +++ b/src/main/resources/templates/user/index.html @@ -0,0 +1,61 @@ + + + +Camp Organizer 2 + + + + +
+ + Das Buchungsportal dess Onkel Werner Freizeiten e.V. +
+ +
+ +

Unsere Freizeiten

+
+
+   +
+
+
+
+
Ort
+
+ +
+
+
+
Jungen und Mädchen
+
+
+
+
Zeit
+
+ +
+
+
+
Preis
+
+
+
+
Ferien
+
+
+
+
+
+ +
+
+
+
+
+
+
+ + \ No newline at end of file