final 19.02
to do fix admin (roles) add status encript password
This commit is contained in:
parent
9684dad527
commit
fa2676bab9
@ -5,6 +5,7 @@ import com.example.nto.service.EmployeeService;
|
|||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -74,10 +75,13 @@ public class EmployeeController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasRole('admin')") // Проверьте, что пользователь имеет роль admin
|
@PreAuthorize("hasRole('admin')")
|
||||||
@GetMapping("/workers")
|
@GetMapping("/workers")
|
||||||
public ResponseEntity<List<Employee>> getAllWorkers() {
|
public ResponseEntity<List<Employee>> getAllWorkers() {
|
||||||
List<Employee> allEmployees = employeeService.findAll(); // Получить всех сотрудников
|
String currentUserName = SecurityContextHolder.getContext().getAuthentication().getName();
|
||||||
|
// Логируем информацию о текущем пользователе
|
||||||
|
System.out.println("Current user: " + currentUserName);
|
||||||
|
List<Employee> allEmployees = employeeService.findAll();
|
||||||
return ResponseEntity.ok(allEmployees);
|
return ResponseEntity.ok(allEmployees);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,39 +4,15 @@ import javax.persistence.*;
|
|||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Code {
|
public class Code {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
private Long value; // Значение кода
|
private Long value;
|
||||||
|
|
||||||
@ManyToOne // Установите связь с Employee
|
@ManyToOne
|
||||||
@JoinColumn(name = "employee_id", nullable = false)
|
@JoinColumn(name = "employee_id", nullable = false)
|
||||||
private Employee employee;
|
private Employee employee;
|
||||||
|
|
||||||
// Геттеры и сеттеры
|
// Геттеры и сеттеры
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setValue(Long value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Employee getEmployee() {
|
|
||||||
return employee;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEmployee(Employee employee) {
|
|
||||||
this.employee = employee;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -27,25 +27,6 @@ public class Employee {
|
|||||||
|
|
||||||
private String role;
|
private String role;
|
||||||
|
|
||||||
public String getLogin() {
|
|
||||||
return login; // Возвращает логин
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRole(String role) {
|
|
||||||
this.role = role; // Устанавливает роль
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRole() {
|
|
||||||
return role; // Возвращает роль (например, 'admin' или 'user')
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.password = password; // Устанавливает пароль
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return password; // Возвращает пароль
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,10 +24,9 @@ CREATE TABLE IF NOT EXISTS code (
|
|||||||
);
|
);
|
||||||
|
|
||||||
-- Вставка данных в таблицу code
|
-- Вставка данных в таблицу code
|
||||||
INSERT INTO code (value)
|
INSERT INTO code (value, employee_id) VALUES
|
||||||
VALUES
|
(1234567890123456789, 1),
|
||||||
(1234567890123456789),
|
(9223372036854775807, 2),
|
||||||
(9223372036854775807),
|
(1122334455667788990, 3),
|
||||||
(1122334455667788990),
|
(998877665544332211, 4),
|
||||||
(998877665544332211),
|
(5566778899001122334, 1);
|
||||||
(5566778899001122334);
|
|
Loading…
x
Reference in New Issue
Block a user