Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ For production these variables are needed.
| CACHE_PASSWORD_RESET_EXPIRY_HOURS | How long are password reset attempts cached in hours | 12 | 12 | N |
| REMEMBER_ME_VALIDITY_SECONDS | How long rememberMe (session) is valid in seconds | 365 | | Y |
| REMEMBER_ME_KEY | Securely generated string to use as a key | somethingMoreSecureThenThis | | Y |
| VERIFICATION_TOKEN_EXPIRY_HOURS | How many hours the verification token is valid | 24 | 24 | N |
| ENABLE_ADMIN_CREATION | Enable initial admin user creation | false | false | Only if an initial admin user needs to be created |
| ADMIN_USERNAME | Admin's username | admin | | Only if an initial admin user is created |
| ADMIN_PASSWORD | Admin's password | somethingMoreSecureThenThis | | Only if an initial admin user is created |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@
*/
package fi.asteriski.nakitin.service;

import static fi.asteriski.nakitin.utils.Constants.TOKEN_EXPIRY_HOURS;

import java.time.LocalDateTime;
import java.util.UUID;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
@Log4j2
public class VerificationTokenService {
@Value("${security.verificationToken.expiryHours}")
private Long tokenExpiryHours;

public String generateVerificationToken() {
return UUID.randomUUID().toString();
}

public LocalDateTime calculateExpiryDate() {
return LocalDateTime.now().plusHours(TOKEN_EXPIRY_HOURS);
return LocalDateTime.now().plusHours(tokenExpiryHours);
}

public boolean isTokenExpired(LocalDateTime expiryDate) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/fi/asteriski/nakitin/utils/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class Constants {
public static final int MAX_PAGE_SIZE = 20;
public static final String DUMMY_PASSWORD = Base64.getEncoder().encodeToString("dummyPassword".getBytes());
public static final String LOG_ERROR_MESSAGE_TEMPLATE = "Error with email. Error was: %s";
public static final int TOKEN_EXPIRY_HOURS = 24;

public static final String HTML_BREAK = "<br/>";
public static final String HTML_TAB = "&nbsp;&nbsp;&nbsp;&nbsp;";
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application-prod.properties
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ cache.passwordReset.expiryHours=${CACHE_PASSWORD_RESET_EXPIRY_HOURS:24}
# Security configuration
security.rememberMe.validitySeconds=${REMEMBER_ME_VALIDITY_SECONDS}
security.rememberMe.key=${REMEMBER_ME_KEY}
security.verificationToken.expiryHours=${VERIFICATION_TOKEN_EXPIRY_HOURS:24}

# Initial user config
app.admin.username=${ADMIN_USERNAME:}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ cache.passwordReset.expiryHours=24
# Security configuration
security.rememberMe.validitySeconds=86400
security.rememberMe.key=uniqueAndSecretKey
security.verificationToken.expiryHours=24
Loading