Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.header.writers.StaticHeadersWriter;

@Configuration
public class WebSecurityConfig {
Expand Down Expand Up @@ -57,6 +58,14 @@ protected SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exce
}).cors(Customizer.withDefaults())
.csrf(csrf->csrf.disable());

// Add headers to prevent caching
http.headers(headers -> {
headers.cacheControl(cache -> cache.disable());
headers.addHeaderWriter(new StaticHeadersWriter("Cache-Control", "no-cache, no-store, must-revalidate"));
headers.addHeaderWriter(new StaticHeadersWriter("Pragma", "no-cache"));
headers.addHeaderWriter(new StaticHeadersWriter("Expires", "0"));
});

return http.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public UsersController(UsersTypeService usersTypeService, UsersService usersServ
this.usersService = usersService;
}


@GetMapping("/register")
public String register(Model model) {
List<UsersType> usersTypes = usersTypeService.getAll();
Expand All @@ -56,7 +57,11 @@ public String userRegistration(@Valid Users users, Model model) {

@GetMapping("/login")
public String login() {
return "login";
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth != null && auth.isAuthenticated() && !(auth instanceof AnonymousAuthenticationToken)) {
return "redirect:/dashboard/"; // Redirect to dashboard if already authenticated
}
return "login"; // Show login page if not authenticated
}

@GetMapping("/logout")
Expand Down