diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index e0e0654..d286b02 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,15 +4,10 @@
-
-
+
-
-
-
-
-
-
+
+
@@ -40,7 +35,7 @@
1739978089147
-
+
+
+ 1740037639602
+
+
+
+ 1740037639602
+
+
@@ -165,7 +168,8 @@
-
+
+
@@ -190,16 +194,6 @@
70
-
- file://$PROJECT_DIR$/src/main/java/com/example/nto/websecurity/WebSecurityConfig.java
- 49
-
-
-
- file://$PROJECT_DIR$/src/main/java/com/example/nto/controller/AdminController.java
- 79
-
-
diff --git a/src/main/java/com/example/nto/controller/AdminController.java b/src/main/java/com/example/nto/controller/AdminController.java
index 5c54e01..c1cdbbf 100644
--- a/src/main/java/com/example/nto/controller/AdminController.java
+++ b/src/main/java/com/example/nto/controller/AdminController.java
@@ -12,6 +12,8 @@ import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
+import javax.annotation.security.RolesAllowed;
+
@Controller
@RequestMapping("/api/admin/")
public class AdminController {
@@ -58,20 +60,20 @@ public class AdminController {
* Такой же метод, как и getEmployeeInfo, только для админов по логину
* @return
*/
- @PreAuthorize("hasAnyRole('ADMIN')")
+ @RolesAllowed("ADMIN")
@GetMapping("/{value}/info")
public Employee getEmployeeInfoAdmin(@PathVariable String value) {
return employeeService.getEmployeeInfoById(Long.parseLong(value));
}
- @PreAuthorize("hasAnyRole('ADMIN')")
+ @RolesAllowed("ADMIN")
@DeleteMapping("/employee/delete/")
public ResponseEntity deleteEmployee(@RequestBody DeleteEmployeeRequest deleteEmployeeRequest) {
employeeService.deleteEmployee(deleteEmployeeRequest.id);
return ResponseEntity.status(HttpStatus.OK).build();
}
- @PreAuthorize("hasRole('DOLBOEB')")
+ @RolesAllowed("ADMIN")
@PutMapping("/employee/update/login/")
public ResponseEntity updateEmployeeLogin(@RequestBody UpdateEmployeeRequest updateEmployeeRequest) {
@@ -81,14 +83,14 @@ public class AdminController {
return ResponseEntity.status(HttpStatus.OK).build();
}
- @PreAuthorize("hasAnyRole('ADMIN')")
+ @RolesAllowed("ADMIN")
@PutMapping("/employee/update/avatar/")
public ResponseEntity updateEmployeeAvatar(@RequestBody UpdateEmployeeRequest updateEmployeeRequest) {
employeeService.updateEmployeeAvatar(updateEmployeeRequest.id, updateEmployeeRequest.field);
return ResponseEntity.status(HttpStatus.OK).build();
}
- @PreAuthorize("hasAnyRole('ADMIN')")
+ @RolesAllowed("ADMIN")
@PutMapping("/employee/update/position/")
public ResponseEntity updatePosition(@RequestBody UpdateEmployeeRequest updateEmployeeRequest) {
employeeService.updateEmployeePosition(updateEmployeeRequest.id, updateEmployeeRequest.field);
diff --git a/src/main/java/com/example/nto/websecurity/WebSecurityConfig.java b/src/main/java/com/example/nto/websecurity/WebSecurityConfig.java
index f088fe9..9baca6e 100644
--- a/src/main/java/com/example/nto/websecurity/WebSecurityConfig.java
+++ b/src/main/java/com/example/nto/websecurity/WebSecurityConfig.java
@@ -10,6 +10,7 @@ import org.springframework.context.annotation.DependsOn;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
+import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@@ -23,6 +24,7 @@ import java.util.List;
@Configuration
@EnableWebSecurity
+@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
@@ -78,6 +80,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.csrf().disable()
.authorizeRequests()
.antMatchers("/api/login/").permitAll()
+ .antMatchers("/api/admin/**").hasRole("ADMIN")
.anyRequest().authenticated()
.and()
.formLogin().permitAll()