Changeset b248810 for jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend
- Timestamp:
- 06/10/24 22:34:32 (6 months ago)
- Branches:
- main
- Children:
- befb988
- Parents:
- 28b3398
- Location:
- jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/JobvistaBackendApplication.java
r28b3398 rb248810 26 26 admin.setRole(Role.ROLE_ADMIN); 27 27 admin.setEmail("admin@admin.com"); 28 admin.setHasAccess(true); 28 29 // admin.setName("admin"); 29 30 // admin.setSurname("admin"); -
jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/config/SecurityConfiguration.java
r28b3398 rb248810 32 32 // TO DO: FIX PERMISSIONS 33 33 .requestMatchers("/api/job-advertisements/**","/api/job-advertisements/view/**","/api/recruiter/info/**", 34 "/api/job-advertisements/apply/**","/api/auth/**", "/api/resume/**", "/api/my-applications/**", "/api/applications/{id}/update" ).permitAll()34 "/api/job-advertisements/apply/**","/api/auth/**", "/api/resume/**", "/api/my-applications/**", "/api/applications/{id}/update", "/api/admin/**").permitAll() 35 35 //.requestMatchers("/api/job-advertisements/**").hasAnyAuthority(Role.ROLE_RECRUITER.name()) 36 36 .anyRequest().authenticated()) -
jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/controllers/AdminController.java
r28b3398 rb248810 2 2 3 3 import lombok.RequiredArgsConstructor; 4 import org.springframework.web.bind.annotation.RequestMapping; 5 import org.springframework.web.bind.annotation.RestController; 4 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.DTO.RecruiterDetailsDTO; 5 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.service.intef.AdminService; 6 import org.springframework.http.HttpStatus; 7 import org.springframework.http.ResponseEntity; 8 import org.springframework.web.bind.annotation.*; 9 10 import java.util.List; 6 11 7 12 @RestController 8 13 @RequestMapping("/api/admin") 9 14 @RequiredArgsConstructor 15 @CrossOrigin(origins = "*") 10 16 public class AdminController { 11 17 18 private final AdminService adminService; 19 20 @PostMapping("/change-access/{recruiter_id}") 21 public ResponseEntity<?> changeAccess(@PathVariable("recruiter_id") Long recruiterId, @RequestBody boolean access) { 22 RecruiterDetailsDTO recruiterDetailsDTO = adminService.changeAccess(recruiterId, access); 23 return new ResponseEntity<>(recruiterDetailsDTO, HttpStatus.OK); 24 } 25 26 @GetMapping("/recruiters") 27 public ResponseEntity<?> findAllRecruiters() { 28 List<RecruiterDetailsDTO> recruiterDetailsDTOList = adminService.findAllRecruiters(); 29 return new ResponseEntity<>(recruiterDetailsDTOList, HttpStatus.OK); 30 } 12 31 } -
jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/models/users/DTO/JwtAuthResponse.java
r28b3398 rb248810 14 14 private String name; 15 15 private String role; 16 private boolean hasAccess; 16 17 private String token; 17 18 private String refreshToken; -
jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/models/users/DTO/RecruiterDetailsDTO.java
r28b3398 rb248810 5 5 import lombok.NoArgsConstructor; 6 6 7 import java.time.LocalDateTime; 8 7 9 @Data 8 10 @AllArgsConstructor 9 11 @NoArgsConstructor 10 12 public class RecruiterDetailsDTO { 13 private Long id; 11 14 private String email; 12 15 private String companyName; 13 16 private String companyDescription; 14 17 private String phoneNumber; 18 private boolean hasAccess; 19 private LocalDateTime registeredOn; 15 20 } -
jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/models/users/User.java
r28b3398 rb248810 11 11 import org.springframework.security.core.userdetails.UserDetails; 12 12 13 import java.time.LocalDateTime; 13 14 import java.util.Collection; 14 15 import java.util.List; … … 32 33 @Enumerated(EnumType.STRING) 33 34 protected Role role; 35 36 @Column(name = "has_access") 37 protected boolean hasAccess; 38 39 protected LocalDateTime registeredOn; 34 40 35 41 -
jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/models/users/mappers/RecruiterMapper.java
r28b3398 rb248810 18 18 public static RecruiterDetailsDTO mapToRecruiterDetailsDTO(Recruiter recruiter) { 19 19 return new RecruiterDetailsDTO( 20 recruiter.getId(), 20 21 recruiter.getEmail(), 21 22 recruiter.getCompanyName(), 22 23 recruiter.getCompanyDescription(), 23 recruiter.getPhoneNumber() 24 recruiter.getPhoneNumber(), 25 recruiter.isHasAccess(), 26 recruiter.getRegisteredOn() 24 27 ); 25 28 } -
jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/service/impl/AuthServiceImpl.java
r28b3398 rb248810 18 18 import org.springframework.stereotype.Service; 19 19 20 import java.time.LocalDateTime; 20 21 import java.util.HashMap; 21 22 … … 34 35 public User signUpJobSeeker(JobSeeker jobSeeker) { 35 36 jobSeeker.setPassword(passwordEncoder.encode(jobSeeker.getPassword())); 37 jobSeeker.setHasAccess(true); 38 jobSeeker.setRegisteredOn(LocalDateTime.now()); 36 39 return jobSeekerRepository.save(jobSeeker); 37 40 } … … 39 42 public User signUpRecruiter(Recruiter recruiter) { 40 43 recruiter.setPassword(passwordEncoder.encode(recruiter.getPassword())); 44 recruiter.setHasAccess(false); 45 recruiter.setRegisteredOn(LocalDateTime.now()); 41 46 return recruiterRepository.save(recruiter); 42 47 } … … 49 54 String refreshJwt = jwtService.generateRefreshToken(new HashMap<>(), user); 50 55 51 return new JwtAuthResponse(user.getId(), user.getEmail(), user.getName(), user.getRole().name(), jwt, refreshJwt);56 return new JwtAuthResponse(user.getId(), user.getEmail(), user.getName(), user.getRole().name(), user.isHasAccess(), jwt, refreshJwt); 52 57 } 53 58 … … 58 63 String jwt = jwtService.generateToken(user); 59 64 60 return new JwtAuthResponse(user.getId(), user.getEmail(), user.getName(), user.getRole().name(), jwt, refreshTokenRequest.getToken());65 return new JwtAuthResponse(user.getId(), user.getEmail(), user.getName(), user.getRole().name(), user.isHasAccess(), jwt, refreshTokenRequest.getToken()); 61 66 } 62 67 return null; -
jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/service/impl/JwtServiceImpl.java
r28b3398 rb248810 6 6 import io.jsonwebtoken.io.Decoders; 7 7 import io.jsonwebtoken.security.Keys; 8 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.User; 8 9 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.service.intef.JwtService; 9 10 import org.springframework.security.core.userdetails.UserDetails; … … 19 20 private final static String SECRET_KEY = "7191b1d33668d4a2316a02f9a40798b77bccd22173bd882c93a0a916a5e921d1"; 20 21 21 public String generateToken(UserDetails userDetails) { 22 return Jwts.builder().setSubject(userDetails.getUsername()) 22 public String generateToken(User user) { 23 return Jwts.builder().setSubject(user.getUsername()) 24 .claim("name", user.getName()) 25 .claim("role", user.getRole()) 26 .claim("access", user.isHasAccess()) 23 27 .setIssuedAt(new Date()) 24 28 .setExpiration(new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 24)) -
jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/service/intef/JwtService.java
r28b3398 rb248810 1 1 package mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.service.intef; 2 2 3 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.User; 3 4 import org.springframework.security.core.userdetails.UserDetails; 4 5 … … 6 7 7 8 public interface JwtService { 8 String generateToken(User Details userDetails);9 String generateToken(User user); 9 10 String generateRefreshToken(Map<String, Object> extraClaims, UserDetails userDetails); 10 11 String extractUsername(String token);
Note:
See TracChangeset
for help on using the changeset viewer.