2 Промежуточный результат
This commit is contained in:
		
							parent
							
								
									1b741b9772
								
							
						
					
					
						commit
						96a39edcbe
					
				| @ -1,10 +1,12 @@ | ||||
| package com.example.nto.config; | ||||
| 
 | ||||
| import com.example.nto.service.EmployeeService; | ||||
| import lombok.RequiredArgsConstructor; | ||||
| import org.springframework.boot.web.servlet.FilterRegistrationBean; | ||||
| import org.springframework.boot.web.servlet.support.ErrorPageFilter; | ||||
| import org.springframework.context.annotation.Bean; | ||||
| import org.springframework.context.annotation.Configuration; | ||||
| import org.springframework.security.authentication.AuthenticationManager; | ||||
| import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; | ||||
| import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||||
| import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||||
| @ -49,6 +51,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | ||||
|                 .passwordEncoder(passwordEncoder()); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     @Bean | ||||
|     public PasswordEncoder passwordEncoder() { | ||||
|         return new BCryptPasswordEncoder(); | ||||
|  | ||||
| @ -29,7 +29,17 @@ public class EmployeeController { | ||||
| 
 | ||||
|     @GetMapping("/login") | ||||
|     public ResponseEntity<EmployeeDTO> login(Authentication authentication) { | ||||
|         System.out.println("out" + authentication.getAuthorities()); | ||||
|         return ResponseEntity.ok(employeeService.getUserByUsername(authentication.getName())); | ||||
|         System.out.println("Authentication object: " + authentication); | ||||
|         String username = authentication.getName(); | ||||
|         System.out.println("Username: " + username); | ||||
| 
 | ||||
|         EmployeeDTO employeeDTO = employeeService.getUserByUsername(username); | ||||
|         if (employeeDTO == null) { | ||||
|             System.out.println("User not found for username: " + username); | ||||
|             return ResponseEntity.status(404).body(null); | ||||
|         } | ||||
| 
 | ||||
|         System.out.println("EmployeeDTO: " + employeeDTO); | ||||
|         return ResponseEntity.ok(employeeDTO); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -19,7 +19,4 @@ public class Credentials { | ||||
|     @Column(name = "hashed_password") | ||||
|     private String hashedPassword; | ||||
| 
 | ||||
|     @OneToMany(mappedBy = "credentials") | ||||
|     @JsonIgnore | ||||
|     private List<Employee> employees; | ||||
| } | ||||
| @ -40,8 +40,6 @@ public class Employee implements UserDetails { | ||||
|     private Credentials credentials; | ||||
|     @Column(name = "photo") | ||||
|     private String photo; | ||||
|     @ManyToMany(fetch = FetchType.EAGER) | ||||
|     private Set<Authority> authorities; | ||||
|     @Column(name = "position") | ||||
|     private String position; | ||||
|     @Column(name = "lastVisit") | ||||
|  | ||||
| @ -113,7 +113,6 @@ public class EmployeeCodeServiceImpl implements EmployeeService, CodeService { | ||||
|         employee.setLogin(dto.getLogin()); | ||||
|         employee.setName(dto.getName()); | ||||
|         employee.setPassword(passwordEncoder.encode(dto.getPassword())); | ||||
|         employee.setAuthorities(Set.of(roleUser.get())); | ||||
|         employee.setCredentials(credentials); | ||||
|         employee.setAuthority(roleUser.get()); | ||||
| 
 | ||||
|  | ||||
| @ -14,10 +14,10 @@ import java.util.Optional; | ||||
| @RequiredArgsConstructor | ||||
| public class UserDetailsServiceImpl implements UserDetailsService { | ||||
| 
 | ||||
|     private final EmployeeRepository usersRepository; | ||||
|     private final EmployeeRepository employeeRepository; | ||||
|     @Override | ||||
|     public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException { | ||||
|         Optional<Employee> optionalUsers = usersRepository.findByLogin(s); | ||||
|         Optional<Employee> optionalUsers = employeeRepository.findByLogin(s); | ||||
| 
 | ||||
|         if(optionalUsers.isEmpty()) { | ||||
|             throw new UsernameNotFoundException("User not found"); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user