Skip to content

deepaksorthiya/spring-boot-security-angular-client-csrf

Repository files navigation

Java Maven Build Test Docker Hub badge


** Spring Boot Security with CSRF protection for SPA(Single Page Applications) Using Angular Framework **


Getting Started

Live Demo URL

Render.com URL : Demo URL

wait for 15-20 seconds to get server up only if not running.

Project Information

This project is using frontend-maven-plugin plugin. It will build angular project from directory src/main/frontend and place build files in frontend/dist/frontend/browser. Check config in pom.xml.

<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>${frontend-maven-plugin.version}</version>
<configuration>
    <workingDirectory>${frontendSrcDir}</workingDirectory>
</configuration>

Maven Resource plugin will copy this angular build files and place it under maven build directory /target/classes/static as spring boot will serve static contents from this directory.

<artifactId>maven-resources-plugin</artifactId>
<executions>
    <execution>
        <id>copy-resources</id>
        <phase>process-classes</phase>
        <goals>
            <goal>copy-resources</goal>
        </goals>
        <configuration>
            <outputDirectory>${basedir}/target/classes/static</outputDirectory>
            <resources>
                <resource>
                    <directory>${frontendSrcDir}/dist/frontend/browser</directory>
                </resource>
            </resources>
        </configuration>
    </execution>
</executions>

Requirements:

Git: 2.51+
Spring Boot: 3.5.11
Maven: 3.9+
Java: 25
(Optional)Docker Desktop: Tested on 4.54.0

Clone this repository:

git clone https://github.com/deepaksorthiya/spring-boot-security-angular-client-csrf.git
cd spring-boot-security-angular-client-csrf

Build Project:

In below command, Maven clean phase will delete node packages. check clean plugin config in POM File. Don't use clean phase second time if you don't want to remove node packages.

./mvnw clean package -DskipTests

Use below option if you don't want to build frontend second time. Don't use clean phase second otherwise it will delete frontend build as well.

./mvnw package -DskipTests -DskipFrontendBuild=true

for native graalvm

./mvnw -Pnative native:compile

It will generate a spring-boot-security-angular-client-csrf in target folder.

Run Project:

./mvnw spring-boot:run

OR

java -jar .\target\spring-boot-security-angular-client-csrf-0.0.1-SNAPSHOT.jar

for native image run

./target/spring-boot-security-angular-client-csrf

Setup Angular Local Development Environment

see README

(Optional)Build Docker Image(docker should be running):

./mvnw clean spring-boot:build-image -DskipTests

for native container image

./mvnw clean -Pnative spring-boot:build-image -DskipTests
docker build --progress=plain -f Dockerfile.native -t deepaksorthiya/spring-boot-security-angular-client-csrf .

(Optional)Running On Docker

docker run -p 8080:8080 --name spring-boot-security-angular-client-csrf deepaksorthiya/spring-boot-security-angular-client-csrf

Users for Testing

USER1 ==> Username: user Password: password
USER2 ==> Username: admin Password : admin

Testing

visit to access application http://localhost:8080

Maven Clean Plugin Config

if you want to remove node packages during maven clean phase add below plugin config in pom.xml. It's already added. you can use

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-clean-plugin</artifactId>
    <configuration>
        <filesets>
            <fileset>
                <directory>src/main/frontend/.angular</directory>
            </fileset>
            <fileset>
                <directory>src/main/frontend/dist</directory>
            </fileset>
            <fileset>
                <directory>src/main/frontend/node</directory>
            </fileset>
            <fileset>
                <directory>src/main/frontend/node_modules</directory>
            </fileset>
        </filesets>
    </configuration>
</plugin>

Reference Documentation

For further reference, please consider the following sections:

Guides

The following guides illustrate how to use some features concretely:

About

spring security with spa client angular with csrf protection

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors 2

  •  
  •