Skip to content

Commit e8422ac

Browse files
authoredDec 11, 2023
Merge pull request #11 from alwinsimon/v1
V1 - Final Configuration completed..
2 parents d1508fe + 5fe82cc commit e8422ac

File tree

3 files changed

+71
-5
lines changed

3 files changed

+71
-5
lines changed
 

‎README.md

+63-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,63 @@
1-
# User-Management-JavaSpringBoot
1+
# User Management - Java Spring Boot
2+
3+
This is a simple Java Spring Boot project designed for User Management with two types of user roles: USER and ADMIN. Authentication is implemented using JSON Web Tokens (JWT), and the default port for the application is 8080. Maven is used as the build tool, and Postgres SQL is the chosen database with JPA for database access.
4+
5+
## Features
6+
7+
- User Management with roles: USER and ADMIN
8+
- JWT Authentication
9+
- Database: Postgres SQL with JPA
10+
- Default Port: 8080
11+
12+
---
13+
14+
## Getting Started
15+
16+
### Prerequisites
17+
18+
Make sure you have the following installed:
19+
20+
- Java Development Kit (JDK)
21+
- Maven
22+
- Postgres SQL
23+
24+
### Installation
25+
26+
1. **Clone the repository:**
27+
28+
```
29+
git clone https://github.com/alwinsimon/User-Management-JavaSpringBoot.git
30+
```
31+
32+
2. **Navigate to the project directory:**
33+
34+
```
35+
cd User-Management-JavaSpringBoot
36+
```
37+
38+
3. **Build the project using Maven:**
39+
40+
41+
42+
4. **Run the application:**
43+
44+
45+
The application will start on the default port: [http://localhost:8080](http://localhost:8080).
46+
47+
---
48+
49+
## API Documentation
50+
51+
Explore the API endpoints using the [Postman live API Documentation](https://documenter.getpostman.com/view/27773540/2s9Ykhgj5q).
52+
53+
## Contributing
54+
55+
Feel free to contribute to the project by creating issues or submitting pull requests.
56+
57+
## License
58+
59+
This project is licensed under the [Apache License](LICENSE).
60+
61+
---
62+
63+
**Repository:** [https://github.com/alwinsimon/User-Management-JavaSpringBoot](https://github.com/alwinsimon/User-Management-JavaSpringBoot)

‎src/main/java/com/alwinsimon/UserManagementJavaSpringBoot/Config/SecurityConfig.java

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.springframework.context.annotation.Bean;
88
import org.springframework.context.annotation.Configuration;
99
import org.springframework.security.authentication.AuthenticationProvider;
10+
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
1011
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
1112
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
1213
import org.springframework.security.config.http.SessionCreationPolicy;
@@ -16,6 +17,7 @@
1617
@Configuration
1718
@EnableWebSecurity
1819
@RequiredArgsConstructor
20+
@EnableMethodSecurity(securedEnabled = true, prePostEnabled = true)
1921
public class SecurityConfig {
2022

2123
private final JwtAuthenticationFilter jwtAuthenticationFilter;

‎src/main/java/com/alwinsimon/UserManagementJavaSpringBoot/Controller/AdminController.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
import com.alwinsimon.UserManagementJavaSpringBoot.Model.User;
44
import com.alwinsimon.UserManagementJavaSpringBoot.Service.AdminService;
5-
import com.alwinsimon.UserManagementJavaSpringBoot.Service.UserService;
65
import lombok.RequiredArgsConstructor;
76
import org.springframework.http.HttpStatus;
87
import org.springframework.http.ResponseEntity;
9-
import org.springframework.security.access.prepost.PreAuthorize;
8+
import org.springframework.security.access.annotation.Secured;
109
import org.springframework.web.bind.annotation.*;
1110

1211
import java.util.List;
@@ -18,7 +17,9 @@
1817
public class AdminController {
1918

2019
private final AdminService adminService;
20+
2121
@GetMapping("/get-users")
22+
@Secured("ADMIN")
2223
public ResponseEntity<List<User>> getAllUsers() {
2324

2425
// API Endpoint to get the LoggedIn User Details using Token received in the Request Header.
@@ -28,11 +29,12 @@ public ResponseEntity<List<User>> getAllUsers() {
2829
}
2930

3031
@DeleteMapping("/delete-user/{email}")
31-
public ResponseEntity<String> deleteUser(@PathVariable("email")String email){
32+
@Secured("ADMIN")
33+
public ResponseEntity<String> deleteUser(@PathVariable("email") String email) {
3234
try {
3335
adminService.deleteUserByEmail(email);
3436
return ResponseEntity.ok("User deleted.");
35-
}catch (Exception e){
37+
} catch (Exception e) {
3638
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("User deletion Failed.");
3739
}
3840
}

0 commit comments

Comments
 (0)
Please sign in to comment.