r/SpringBoot • • Oct 18 '24

Why would Spring generate for me a security password and I already have my custom implementation

Post image
22 Upvotes

25 comments sorted by

4

u/g00glen00b Oct 18 '24

Can you show us your custom implementation?

2

u/saltysnailsss Oct 18 '24

4

u/g00glen00b Oct 18 '24

The UserDetailsServiceAutoConfiguration only kicks in if you don't have your own AuthenticationProvider, AuthenticationManager, JwtDecoder or UserDetailsService bean. You have those, so I can't explain either. In fact, I just tried to put your config in a new Spring Boot project, and it doesn't generate the default password for me. Are you sure that your ProjectConfig is included?

6

u/saltysnailsss Oct 18 '24

bro you solved everything!!

i wondered if there's a possibility the main spring boot class wasn't able to access my custom config... turns out i had put em in a package the main class wasn't able to access

once i moved em to the right place everything was ok

1

u/nothingjustlook Oct 18 '24

Just create sub packages by clicking on package which hosts main spring class.

2

u/bwrca Oct 18 '24

Been a while but there was a way you could include external packages (that are not scanned by default) by an annotation at the point you're initiatlizing the application.

4

u/nothingjustlook Oct 18 '24

Componentscan with packages name as attributes

1

u/saltysnailsss Oct 18 '24

yeah its included.. i've tried everything, came to reddit as a last resort

3

u/Master_Carrot_9631 Oct 18 '24

You can try adding the @EnableWebSecurity annotation to your configuration file

1

u/saltysnailsss Oct 18 '24

I've already done that but still not working

1

u/Master_Carrot_9631 Oct 18 '24

Have you created a custom filter chain bean?

1

u/saltysnailsss Oct 18 '24

https://imgur.com/gallery/zepqkkv

yeah you can view in the link above

2

u/Master_Carrot_9631 Oct 18 '24

There is no custom filter chain bean in the link provided nor have you written the annotation I mentioned maybe you're providing a different link than the one you think.

1

u/saltysnailsss Oct 18 '24

there are 2 pics in the link, the custom filter chain is in the 2nd pic

1

u/Master_Carrot_9631 Oct 18 '24

Try creating an autowired constructor for the provider as well as the jwt filter maybe it's causing some sort of issue. But other than that I cannot find anything else wrong in the code. I usually don't explicitly configure the authentication provider in the filter chain, instead I let spring do it for me in the background.

1

u/Master_Carrot_9631 Oct 18 '24

Is there a proper password encoder bean configured cause if its not spring goes back to its default settings.

1

u/saltysnailsss Oct 18 '24

yeah there is.. wasn't captured in the screenshot

1

u/Master_Carrot_9631 Oct 18 '24

Oh ok I'll check

1

u/Leos_Leo Oct 18 '24

Just today i had a similar problem if i understand you correctly. When you move those beans into a package that you depend n, you need to tell spring to scan these. I did so by adding @import({MyPackageClass.class}) at the Application class. Maybe you need to import all or just some of the beans in question, if you need to include multiple you could consider import one that the imports the other inside your library.

Hope this helps or you find a solution. Best wishes

1

u/saltysnailsss Oct 19 '24

yes you are right.. one has to instruct spring to scan the packages containing ones custom implementation

2

u/AMZ_script Oct 18 '24

You should use annotation spring enable security , that error is normal thus is how spring security works

1

u/[deleted] Oct 18 '24

Missing ๐Ÿซ˜

1

u/[deleted] Oct 18 '24

Cause, it doesnโ€™t give a ๐Ÿ’ฉ about your password! ๐Ÿ˜†๐Ÿ˜†

1

u/reddit04029 Oct 18 '24

Itโ€™s because of this dependency

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>

Replace that with spring secuirty if you want full control over your security.