autocomit
This commit is contained in:
+2
-1
@@ -12,7 +12,8 @@ WORKDIR /app/frontend
|
|||||||
|
|
||||||
# Copy frontend package files and install dependencies
|
# Copy frontend package files and install dependencies
|
||||||
COPY frontend/package*.json ./
|
COPY frontend/package*.json ./
|
||||||
RUN npm install --only=production
|
RUN npm install
|
||||||
|
#--only=production
|
||||||
|
|
||||||
# Copy frontend source and build
|
# Copy frontend source and build
|
||||||
COPY frontend/ ./
|
COPY frontend/ ./
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package com.ldpv2.security;
|
|||||||
|
|
||||||
import com.ldpv2.domain.entity.User;
|
import com.ldpv2.domain.entity.User;
|
||||||
import com.ldpv2.repository.UserRepository;
|
import com.ldpv2.repository.UserRepository;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
import org.springframework.security.core.userdetails.UserDetails;
|
||||||
@@ -14,18 +16,32 @@ import java.util.Collections;
|
|||||||
@Service
|
@Service
|
||||||
public class UserDetailsServiceImpl implements UserDetailsService {
|
public class UserDetailsServiceImpl implements UserDetailsService {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(UserDetailsServiceImpl.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserRepository userRepository;
|
private UserRepository userRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||||
User user = userRepository.findByUsername(username)
|
logger.debug("Attempting to load user: {}", username);
|
||||||
.orElseThrow(() -> new UsernameNotFoundException("User not found: " + username));
|
|
||||||
|
|
||||||
return org.springframework.security.core.userdetails.User.builder()
|
User user = userRepository.findByUsername(username)
|
||||||
|
.orElseThrow(() -> {
|
||||||
|
logger.error("User not found: {}", username);
|
||||||
|
return new UsernameNotFoundException("User not found: " + username);
|
||||||
|
});
|
||||||
|
|
||||||
|
logger.debug("User found: {}, role: {}", user.getUsername(), user.getRole());
|
||||||
|
logger.debug("Password hash starts with: {}", user.getPassword().substring(0, 10));
|
||||||
|
|
||||||
|
UserDetails userDetails = org.springframework.security.core.userdetails.User.builder()
|
||||||
.username(user.getUsername())
|
.username(user.getUsername())
|
||||||
.password(user.getPassword())
|
.password(user.getPassword())
|
||||||
.authorities(Collections.singletonList(new SimpleGrantedAuthority("ROLE_" + user.getRole())))
|
.authorities(Collections.singletonList(new SimpleGrantedAuthority("ROLE_" + user.getRole())))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
logger.debug("UserDetails created successfully for: {}", username);
|
||||||
|
|
||||||
|
return userDetails;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,11 @@ import com.ldpv2.dto.response.UserResponse;
|
|||||||
import com.ldpv2.exception.BadRequestException;
|
import com.ldpv2.exception.BadRequestException;
|
||||||
import com.ldpv2.repository.UserRepository;
|
import com.ldpv2.repository.UserRepository;
|
||||||
import com.ldpv2.security.JwtTokenProvider;
|
import com.ldpv2.security.JwtTokenProvider;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
|
import org.springframework.security.authentication.BadCredentialsException;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
@@ -20,6 +23,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
@Service
|
@Service
|
||||||
public class AuthService {
|
public class AuthService {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(AuthService.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserRepository userRepository;
|
private UserRepository userRepository;
|
||||||
|
|
||||||
@@ -34,13 +39,17 @@ public class AuthService {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public AuthResponse register(RegisterRequest request) {
|
public AuthResponse register(RegisterRequest request) {
|
||||||
|
logger.debug("Registration attempt for username: {}", request.getUsername());
|
||||||
|
|
||||||
// Check if username exists
|
// Check if username exists
|
||||||
if (userRepository.existsByUsername(request.getUsername())) {
|
if (userRepository.existsByUsername(request.getUsername())) {
|
||||||
|
logger.warn("Registration failed: Username already exists: {}", request.getUsername());
|
||||||
throw new BadRequestException("Username already exists");
|
throw new BadRequestException("Username already exists");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if email exists
|
// Check if email exists
|
||||||
if (userRepository.existsByEmail(request.getEmail())) {
|
if (userRepository.existsByEmail(request.getEmail())) {
|
||||||
|
logger.warn("Registration failed: Email already exists: {}", request.getEmail());
|
||||||
throw new BadRequestException("Email already exists");
|
throw new BadRequestException("Email already exists");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,6 +61,7 @@ public class AuthService {
|
|||||||
user.setRole("USER");
|
user.setRole("USER");
|
||||||
|
|
||||||
user = userRepository.save(user);
|
user = userRepository.save(user);
|
||||||
|
logger.info("User registered successfully: {}", user.getUsername());
|
||||||
|
|
||||||
// Authenticate the user
|
// Authenticate the user
|
||||||
Authentication authentication = authenticationManager.authenticate(
|
Authentication authentication = authenticationManager.authenticate(
|
||||||
@@ -65,17 +75,33 @@ public class AuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public AuthResponse login(LoginRequest request) {
|
public AuthResponse login(LoginRequest request) {
|
||||||
|
logger.debug("Login attempt for username: {}", request.getUsername());
|
||||||
|
|
||||||
|
try {
|
||||||
|
// This will call UserDetailsService.loadUserByUsername()
|
||||||
Authentication authentication = authenticationManager.authenticate(
|
Authentication authentication = authenticationManager.authenticate(
|
||||||
new UsernamePasswordAuthenticationToken(request.getUsername(), request.getPassword())
|
new UsernamePasswordAuthenticationToken(request.getUsername(), request.getPassword())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
logger.debug("Authentication successful for: {}", request.getUsername());
|
||||||
|
|
||||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||||
String token = tokenProvider.generateToken(authentication);
|
String token = tokenProvider.generateToken(authentication);
|
||||||
|
|
||||||
User user = userRepository.findByUsername(request.getUsername())
|
User user = userRepository.findByUsername(request.getUsername())
|
||||||
.orElseThrow(() -> new BadRequestException("User not found"));
|
.orElseThrow(() -> new BadRequestException("User not found"));
|
||||||
|
|
||||||
|
logger.info("Login successful for user: {}", user.getUsername());
|
||||||
|
|
||||||
return new AuthResponse(token, mapToUserResponse(user));
|
return new AuthResponse(token, mapToUserResponse(user));
|
||||||
|
|
||||||
|
} catch (BadCredentialsException e) {
|
||||||
|
logger.error("Login failed for username: {} - Bad credentials", request.getUsername());
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Login failed for username: {} - {}", request.getUsername(), e.getMessage());
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private UserResponse mapToUserResponse(User user) {
|
private UserResponse mapToUserResponse(User user) {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
# PostgreSQL Database (separate container)
|
# PostgreSQL Database (separate container)
|
||||||
postgres:
|
postgres:
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
echo "=========================================="
|
||||||
|
echo "LDPv2 - Database Diagnostics"
|
||||||
|
echo "=========================================="
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "1. Checking if user table exists:"
|
||||||
|
echo "-----------------------------------"
|
||||||
|
docker exec ldpv2-postgres psql -U ldpv2_user -d ldpv2 -c "\dt users"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "2. Checking users in database:"
|
||||||
|
echo "-----------------------------------"
|
||||||
|
docker exec ldpv2-postgres psql -U ldpv2_user -d ldpv2 -c "SELECT id, username, email, role, created_at FROM users;"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "3. Checking password hash for admin:"
|
||||||
|
echo "-----------------------------------"
|
||||||
|
docker exec ldpv2-postgres psql -U ldpv2_user -d ldpv2 -c "SELECT username, LEFT(password, 20) || '...' as password_hash FROM users WHERE username='admin';"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "4. Checking all tables:"
|
||||||
|
echo "-----------------------------------"
|
||||||
|
docker exec ldpv2-postgres psql -U ldpv2_user -d ldpv2 -c "\dt"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "5. Checking Liquibase changelog (executed migrations):"
|
||||||
|
echo "-----------------------------------"
|
||||||
|
docker exec ldpv2-postgres psql -U ldpv2_user -d ldpv2 -c "SELECT id, author, filename, dateexecuted, exectype FROM databasechangelog ORDER BY dateexecuted;"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "6. Testing BCrypt hash verification:"
|
||||||
|
echo "-----------------------------------"
|
||||||
|
echo "The password 'admin123' should hash to something starting with \$2a\$10\$"
|
||||||
|
echo "Expected hash in initial-data.xml: \$2a\$10\$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "=========================================="
|
||||||
|
echo "Diagnostics complete!"
|
||||||
|
echo "=========================================="
|
||||||
Reference in New Issue
Block a user