File tree 2 files changed +5
-0
lines changed
src/main/java/com/alwinsimon/UserManagementJavaSpringBoot
2 files changed +5
-0
lines changed Original file line number Diff line number Diff line change 7
7
import org .springframework .context .annotation .Bean ;
8
8
import org .springframework .context .annotation .Configuration ;
9
9
import org .springframework .security .authentication .AuthenticationProvider ;
10
+ import org .springframework .security .config .annotation .method .configuration .EnableMethodSecurity ;
10
11
import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
11
12
import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
12
13
import org .springframework .security .config .http .SessionCreationPolicy ;
16
17
@ Configuration
17
18
@ EnableWebSecurity
18
19
@ RequiredArgsConstructor
20
+ @ EnableMethodSecurity (securedEnabled = true , prePostEnabled = true )
19
21
public class SecurityConfig {
20
22
21
23
private final JwtAuthenticationFilter jwtAuthenticationFilter ;
Original file line number Diff line number Diff line change 5
5
import lombok .RequiredArgsConstructor ;
6
6
import org .springframework .http .HttpStatus ;
7
7
import org .springframework .http .ResponseEntity ;
8
+ import org .springframework .security .access .annotation .Secured ;
8
9
import org .springframework .web .bind .annotation .*;
9
10
10
11
import java .util .List ;
@@ -18,6 +19,7 @@ public class AdminController {
18
19
private final AdminService adminService ;
19
20
20
21
@ GetMapping ("/get-users" )
22
+ @ Secured ("ADMIN" )
21
23
public ResponseEntity <List <User >> getAllUsers () {
22
24
23
25
// API Endpoint to get the LoggedIn User Details using Token received in the Request Header.
@@ -27,6 +29,7 @@ public ResponseEntity<List<User>> getAllUsers() {
27
29
}
28
30
29
31
@ DeleteMapping ("/delete-user/{email}" )
32
+ @ Secured ("ADMIN" )
30
33
public ResponseEntity <String > deleteUser (@ PathVariable ("email" ) String email ) {
31
34
try {
32
35
adminService .deleteUserByEmail (email );
You can’t perform that action at this time.
0 commit comments