r/SpringBoot • u/Ashutosh_Rajput • Aug 31 '24
Rate my first Springboot Application.
I am Building a application that can tell you what you CBC report in telling about your body.
https://github.com/Ashutosh-rajput/ReportGenerator
My application have these features.
Caching using redis.
Jwt token security.
Custom Validation.
Global Exception Handler.
Refresh Token .
Blacklisting refresh and jwt token (logout).
Future plans:
Adding Oauth 2.0 with Jwt (Can't find good tutorial for this if you have kindly share).
Adding Machine learning to train model for better result .
Adding more assessment such as KFT and LFT.
Any Suggestion please provide or comment .
4
u/bloowper Aug 31 '24
Take a look at modular modilith concept, this type of organization is harder to maintain in long run.
1
1
0
2
u/JBraddockm Aug 31 '24
I am also working on something similar, and these are some of the things I noticed when I took a look at your repo.
You can refactor your AuthenticationProvider, and AuthenticationManager beans as follows, and remove AuthenticationProvider from the filter chain. This should remove the AuthenticationManager warning you might be getting in the console. ProviderManager is the recommended way for creating AuthenticationManager.
@Bean
public AuthenticationManager authenticationManager() {
DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();
daoAuthenticationProvider.setUserDetailsService(userDetailsService());
daoAuthenticationProvider.setPasswordEncoder(passwordEncoder());
return new ProviderManager(daoAuthenticationProvider);
}I believe your custom filters should come before AuthorizationFilter.class unless you have specific reasons.
.addFilterBefore(jwtAuthFilter(), AuthorizationFilter.class);Your app relies on thirt-party libraries for encoding/decoding JWT tokens. Just so you know, Spring's spring-boot-starter-oauth2-resource-server can do all these and more. If you want to learn how to do it, you can take a look at this tutorial.
You can use BearerTokenResolver to extract the token from the HTTP request rather than doing it manually.
private final BearerTokenResolver bearerTokenResolver = new DefaultBearerTokenResolver();
String token = this.bearerTokenResolver.resolve(request);If I am not mistaken, after each request, the security context is cleared, which means that in each filter check, the context is always null. There is no need to check if the context is null.
For exception handling, you can also take a look at creating your AuthenticationEntryPoint, and extending ResponseEntityExceptionHandler in your global exception handling class.
1
u/Ashutosh_Rajput Aug 31 '24
Hey thanks for suggestions some parts of comment i understand and some not as I am beginner only and I have lack of theory knowledge of spring security if you suggest some resource will be help full.
1
u/JBraddockm Aug 31 '24
I've learned a lot from these two videos by Daniel Garnier-Moiroux where he talks about how Spring Security works.
2
u/Mikey-3198 Aug 31 '24
You can improve the exposed api that clients will be consuming.
For example this controller could be improved.
Removing the unnessary path in the route. The delete could just be
DELETE /result/{id}and the other endpoint GET/result/byuserid/{id}. At the moment the path is very verbose, you can get away with using the correct http verbs without the need to also include the name of the action in the path. I.e your doing a http delete, no need to inlcudedeletecbcresultin the path.The naming of the methods should ideally be in camal case and easily readable i.e
deleteResultinstead ofdeleteresult. I'd renamedetresultbyuseridtodeleteResultByIdcontracting method names like this is makes this hard to read.Inside
detresultbyuseridyou are returing an Optional from the service, you could use this to return a 404 not found if the optonial is empty.
I'd recommend in general to look at RESTful api design. https://learn.microsoft.com/en-us/azure/architecture/best-practices/api-design#organize-the-api-design-around-resources
-1
u/Ashutosh_Rajput Aug 31 '24
Actually this is my old project and i am just thing that i am learning to test my skills.
1
u/pythonby_toji Sep 01 '24
I want to learn more about global exceptional handler. Recommend me some good resources.
2
u/Ashutosh_Rajput Sep 01 '24
It just a class just add in your project and you can manage all custom exception like i have also added exception for jwt service so start with making small custom exception there are ton of videos on youtube about this.
1
u/Rajput_11 Sep 01 '24
Can you explain what your project does ? I didn't understand.
1
u/Ashutosh_Rajput Sep 01 '24
The when take your CBC report which is complete not readable to normal human so goal is to make application that can read your report and give summary of report.
2
u/chehsunliu Sep 01 '24 edited Sep 02 '24
I would suggest constructor injection instead of field injection.
2
u/AdolfKonsol Sep 01 '24
You can use jhipster spring boot server and front end creator it will help you create your desired application with all required features available
1
Sep 01 '24 edited Apr 17 '26
Wiped clean. Redact removed this post along with thousands of others. It also handles data broker removals so your personal info stops getting sold.
terrific shaggy handle payment telephone crush pause memory normal oatmeal
1
1
9
u/hillywoodsfinest87 Aug 31 '24
I see you are using a lot of autowired for your dependencies, here is some food for thought
https://www.baeldung.com/constructor-injection-in-spring
https://reflectoring.io/constructor-injection/