Start United States USA — software Get Started With Spring Boot, SAML, and Okta Get Started With Spring...

Get Started With Spring Boot, SAML, and Okta Get Started With Spring Boot, SAML, and Okta

512
0
TEILEN

When it comes to Spring Boot app security, the Okta platform and SAML can work with your app to provide authentication and authorization capabilities.
Today I’ d like to show you how to build a Spring Boot application that leverages Okta’s Platform API for authentication via SAML. SAML (Security Assertion Markup Language) is an XML-based standard for securely exchanging authentication and authorization information between entities — specifically between identity providers, service providers, and users. Well-known IdPs include Salesforce, Okta, OneLogin, and Shibboleth.
My Okta developer experience began a couple years ago (in December 2014) when I worked for a client that was adopting it. I was tasked with helping them decide on a web framework to use, so I built prototypes with Node, Ruby, and Spring. I documented my findings in a blog post. Along the way, I tweeted my issues with Spring Boot, and asked how to fix it on Stack Overflow. I ended up figuring out the solution through trial-and-error and my findings made it into the official Spring documentation. Things have changed a lot since then and now Spring Security 4.2 has support for auto-loading custom DSLs. And guess what, there’s even a DSL for SAML configuration!
Ready to get started? You can follow along in with the written tutorial below, check out the code on GitHub, or watch the screencast I made to walk you through the same process.
Fast forward two years, and I find myself as an Okta employee. To start developing with Okta, I created a new developer account at https: //developer.okta.com. Make sure you take a screenshot or write down your Okta URL after you’ ve signed up. You’ ll need this URL to get back to the admin console.
You’ ll receive an email to activate your account and change your temporary password. After completing these steps, you’ ll land on your dashboard with some annotations about “apps”.
At the time of this writing, the easiest way to create a SAML-aware Spring Boot application is to use Spring Security’s SAML DSL project. It contains a sample project that provides instructions for configuring Okta as a SAML provider. These instructions will likely work for you if you’ re experienced Spring Boot and Okta developer. If you’ re new to both, this “start from scratch” tutorial might work better for you.
Just like I did, the first thing you’ ll need to do is create a developer account at https: //developer.okta.com. After activating your account, login to it and click on the “Admin” button in the top right.
On the next screen, click “Add Applications” in the top right.
This will bring you to a screen with a “Create New App” green button on the left.
Click the button and choose “Web” for the platform and “SAML 2.0” for the sign on method.
Click the “Create” button. The next screen will prompt you for an application name. I used “Spring SAML”, but any name will work.
Click the “Next” button. This brings you to the second step, configuring SAML. Enter the following values:
Scroll to the bottom of the form and click “Next”. This will bring you to the third step, feedback. Choose “I’ m an Okta customer adding an internal app” and optionally select the App type.
The final setup step you’ ll need is to assign people to the application. Click on the “People” tab and the “Assign to People” button. You’ ll see a list of people with your account in it.
Click the assign button, accept the default username (your email) , and click the “Done” button.
Navigate to https: //start.spring.io in your favorite browser and select Security, Web, Thymeleaf, and DevTools as dependencies.
Click “Generate Project”, download the generated ZIP file and open it in your favorite editor. Add the spring-security-saml-dsl dependency to your pom.xml .
You’ ll also need to add the Spring Milestone repository since a milestone release is all that’s available at the time of this writing.
If you’ d like to see instructions for Gradle, please view the project’s README.md .
In src/main/resources/application.properties, add the following key/value pairs. Make sure to use the “Identity Provider metadata” value you copied earlier (hint: you can find it again under the “Sign On” tab in your Okta application) .
From a terminal window, navigate to the src/main/resources directory of your app and create a saml directory. Navigate into the directory and run the following command. Use “secret” when prompted for a keystore password.
The values for the rest of the questions don’ t matter since you’ re not generating a real certificate. However, you will need to answer “yes” to the following question.
Create a SecurityConfiguration.java file in the com.example package.
Create an IndexController.java file in the same directory and use it to set the default view to index .
Since you chose Thymeleaf when creating your application, you can create a src/main/resources/templates/index.html and it will automatically be rendered after you sign-in. Create this file and populate it with the following HTML.
Start the app using your IDE or mvn spring-boot: run and navigate to https: //localhost: 8443. If you’ re using Chrome, you’ ll likely see a privacy error.
Click the “ADVANCED” link at the bottom. Then click the “proceed to localhost (unsafe) ” link.
Next, you’ ll be redirected to Okta to sign in and redirected back to your app. If you’ re already logged in, you won’ t see anything from Okta. If you sign out from Okta, you’ ll see a login screen such as the one below.
After you’ ve logged in, you should see a screen like the one below.

Continue reading...