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