Skip to content

Commit

Permalink
Reverse-Proxy raus, weil ROOT-Context kein Reload hat
Browse files Browse the repository at this point in the history
  • Loading branch information
commel committed Sep 30, 2023
1 parent 698e5c7 commit d71fda8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 19 deletions.
7 changes: 0 additions & 7 deletions doc/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ services:
- './tomcat/conf/tomcat-users.xml:/usr/local/tomcat/conf/tomcat-users.xml'
- './tomcat/lib/postgresql-42.3.1.jar:/usr/local/tomcat/lib/postgresql-42.3.1.jar'
- '../target/holarseweb.war:/usr/local/tomcat/webapps/holarseweb.war'
reverse-proxy:
container_name: reverse-proxy
image: caddy:latest
ports:
- "80:80"
volumes:
- ./reverse-proxy/:/etc/caddy/
volumes:
website_my_pgdata:
external: true
Expand Down
5 changes: 2 additions & 3 deletions doc/tomcat/conf/server.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,8 @@
resourceName="UserDatabase"/>
</Realm>

<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="false" deployOnStartup="false">
<Context path="" docBase="holarseweb"></Context>

<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" deployOnStartup="true">

<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
Expand Down
56 changes: 48 additions & 8 deletions src/main/java/de/holarse/web/controller/RegisterController.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package de.holarse.web.controller;

import de.holarse.backend.db.User;
import de.holarse.backend.db.UserData;
import de.holarse.backend.db.UserSlug;
import de.holarse.backend.db.UserStatus;
import de.holarse.backend.db.repositories.RoleRepository;
import de.holarse.backend.db.repositories.UserRepository;
import de.holarse.backend.types.PasswordType;
import de.holarse.web.controller.commands.RegisterForm;
import de.holarse.web.defines.WebDefines;
import de.holarse.web.services.JobService;
Expand All @@ -13,13 +16,17 @@
import java.time.OffsetDateTime;
import java.util.Optional;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityTransaction;
import jakarta.persistence.PersistenceContext;
import jakarta.transaction.Transactional;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.apache.commons.math3.random.RandomDataGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -55,6 +62,10 @@ public class RegisterController {

@Autowired
RegisterFormValidationService rfValidationService;

@Autowired
@Qualifier("bcryptEncoder")
private PasswordEncoder passwordEncoder;

@GetMapping
public ModelAndView index(final ModelAndView mv) {
Expand Down Expand Up @@ -82,17 +93,42 @@ public ModelAndView register(@Valid @ModelAttribute("registerForm") final Regist

log.info("Registration form ok");

final EntityTransaction tx = em.getTransaction();
tx.begin();
// Unbestätigten Benutzer anlegen
final User newUser = registerService.createUnverifiedUser(registerForm);
newUser.getRoles().add(roleRepository.findByCode("TRUSTED_USER"));
final User user = new User();
user.setLogin(registerForm.getUsername());
user.setEmail(registerForm.getEmail());
user.setHashType(PasswordType.bcrypt);
user.setDigest(passwordEncoder.encode(registerForm.getPassword()));
em.persist(user);

final UserStatus userStatus = new UserStatus();
userStatus.setCreated(OffsetDateTime.now());
userStatus.setFailedLogins(0);
userStatus.setLocked(false);
userStatus.setVerified(false);
userStatus.setVerificationHash(generateVerificationHash());
userStatus.setVerificationHashValidUntil(OffsetDateTime.now().plusMinutes(30));
user.setUserStatus(userStatus);

final UserData userData = new UserData();
user.setUserData(userData);

user.getRoles().add(roleRepository.findByCode("TRUSTED_USER"));

// Slugs
UserSlug userSlug = slugService.slugify(newUser);
userSlug.setUser(newUser);
newUser.getUserSlugs().add(userSlug);
em.persist(newUser);
mv.addObject("validationKey", newUser.getUserStatus().getVerificationHash());

UserSlug userSlug = slugService.slugify(user);
userSlug.setUser(user);
user.getUserSlugs().add(userSlug);
mv.addObject("validationKey", user.getUserStatus().getVerificationHash());

em.persist(user);
em.persist(userStatus);
em.persist(userData);
em.persist(userSlug);
tx.commit();

mv.addObject(WebDefines.DEFAULT_VIEW_ATTRIBUTE_NAME, "sites/accounts/registered");
return mv;
}
Expand All @@ -115,5 +151,9 @@ public ModelAndView verify(@NotNull @RequestParam("v") final String verification

return mv;
}

public String generateVerificationHash() {
return new RandomDataGenerator().nextSecureHexString(12);
}

}
2 changes: 1 addition & 1 deletion src/main/resources/log4j.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ log4j.logger.org.hibernate = WARN
log4j.logger.org.hibernate.SQL=WARN
log4j.logger.org.hibernate.type=WARN

log4j.logger.org.springframework.security=TRACE
log4j.logger.org.springframework.security=WARN
#log4j.logger.com.fasterxml.jackson=WARN
log4j.logger.de.holarse=DEBUG
log4j.logger.de.holarse.renderer=WARN
Expand Down

0 comments on commit d71fda8

Please sign in to comment.