Reader small image

You're reading from  Spring Boot and Angular

Product typeBook
Published inDec 2022
Reading LevelBeginner
PublisherPackt
ISBN-139781803243214
Edition1st Edition
Languages
Right arrow
Authors (2):
Devlin Basilan Duldulao
Devlin Basilan Duldulao
author image
Devlin Basilan Duldulao

Devlin Basilan Duldulao is a full-stack engineer with over 8 years of web, mobile, and cloud development experience. He has been a recipient of Microsoft's Most Valuable Professional (MVP) award since 2018 and earned the title of Auth0 Ambassador for his passion for sharing best practices in application security. Devlin has passed some prestigious software and cloud development exams, such as MSCD, Azure Associate Developer, AWS Associate Developer, and Terraform Associate. He has also authored the book ASP.NET Core and Vue.js and coauthored the book Practical Enterprise React in 2020 and 2021, amid the pandemic.
Read more about Devlin Basilan Duldulao

Seiji Ralph Villafranca
Seiji Ralph Villafranca
author image
Seiji Ralph Villafranca

Seiji Ralph Villafranca graduated Cum Laude with a degree of Bachelor of Science In Computer Science at University of Santo Tomas in the Philippines. He has 6 years of experience in Web and Mobile Development and has also earned the title of Auth0 Ambassador for having passions in application securities, He holds several certifications in Angular Development from Beginner to Expert Level. Seiji is also one of the Community Leaders of Angular Philippines which is the largest Angular group in the Philippines, the community has lead him to speak in different meetups of tech communities, workshops and even local and international conferences, he is enthusiastic in sharing knowledge in coding, organizing events and meetups for the community as well as writing content for students and professionals. He also has been a mentor in several hackathons as he loves the startup community. Seiji loves to develop new projects that are on web or mobile, he is currently a senior software engineer in a company based in Malaysia, He is not just a coder but also a mentor, teacher and trainer for students, professionals and companies.
Read more about Seiji Ralph Villafranca

View More author details
Right arrow

Adding a CORS policy

We have learned how CORS works and the advantage it brings to the security of our applications. Now, we will configure and implement a CORS policy in our Spring Boot project.

There are several ways to configure CORS on our project. We will discuss them one by one.

CORS applications for each method

We can enable CORS on a single endpoint; this means that we can specify different permitted origins for other endpoints. Let’s have a look at the following example:

@CrossOrigin
@GetMapping
public List<AntiHeroDto> getAntiHeroes(Pageable pageable) {
  ..code implementation
}

In our Spring Boot project, we have the getAntiHeroes() method. To enable CORS on a specific method, we will use the @CrossOrigin annotation. We can see that we have not configured any other settings, and this applies the following:

  • All origins are permitted.
  • HTTP methods that are allowed are the ones configured for the method (in this method, the...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Spring Boot and Angular
Published in: Dec 2022Publisher: PacktISBN-13: 9781803243214

Authors (2)

author image
Devlin Basilan Duldulao

Devlin Basilan Duldulao is a full-stack engineer with over 8 years of web, mobile, and cloud development experience. He has been a recipient of Microsoft's Most Valuable Professional (MVP) award since 2018 and earned the title of Auth0 Ambassador for his passion for sharing best practices in application security. Devlin has passed some prestigious software and cloud development exams, such as MSCD, Azure Associate Developer, AWS Associate Developer, and Terraform Associate. He has also authored the book ASP.NET Core and Vue.js and coauthored the book Practical Enterprise React in 2020 and 2021, amid the pandemic.
Read more about Devlin Basilan Duldulao

author image
Seiji Ralph Villafranca

Seiji Ralph Villafranca graduated Cum Laude with a degree of Bachelor of Science In Computer Science at University of Santo Tomas in the Philippines. He has 6 years of experience in Web and Mobile Development and has also earned the title of Auth0 Ambassador for having passions in application securities, He holds several certifications in Angular Development from Beginner to Expert Level. Seiji is also one of the Community Leaders of Angular Philippines which is the largest Angular group in the Philippines, the community has lead him to speak in different meetups of tech communities, workshops and even local and international conferences, he is enthusiastic in sharing knowledge in coding, organizing events and meetups for the community as well as writing content for students and professionals. He also has been a mentor in several hackathons as he loves the startup community. Seiji loves to develop new projects that are on web or mobile, he is currently a senior software engineer in a company based in Malaysia, He is not just a coder but also a mentor, teacher and trainer for students, professionals and companies.
Read more about Seiji Ralph Villafranca