# Get Started with Spring Boot and SAML

**URL:** <https://devforum.okta.com/t/get-started-with-spring-boot-and-saml/21496>\
**Category:** Developer Blog Comments\
**Created:** [August 5, 2022, 3:09pm UTC](https://devforum.okta.com/t/get-started-with-spring-boot-and-saml/21496 "2022-08-05T15:09:36Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [August 5, 2022, 3:09pm UTC](https://devforum.okta.com/t/get-started-with-spring-boot-and-saml/21496/1 "2022-08-05T15:09:36Z")

</div>

Spring is a long-time friend to enterprise companies throughout the world. When Spring Boot came along in 2014, it greatly simplified configuring a Spring application. This led to widespread adoption and continued investment in related Spring projects.

One of my favorite Spring projects is Spring Security. In most cases, it simplifies web security to just a few lines of code. HTTP Basic, JDBC, JWT, OpenID Connect/OAuth 2.0, you name it—Spring Security does it!

You might notice I didn’t mention SAML as an authentication type. That’s because I don’t recommend it. The specification for SAML 2.0 was published in March 2005, before smartphones or smart devices even existed. OpenID Connect (OIDC) is much easier for developers to use and understand. Using SAML in 2022 is like implementing a web service using WS-\* instead of REST.

My recommendation: just use OIDC.

If you _must_ use SAML with Spring Boot, this tutorial should make it quick and easy.

* * *
This is a companion discussion topic for the original entry at [https://developer.okta.com/blog/2022/08/05/spring-boot-saml](https://developer.okta.com/blog/2022/08/05/spring-boot-saml)

---

<div class="post-metadata">

**Author:** ![sarran](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@sarran](https://devforum.okta.com/u/sarran)\
**Post date:** [February 17, 2023, 10:44am UTC](https://devforum.okta.com/t/get-started-with-spring-boot-and-saml/21496/2 "2023-02-17T10:44:03Z")

</div>

i am not group as Everyone but not getting ROLE\_ADMIN ROLES\_USER in all your attributes

---

<div class="post-metadata">

**Author:** ![oktadev-blog](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/oktadev-blog/32/3422_2.png) [@oktadev-blog](https://devforum.okta.com/u/oktadev-blog)\
**Post date:** [February 17, 2023, 10:44am UTC](https://devforum.okta.com/t/get-started-with-spring-boot-and-saml/21496/3 "2023-02-17T10:44:03Z")

</div>

Listed on February 17, 2023, 10:44am UTC



---

<div class="post-metadata">

**Author:** ![mraible](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/mraible/32/37_2.png) [@mraible](https://devforum.okta.com/u/mraible)\
**Post date:** [February 17, 2023, 5:15pm UTC](https://devforum.okta.com/t/get-started-with-spring-boot-and-saml/21496/4 "2023-02-17T17:15:39Z")

</div>

Hello @sarran,

Are you trying to configure your app to use Okta or Auth0? I ask because they each have different ways to configure group attributes.

---

<div class="post-metadata">

**Author:** ![sarran](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@sarran](https://devforum.okta.com/u/sarran)\
**Post date:** [February 20, 2023, 4:52pm UTC](https://devforum.okta.com/t/get-started-with-spring-boot-and-saml/21496/5 "2023-02-20T16:52:53Z")

</div>

Thanks for your reply but I fixed that thing

---

<div class="post-metadata">

**Author:** ![vikasojha0536](https://avatars.discourse-cdn.com/v4/letter/v/a9a28c/32.png) [@vikasojha0536](https://devforum.okta.com/u/vikasojha0536)\
**Post date:** [September 10, 2023, 9:59am UTC](https://devforum.okta.com/t/get-started-with-spring-boot-and-saml/21496/6 "2023-09-10T09:59:32Z")

</div>

Hello @mraible

Thanks for the video explanation. I learnt a lot from this.  
Actually I have a requirement where in I have to pass the saml response as token in the x-boa-security-header in string format while calling the next service. How can we do it? Is there any reference i can see?

What i want to achieve is from the rest api → call the saml endpoint for getting the token → and then call the next service by passing this string token as header

Kr,  
Vikas

---

<div class="post-metadata">

**Author:** ![mraible](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/mraible/32/37_2.png) [@mraible](https://devforum.okta.com/u/mraible)\
**Post date:** [September 11, 2023, 7:39pm UTC](https://devforum.okta.com/t/get-started-with-spring-boot-and-saml/21496/7 "2023-09-11T19:39:32Z")

</div>

Are you using Okta or Auth0 for SAML?

---

<div class="post-metadata">

**Author:** ![vikasojha0536](https://avatars.discourse-cdn.com/v4/letter/v/a9a28c/32.png) [@vikasojha0536](https://devforum.okta.com/u/vikasojha0536)\
**Post date:** [September 12, 2023, 5:29pm UTC](https://devforum.okta.com/t/get-started-with-spring-boot-and-saml/21496/8 "2023-09-12T17:29:17Z")

</div>

I am trying to use okta

---

<div class="post-metadata">

**Author:** ![mraible](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/mraible/32/37_2.png) [@mraible](https://devforum.okta.com/u/mraible)\
**Post date:** [September 14, 2023, 3:21pm UTC](https://devforum.okta.com/t/get-started-with-spring-boot-and-saml/21496/9 "2023-09-14T15:21:40Z")

</div>

Unfortunately, I don’t know how to do this. I’ve asked on an internal channel, but haven’t received any response yet.

---

<div class="post-metadata">

**Author:** ![nk922](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@nk922](https://devforum.okta.com/u/nk922)\
**Post date:** [January 31, 2024, 3:42pm UTC](https://devforum.okta.com/t/get-started-with-spring-boot-and-saml/21496/10 "2024-01-31T15:42:38Z")

</div>

Very informative post! I have quick question around downloading the SP metadata file. How can I download the SP metadata file for this sample application?

Thanks!

---

<div class="post-metadata">

**Author:** ![mraible](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/mraible/32/37_2.png) [@mraible](https://devforum.okta.com/u/mraible)\
**Post date:** [January 31, 2024, 5:55pm UTC](https://devforum.okta.com/t/get-started-with-spring-boot-and-saml/21496/11 "2024-01-31T17:55:48Z")

</div>

Hi @nk922 and welcome to the Okta developer community!

You don’t need to download the SP metadata file to implement SAML with Spring Boot. You just need to [point to its URL](https://developer.okta.com/blog/2022/08/05/spring-boot-saml#add-a-saml-application-on-okta). For example:

```auto
https://dev-13337.okta.com/app/<random-characters>/sso/saml/metadata

```

If this doesn’t help, can you please explain more about your use case and what you’re trying to accomplish?

---

<div class="post-metadata">

**Author:** ![Isai](https://avatars.discourse-cdn.com/v4/letter/i/2acd7d/32.png) [@Isai](https://devforum.okta.com/u/Isai)\
**Post date:** [April 2, 2024, 4:36pm UTC](https://devforum.okta.com/t/get-started-with-spring-boot-and-saml/21496/12 "2024-04-02T16:36:09Z")

</div>

Did you find how to achieve this?

---

<div class="post-metadata">

**Author:** ![ychandolu](https://avatars.discourse-cdn.com/v4/letter/y/f0a364/32.png) [@ychandolu](https://devforum.okta.com/u/ychandolu)\
**Post date:** [January 11, 2025, 5:07pm UTC](https://devforum.okta.com/t/get-started-with-spring-boot-and-saml/21496/15 "2025-01-11T17:07:25Z")

</div>

Hi Matt,

In your code what changes need to be made to use my own custom login page, for e.g. mylogin.html. In mylogin.html page I want to display the IDPs in a drop down for example and add my branding background, images etc. So, my question is about using my own custom login page. Can you please suggest the changes required?

I tried the below in SecurityConfiguration as suggested in one of the online article, but it did not work. A 302 loop is going on and then finally browser displayed “This page is not working” error.

saml2Login(saml2 → saml2  
.authenticationManager(new ProviderManager(authenticationProvider)).loginPage(“/saml-login”))

Can you please suggest?

Thanks  
Yuva

---

<div class="post-metadata">

**Author:** ![ychandolu](https://avatars.discourse-cdn.com/v4/letter/y/f0a364/32.png) [@ychandolu](https://devforum.okta.com/u/ychandolu)\
**Post date:** [January 11, 2025, 7:36pm UTC](https://devforum.okta.com/t/get-started-with-spring-boot-and-saml/21496/16 "2025-01-11T19:36:29Z")

</div>

Hi Matt,

After a bit of searching in the internet and a bit of trial & error, I am able to use my own custom login page. My login page is saml-login.html. Posting my changes here hoping they may be helpful for someone else. Calling .permitAll on loginPage stopped the 302 loop.

# SecurityConfiguration.java

http.authorizeHttpRequests(authorize → authorize  
.anyRequest().authenticated())  
.saml2Login(saml2 → saml2  
.authenticationManager(new ProviderManager(authenticationProvider)))  
.saml2Logout(withDefaults());

```
    http.saml2Login().loginPage("/saml-login").permitAll();

```

# SamlLoginController.java (new class)

@Controller  
public class SamlLoginController {

```
@Autowired
private RelyingPartyRegistrationRepository relyingPartyRegistrationRepository;

@GetMapping("/saml-login")
String samlLogin(Model model) {

	System.out.println("------------- in mylogin conroller");

	InMemoryRelyingPartyRegistrationRepository repo = (InMemoryRelyingPartyRegistrationRepository)relyingPartyRegistrationRepository;
	Iterator<RelyingPartyRegistration> iterator = repo.iterator();

	List<RelyingPartyRegistration> idpList = new ArrayList<RelyingPartyRegistration>(2);
	while (iterator.hasNext()) {
		RelyingPartyRegistration reg = (RelyingPartyRegistration)iterator.next();
		idpList.add(reg);
	}

	model.addAttribute("idpList", idpList);

	return "saml-login";

}

```

}

# saml-login.html

# Welcome

Login Using One of the SAML IDPs

- 

Thanks  
Yuva

---

<div class="post-metadata">

**Author:** ![ychandolu](https://avatars.discourse-cdn.com/v4/letter/y/f0a364/32.png) [@ychandolu](https://devforum.okta.com/u/ychandolu)\
**Post date:** [January 11, 2025, 7:43pm UTC](https://devforum.okta.com/t/get-started-with-spring-boot-and-saml/21496/17 "2025-01-11T19:43:32Z")

</div>

Hi Matt,

I am able to make my custom saml-login.htm page working after a bit of searching and a bit of trials. .permitAll on loginPage stopped the 302 loop. Sharing the changes hoping it may be useful for someone.

# SecurityConfiguration.java

http.authorizeHttpRequests(authorize → authorize  
.anyRequest().authenticated())  
.saml2Login(saml2 → saml2  
.authenticationManager(new ProviderManager(authenticationProvider)))  
.saml2Logout(withDefaults());

```
    http.saml2Login().loginPage("/saml-login").permitAll();

```

# SamlLoginController.java (new class)

@Controller  
public class SamlLoginController {

```
@Autowired
private RelyingPartyRegistrationRepository relyingPartyRegistrationRepository;

@GetMapping("/saml-login")
String samlLogin(Model model) {

	System.out.println("------------- in mylogin conroller");

	InMemoryRelyingPartyRegistrationRepository repo = (InMemoryRelyingPartyRegistrationRepository)relyingPartyRegistrationRepository;
	Iterator<RelyingPartyRegistration> iterator = repo.iterator();

	List<RelyingPartyRegistration> idpList = new ArrayList<RelyingPartyRegistration>(2);
	while (iterator.hasNext()) {
		RelyingPartyRegistration reg = (RelyingPartyRegistration)iterator.next();
		idpList.add(reg);
	}

	model.addAttribute("idpList", idpList);

	return "saml-login";

}

```

}

# saml-login.html
 SAML IDP Login 
# Welcome

Login Using One of the SAML IDPs

-
