Skip to content

Commit 033706a

Browse files
authored
Merge pull request #209 from devondragon/small-fixes-improvements
Small-fixes-improvements
2 parents d183b4d + 07b2703 commit 033706a

File tree

51 files changed

+5044
-1418
lines changed

Some content is hidden

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

51 files changed

+5044
-1418
lines changed

README.md

Lines changed: 263 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ Check out the [Spring User Framework Demo Application](https://github.com/devond
1818
- [Maven](#maven)
1919
- [Gradle](#gradle)
2020
- [Quick Start](#quick-start)
21+
- [Prerequisites](#prerequisites)
22+
- [Step 1: Add Dependencies](#step-1-add-dependencies)
23+
- [Step 2: Database Configuration](#step-2-database-configuration)
24+
- [Step 3: JPA Configuration](#step-3-jpa-configuration)
25+
- [Step 4: Email Configuration (Optional but Recommended)](#step-4-email-configuration-optional-but-recommended)
26+
- [Step 5: Essential Framework Configuration](#step-5-essential-framework-configuration)
27+
- [Step 6: Create User Profile Extension (Optional)](#step-6-create-user-profile-extension-optional)
28+
- [Step 7: Start Your Application](#step-7-start-your-application)
29+
- [Step 8: Test Core Features](#step-8-test-core-features)
30+
- [Step 9: Customize Pages (Optional)](#step-9-customize-pages-optional)
31+
- [Complete Example Configuration](#complete-example-configuration)
32+
- [Next Steps](#next-steps)
2133
- [Configuration](#configuration)
2234
- [Security Features](#security-features)
2335
- [Role-Based Access Control](#role-based-access-control)
@@ -84,37 +96,135 @@ Check out the [Spring User Framework Demo Application](https://github.com/devond
8496
<dependency>
8597
<groupId>com.digitalsanctuary</groupId>
8698
<artifactId>ds-spring-user-framework</artifactId>
87-
<version>3.3.0</version>
99+
<version>3.4.0</version>
88100
</dependency>
89101
```
90102

91103
### Gradle
92104

93105
```groovy
94-
implementation 'com.digitalsanctuary:ds-spring-user-framework:3.3.0'
106+
implementation 'com.digitalsanctuary:ds-spring-user-framework:3.4.0'
95107
```
96108

97109
## Quick Start
98110

99-
1. **Add the dependency** as shown above
111+
Follow these steps to get up and running with the Spring User Framework in your application.
100112

101-
2. **Set essential configuration** in your `application.yml`:
113+
### Prerequisites
102114

115+
- Java 17 or higher
116+
- Spring Boot 3.0+
117+
- A database (MariaDB, PostgreSQL, MySQL, H2, etc.)
118+
- SMTP server for email functionality (optional but recommended)
119+
120+
### Step 1: Add Dependencies
121+
122+
1. **Add the main framework dependency**:
123+
124+
Maven:
125+
```xml
126+
<dependency>
127+
<groupId>com.digitalsanctuary</groupId>
128+
<artifactId>ds-spring-user-framework</artifactId>
129+
<version>3.3.0</version>
130+
</dependency>
131+
```
132+
133+
Gradle:
134+
```groovy
135+
implementation 'com.digitalsanctuary:ds-spring-user-framework:3.3.0'
136+
```
137+
138+
2. **Add required dependencies**:
139+
140+
**Important**: This framework requires these additional Spring Boot starters to function properly:
141+
142+
Maven:
143+
```xml
144+
<dependency>
145+
<groupId>org.springframework.boot</groupId>
146+
<artifactId>spring-boot-starter-thymeleaf</artifactId>
147+
</dependency>
148+
<dependency>
149+
<groupId>org.springframework.boot</groupId>
150+
<artifactId>spring-boot-starter-mail</artifactId>
151+
</dependency>
152+
<dependency>
153+
<groupId>org.springframework.boot</groupId>
154+
<artifactId>spring-boot-starter-data-jpa</artifactId>
155+
</dependency>
156+
<dependency>
157+
<groupId>org.springframework.boot</groupId>
158+
<artifactId>spring-boot-starter-security</artifactId>
159+
</dependency>
160+
<dependency>
161+
<groupId>org.springframework.retry</groupId>
162+
<artifactId>spring-retry</artifactId>
163+
</dependency>
164+
```
165+
166+
Gradle:
167+
```groovy
168+
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
169+
implementation 'org.springframework.boot:spring-boot-starter-mail'
170+
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
171+
implementation 'org.springframework.boot:spring-boot-starter-security'
172+
implementation 'org.springframework.retry:spring-retry'
173+
```
174+
175+
### Step 2: Database Configuration
176+
177+
Configure your database in `application.yml`. The framework supports all databases compatible with Spring Data JPA:
178+
179+
**MariaDB/MySQL:**
103180
```yaml
104181
spring:
105182
datasource:
106-
url: jdbc:mariadb://localhost:3306/yourdb
183+
url: jdbc:mariadb://localhost:3306/yourdb?createDatabaseIfNotExist=true
107184
username: dbuser
108185
password: dbpassword
109186
driver-class-name: org.mariadb.jdbc.Driver
187+
```
188+
189+
**PostgreSQL:**
190+
```yaml
191+
spring:
192+
datasource:
193+
url: jdbc:postgresql://localhost:5432/yourdb
194+
username: dbuser
195+
password: dbpassword
196+
driver-class-name: org.postgresql.Driver
197+
```
198+
199+
**H2 (for development/testing):**
200+
```yaml
201+
spring:
202+
datasource:
203+
url: jdbc:h2:mem:testdb
204+
driver-class-name: org.h2.Driver
205+
```
206+
207+
### Step 3: JPA Configuration
208+
209+
```yaml
210+
spring:
110211
jpa:
111212
hibernate:
112-
ddl-auto: update
213+
ddl-auto: update # Creates/updates tables automatically
214+
show-sql: false # Set to true for SQL debugging
215+
```
216+
217+
### Step 4: Email Configuration (Optional but Recommended)
218+
219+
For password reset and email verification features:
220+
221+
```yaml
222+
spring:
113223
mail:
114-
host: smtp.example.com
224+
host: smtp.gmail.com # or your SMTP server
115225
port: 587
116-
username: your-username
117-
password: your-password
226+
username: your-[email protected]
227+
password: your-app-password
118228
properties:
119229
mail:
120230
smtp:
@@ -124,29 +234,139 @@ spring:
124234

125235
user:
126236
mail:
127-
fromAddress: [email protected]
237+
fromAddress: [email protected] # Email "from" address
238+
```
239+
240+
### Step 5: Essential Framework Configuration
241+
242+
Add these minimal settings to get started:
243+
244+
```yaml
245+
user:
246+
# Basic security settings
128247
security:
129-
defaultAction: deny
130-
bcryptStrength: 12
131-
failedLoginAttempts: 5
132-
accountLockoutDuration: 15
248+
defaultAction: deny # Secure by default
249+
bcryptStrength: 12 # Password hashing strength
250+
failedLoginAttempts: 5 # Account lockout threshold
251+
accountLockoutDuration: 15 # Lockout duration in minutes
252+
253+
# Registration settings
254+
registration:
255+
sendVerificationEmail: false # true = email verification required
256+
# false = auto-enable accounts
133257
```
134258

135-
3. **Create a UserProfile extension** for your application-specific user data:
259+
### Step 6: Create User Profile Extension (Optional)
260+
261+
If you need additional user data beyond the built-in fields, create a profile extension:
136262

137263
```java
138264
@Entity
139265
@Table(name = "app_user_profile")
140266
public class AppUserProfile extends BaseUserProfile {
141-
// Add your application-specific fields
142-
private String preferredLanguage;
143-
private boolean receiveNewsletter;
267+
private String department;
268+
private String phoneNumber;
269+
private LocalDate birthDate;
144270

145271
// Getters and setters
272+
public String getDepartment() { return department; }
273+
public void setDepartment(String department) { this.department = department; }
274+
275+
// ... other getters and setters
146276
}
147277
```
148278

149-
4. **Run your application** and navigate to `/user/login.html` to see the login page.
279+
### Step 7: Start Your Application
280+
281+
1. **Run your Spring Boot application**:
282+
```bash
283+
mvn spring-boot:run
284+
# or
285+
./gradlew bootRun
286+
```
287+
288+
2. **Verify the framework is working**:
289+
- Navigate to `http://localhost:8080/user/login.html` to see the login page
290+
- Check your database - user tables should be created automatically
291+
- Look for framework startup messages in the console
292+
293+
### Step 8: Test Core Features
294+
295+
**Create your first user:**
296+
- Navigate to `/user/register.html`
297+
- Fill out the registration form
298+
- If `sendVerificationEmail=false`, you can login immediately
299+
- If `sendVerificationEmail=true`, check your email for verification link
300+
301+
**Test login:**
302+
- Navigate to `/user/login.html`
303+
- Use the credentials you just created
304+
305+
### Step 9: Customize Pages (Optional)
306+
307+
The framework provides default HTML templates, but you can override them:
308+
309+
1. **Create custom templates** in `src/main/resources/templates/user/`:
310+
- `login.html` - Login page
311+
- `register.html` - Registration page
312+
- `forgot-password.html` - Password reset page
313+
- And more...
314+
315+
2. **Use your own CSS** by adding stylesheets to `src/main/resources/static/css/`
316+
317+
### Complete Example Configuration
318+
319+
Here's a complete `application.yml` for a typical setup:
320+
321+
```yaml
322+
spring:
323+
datasource:
324+
url: jdbc:mariadb://localhost:3306/myapp?createDatabaseIfNotExist=true
325+
username: appuser
326+
password: apppass
327+
driver-class-name: org.mariadb.jdbc.Driver
328+
329+
jpa:
330+
hibernate:
331+
ddl-auto: update
332+
show-sql: false
333+
334+
mail:
335+
host: smtp.gmail.com
336+
port: 587
337+
338+
password: myapppassword
339+
properties:
340+
mail:
341+
smtp:
342+
auth: true
343+
starttls:
344+
enable: true
345+
346+
user:
347+
mail:
348+
fromAddress: [email protected]
349+
350+
security:
351+
defaultAction: deny
352+
bcryptStrength: 12
353+
failedLoginAttempts: 3
354+
accountLockoutDuration: 30
355+
356+
registration:
357+
sendVerificationEmail: true
358+
359+
# Optional: Audit logging
360+
audit:
361+
logEvents: true
362+
logFilePath: ./logs/audit.log
363+
```
364+
365+
### Next Steps
366+
367+
- Read the [Configuration Guide](CONFIG.md) for advanced settings
368+
- See [Extension Examples](PROFILE.md) for custom user profiles
369+
- Check out the [Demo Application](https://github.com/devondragon/SpringUserFrameworkDemoApp) for a complete example
150370
151371
## Configuration
152372
@@ -208,12 +428,32 @@ user:
208428
209429
### Registration
210430
211-
Default registration flow includes:
431+
The registration flow is configurable and can operate in two modes:
432+
433+
**Auto-Enable Mode** (default: `user.registration.sendVerificationEmail=false`):
434+
- Form submission validation
435+
- Email uniqueness check
436+
- User account is immediately enabled and can login
437+
- No verification email is sent
438+
- User has full access immediately after registration
439+
440+
**Email Verification Mode** (`user.registration.sendVerificationEmail=true`):
212441
- Form submission validation
213442
- Email uniqueness check
214-
- Email verification (optional)
215-
- Welcome email
216-
- Configurable initial roles
443+
- User account is created but **disabled**
444+
- Verification email is sent with confirmation link
445+
- User must click verification link to enable account
446+
- Account remains disabled until email verification is completed
447+
- Configurable initial roles assigned after verification
448+
449+
**Configuration Example:**
450+
```yaml
451+
user:
452+
registration:
453+
sendVerificationEmail: true # Enable email verification (default: false)
454+
```
455+
456+
**Note:** When email verification is disabled, user accounts are immediately active and functional. When enabled, accounts require email confirmation before login is possible.
217457

218458
### Profile Management
219459

0 commit comments

Comments
 (0)