Giter Club home page Giter Club logo

spring-security-boot-preauth's Introduction

Warning
This application is only a demo and NOT SECURE. See below for details.

Overview

A sample application that shows how to allow an external system authenticate with Spring Security. In this example, we assume that something is added to the request by an external system. The application works as follows:

  • TokenFilter obtains a token from the request. This is currently implemented by obtaining the value of the cookie named token.

  • TokenFilter validates the token. There is no validation for this simple demo which means this sample is NOT SECURE. In a production application, you would need to ensure that the token is validated.

  • TokenFilter translates the token into a valid user. To keep things simple, this is currently done by assuming the token is the user name. The roles are a hard coded constant. In a production application, the translation would be the result of validating the token.

  • TokenFilter sets the current user on the SecurityContextHolder. The SecurityContextHolder is the central place to discover what the current user is. As demonstrated in TokenFilter the way Spring Security determines the user is declarative.

Note
It is important to note that SecurityContextHolder is associating the current user to the Thread. In a web environment, the Threads are pooled. This means it is very important to clear the SecurityContextHolder after the request executes. If your code executes after Spring Security’s FilterChainProxy, then the SecurityContextHolder is cleared out for you.

Running the sample

You can run the sample using:

$ ./mvnw spring-boot:run

You will not have access.

Set a cookie named token to a username. An easy way to do this is to type the following in the address bar:

javascript:document.cookie='token=rob'
Note
Some browsers prevent copy pasting in the javascript: prefix for security reasons. This means you may need to type this manually.

You will be authenticated as rob.

spring-security-boot-preauth's People

Stargazers

Brandon Atkinson avatar Brian Byers avatar

Watchers

Rob Winch avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.