Refactored feature critical authentication classes
This commit is contained in:
parent
4e75e25d62
commit
ba239764bf
@ -1,5 +1,6 @@
|
|||||||
package de.w665.biblenotes.config;
|
package de.w665.biblenotes.config;
|
||||||
|
|
||||||
|
import de.w665.biblenotes.rest.security.JwtAuthenticationFilter;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.security.config.Customizer;
|
import org.springframework.security.config.Customizer;
|
||||||
|
@ -54,45 +54,6 @@ public class RethinkDBService {
|
|||||||
log.debug("Database " + config.getDatabase() + " already exists. Error: " + e.getClass().getSimpleName());
|
log.debug("Database " + config.getDatabase() + " already exists. Error: " + e.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
|
|
||||||
// rethinkdb check if table file_uploads exists
|
|
||||||
try {
|
|
||||||
r.db(config.getDatabase()).tableCreate("file_uploads").run(connection).stream();
|
|
||||||
log.debug("Table 'file_uploads' created successfully.");
|
|
||||||
} catch (ReqlOpFailedError e) {
|
|
||||||
log.debug("Table 'file_uploads' already exists.");
|
|
||||||
if(autoResetOnStartup) {
|
|
||||||
log.debug("Clearing content...");
|
|
||||||
r.db(config.getDatabase()).table("file_uploads").delete().run(connection);
|
|
||||||
log.debug("Table 'file_uploads' cleared successfully.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// rethinkdb check if table id_store exists
|
|
||||||
try {
|
|
||||||
r.db(config.getDatabase()).tableCreate("id_store").run(connection).stream();
|
|
||||||
log.debug("Table 'id_store' created successfully.");
|
|
||||||
} catch (ReqlOpFailedError e) {
|
|
||||||
log.debug("Table 'id_store' already exists.");
|
|
||||||
if(autoResetOnStartup) {
|
|
||||||
log.debug("Clearing content...");
|
|
||||||
r.db(config.getDatabase()).table("id_store").delete().run(connection);
|
|
||||||
log.debug("Table 'id_store' cleared successfully.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// rethinkdb check if table expired_file_uploads exists
|
|
||||||
try {
|
|
||||||
r.db(config.getDatabase()).tableCreate("expired_file_uploads").run(connection).stream();
|
|
||||||
log.debug("Table 'expired_file_uploads' created successfully.");
|
|
||||||
} catch (ReqlOpFailedError e) {
|
|
||||||
log.debug("Table 'expired_file_uploads' already exists.");
|
|
||||||
if(autoResetOnStartup) {
|
|
||||||
log.debug("Clearing content...");
|
|
||||||
r.db(config.getDatabase()).table("expired_file_uploads").delete().run(connection);
|
|
||||||
log.debug("Table 'expired_file_uploads' cleared successfully.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// rethinkdb check if table users exists
|
// rethinkdb check if table users exists
|
||||||
try {
|
try {
|
||||||
r.db(config.getDatabase()).tableCreate("users").run(connection).stream();
|
r.db(config.getDatabase()).tableCreate("users").run(connection).stream();
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
package de.w665.biblenotes.rest.security;
|
package de.w665.biblenotes.rest.security;
|
||||||
|
|
||||||
|
import de.w665.biblenotes.service.AuthenticationService;
|
||||||
import jakarta.servlet.FilterChain;
|
import jakarta.servlet.FilterChain;
|
||||||
import jakarta.servlet.ServletException;
|
import jakarta.servlet.ServletException;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
|
@ -1,5 +1,13 @@
|
|||||||
package de.w665.biblenotes.service;
|
package de.w665.biblenotes.service;
|
||||||
|
|
||||||
|
import de.w665.biblenotes.db.repo.UserLoginRepository;
|
||||||
|
import de.w665.biblenotes.db.repo.UserRepository;
|
||||||
|
import de.w665.biblenotes.model.User;
|
||||||
|
import de.w665.biblenotes.model.UserLogin;
|
||||||
|
import io.jsonwebtoken.Claims;
|
||||||
|
import io.jsonwebtoken.Jwt;
|
||||||
|
import io.jsonwebtoken.Jwts;
|
||||||
|
import io.jsonwebtoken.security.Keys;
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
@ -17,9 +25,9 @@ public class AuthenticationService {
|
|||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
private final UserLoginRepository userLoginRepository;
|
private final UserLoginRepository userLoginRepository;
|
||||||
|
|
||||||
@Value("${secureapi.jwt.secret}")
|
@Value("${jwt.secret}")
|
||||||
private String secretString;
|
private String secretString;
|
||||||
@Value("${secureapi.jwt.expiration}")
|
@Value("${jwt.expiration}")
|
||||||
private long expirationTime; // in milliseconds
|
private long expirationTime; // in milliseconds
|
||||||
private SecretKey secretKey;
|
private SecretKey secretKey;
|
||||||
|
|
||||||
@ -58,7 +66,7 @@ public class AuthenticationService {
|
|||||||
Date expiryDate = new Date(nowMillis + expirationTime);
|
Date expiryDate = new Date(nowMillis + expirationTime);
|
||||||
|
|
||||||
return Jwts.builder()
|
return Jwts.builder()
|
||||||
.subject("SharePulse Authentication Token")
|
.subject("Biblenotes Authentication Token")
|
||||||
.issuedAt(now)
|
.issuedAt(now)
|
||||||
.claim("role", username.getRole())
|
.claim("role", username.getRole())
|
||||||
.claim("username", username.getUsername())
|
.claim("username", username.getUsername())
|
||||||
|
@ -1 +1,19 @@
|
|||||||
|
biblenotes.auto-reset-on-startup=false
|
||||||
|
biblenotes.management.user.username=admin
|
||||||
|
biblenotes.management.user.password=admin
|
||||||
|
|
||||||
|
# Database
|
||||||
|
rethinkdb.host=localhost
|
||||||
|
rethinkdb.port=28015
|
||||||
|
rethinkdb.database=biblenotes
|
||||||
|
|
||||||
|
# Logging
|
||||||
|
logging.level.de.w665.biblenotes=INFO
|
||||||
|
|
||||||
|
# Static path
|
||||||
|
spring.web.resources.static-locations=classpath:/static/browser/
|
||||||
|
|
||||||
|
server.port=80
|
||||||
spring.application.name=biblenotes
|
spring.application.name=biblenotes
|
||||||
|
jwt.secret=sampleKeyToChangeInProduction
|
||||||
|
jwt.expiration=3600000
|
Loading…
x
Reference in New Issue
Block a user