Spring Security 5.5 From Taxi To Takeoff

Overview

Spring Security 5.5 From Taxi to Takeoff

This repository is for the SpringOne 2021 presentation titled "Spring Security 5.5 From Taxi to Takeoff". It contains the following four applications:

  • spa - An Angular-based Single Page Application
  • flights-web - A Spring-powered OAuth 2.0 client application
  • flights-api - A REST API secured with Spring Security OAuth 2.0 Resource Server
  • sso - A Spring-powered OAuth 2.0 Authorization Server

The final state is a single-page application that authenticates the user with OpenID Connect 1.0 and collaborates with a REST API using OAuth 2.0 bearer tokens.

Getting Started

First, start the authorization server, with the following command:

./gradlew :sso:bootRun

Next, start the REST API like so:

./gradlew :flights-api:bootRun

You will need the Angular CLI installed. Then, start the SPA and OAuth 2.0 Client application using the following command:

./gradlew :flights-web:bootRun

Finally, navigate to http://127.0.0.1:8000

Following Along

To follow along with the presentation, start with the main branch:

git checkout main

Each checkpoint along the way contains a specific commit message you can use to quickly hop around in the presentation. For example, to switch to Step 1 - Secure by default, do the following:

./look-at 'Step 1'

This will safely attempt to switch to a particular commit, but you will be in 'detached HEAD' state. To reset to a particular point such as Step 11 - Secure BFF application ,git checkout main again, and do the following:

./jump-to 'Step 11'

This will hard-reset to the specified commit and discard changes in your working directory.

Comments
  • Authorization Server - Replace form Login with Another application

    Authorization Server - Replace form Login with Another application

    Hi,

    First of great presentation learned a lot and raised a few more questions for me.

    But wanted to know about a different approach for the authorization server. Is it possible to change the authorization server to not use form login and maybe replace it with a React/Next or any other front end framework for handling that part of the flow.

    Is it a good idea to do that???

    opened by bamofah 9
  • SSO server won't redirect to web

    SSO server won't redirect to web

    This is what I have tried against the latest commit in main branch

    1. Map 127.0.0.1 to auth-server in my local hosts file
    2. Start sso application
    3. Start api application
    4. Start web application
    5. Hit web application by going to http://localhost:8000
    6. I was redirected to sso application login url at: http://auth-server:9000/login
    7. Enter credential: josh/control
    8. I then got this sso error url = http://auth-server:9000/error?response_type=code&client_id=air-traffic-control&scope=openid%20flights:read%20flights:write&state=89B_tqK-vGVQLLPdbujyMxUGr5J2d6A2PdzJOmjUC-A%3D&redirect_uri=http://localhost:8000/login/oauth2/code/air-traffic-control-client&nonce=QVIN4qjrngwR_pl0jVoYIw8theirJRArL8OOQ8yomh4

    As a side note, I also tried the samples from spring-authorization server project - https://github.com/spring-projects/spring-authorization-server/tree/main/samples and it works as expected.

    opened by keeplearningandtrying 6
  • If I release the page and static resources, I get the following error

    If I release the page and static resources, I get the following error

    I changed the configuration of flights-web a bit like this:

    @Bean
        SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
            // @formatter:off
            http
                    .authorizeExchange(authorizeExchangeSpec -> authorizeExchangeSpec
                            .pathMatchers("/app/**", "/*.*.js", "/*.*.css", "/assets/**")
                            .permitAll())
                    .authorizeExchange((authorize) -> authorize
                            .anyExchange().authenticated()
                    )
                    .oauth2Login(Customizer.withDefaults())
                    .csrf((csrf) -> csrf
                            .csrfTokenRepository(CookieServerCsrfTokenRepository.withHttpOnlyFalse())
                    );
            // @formatter:on
            return http.build();
        }
    

    Then I got the following result: 捕获2 Maybe when the page wants to use ajax to call the interface, it gets a 302, but ajax can't handle 302 efficiently

    opened by lylJson 3
  • Redirect user to original URL after successful authentication

    Redirect user to original URL after successful authentication

    Thanks a lot for your video presentation and this repository :slightly_smiling_face:

    I have a very similar setup of applications/components but I currently got stuck with the security configuration in the gateway. Mabye you can get me out of there.

    The basic parts of the application are:

    • A single-page application in Vue
    • A Spring Cloud Gateway acting as OAuth2 client for a Keycloak IDP
    • A Spring Boot API backend

    The integration itself is working but for the time being I'm getting redirected to a hard-coded URL after a successful authentication. Now I'd like to change this behavior, so that if the user originally visited http://localhost:8093/profile, then the gateway should redirect the user to exactly this URL after login.

    @Configuration
    @EnableWebFluxSecurity
    public class SecurityConfiguration {
    
        @Bean
        public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity httpSecurity) {
            httpSecurity
                    .csrf().disable()
                    .authorizeExchange()
                    .anyExchange().authenticated()
                    .and()
                    .oauth2Login()
                    // Use original user-agent URL here?
                    .authenticationSuccessHandler(new RedirectServerAuthenticationSuccessHandler("http://localhost:8093"))
                    .and()
                    .exceptionHandling().authenticationEntryPoint(new HttpStatusServerEntryPoint(HttpStatus.UNAUTHORIZED))
                    .and()
                    .oauth2ResourceServer().jwt();
            return httpSecurity.build();
        }
    }
    

    This question is also available at https://stackoverflow.com/q/71176804/478406 but the answer seems not to apply when using @EnableWebfluxSecurity.

    opened by straurob 2
  • Access OIDC token information from Angular SPA

    Access OIDC token information from Angular SPA

    What would be the best way to access the information encoded in the OpenID token from the Angular SPA side? For example, I want to display the user's name in the SPA after login.

    As far as I understand no tokens at all are available directly to the SPA.

    opened by godfriedmeesters 1
  • What should I do if I deploy the static resources of the SPA in nginx?

    What should I do if I deploy the static resources of the SPA in nginx?

    Now the spa is served as static content from the /static directory of flights-web. I mean deploy the '/static directory' to nginx, because usually the static resources are developed by another group of people who are now deploying their SPA pages directly on nginx.

    opened by lylJson 1
  • Currently the main branch `:filghts-api:bootRun` task fails

    Currently the main branch `:filghts-api:bootRun` task fails "out-of-the-box" on Windows

    Hello, and first I want to say thanks for a solid presentation package with a Youtube video together with this Github repo.

    When I attempted to follow along, I grabbed the repo, and ran through the "Getting Started" section. I am on Windows BTW and the error was:

    > Task :flights-api:generateAot FAILED
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':flights-api:generateAot'.
    > No access hint found for import selector: org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration$JpaRepositoriesImportSelector
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    
    * Get more help at https://help.gradle.org
    
    BUILD FAILED in 25s
    3 actionable tasks: 3 executed
    Press any key to continue . . .
    

    When I then looked at the Git repo history, I discovered that the "main" branch was already done with all the steps. So I checked out "demo" to find a state prior to the work I'm about to "follow along" -- and that built fine! 😃

    So right after finishing this issue report, I'll go right back and go through the demo, following along. I am way too new at this to have any clue what was going wrong above.

    When I encounter the build issue again while going through the demo, I should have more details to add that may be helpful. In the meantime, here's the versions I'm working with:

    Microsoft Windows [Version 10.0.20348.825]
    (c) Microsoft Corporation. All rights reserved.
    
    C:\devplay\spring-security-5_5-from-taxi-to-takeoff\springone-2021>node --version
    v19.0.0
    
    C:\devplay\spring-security-5_5-from-taxi-to-takeoff\springone-2021>npm --version
    8.19.2
    
    C:\devplay\spring-security-5_5-from-taxi-to-takeoff\springone-2021>gradle --version
    
    ------------------------------------------------------------
    Gradle 7.5.1
    ------------------------------------------------------------
    
    Build time:   2022-08-05 21:17:56 UTC
    Revision:     d1daa0cbf1a0103000b71484e1dbfe096e095918
    
    Kotlin:       1.6.21
    Groovy:       3.0.10
    Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
    JVM:          11.0.11 (AdoptOpenJDK 11.0.11+9)
    OS:           Windows Server 2019 10.0 amd64
    
    
    C:\devplay\spring-security-5_5-from-taxi-to-takeoff\springone-2021>
    
    opened by nebbish 1
Owner
Steve Riesenberg
Steve Riesenberg
参考 DDD/Clean Architecture 设计理念,整合 Spring Boot/Spring Security/Mybatis Plus/Vavr 的 Spring Realworld 应用案例

Demo · 更多项目 · 参考资料 ms-spring-ddd-examples Unified Domain-driven Layered Architecture for MicroService Apps,试图探索一套切实可行的应用架构规范,可以复制、可以理解、可以落地、可以控制复杂性的指导

王下邀月熊 19 Sep 23, 2022
Spring Boot & MongoDB Login and Registration example with JWT, Spring Security, Spring Data MongoDB

Spring Boot Login and Registration example with MongoDB Build a Spring Boot Auth with HttpOnly Cookie, JWT, Spring Security and Spring Data MongoDB. Y

null 15 Dec 30, 2022
Spring Boot Login and Registration example with MySQL, JWT, Rest Api - Spring Boot Spring Security Login example

Spring Boot Login example with Spring Security, MySQL and JWT Appropriate Flow for User Login and Registration with JWT Spring Boot Rest Api Architect

null 58 Jan 5, 2023
Spring Boot JWT Authentication example with Spring Security & Spring Data JPA

Spring Boot JWT Authentication example with Spring Security & Spring Data JPA

null 1 Jan 26, 2022
Rate limiting private REST APIs using Java Spring-boot, spring-security and bucket4j

Rate limiting REST APIs using Spring-security filter and Bucket4J Deployed Application (Swagger-ui on heroku) Inspired from: Baeldung Article Applicat

null 20 Jul 18, 2022
Zitadel.ch Example Project with Spring Boot and Spring Security

Zitadel Example Project with Spring Boot and Spring Security This example contains two Spring Boot Apps (app and api) which use the Zitadel IdP as Ope

Thomas Darimont 2 May 3, 2022
一个小而美的低代码全栈开发平台,一键生成后端api接口+前端页面代码+在线接口文档,节省50%的前后端开发的工作量。基于springboot +mybatis+spring security+vue 技术栈

YOMA [toc] 一个小而美的低代码全栈开发平台,一键生成后端api接口+前端页面代码+在线接口文档,节省50%的前后端开发的工作量,平台代码100%开源。平台适用于企业信息化、政务、中小型互联网等项目 平台采用前后端分离架构,基于如下流行的开源框架,易上手+便于后期维护 后端:https://

Shihao Ma 149 Dec 9, 2022
🦄 开源社区系统:基于 SpringBoot + MyBatis + MySQL + Redis + Kafka + Elasticsearch + Spring Security + ... 并提供详细的开发文档和配套教程。包含帖子、评论、私信、系统通知、点赞、关注、搜索、用户设置、数据统计等模块。

Echo — 开源社区系统 项目上线到服务器之后可能会出现各种各样的 BUG,比如 Elasticsearch 服务启动失败导致搜索模块不可用,但是在本地运行是完全没问题的,所以各位小伙伴可以放心下载部署。 ?? 项目简介 Echo 是一套前后端不分离的开源社区系统,基于目前主流 Java Web

小牛肉 434 Jan 7, 2023
基于SpringBoot,Spring Security,JWT,Vue & Element 的前后端分离权限管理系统

平台简介 芋道,一套全部开源的企业级的快速开发平台,毫无保留给个人及企业免费使用。 有任何问题,或者想要的功能,可以在 Issues 中提给艿艿。 前端采用 vue-element-admin。 后端采用 Spring Boot、MySQL、Redis。 权限认证使用 Spring Security

芋道源码 8.2k Jan 1, 2023
基于 Spring Security OAuth 的统一账号管理平台

基于 Spring Security OAuth 的统一账号管理平台 前后端演示地址: https://tao.flizi.cn 支持密码模式演示 输入账号 123456, 密码: 123456, 以及验证码后点击登录 支持授权登录演示 输入手机号 123456, 密码: 123456, 以及验证码

知一 132 Nov 9, 2022
【多模块微服务脚手架平台——Ancba】前后端分离架构SpringBoot 2.x、SpringCloud、SpringAdmin、Spring Security、Mybatis-plus、(Shiro)、JWT、Feign、Nacos、Knif4j等。

Ancba 打造Blog.Core项目的SpringBoot微服务版,但是更强大 ?? Ancba (Another New CLI By Alacrity) 另一个全新的敏捷脚手架(单体/模块化/微服务都可支持)。 核心知识点与进度 ?? 在 ..../resources/application-

ansonzhang 35 Nov 29, 2022
Projeto Base - Spring Security - Blog Pessoal

Implementando a Camada de Segurança com o Spring Security no Blog Pessoal Nesta atividade iremos implementar a camada de segurança da aplicação com o

Rafael Queiróz 10 Aug 9, 2021
A Spring Security based Authentication microservice with MySQL

Spring Security Microservice using JWT and MySQL Background This is an open source, production-ready application that provides role-based user authent

Safeer Ansari 4 Sep 28, 2021
Spring Boot Security Login example with JWT and H2 example

Spring Boot Security Login example with JWT and H2 example Appropriate Flow for User Login and Registration with JWT and HttpOnly Cookie Spring Boot R

null 50 Dec 21, 2022
Operating Systems - Concepts of computer operating systems including concurrency, memory management, file systems, multitasking, performance analysis, and security. Offered spring only.

Nachos for Java README Welcome to Nachos for Java. We believe that working in Java rather than C++ will greatly simplify the development process by p

Sabir Kirpal 1 Nov 28, 2021
该仓库中主要是 Spring Boot 的入门学习教程以及一些常用的 Spring Boot 实战项目教程,包括 Spring Boot 使用的各种示例代码,同时也包括一些实战项目的项目源码和效果展示,实战项目包括基本的 web 开发以及目前大家普遍使用的线上博客项目/企业大型商城系统/前后端分离实践项目等,摆脱各种 hello world 入门案例的束缚,真正的掌握 Spring Boot 开发。

Spring Boot Projects 该仓库中主要是 Spring Boot 的入门学习教程以及一些常用的 Spring Boot 实战项目教程,包括 Spring Boot 使用的各种示例代码,同时也包括一些实战项目的项目源码和效果展示,实战项目包括基本的 web 开发以及目前大家普遍使用的前

十三 4.5k Dec 30, 2022
基于SpringCloud2.1的微服务开发脚手架,整合了spring-security-oauth2、nacos、feign、sentinel、springcloud-gateway等。服务治理方面引入elasticsearch、skywalking、springboot-admin、zipkin等,让项目开发快速进入业务开发,而不需过多时间花费在架构搭建上。持续更新中

快速开始 先决条件 首先本机先要安装以下环境,建议先学习了解springboot和springcloud基础知识。 git java8 maven 开发环境搭建 linux和mac下可在项目根目录下执行 ./install.sh 快速搭建开发环境。如要了解具体的步骤,请看如下文档。 具体步骤如下:

zhoutaoo 7.9k Jan 6, 2023
springboot 框架与其它组件结合如 jpa、mybatis、websocket、security、shiro、cache等

致歉 由于自己懒以及身体对issuse 解决的不及时。请大家以后提issuse 的时候写清楚 模块名 比如“springboot-SpringSecurity4” 和问题,我会抽时间抓紧解决。 springboot-SpringSecurity0 包含两部分代码: 第一是 博客 springboot

abel 5.9k Jan 5, 2023
完整教学!从0到1开发,手把手教你学会开发一个spring security + jwt + vue的前后端分离项目! 线上演示:https://markerhub.com/vueadmin/

VueAdmin - 基于SpringBoot+Jwt+Vue的前后端分离后台管理系统 完整教学!从0到1开发,手把手教你学会开发一个spring security + jwt + vue的前后端分离项目! 线上体验:https://www.markerhub.com/vueadmin/ 说明: 首

MarkerHub 235 Jan 4, 2023