In this article, I am going to demostrate how we could access the REST api secured by Spring Security to display in front-end. We are going to use Spring Tool Suite (STS).
Create a new Java Project in STS and add the files into it similar to the following structure.
│ pom.xml
├───src
│ └───main
│ ├───java
│ │ └───com
│ │ └───p1coder
│ │ │ MvcConfiguration.java
│ │ │ SecurityConfig.java
│ │ │ SpringBootWebApplication.java
│ │ ├───controller
│ │ │ ProductController.java
│ │ │ RequestHandler.java
│ │ ├───domain
│ │ │ Product.java
│ │ │ UserPreference.java
│ │ └───service
│ │ ProductService.java
│ │ RestApiService.java
│ └───webapp
│ └───WEB-INF
│ └───views
│ └───product
│ display.jsp
Fill each file with the sample code from each code section.
After maven update the reference packages, we can execute the sample by right click on project and choosing "Run as" -> "Spring Boot App".
In RequestHandler.java, we have REST api routes accessible by either PathVariable or RequestParam, which read the repository layer data.
If we directly access "http://localhost:8080/getAllProducts" api, we will get authentication dialog box as we secure the route ("/getAllProducts**") in "SecurityConfig.java" file. This route is granted only to "admin" role by extending the WebSecurityConfigurerAdapter class.
We will see the sample listing when we access "http://localhost:8080/products" page. We implement the data retrieval logic and pass api credential to REST api.
In RestApiService.java, BasicAuthenticationInterceptor is used to authenticate while retrieving by HTTP GET execute on RestTemplate instance.
In ProductController.java, ObjectMapper instance is used to deserialize the generic return value from data service call instantiated by @Autowired Dependency Injection.
Create a new Java Project in STS and add the files into it similar to the following structure.
│ pom.xml
├───src
│ └───main
│ ├───java
│ │ └───com
│ │ └───p1coder
│ │ │ MvcConfiguration.java
│ │ │ SecurityConfig.java
│ │ │ SpringBootWebApplication.java
│ │ ├───controller
│ │ │ ProductController.java
│ │ │ RequestHandler.java
│ │ ├───domain
│ │ │ Product.java
│ │ │ UserPreference.java
│ │ └───service
│ │ ProductService.java
│ │ RestApiService.java
│ └───webapp
│ └───WEB-INF
│ └───views
│ └───product
│ display.jsp
Fill each file with the sample code from each code section.
MvcConfiguration.java
SecurityConfig.java
SpringBootWebApplication.java
ProductController.java
RequestHandler.java
ProductController.java
RequestHandler.java
Product.java
UserPreference.java
ProductService.java
RestApiService.java
display.jsp
pom.xml
In RequestHandler.java, we have REST api routes accessible by either PathVariable or RequestParam, which read the repository layer data.
If we directly access "http://localhost:8080/getAllProducts" api, we will get authentication dialog box as we secure the route ("/getAllProducts**") in "SecurityConfig.java" file. This route is granted only to "admin" role by extending the WebSecurityConfigurerAdapter class.
We will see the sample listing when we access "http://localhost:8080/products" page. We implement the data retrieval logic and pass api credential to REST api.
In RestApiService.java, BasicAuthenticationInterceptor is used to authenticate while retrieving by HTTP GET execute on RestTemplate instance.
In ProductController.java, ObjectMapper instance is used to deserialize the generic return value from data service call instantiated by @Autowired Dependency Injection.
I read like this type of article only. You mentioned more important points in this article. Thankyou for interesting article.
ReplyDeletecore java training in chennai
c c++ classes
c c++ training
c++ course
c c++ course fee
javascript course in chennai
Appium Training in Chennai
JMeter Training in Chennai
Thank you, Velraj.
DeleteI have gone through your blog, it was very much useful for me and because of your blog, and also I gained many unknown information, the way you have clearly explained is really fantastic. Kindly post more like this, Thank You.
ReplyDeleteAviation Academy in Chennai
Air hostess training in Chennai
Airport management courses in Chennai
Ground staff training in Chennai
best aviation academy in Chennai
best air hostess training institute in Chennai
airline management courses in Chennai
airport ground staff training in Chennai
I am glad to know this blog helps the reader, Kiruthika. Thanks.
DeleteGreat post. You have written a valuable content in a interesting way. Kindly share more updates.
ReplyDeleteIELTS Coaching in Mulund
IELTS Training in Mulund West
IELTS Courses in Mulund
IELTS Coaching Centres in Mulund
Spoken English Class in Chennai
Spoken English in Chennai
IELTS Coaching in Chennai
Thank you, Anbarasan14.
DeleteSuch a wonderful post, Your explanation way is too good and this is very easy to understand with depth content. Kindly updating for me.
ReplyDeleteCorporate Training in Chennai
Corporate Training
Power BI Training in Chennai
Excel Training in Chennai
Linux Training in Chennai
Unix Training in Chennai
Tableau Training in Chennai
Oracle Training in Chennai
Pega Training in Chennai
Oracle DBA Training in Chennai
Thank you, Rathinam.
DeleteThanks, Yuvaprithika.
ReplyDeleteweighing machine for kitchen
ReplyDeleteIt was good explanation and wonderful content. Keep posting...
ReplyDeleteIELTS Coaching in Chennai
IELTS Classes in Chennai
german language course
Japanese Language Course in Chennai
Spoken English in Chennai
TOEFL Training in Chennai
IELTS Coaching in Velachery
IELTS Coaching in Tambaram
It looks deeply awesome article!thanks for sharing such a information with us..
ReplyDeleteAWS Training in Chennai
AWS Certification in Chennai
digital marketing course in chennai
Data Science Course in Chennai
Selenium Course in Chennai
ccna Training in Chennai
Java Course in Chennai
Tally Classes in Chennai
AWS Training in Chennai
AWS Certification in Chennai
The article is so informative. This is more helpful for our
ReplyDeleteselenium training in chennai
selenium online courses best selenium online training
selenium testing training
selenium classes
Thanks for sharing.
Thanks for sharing an informative blog keep rocking bring more details.I like the helpful info you provide in your articles. I’ll bookmark your weblog and check again here regularly. I am quite sure I will learn much new stuff right here! Good luck for the next!
ReplyDeleteWeb Designing Training Institute in Chennai | web design training class in chennai | web designing course in chennai with placement
Mobile Application Development Courses in chennai
Data Science Training in Chennai | Data Science courses in Chennai
Professional packers and movers in chennai | PDY Packers | Household Goods Shifting
Web Designing Training Institute in Chennai | Web Designing courses in Chennai
Google ads services | Google Ads Management agency
Web Designing Course in Chennai | Web Designing Training in Chennai
Thanks for the interesting blog that you have implemented here. Very helpful and innovative. Waiting for your next upcoming article.
ReplyDeleteDigital Marketing Course In Kolkata
I want to thank for sharing this blog, really great and informative. Share more stuff like this. greate work
ReplyDeleteAi & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai
adana escort - adıyaman escort - afyon escort - aksaray escort - antalya escort - aydın escort - balıkesir escort - batman escort - bitlis escort - burdur escort - bursa escort - diyarbakır escort - edirne escort - erzurum escort - eskişehir escort - eskişehir escort - eskişehir escort - eskişehir escort - gaziantep escort - gebze escort - giresun escort - hatay escort - ısparta escort - karabük escort - kastamonu escort - kayseri escort - kilis escort - kocaeli escort - konya escort - kütahya escort - malatya escort - manisa escort - maraş escort - mardin escort - mersin escort - muğla escort - niğde escort - ordu escort - osmaniye escort - sakarya escort - samsun escort - siirt escort - sincan escort - tekirdağ escort - tokat escort - uşak escort - van escort - yalova escort - yozgat escort - urfa escort - zonguldak escort
ReplyDeleteinstagram takipçi satın al
ReplyDeleteaşk kitapları
tiktok takipçi satın al
instagram beğeni satın al
youtube abone satın al
twitter takipçi satın al
tiktok beğeni satın al
tiktok izlenme satın al
twitter takipçi satın al
tiktok takipçi satın al
youtube abone satın al
tiktok beğeni satın al
instagram beğeni satın al
trend topic satın al
trend topic satın al
youtube abone satın al
instagram takipçi satın al
beğeni satın al
tiktok izlenme satın al
sms onay
youtube izlenme satın al
tiktok beğeni satın al
sms onay
sms onay
perde modelleri
instagram takipçi satın al
takipçi satın al
tiktok jeton hilesi
instagram takipçi satın al pubg uc satın al
sultanbet
marsbahis
betboo
betboo
betboo
takipçi satın al
ReplyDeleteinstagram takipçi satın al
https://www.takipcikenti.com
At this time I am going away to do my breakfast, afterward having my breakfast coming over again to read further news
ReplyDeleteragdoll cat for sale
ragdoll cats for sale
aussiedoodle for sale
bernedoodles for sale
havanese puppies for sale under $1,000
great dane puppies for sale
great dane puppy for sale
great dane puppies near me
great dane puppies for sale near me
https://thegorgeousdoodles.com/
I take pleasure in, result in I discovered exactly what I used to be taking a look
ReplyDeletefor. You’ve ended my 4 day lengthy hunt! God Bless you man.
great dane puppies for sale
great dane puppy for sale
great dane puppies near me
great dane puppies for sale near me
ragdoll kittens for sale near me
ragdoll kitten near me
goldendoodle for sale
teacup havanese puppies for sale
pomeranian teacup for sale
great dane puppy for sale
https://www.redemptionbullies.com/
Ahaa, its nice dialogue about this piece of writing at this place at this webpage,
ReplyDeleteI have read all that, so at this time me also commenting here.
havanese dogs for sale
havanese puppies for sale
teacup havanese puppy
chocolate havanese puppy for sale
teacup pomeranian for sale
doodle puppies
aussiedoodle puppies for sale
bernedoodle puppies for sale
goldendoodle puppies for sale
yorkie puppies for sale
https://www.fluffyhavanese.com/
Thanks for sharing your thoughts. I truly appreciate your efforts and I will be waiting for your further
ReplyDeletewrite ups thanks once again
pomeranian puppies for sales
pomeranian for sale
teacup pomeranian for sale near me
pomeranians for sale near me
teacup pomeranian for sale
pomeranian puppies for sales
pomeranian for sale
teacup pomeranian for sale
havanese puppies for sale near me
https://www.pomeranianpuppiesforsales.com/
Good content. You write beautiful things.
ReplyDeletehacklink
taksi
vbet
mrbahis
sportsbet
korsan taksi
hacklink
sportsbet
mrbahis
Good text Write good content success. Thank you
ReplyDeletekralbet
mobil ödeme bahis
kibris bahis siteleri
tipobet
poker siteleri
slot siteleri
betmatik
betpark