Skip to content

Commit

Permalink
feat: finished auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Toto-hitori committed Feb 6, 2024
1 parent 6b18c5c commit 8dd1e5c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package lab.en2b.quizapi.auth.config;

import lab.en2b.quizapi.auth.jwt.JwtAuthFilter;
import lab.en2b.quizapi.commons.user.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -16,6 +17,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.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
Expand All @@ -27,6 +29,10 @@ public class SecurityConfig {
@Autowired
public UserService userService;
@Bean
public JwtAuthFilter authenticationJwtTokenFilter() {
return new JwtAuthFilter();
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
Expand Down Expand Up @@ -58,6 +64,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http, Authentication
.anyRequest().authenticated())
.csrf(AbstractHttpConfigurer::disable)
.authenticationManager(authenticationManager)
.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class)
.build();
//TODO: add exception handling
}
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/lab/en2b/quizapi/commons/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class User {
private Instant refreshExpiration;

@NotNull
@ManyToMany
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name="users_roles",
joinColumns=
@JoinColumn(name="user_id", referencedColumnName="id"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package lab.en2b.quizapi.questions.question;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/questions")
public class QuestionController {
@GetMapping("/dummy")
private String getDummyQuestion(){
return "Who the hell is Steve Jobs?";
}
}

0 comments on commit 8dd1e5c

Please sign in to comment.