Skip to content

Commit 49ecff1

Browse files
committed
many changes over a month commited all at once
1 parent 0b79f22 commit 49ecff1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1075
-848
lines changed

notes.txt

+4
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ Backdrops
9595
1.778 2999 x 1687
9696
1.778 3840 x 2160
9797

98+
Stills
99+
1357 x 764
100+
1.777 1920 × 1080
101+
1.777 3840 x 2160
98102
######################################################################################################################################################
99103
Filters :
100104

pom.xml

+6-17
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,6 @@
7575
<artifactId>spring-boot-starter-security</artifactId>
7676
<version>3.0.4</version>
7777
</dependency>
78-
<dependency>
79-
<groupId>io.jsonwebtoken</groupId>
80-
<artifactId>jjwt-impl</artifactId>
81-
<version>0.11.5</version>
82-
<scope>runtime</scope>
83-
</dependency>
84-
<dependency>
85-
<groupId>io.jsonwebtoken</groupId>
86-
<artifactId>jjwt-api</artifactId>
87-
<version>0.11.5</version>
88-
</dependency>
89-
<dependency>
90-
<groupId>io.jsonwebtoken</groupId>
91-
<artifactId>jjwt-jackson</artifactId>
92-
<version>0.11.5</version>
93-
<scope>runtime</scope>
94-
</dependency>
9578
<dependency>
9679
<groupId>org.springframework.boot</groupId>
9780
<artifactId>spring-boot-starter-test</artifactId>
@@ -102,6 +85,12 @@
10285
<artifactId>opencsv</artifactId>
10386
<version>5.7.1</version>
10487
</dependency>
88+
<dependency>
89+
<groupId>org.thymeleaf.extras</groupId>
90+
<artifactId>thymeleaf-extras-springsecurity6</artifactId>
91+
<version>3.1.1.RELEASE</version>
92+
</dependency>
93+
10594
</dependencies>
10695
<build>
10796
<plugins>
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,51 @@
11
package servie.track_servie.config;
22

33
import lombok.RequiredArgsConstructor;
4-
import servie.track_servie.filters.AuthenticationTokenFilter;
5-
// import org.springframework.boot.web.servlet.FilterRegistrationBean;
4+
import servie.track_servie.service.CustomUserDetailsService;
65
import org.springframework.context.annotation.Bean;
76
import org.springframework.context.annotation.Configuration;
8-
// import org.springframework.core.Ordered;
9-
import org.springframework.security.authentication.AuthenticationProvider;
7+
import org.springframework.security.authentication.AuthenticationManager;
8+
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
109
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
1110
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
12-
import org.springframework.security.config.http.SessionCreationPolicy;
11+
import org.springframework.security.config.annotation.web.configurers.LogoutConfigurer;
12+
import org.springframework.security.core.userdetails.UserDetailsService;
13+
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
14+
import org.springframework.security.crypto.password.PasswordEncoder;
1315
import org.springframework.security.web.SecurityFilterChain;
14-
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
15-
// import org.springframework.web.cors.CorsConfiguration;
16-
// import org.springframework.web.cors.CorsConfigurationSource;
17-
// import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
18-
// import org.springframework.web.filter.CorsFilter;
19-
// import java.util.Arrays;
20-
// import java.util.List;
2116

2217
@Configuration
2318
@EnableWebSecurity
2419
@RequiredArgsConstructor
2520
public class ApiSecurity
2621
{
27-
private final AuthenticationTokenFilter jwtAuthFilter;
28-
private final AuthenticationProvider authenticationProvider;
22+
@Bean
23+
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception
24+
{
25+
http.authorizeHttpRequests(reuest -> reuest.requestMatchers("src/main/resources/static/css/mystyles.css", "/track-servie/auth/register", "/track-servie/auth/login").permitAll().anyRequest().authenticated())
26+
.formLogin(form -> form.loginPage("/track-servie/auth/login")
27+
.defaultSuccessUrl("/track-servie/servies", true).permitAll())
28+
.logout(LogoutConfigurer::permitAll);
29+
return http.build();
30+
}
2931

30-
@Bean
31-
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception
32-
{
33-
http.csrf().disable().authorizeHttpRequests(auth ->
34-
{
35-
auth.requestMatchers("/track-servie/**").permitAll();
36-
auth.anyRequest().authenticated();
37-
}).sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().authenticationProvider(authenticationProvider).addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class);
38-
return http.build();
39-
}
40-
// @Bean
41-
// public FilterRegistrationBean corsFilter()
42-
// {
43-
// UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
44-
// CorsConfiguration config = new CorsConfiguration();
45-
// config.setAllowCredentials(true);
46-
// config.setAllowedOriginPatterns(Arrays.asList("*"));
47-
// config.setAllowedMethods(Arrays.asList("POST", "OPTIONS", "GET", "DELETE", "PUT"));
48-
// config.setAllowedHeaders(Arrays.asList("X-Requested-With", "Origin", "Content-Type", "Accept", "Authorization", "X-USER-ID"));
49-
// source.registerCorsConfiguration("/**", config);
50-
// FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
51-
// bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
52-
// return bean;
53-
// }
54-
// @Bean
55-
// CorsConfigurationSource corsConfigurationSource()
56-
// {
57-
// CorsConfiguration configuration = new CorsConfiguration();
58-
// configuration.setAllowedOrigins(List.of("*"));
59-
// // configuration.setAllowedOrigins(Arrays.asList("http://localhost:8080"));
60-
// configuration.setAllowedMethods(List.of("*"));
61-
// // configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS"));
62-
// configuration.setAllowedHeaders(List.of("*"));
63-
// // configuration.setAllowedHeaders(Arrays.asList("*"));
64-
// configuration.setAllowCredentials(true);
65-
// UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
66-
// source.registerCorsConfiguration("/**", configuration);
67-
// return source;
68-
// }
32+
@Bean
33+
public PasswordEncoder passwordEncoder()
34+
{
35+
return new BCryptPasswordEncoder();
36+
}
37+
38+
@Bean
39+
public UserDetailsService userDetailsService()
40+
{
41+
return new CustomUserDetailsService();
42+
}
43+
44+
@Bean
45+
public AuthenticationManager authenticationManager(HttpSecurity http) throws Exception
46+
{
47+
AuthenticationManagerBuilder authenticationManagerBuilder = http.getSharedObject(AuthenticationManagerBuilder.class);
48+
authenticationManagerBuilder.userDetailsService(userDetailsService()).passwordEncoder(passwordEncoder());
49+
return authenticationManagerBuilder.build();
50+
}
6951
}

src/main/java/servie/track_servie/config/AppConfig.java

+5-42
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,16 @@
22

33
import org.springframework.context.annotation.Bean;
44
import org.springframework.context.annotation.Configuration;
5-
import org.springframework.security.authentication.AuthenticationManager;
6-
import org.springframework.security.authentication.AuthenticationProvider;
7-
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
8-
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
9-
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
10-
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
11-
import org.springframework.security.crypto.password.PasswordEncoder;
125
import org.springframework.web.client.RestTemplate;
136
import lombok.RequiredArgsConstructor;
14-
import servie.track_servie.service.JwtUserDetailsService;
157

168
@Configuration
179
@RequiredArgsConstructor
1810
public class AppConfig
1911
{
20-
private final JwtUserDetailsService jwtUserDetailsService;
21-
22-
@Bean
23-
public RestTemplate getRestTemplate()
24-
{
25-
return new RestTemplate();
26-
}
27-
28-
@Bean
29-
public AuthenticationProvider authenticationProvider()
30-
{
31-
DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider();
32-
authenticationProvider.setUserDetailsService(jwtUserDetailsService);
33-
authenticationProvider.setPasswordEncoder(passwordEncoder());
34-
return authenticationProvider;
35-
}
36-
37-
@Bean
38-
public AuthenticationManager authenticationManager(AuthenticationConfiguration config) throws Exception
39-
{
40-
return config.getAuthenticationManager();
41-
}
42-
43-
@Bean
44-
public PasswordEncoder passwordEncoder()
45-
{
46-
return new BCryptPasswordEncoder();
47-
}
48-
49-
@Bean
50-
public WebSecurityCustomizer webSecurityCustomizer()
51-
{
52-
return (web) -> web.ignoring().requestMatchers("/css/**", "/templates/**");
53-
}
12+
@Bean
13+
public RestTemplate getRestTemplate()
14+
{
15+
return new RestTemplate();
16+
}
5417
}
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,44 @@
11
package servie.track_servie.controller;
22

33
import org.springframework.beans.factory.annotation.Autowired;
4-
import org.springframework.security.authentication.AuthenticationManager;
5-
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
6-
import org.springframework.security.core.Authentication;
7-
import org.springframework.security.core.context.SecurityContextHolder;
84
import org.springframework.stereotype.Controller;
95
import org.springframework.ui.Model;
106
import org.springframework.web.bind.annotation.GetMapping;
117
import org.springframework.web.bind.annotation.ModelAttribute;
128
import org.springframework.web.bind.annotation.PostMapping;
139
import org.springframework.web.bind.annotation.RequestMapping;
14-
import servie.track_servie.payload.dtos.LoginRequest;
15-
import servie.track_servie.utils.jwt.JwtUtils;
10+
import servie.track_servie.entity.User;
11+
import servie.track_servie.service.UserService;
1612

1713
@Controller
18-
@RequestMapping("auth")
14+
@RequestMapping("/track-servie/auth")
1915
public class AuthController
2016
{
2117
@Autowired
22-
AuthenticationManager authenticationManager;
23-
@Autowired
24-
JwtUtils jwtUtils;
18+
private UserService userService;
2519

26-
@GetMapping("login")
27-
public String showLoginPage(Model model)
20+
@GetMapping("/login")
21+
public String getLoginForm()
2822
{
29-
model.addAttribute("loginForm", new LoginRequest());
3023
return "LoginPage";
3124
}
25+
// @PostMapping("/login")
26+
// public String getLoginForm(@ModelAttribute User user)
27+
// {
28+
// return "LoginPage";
29+
// }
30+
31+
@GetMapping("/register")
32+
public String register(Model model)
33+
{
34+
model.addAttribute("user", new User());
35+
return "RegistrationPage";
36+
}
3237

33-
@PostMapping("login")
34-
// @CrossOrigin(origins = "http://localhost:8080")
35-
public String authenticateUser(@ModelAttribute("loginForm") LoginRequest loginRequest, Model model)
38+
@PostMapping("/register")
39+
public String register(@ModelAttribute User user)
3640
{
37-
Authentication authentication;
38-
try
39-
{
40-
authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(loginRequest.getEmail(), loginRequest.getPassword()));
41-
}
42-
catch(RuntimeException e)
43-
{
44-
// return new ResponseEntity<>(new Response("Invalid credentials."),
45-
// HttpStatus.FORBIDDEN);
46-
return "redirect:/track-servie/auth/login";
47-
}
48-
SecurityContextHolder.getContext().setAuthentication(authentication);
49-
String jwtToken = jwtUtils.generateJwtToken(authentication);
50-
// AuthUser userDetails = (AuthUser) authentication.getPrincipal();
51-
// List<String> roles =
52-
// userDetails.getAuthorities().stream().map(GrantedAuthority::getAuthority)
53-
// .collect(Collectors.toList());
54-
// Map<String, Object> responseData = new HashMap<>();
55-
// responseData.put("email", userDetails.getUsername());
56-
// responseData.put("roles", roles);
57-
// response.addHeader("Authorization", "Bearer " + jwtToken);
58-
// request.setAttribute("Authorization", "Bearer " + jwtToken);
59-
// Map<String, String> headers = new HashMap<>();
60-
// headers.put("Authorization", "Bearer " + jwtToken);
61-
// HttpServletRequestWrapper requestWrapper = new
62-
// CustomHttpServletRequestWrapper(request, headers);
63-
// redirectAttributes.addFlashAttribute("requestWrapper", requestWrapper);
64-
// redirectAttributes.addAttribute("type", "tv");
65-
// redirectAttributes.addAttribute("query", "breaking bad");
66-
// return "redirect:/track-servie/servies/search";
67-
model.addAttribute("jwtToken", jwtToken);
68-
return "redirect:/track-servie/servies";
41+
userService.register(user);
42+
return "redirect:/track-servie/auth/login?success";
6943
}
70-
}
71-
// HttpHeaders headers = new HttpHeaders();
72-
// headers.set("Authorization", "Bearer " + jwtToken);
73-
// CustomHttpServletResponseWrapper responseWrapper = new
74-
// CustomHttpServletResponseWrapper(headers2, "Bearer " + jwtToken);
75-
// redirectAttributes.addFlashAttribute("headers", responseWrapper);
44+
}

src/main/java/servie/track_servie/controller/EpisodeController.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import java.util.List;
44
import org.springframework.beans.factory.annotation.Autowired;
5-
import org.springframework.beans.factory.annotation.Value;
5+
import org.springframework.security.core.annotation.AuthenticationPrincipal;
6+
import org.springframework.security.core.userdetails.UserDetails;
67
import org.springframework.stereotype.Controller;
78
import org.springframework.ui.Model;
89
import org.springframework.web.bind.annotation.GetMapping;
@@ -11,6 +12,7 @@
1112
import org.springframework.web.bind.annotation.RequestParam;
1213
import servie.track_servie.payload.dtos.episodePageDtos.EpisodeDtoEpisodePage;
1314
import servie.track_servie.payload.dtos.operationsImage.Image;
15+
import servie.track_servie.repository.UserRepository;
1416
import servie.track_servie.service.EpisodeService;
1517

1618
@Controller
@@ -19,8 +21,8 @@ public class EpisodeController
1921
{
2022
@Autowired
2123
EpisodeService episodeService;
22-
@Value("${user-id}")
23-
private Integer userId;
24+
@Autowired
25+
private UserRepository userRepository;
2426

2527
// Returns EpisodePage containing selected Episode from SeasonPage
2628
@GetMapping("")
@@ -41,16 +43,18 @@ public String getEpisode(@PathVariable Integer tmdbId, @PathVariable Integer sea
4143

4244
// Toggles the watch button of Episode located on SeasonPage
4345
@GetMapping("toggleback")
44-
public String toggleEpisodeWatch(@PathVariable Integer tmdbId, @PathVariable Integer seasonNo, @PathVariable Integer episodeNo)
46+
public String toggleEpisodeWatch(@PathVariable Integer tmdbId, @PathVariable Integer seasonNo, @PathVariable Integer episodeNo, @AuthenticationPrincipal UserDetails userDetails)
4547
{
48+
Integer userId = userRepository.findByEmail(userDetails.getUsername()).get().getId();
4649
episodeService.toggleEpisodeWatch(userId, tmdbId, seasonNo, episodeNo);
4750
return "redirect:/track-servie/servies/"+tmdbId+"/Season/"+seasonNo;
4851
}
4952

5053
// Toggles the watch button of Episode located on EpisodePage
5154
@GetMapping("toggle")
52-
public String toggleEpWatch(@PathVariable Integer tmdbId, @PathVariable Integer seasonNo, @PathVariable Integer episodeNo)
55+
public String toggleEpWatch(@PathVariable Integer tmdbId, @PathVariable Integer seasonNo, @PathVariable Integer episodeNo, @AuthenticationPrincipal UserDetails userDetails)
5356
{
57+
Integer userId = userRepository.findByEmail(userDetails.getUsername()).get().getId();
5458
episodeService.toggleEpisodeWatch(userId, tmdbId, seasonNo, episodeNo);
5559
return "redirect:/track-servie/servies/"+tmdbId+"/Season/"+seasonNo+"/Episode/"+episodeNo;
5660
}

src/main/java/servie/track_servie/controller/ExportController.java

-4
This file was deleted.

0 commit comments

Comments
 (0)