StackoverflowError on Login Request

Hi, i'm struggling [Handler dispatch failed: java.lang.StackOverflowError] with root cause java.lang.StackOverflowError: null
310 Replies
JavaBot
JavaBot2w ago
This post has been reserved for your question.
Hey @Icca! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Icca
IccaOP2w ago
SpringSecurityConfig.java : @Configuration public class SpringSecurityConfig { @Value("${jwt.key}") private String jwtKey; @Bean public UserDetailsService userDetailsService(CustomUserDetailsService customUserDetailsService) { return customUserDetailsService; } @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { return http .csrf(csrf -> csrf.disable()) .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) .authorizeHttpRequests(auth -> auth .requestMatchers("/auth/register", "/auth/login").permitAll() .anyRequest().authenticated() ) .oauth2ResourceServer(oauth2 -> oauth2.jwt(Customizer.withDefaults())) .build(); } @Bean public BCryptPasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } @Bean public JwtDecoder jwtDecoder() { SecretKeySpec secretKey = new SecretKeySpec(jwtKey.getBytes(), "HmacSHA256"); return NimbusJwtDecoder.withSecretKey(secretKey).macAlgorithm(MacAlgorithm.HS256).build(); } @Bean public JwtEncoder jwtEncoder() { if (jwtKey == null || jwtKey.isEmpty()) { throw new IllegalArgumentException("JWT KEY manquant"); } SecretKeySpec secretKey = new SecretKeySpec(jwtKey.getBytes(), "HmacSHA256"); return new NimbusJwtEncoder(new ImmutableSecret<>(secretKey.getEncoded())); } @Bean public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception { return authenticationConfiguration.getAuthenticationManager(); } } CustomUserDetailsService.java : @Service public class CustomUserDetailsService implements UserDetailsService { private final UserRepository userRepository; public CustomUserDetailsService(UserRepository userRepository) { this.userRepository = userRepository; } @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { Users user = userRepository.findByUsername(username) .orElseThrow(() -> new UsernameNotFoundException("Utilisateur non trouvé : " + username)); return User.builder() .username(user.getUsername()) .password(user.getPassword()) .authorities("USER") .build(); } } UserService.java : @Service public class UserService { @Autowired private UserRepository userRepository; @Autowired private BCryptPasswordEncoder passwordEncoder; public UserViewModel saveUser(UserCreateModel userCreateModel, String email) { String encodedPassword = passwordEncoder.encode(userCreateModel.getPassword()); Users newUser = new Users(); newUser.setUsername(userCreateModel.getUsername()); newUser.setPassword(encodedPassword); newUser.setEmail(email); Users savedUser = userRepository.save(newUser); return new UserViewModel(savedUser.getId(), savedUser.getUsername(), savedUser.getEmail(), savedUser.getCreatedAt(), savedUser.getUpdatedAt()); } } UserController.java : @RestController @RequestMapping("/auth") public class UserController { @Autowired private UserService userService; @Autowired private AuthenticationManager authenticationManager; @Autowired private JWTService jwtService; public UserController(AuthenticationManager authenticationManager, JWTService jwtService) { this.authenticationManager = authenticationManager; this.jwtService = jwtService; } // Route pour l'enregistrement d'un nouvel utilisateur @PostMapping("/register") public UserViewModel register(@RequestBody UserCreateModel userCreateModel) { // Récupérer l'email depuis le modèle de création ou en paramètre String email = userCreateModel.getEmail(); // Ajout de l'email dans la requête // Appeler le service pour enregistrer l'utilisateur return userService.saveUser(userCreateModel, email); } // Route pour la connexion et la génération du token @PostMapping("/login") public String login(@RequestBody UserCreateModel loginRequest) { try { // Authentification de l'utilisateur Authentication authentication = authenticationManager.authenticate( new UsernamePasswordAuthenticationToken( loginRequest.getUsername(), loginRequest.getPassword() ) ); // Générer un JWT après authentification réussie return jwtService.generateToken(authentication); } catch (AuthenticationException e) { throw new RuntimeException("Nom d'utilisateur ou mot de passe incorrect", e); } } }
dan1st
dan1st2w ago
Can you show the stack trace? if something repeats a lot, you can truncate it but please still make it clear what's repeating Also which request fails exactly?
Icca
IccaOP2w ago
at org.springframework.aop.support.AopUtils.isEqualsMethod(AopUtils.java:166) ~[spring-aop-6.2.0.jar:6.2.0] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:175) ~[spring-aop-6.2.0.jar:6.2.0] at jdk.proxy2/jdk.proxy2.$Proxy124.authenticate(Unknown Source) ~[na:na] at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:359) ~[spring-aop-6.2.0.jar:6.2.0] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:216) ~[spring-aop-6.2.0.jar:6.2.0] at jdk.proxy2/jdk.proxy2.$Proxy124.authenticate(Unknown Source) ~[na:na] The POST one
dan1st
dan1st2w ago
which one? /login? /register?
Icca
IccaOP2w ago
Im kinda beginner on Java sorry :3 /login* its on the title
dan1st
dan1st2w ago
is there not more to it?
Icca
IccaOP2w ago
There is a loooot more
dan1st
dan1st2w ago
can you truncate the repeating parts?
Icca
IccaOP2w ago
How do i truncate ? Im not that good at english :3
dan1st
dan1st2w ago
I still need at least one or two versions of the repeating part and the thing before and after
Icca
IccaOP2w ago
Do i have to give you an .txt of it ?
ayylmao123xdd
ayylmao123xdd2w ago
wazaaaaaaaap
dan1st
dan1st2w ago
I mean removing the duplicates works as well like normally you should have the same 5 lines or whatever over and over
dan1st
dan1st2w ago
Did you define your own AuthenticationManager?
ayylmao123xdd
ayylmao123xdd2w ago
looks like generate token might be the problem
dan1st
dan1st2w ago
Also why are you using a mix between constructor autowiring and @Autowired?
Icca
IccaOP2w ago
Im a full beginner XD
ayylmao123xdd
ayylmao123xdd2w ago
can you show the generate token method
Icca
IccaOP2w ago
yup
ayylmao123xdd
ayylmao123xdd2w ago
ok show then
Icca
IccaOP2w ago
public String generateToken(Authentication authentication) { String username = authentication.getName(); return Jwts.builder() .setSubject(username) .setIssuedAt(new Date()) .setExpiration(new Date(System.currentTimeMillis() + 86400000)) // 24h .signWith(key, SignatureAlgorithm.HS256) .compact(); }
dan1st
dan1st2w ago
Can you show what's before that repeating part and what's after it? or just paste the whole log in a file and post it here
Icca
IccaOP2w ago
Icca
IccaOP2w ago
And there is nothing after the repeating part Like at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:216) ~[spring-aop-6.2.0.jar:6.2.0] at jdk.proxy2/jdk.proxy2.$Proxy124.authenticate(Unknown Source) ~[na:na] at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]
ayylmao123xdd
ayylmao123xdd2w ago
yea the console doesnt print after that
Icca
IccaOP2w ago
That's the three last line
dan1st
dan1st2w ago
there should be something between
2025-01-07T16:22:33.574+01:00 ERROR 42500 --- [nio-3001-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]  : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed: java.lang.StackOverflowError] with root cause
2025-01-07T16:22:33.574+01:00 ERROR 42500 --- [nio-3001-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]  : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed: java.lang.StackOverflowError] with root cause
and
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:359) ~[spring-aop-6.2.0.jar:6.2.0]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:359) ~[spring-aop-6.2.0.jar:6.2.0]
at least different lines starting with at ah no my fault after it at the end
Icca
IccaOP2w ago
Icca
IccaOP2w ago
i did Ctrl A and paste it here
ayylmao123xdd
ayylmao123xdd2w ago
o mamma mia 110 kb 😱
Icca
IccaOP2w ago
So nothing wrong here ? @ayylmao123xdd
dan1st
dan1st2w ago
and the at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na] is really the last line?
Icca
IccaOP2w ago
yup
dan1st
dan1st2w ago
ok
ayylmao123xdd
ayylmao123xdd2w ago
yea seems to be ok
Icca
IccaOP2w ago
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na] that's the last line i have on my console
ayylmao123xdd
ayylmao123xdd2w ago
wait
dan1st
dan1st2w ago
Did you define any AuthenticationManager anywhere? Like your own implementation?
ayylmao123xdd
ayylmao123xdd2w ago
@dan1st | Daniel look there building username and setting username
dan1st
dan1st2w ago
that's not what I asked for
ayylmao123xdd
ayylmao123xdd2w ago
ye but isnt that the cause
dan1st
dan1st2w ago
I asked for the full concrete AuthenticationManager implemenetation
Icca
IccaOP2w ago
i have this on my springsecurityConfig : @Bean public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception { return authenticationConfiguration.getAuthenticationManager(); }
dan1st
dan1st2w ago
Can you check whether CustomUserDetailsService#loadUserByUsername is called before the exception? using a debugger that's exactly what I wanted to see What's AuthenticationConfiguration?
Icca
IccaOP2w ago
i don't know AHAHAH should i get rid of it ?
dan1st
dan1st2w ago
no well you could try
ayylmao123xdd
ayylmao123xdd2w ago
can you try 2 different variables because you have
dan1st
dan1st2w ago
But can you show me the exact class name of AuthenticationConfiguration?
ayylmao123xdd
ayylmao123xdd2w ago
string username = .setsubject username
Icca
IccaOP2w ago
ayylmao123xdd
ayylmao123xdd2w ago
so in set subject for testing you can set subject to just "" and check if it works
Icca
IccaOP2w ago
like that ?
No description
dan1st
dan1st2w ago
ok so that's a Spring class - I see Can you try commenting out that method completely? and restarting the application Does that change the result?
Icca
IccaOP2w ago
*/ to comment right ??
ayylmao123xdd
ayylmao123xdd2w ago
public String generateToken(Authentication authentication) {

String username = authentication.getName();
return Jwts.builder()
.setSubject("")
.setIssuedAt(new Date())
.setExpiration(new Date(System.currentTimeMillis() + 86400000)) // 24h
.signWith(key, SignatureAlgorithm.HS256)
.compact();
}
public String generateToken(Authentication authentication) {

String username = authentication.getName();
return Jwts.builder()
.setSubject("")
.setIssuedAt(new Date())
.setExpiration(new Date(System.currentTimeMillis() + 86400000)) // 24h
.signWith(key, SignatureAlgorithm.HS256)
.compact();
}
try that if daniels solution doesnt work
Icca
IccaOP2w ago
i do the whole class or just that
No description
dan1st
dan1st2w ago
/* at the beginning, */ at the end just the things in that screenshot
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
lik that ?
dan1st
dan1st2w ago
I meant the whole method
Icca
IccaOP2w ago
k
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
im restarting
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
i guess there is a problem there too
ayylmao123xdd
ayylmao123xdd2w ago
@Icca try this code i sent
dan1st
dan1st2w ago
ah, I see
ayylmao123xdd
ayylmao123xdd2w ago
and uncomment
dan1st
dan1st2w ago
Do you have any AuthenticationProvider bean?
Icca
IccaOP2w ago
i don't think sooo, this could be in controllers or configuration ? Ok, im doing it
dan1st
dan1st2w ago
probably configuration
Icca
IccaOP2w ago
nop
Icca
IccaOP2w ago
No description
dan1st
dan1st2w ago
Do you have the Spring Tools plugin installed?
ayylmao123xdd
ayylmao123xdd2w ago
does it work
dan1st
dan1st2w ago
Can you show your UserDetailService?
Icca
IccaOP2w ago
nop ): y
ayylmao123xdd
ayylmao123xdd2w ago
still same error or what
Icca
IccaOP2w ago
No description
ayylmao123xdd
ayylmao123xdd2w ago
stackoverflow
dan1st
dan1st2w ago
it's probably something similar to https://stackoverflow.com/a/75959980/10871900
Stack Overflow
Spring Boot authentication throws java.lang.StackOverflowError: null
I can successfully signup users. However, when it comes to logging in the following error is thrown. I couldn't solve this problem for days. stacktrace Servlet.service() for servlet [dispatcherServ...
Icca
IccaOP2w ago
yes
No description
ayylmao123xdd
ayylmao123xdd2w ago
but you have set subject (username)
Icca
IccaOP2w ago
cause he asked for that
ayylmao123xdd
ayylmao123xdd2w ago
in what i sent it was
Icca
IccaOP2w ago
so i ctrl Z
ayylmao123xdd
ayylmao123xdd2w ago
set subject ("")
Icca
IccaOP2w ago
after he asked
ayylmao123xdd
ayylmao123xdd2w ago
try to do it like that
dan1st
dan1st2w ago
(meaning the CustomUserDetailService class)
Icca
IccaOP2w ago
i did im doing it again
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
No description
ayylmao123xdd
ayylmao123xdd2w ago
interesting
dan1st
dan1st2w ago
Can you check whether the login method is called? e.g. using a debugger?
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
what is E.g ? :3
dan1st
dan1st2w ago
It looks like login is called which calls authenticationManager.authenticate which fails Are you asking what a debugger is?
JavaBot
JavaBot2w ago
It looks like you are having issues with debugging or issues that can be solved using a debugger. Check out this article on dev.java to see how debugging works and how to use a debugger. This Stack Overflow question and its answers also explain debugging in general. These links describe how to use the debugger in some IDEs: • Debugging in IntelliJDebugging in Eclipse
ayylmao123xdd
ayylmao123xdd2w ago
no he doesnt know what eg is
Icca
IccaOP2w ago
i didnt knew what e.g means :3
ayylmao123xdd
ayylmao123xdd2w ago
it means for example
dan1st
dan1st2w ago
it means for example
Icca
IccaOP2w ago
thanks
JavaBot
JavaBot2w ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
ayylmao123xdd
ayylmao123xdd2w ago
copycat ezzzzzzzzzzzz what did the logs show btw
Icca
IccaOP2w ago
which one
Icca
IccaOP2w ago
i have a debugger here
No description
Icca
IccaOP2w ago
but nothing show
ayylmao123xdd
ayylmao123xdd2w ago
hmmmmmmm
ayylmao123xdd
ayylmao123xdd2w ago
@dan1st | Daniel any possibility authentication manager is calling itself all the time
dan1st
dan1st2w ago
ONLY FOR TESTING: Can you try replacing that with
@Bean
AuthenticationManager authenticationManager(UserDetailsService userDetailsService, PasswordEncoder passwordEncoder){
return auth -> {
UserDetails userDetails = userDetailsService.loadByUsername(String.valueOf(auth.getPrincipal()))
if(!passwordEncoder.matches(String.valueOf(auth.getPrincipal()), userDetails.Password())){
throw new BadCredentialsException();
}
return auth;
}
}
@Bean
AuthenticationManager authenticationManager(UserDetailsService userDetailsService, PasswordEncoder passwordEncoder){
return auth -> {
UserDetails userDetails = userDetailsService.loadByUsername(String.valueOf(auth.getPrincipal()))
if(!passwordEncoder.matches(String.valueOf(auth.getPrincipal()), userDetails.Password())){
throw new BadCredentialsException();
}
return auth;
}
}
that's what I'm trying to find out the whole time
ayylmao123xdd
ayylmao123xdd2w ago
Bean btw uppercase
dan1st
dan1st2w ago
fixed yeah I wrote that in Discord
ayylmao123xdd
ayylmao123xdd2w ago
skibidi im on mobile so cant see logs
dan1st
dan1st2w ago
the login method in your controller - do you know how a debugger works? the logs are just
at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:359) ~[spring-aop-6.2.0.jar:6.2.0]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:216) ~[spring-aop-6.2.0.jar:6.2.0]
at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:359) ~[spring-aop-6.2.0.jar:6.2.0]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:216) ~[spring-aop-6.2.0.jar:6.2.0]
which is what happens when an AuthenticationManager and an AuthenticationProvider fight for each other
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
im trying to fix the text
dan1st
dan1st2w ago
What's the error? And are there quick fixes? you might need to import BadCredentialsException from Spring Security
Icca
IccaOP2w ago
FIXED HALF
No description
dan1st
dan1st2w ago
getPassword()
Icca
IccaOP2w ago
No description
dan1st
dan1st2w ago
That was an error when deleting too much
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
fixed all im restarting the server now
ayylmao123xdd
ayylmao123xdd2w ago
niceeeee
dan1st
dan1st2w ago
I intentionally didn't make it public but that doesn't make a difference
Icca
IccaOP2w ago
OMG
Icca
IccaOP2w ago
No description
dan1st
dan1st2w ago
btw you have Spring Tools 4 installed xd
Icca
IccaOP2w ago
No description
dan1st
dan1st2w ago
Does it work?
Icca
IccaOP2w ago
Still 401 but YEAH WORKED
Icca
IccaOP2w ago
No description
ayylmao123xdd
ayylmao123xdd2w ago
😱
Icca
IccaOP2w ago
yeah ): xd
dan1st
dan1st2w ago
ok so my implementation was just for testing It isn't what you should actually use
Icca
IccaOP2w ago
oh ):
dan1st
dan1st2w ago
So your AuthenticationManager was the issue
Icca
IccaOP2w ago
ok so now you know what is the problem i guess hmmm okk
dan1st
dan1st2w ago
If you press Ctrl+3, you should get a popup enter "beans" there there should be something like "Spring Beans view"
Icca
IccaOP2w ago
No description
dan1st
dan1st2w ago
ehhhhh hold on
Icca
IccaOP2w ago
without the S :3
No description
dan1st
dan1st2w ago
it should be "Spring Symbols"
dan1st
dan1st2w ago
No description
Icca
IccaOP2w ago
yeah something green
dan1st
dan1st2w ago
then you should get something like that
No description
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
like that i guess
dan1st
dan1st2w ago
yeah the view
Icca
IccaOP2w ago
.
No description
dan1st
dan1st2w ago
in the search, enter authenticationprovider
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
there is no provider
dan1st
dan1st2w ago
ok Do you have any existing logic for validating the password etc?
Icca
IccaOP2w ago
how can i check ? idk what you talking about )): im sorry i only have encrypter
Icca
IccaOP2w ago
No description
dan1st
dan1st2w ago
Did you write the code?
Icca
IccaOP2w ago
like here, on my JWTService.java not at all i started, but then i used AI sorry don't blame me ): its really too hard
dan1st
dan1st2w ago
ok
Icca
IccaOP2w ago
but like, i can understand it like 70% I have to understand it 100% in 1, 2 weeks ^_^
dan1st
dan1st2w ago
so essetially something needs to take the username/password and validate it that's what happens here an AuthenticationManager is typically responsible for handling the authentication
Icca
IccaOP2w ago
i have my Users.java entities
No description
dan1st
dan1st2w ago
yeah the AuthenticationManager would contain the logic doing that stuff
Icca
IccaOP2w ago
im using mysql ohhh i see
Icca
IccaOP2w ago
i put that here just in case
No description
dan1st
dan1st2w ago
Here, I wrote a prototypical one that should somewhat work but you would probably want a proper implementation
Icca
IccaOP2w ago
yes i understand
dan1st
dan1st2w ago
instead of using UserDetailService, it could actually get the Users instance or whatever from the DB
Icca
IccaOP2w ago
ok, but i need it to use UserDetailService right ?
dan1st
dan1st2w ago
and perform all checks you would want You don't have to
Icca
IccaOP2w ago
Oh !
dan1st
dan1st2w ago
I just used it because you already have it normally you would have a bean class (@Configuration or @Service) that implements AuthenticationManager and implements the authenticate method my code is a shortcut that does that you could put it in its own class and you can decide what you want to do with it alternatively you could change the login method/endpoint to do that work and not use the AuthenticationManager
Icca
IccaOP2w ago
authenticationManager is inside the class SpringSecurityConfig which is a @Configuration class
No description
Icca
IccaOP2w ago
the easiest one is the alternative one i guess
dan1st
dan1st2w ago
If you don't want an AuthenticationManager, you could also leave it as you had it before and define an AuthenticationProvider I think
Icca
IccaOP2w ago
Do i really need an authenticationManager ?
dan1st
dan1st2w ago
that one is a valid AuthenticationManager I think it's not strictly necessary
Icca
IccaOP2w ago
What if i keep your code ?
dan1st
dan1st2w ago
you could also let Spring create both of them and let it just use the information in the UserDetailService it shobut I am not entirely sure why Spring doesn't do that with your project
Icca
IccaOP2w ago
might be my dependency too
dan1st
dan1st2w ago
Maybe it's related to the session.sessionCreationPolicy(SessionCreationPolicy.STATELESS) Oh I think I found it
dan1st
dan1st2w ago
this is the AuthenticationProvider using a UserDetailsService I think you can also do
@Bean
AuthenticationProvider authenticationProvider(){
return new DaoAuthenticationProvider();
}
@Bean
AuthenticationProvider authenticationProvider(){
return new DaoAuthenticationProvider();
}
and use your old AuthenticationManager or no AuthenticationManager at all
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
im trying like this
dan1st
dan1st2w ago
I think one of these options should work Do you have an AuthenticationManager now?
Icca
IccaOP2w ago
nop, and error occure my bad
Icca
IccaOP2w ago
No description
dan1st
dan1st2w ago
then you could try with your previous AuthenticationManager that might work but I didn't test it
Icca
IccaOP2w ago
so
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
with that, there is an error :
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
dan1st
dan1st2w ago
oh that can be fixed
@Bean
AuthenticationProvider authenticationProvider(UserDetailsService userDetailsService){
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
provider.setUserDetailsService(userDetailsService);
return provider;
}
@Bean
AuthenticationProvider authenticationProvider(UserDetailsService userDetailsService){
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
provider.setUserDetailsService(userDetailsService);
return provider;
}
Icca
IccaOP2w ago
thanks
Icca
IccaOP2w ago
lets try
No description
Icca
IccaOP2w ago
worked ! Now, postman time !
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
still 401 but everything else works
dan1st
dan1st2w ago
I meant that this one should work even without the custom AuthenticationManager if you want that
Icca
IccaOP2w ago
oh ok let me try to redo it so
dan1st
dan1st2w ago
at the end you can choose which one you want Do you know how to use a debugger?
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
not really ): i just put the "print " thing ^^
dan1st
dan1st2w ago
Did you send a request to /auth/login there?
Icca
IccaOP2w ago
yes ! ok with the last code i have another error
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
No description
No description
No description
dan1st
dan1st2w ago
Do you have any filter for JWT?
Icca
IccaOP2w ago
i do my request like that
Icca
IccaOP2w ago
No description
dan1st
dan1st2w ago
ok yeah for now just use the AuthenticationProvider I told you about
Icca
IccaOP2w ago
ok so i get rid of authenticationManager
dan1st
dan1st2w ago
my fault I meant using the AuthenticatioManager I told you about which checks with UserDetailsService and PasswordEncoder and remove the AuthenticationProvider (for now)
Icca
IccaOP2w ago
ok
Icca
IccaOP2w ago
like that
No description
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
still an error with postman
dan1st
dan1st2w ago
wait, don't put jwtKey here
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
yeah but it dosnt work ):
dan1st
dan1st2w ago
you can do throw new BadCredentialsException("username or password wrong")
JavaBot
JavaBot2w ago
It looks like you are having issues with debugging or issues that can be solved using a debugger. Check out this article on dev.java to see how debugging works and how to use a debugger. This Stack Overflow question and its answers also explain debugging in general. These links describe how to use the debugger in some IDEs: • Debugging in IntelliJDebugging in Eclipse
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
oh ok !
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
nice !
dan1st
dan1st2w ago
That one shows you how to use a debugger
Icca
IccaOP2w ago
thanks ! i'll keep tthat in mind
dan1st
dan1st2w ago
I really recommend reading that (Disclaimer: I wrote the dev.java article)
Icca
IccaOP2w ago
D:
dan1st
dan1st2w ago
So I would like you to debug the authentication provider
Icca
IccaOP2w ago
Damnnn im not talking to a random XD Ok ! SHould i do it now ?
Icca
IccaOP2w ago
No description
dan1st
dan1st2w ago
Set a breakpoint in the UserDetails userDetails = ... line by double-clicking to the left of that line
dan1st
dan1st2w ago
should look like that
No description
Icca
IccaOP2w ago
No description
dan1st
dan1st2w ago
eh no don't collapse it that's the wrong icon
Icca
IccaOP2w ago
oh aha wait im trying again XD
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
Oh !! Yeah i see ! a breakpoint !
dan1st
dan1st2w ago
perfect
Icca
IccaOP2w ago
niiceee
dan1st
dan1st2w ago
now run the application in debug mode
dan1st
dan1st2w ago
meaning you start it with this icon
No description
Icca
IccaOP2w ago
i did it now
dan1st
dan1st2w ago
I wanted a good resource to explain debugging - Because I have to constantly explain it
Icca
IccaOP2w ago
i do my request on postman ?
dan1st
dan1st2w ago
yes
Icca
IccaOP2w ago
ahaha understandable oh, its loading indefinetly
dan1st
dan1st2w ago
check Eclipse
Icca
IccaOP2w ago
No description
dan1st
dan1st2w ago
switch and you should get a green line
Icca
IccaOP2w ago
No description
dan1st
dan1st2w ago
Eclipse stopped (suspended) the application at the green line - this should be at your breakpoint yes
dan1st
dan1st2w ago
Can you reset the debug perspective like this?
No description
dan1st
dan1st2w ago
right click on the debug icon on the top right and click reset
Icca
IccaOP2w ago
No description
dan1st
dan1st2w ago
not there on the right
Icca
IccaOP2w ago
i did
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
yup, found it
dan1st
dan1st2w ago
perfect so on the right, you see your current variables and their values
Icca
IccaOP2w ago
yes ! auth, with the value
dan1st
dan1st2w ago
Can you expand auth there?
Icca
IccaOP2w ago
No description
dan1st
dan1st2w ago
Note: You are in the application, the application waits for you you see your username and password there
Icca
IccaOP2w ago
yes !!
dan1st
dan1st2w ago
Now press F6 once
Icca
IccaOP2w ago
OMG that is beautiful i have no idea wtf is going on OK
dan1st
dan1st2w ago
the green line should move down
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
huuh, i saw some animations
dan1st
dan1st2w ago
yes this means Eclipse executed line 79
Icca
IccaOP2w ago
oh !! ok !
dan1st
dan1st2w ago
and now it's waiting at line 80
Icca
IccaOP2w ago
OH YES
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
i see the arrow
dan1st
dan1st2w ago
you can expand the userDetails in the variables view
Icca
IccaOP2w ago
No description
dan1st
dan1st2w ago
Do you see the capabilities of using a debugger?
Icca
IccaOP2w ago
That is insaaaaneee
dan1st
dan1st2w ago
Now I'll show you more
Icca
IccaOP2w ago
Bro i keep being amazed xD
dan1st
dan1st2w ago
so you would maybe like to see the result of the passwordEncoder.matches() method, maybe even before it's executed?
Icca
IccaOP2w ago
yes withtout even moving the green line u mean
dan1st
dan1st2w ago
now copy the passwordEncoder.matches(...)
Icca
IccaOP2w ago
i guess
dan1st
dan1st2w ago
then go to the "Expressions" view
No description
Icca
IccaOP2w ago
!passwordEncoder.matches(String.valueOf(auth.getPrincipal()), userDetails.getPassword()))
dan1st
dan1st2w ago
add "Add new expression" and paste it there then I think that's one ) too much
Icca
IccaOP2w ago
ok done it without the )
dan1st
dan1st2w ago
then Eclipse should try to evaluate it and get a result
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
so it mean that its work
Icca
IccaOP2w ago
No description
Icca
IccaOP2w ago
FOUND IT ! Everything working well !
No description
Icca
IccaOP2w ago
i used Dao so spring could automaticly work with the authentification, AND with the password/encryptage. When using AuthenticationConfiguration its easier to manage the Auth.
No description
Icca
IccaOP2w ago
Thanks a lot for your help, i'll remember you as my hero ✅ 🙂
JavaBot
JavaBot2w ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
JavaBot
JavaBot2w ago
Post Closed
This post has been closed by <@641713741355941917>.

Did you find this page helpful?