Skip to content

Commit 6d08965

Browse files
committed
Massive Refactoring to be a Maven Library
Changed this SpringBoot Application into a Maven Library, which can be included via Gradle or Maven in your SpringBoot Application. Removed front end html, javascript, css, etc.. Updated all libraries. Setup Maven Central build steps. Created a CHANGELOG and automatic CHANGELOG generation. Bumped version to 3.0.0. And much much more!
1 parent d48d262 commit 6d08965

145 files changed

Lines changed: 2003 additions & 9660 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
"java.configuration.updateBuildConfiguration": "automatic",
66
"java.compile.nullAnalysis.mode": "automatic",
77
"java.transport": "stdio",
8-
"java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx2G -Xms100m -javaagent:\"/Users/devon/.vscode/extensions/gabrielbb.vscode-lombok-1.0.1/server/lombok.jar\""
8+
"java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx2G -Xms100m -javaagent:\"/Users/devon/.vscode/extensions/gabrielbb.vscode-lombok-1.0.1/server/lombok.jar\"",
9+
"debug.javascript.defaultRuntimeExecutable": {
10+
"pwa-node": "/Users/devon/.local/share/mise/shims/node"
11+
}
912
}
File renamed without changes.

CONFIG.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ Welcome to the User Framework SpringBoot Configuration Guide! This document outl
2323
- **DDL Auto (`spring.jpa.hibernate.ddl-auto`)**: Hibernate schema generation strategy, defaults to `update`.
2424
- **Dialect (`spring.jpa.properties.hibernate.dialect`)**: Set this to the appropriate dialect for your database, defaults to `org.hibernate.dialect.MariaDBDialect`.
2525

26-
### Application Properties
27-
28-
- **Name (`spring.application.name`)**: Set your application's name, defaults to `User Framework`.
2926

3027
## User Settings
3128

@@ -47,18 +44,12 @@ Welcome to the User Framework SpringBoot Configuration Guide! This document outl
4744

4845
- **From Address (`spring.mail.fromAddress`)**: The email address used as the sender in outgoing emails.
4946

50-
## Copyright
51-
52-
- **First Year (`spring.copyrightFirstYear`)**: The starting year for the copyright notice.
5347

5448
## Role and Privileges
5549

5650
- **Roles and Privileges (`spring.roles-and-privileges`)**: Map out roles to their respective privileges.
5751
- **Role Hierarchy (`spring.role-hierarchy`)**: Define the hierarchy and inheritance of roles.
5852

59-
## New Relic Monitoring
60-
61-
- **API Key and Account ID (`management.newrelic.metrics.export`)**: Required if you're integrating with New Relic for monitoring.
6253

6354
## Server and Session Settings
6455

Dockerfile

Lines changed: 0 additions & 3 deletions
This file was deleted.

PUBLISH.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Maven Publishing Guide
2+
3+
# Build and Publish Command Reference
4+
5+
## Building the Project
6+
7+
To build the project, run:
8+
9+
```sh
10+
./gradlew build
11+
```
12+
13+
14+
## Publish to Local Maven
15+
16+
```shell
17+
gradle publishLocal
18+
```
19+
20+
## Publish to Private Maven repository
21+
22+
```shell
23+
gradle publishReposilite
24+
```
25+
26+
27+
## Publish to Maven Central
28+
29+
```shell
30+
gradle publishMavenCentral
31+
```
32+
33+
34+

QUICKSTART.md

Lines changed: 0 additions & 33 deletions
This file was deleted.

README.md

Lines changed: 72 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
1+
## Table of Contents
2+
- [SpringUserFramework](#springuserframework)
3+
- [Summary](#summary)
4+
- [Features](#features)
5+
- [How To Get Started](#how-to-get-started)
6+
- [Refer to the Demo Project](#refer-to-the-demo-project)
7+
- [Configuring Your Local Environment](#configuring-your-local-environment)
8+
- [Database](#database)
9+
- [Mail Sending (SMTP)](#mail-sending-smtp)
10+
- [SSO OAuth2 with Google and Facebook](#sso-oauth2-with-google-and-facebook)
11+
- [Overriding Spring Security Messages](#overriding-spring-security-messages)
12+
- [Notes](#notes)
13+
14+
115
# SpringUserFramework
216

3-
SpringUserFramework is a Java Spring Boot User Management Framework designed to simplify the implementation of user management features in your Spring-based web application. It is built on top of [Spring Security](https://spring.io/projects/spring-security) and provides out-of-the-box support for registration, login, logout, and forgot password flows. The framework includes basic example pages that are unstyled, allowing for seamless integration into your application.
17+
SpringUserFramework is a Java Spring Boot User Management Framework designed to simplify the implementation of user management features in your SpringBoot web application. It is built on top of [Spring Security](https://spring.io/projects/spring-security) and provides out-of-the-box support for registration, login, logout, and forgot password flows. It also supports SSO with Google and Facebook.
18+
19+
The framework includes basic example pages that are unstyled, allowing for seamless integration into your application.
420

521
## Summary
622

@@ -21,6 +37,8 @@ The framework provides support for the following features:
2137
- Login and logout functionality.
2238
- Forgot password flow.
2339
- Database-backed user store using Spring JPA.
40+
- SSO support for Google
41+
- SSO support for Facebook
2442
- Configuration options to control anonymous access, whitelist URIs, and protect specific URIs requiring a logged-in user session.
2543
- CSRF protection enabled by default, with example jQuery AJAX calls passing the CSRF token from the Thymeleaf page context.
2644
- Audit event framework for recording and logging security events, customizable to store audit events in a database or publish them via a REST API.
@@ -31,85 +49,87 @@ The framework provides support for the following features:
3149

3250
## How To Get Started
3351

34-
### Quickstart Guide
35-
You can jump right in and get started by following the [Quickstart Guide](QUICKSTART.md).
36-
37-
For more information, read on.
38-
39-
### Configuring Your Local Environment
40-
There is an example configuration file in /src/main/resources called application-local.yml-example. By default this project's gradle bootRun command runs Spring using the "local" profile. So you can just copy that file to application-local.yml and replace the values (keys, URLs, etc..) with your values. If you are using a different profile to run (such as default) you will just need to ensure the same configs are in place in your active configuration file(s).
41-
42-
You can read more about the required configuration values in the [Configuration Guide](CONFIG.md).
43-
44-
Missing or incorrect configuration values will make this framework not work correctly.
52+
This Framework is now available as a library on Maven Central. You can add it to your Gradle project by adding the following dependency to your `build.gradle` file:
4553

46-
### Database
47-
This framework uses a database as a user store. By buildling on top of Spring JPA it is easy to use which ever datastore you like. The example configuration in application.yml is for a [MariaDB](https://mariadb.com) 10.5 database. You will need to create a user and a database and configure the database name, username, and password.
54+
```groovy
55+
implementation 'com.digitalsanctuary:ds-spring-user-framework:3.0.0'
56+
```
4857

49-
You can do this using docker with a command like this:
58+
Or to your Maven project by adding it to your `pom.xml` file:
5059

51-
```
52-
docker run -p 127.0.0.1:3306:3306 --name springuserframework -e MARIADB_ROOT_PASSWORD=springuserroot -e MARIADB_DATABASE=springuser -e MARIADB_USER=springuser -e MARIADB_PASSWORD=springuser -d mariadb:latest
60+
```xml
61+
<dependency>
62+
<groupId>com.digitalsanctuary</groupId>
63+
<artifactId>ds-spring-user-framework</artifactId>
64+
<version>3.0.0</version>
65+
</dependency>
5366
```
5467

55-
Or on Apple Silicon:
68+
Please check for the latest version on [Maven Central](https://central.sonatype.com/artifact/com.digitalsanctuary/ds-spring-user-framework) (this README may not always be up to date).
69+
When upgrading to a new version, please check the [CHANGELOG](CHANGELOG.md) for any breaking changes or new features.
5670

57-
```
58-
docker run -p 127.0.0.1:3306:3306 --name springuserframework -e MARIADB_ROOT_PASSWORD=springuserroot -e MARIADB_DATABASE=springuser -e MARIADB_USER=springuser -e MARIADB_PASSWORD=springuser -d arm64v8/mariadb:latest
59-
```
6071

61-
### Mail Sending (SMTP)
62-
The framework sends emails for verficiation links, forgot password flow, etc... so you need to configure the outbound SMTP server and authentication information.
72+
### Refer to the Demo Project
73+
I have created a demo project that uses this framework. You can find it here: [SpringUserFrameworkDemo](https://github.com/devondragon/SpringUserFrameworkDemoApp). This demo project is a full SpringBoot application that uses this framework as a library. You can use it as a reference for how to use this framework in your own project. It demonstrates all of the configuration values and how to override them in your own `application.yml` file. It also has functioning examples for all front end pages, javascript, etc...
6374

64-
### SSO OAuth2 with Google and Facebook
65-
The framework supports SSO OAuth2 with Google and Facebook. To enable this you need to configure the client id and secret for each provider.
75+
In addition to being a fully functional reference, you can also use the demo project as a starting point for your own project. Just clone the repo and start building your own application on top of it.
6676

67-
For public OAuth you will need a public hostname and HTTPS enabled. You can use ngrok to create a public hostname and tunnel to your local machine. You can then use the ngrok hostname in your Google and Facebook developer console configuration.
6877

78+
### Configuring Your Local Environment
6979

70-
### New Relic
71-
Out of the box the project includes the New Relic Telemetry module, and as such requires a New Relic account id, and associated API key. If you don't use New Relic you can remove the dependancy from the build.gradle file and ignore the configuration values.
80+
You can read more about the required configuration values in the [Configuration Guide](CONFIG.md).
7281

73-
Beyond that the default configurations should be all you need, although of course you can customize things however you like.
82+
Missing or incorrect configuration values will make this framework not work correctly.
7483

75-
## Docker
84+
### Database
85+
This framework uses a database as a user store. By building on top of Spring JPA it is easy to use whichever database you like.
7686

77-
After running gradle build, you can build a simple Docker image of the application using the provided Dockerfile. Please note that this Dockerfile is basic and does not incorporate advanced features such as layering or buildpacks that you may require for production applications.
87+
If you set your JPA Hibernate ddl-auto property to "create" it will create the tables for you. If you set it to "update" it will update the tables for you. If you set it to "none" you will need to create the tables yourself.
7888

79-
Additionally, a docker-compose file is included, which launches a stack with the Spring Boot Application, MariaDB Database, and Postfix Mail Server. The configurations in the docker-compose file are set to make everything work smoothly. However, please be aware that sending emails from your computer (via the docker Postfix Mail Server) may be blocked by email providers due to spam checks. You can use temporary email addresses from [10MinuteMail.com](https://10minutemail.com) for testing purposes, but for real use, it is recommended to configure the Spring Boot application to use a real mail server for outbound transactional emails.
89+
If you are not using automatic schema updates or Flyway, you can set up your database manually using the provided `schema.sql` file:
8090

91+
```bash
92+
mysql -u username -p database_name < src/main/resources/schema.sql
93+
```
8194

95+
Flyway support will be coming soon. This will allow you to automatically update your database schema as you deploy new versions of your application.
8296

83-
## Overriding Spring Security Messages
8497

85-
You may want to override the default Spring Security user facing messages. You can do this in your messages.properties file, by adding any of the message keys from Spring Security (found here: [Spring Security Messages](https://github.com/spring-projects/spring-security/blob/main/core/src/main/resources/org/springframework/security/messages.properties)) and providing your own values.
98+
### Mail Sending (SMTP)
99+
The framework sends emails for verification links, forgot password flow, etc... so you need to configure the outbound SMTP server and authentication information. This is done in the `application.yml` file. You can see the example configuration in the Demo Project's `application.yml` file. Please also refer to the [Spring Boot Mail Properties](https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html#mail-properties) for more information on the available properties.
86100

87101

88-
## Dev Tools
102+
### SSO OAuth2 with Google and Facebook
103+
The framework supports SSO OAuth2 with Google and Facebook. To enable this you need to configure the client id and secret for each provider. This is done in the application.yml (or application.properties) file using the [Spring Security OAuth2 properties](https://docs.spring.io/spring-security/reference/servlet/oauth2/login/core.html). You can see the example configuration in the Demo Project's `application.yml` file.
104+
105+
Here is a quick example for your reference:
106+
107+
```yaml
108+
spring:
109+
security:
110+
oauth2:
111+
client:
112+
registration:
113+
google:
114+
client-id: YOUR_GOOGLE_CLIENT_ID
115+
client-secret: YOUR_GOOGLE_CLIENT_SECRET
116+
redirect-uri: "{baseUrl}/login/oauth2/code/google"
117+
facebook:
118+
client-id: YOUR_FACEBOOK_CLIENT_ID
119+
client-secret: YOUR_FACEBOOK_CLIENT_SECRET
120+
redirect-uri: "{baseUrl}/login/oauth2/code/facebook"
121+
```
89122
90-
### SpringBoot DevTools Auto Restart and Live Reload
91-
Read the following articles:
92-
- https://www.digitalsanctuary.com/java/springboot-devtools-auto-restart-and-live-reload.html
93-
- https://www.digitalsanctuary.com/java/how-to-get-springboot-livereload-working-over-https.html
123+
For public OAuth you will need a public hostname and HTTPS enabled. You can use ngrok or Cloudflare tunnels to create a public hostname and tunnel to your local machine during development. You can then use the ngrok hostname in your Google and Facebook developer console configuration.
94124
95-
### Live Reload over HTTPS Setup
96-
If you are running your local dev env using HTTPS or referencing it from a ngrok tunnel using HTTPS, you will need to make a few changes to get Live Reload to work. First you need to tell the application to use HTTPS by setting the following properties in your application.yml file:
97125
98-
```
99-
spring.devtools.livereload.https=true
100-
```
101126
102-
You then need to install mitmproxy and configure it to intercept the HTTPS traffic. You can do this by running the following command:
103127
104-
```
105-
mitmproxy --mode reverse:http://localhost:35729 -p 35739
106-
```
128+
## Overriding Spring Security Messages
129+
130+
You may want to override the default Spring Security user facing messages. You can do this in your messages.properties file, by adding any of the message keys from Spring Security (found here: [Spring Security Messages](https://github.com/spring-projects/spring-security/blob/main/core/src/main/resources/org/springframework/security/messages.properties)) and providing your own values.
107131
108-
By default, mitmproxy uses self-signed SSL certificates, so you need to tell your browser to trust them before this will work. You can do this by opening https://localhost:35739/livereload.js in your browser and going through the steps to trust the server and certificate.
109132
110-
Alternatively, you can configure mitmproxy to use real certificates and avoid this step. Follow these directions: https://docs.mitmproxy.org/stable/concepts-certificates/
111133
112134
## Notes
113-
Much of this is based on the [Baeldung course on Spring Security](https://www.baeldung.com/learn-spring-security-course). If you want to learn more about Spring Security or would like to add SSO integration or 2FA to your application, that guide is a great place to start.
114-
115135
Please note that there is no warranty or guarantee of functionality, quality, performance, or security made by the author. The code is available freely, but you assume all responsibility and liability for its usage in your application.

0 commit comments

Comments
 (0)