Changeset b248810 for jobvista-backend


Ignore:
Timestamp:
06/10/24 22:34:32 (5 months ago)
Author:
223021 <daniel.ilievski.2@…>
Branches:
main
Children:
befb988
Parents:
28b3398
Message:

Added no access page for new recruiters and admin panel for granting access

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  
    2626                        admin.setRole(Role.ROLE_ADMIN);
    2727                        admin.setEmail("admin@admin.com");
     28                        admin.setHasAccess(true);
    2829//                      admin.setName("admin");
    2930//                      admin.setSurname("admin");
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/config/SecurityConfiguration.java

    r28b3398 rb248810  
    3232                        // TO DO: FIX PERMISSIONS
    3333                        .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()
    3535                        //.requestMatchers("/api/job-advertisements/**").hasAnyAuthority(Role.ROLE_RECRUITER.name())
    3636                        .anyRequest().authenticated())
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/controllers/AdminController.java

    r28b3398 rb248810  
    22
    33import lombok.RequiredArgsConstructor;
    4 import org.springframework.web.bind.annotation.RequestMapping;
    5 import org.springframework.web.bind.annotation.RestController;
     4import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.DTO.RecruiterDetailsDTO;
     5import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.service.intef.AdminService;
     6import org.springframework.http.HttpStatus;
     7import org.springframework.http.ResponseEntity;
     8import org.springframework.web.bind.annotation.*;
     9
     10import java.util.List;
    611
    712@RestController
    813@RequestMapping("/api/admin")
    914@RequiredArgsConstructor
     15@CrossOrigin(origins = "*")
    1016public class AdminController {
    1117
     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    }
    1231}
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/models/users/DTO/JwtAuthResponse.java

    r28b3398 rb248810  
    1414    private String name;
    1515    private String role;
     16    private boolean hasAccess;
    1617    private String token;
    1718    private String refreshToken;
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/models/users/DTO/RecruiterDetailsDTO.java

    r28b3398 rb248810  
    55import lombok.NoArgsConstructor;
    66
     7import java.time.LocalDateTime;
     8
    79@Data
    810@AllArgsConstructor
    911@NoArgsConstructor
    1012public class RecruiterDetailsDTO {
     13    private Long id;
    1114    private String email;
    1215    private String companyName;
    1316    private String companyDescription;
    1417    private String phoneNumber;
     18    private boolean hasAccess;
     19    private LocalDateTime registeredOn;
    1520}
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/models/users/User.java

    r28b3398 rb248810  
    1111import org.springframework.security.core.userdetails.UserDetails;
    1212
     13import java.time.LocalDateTime;
    1314import java.util.Collection;
    1415import java.util.List;
     
    3233    @Enumerated(EnumType.STRING)
    3334    protected Role role;
     35
     36    @Column(name = "has_access")
     37    protected boolean hasAccess;
     38
     39    protected LocalDateTime registeredOn;
    3440
    3541
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/models/users/mappers/RecruiterMapper.java

    r28b3398 rb248810  
    1818    public static RecruiterDetailsDTO mapToRecruiterDetailsDTO(Recruiter recruiter) {
    1919        return new RecruiterDetailsDTO(
     20                recruiter.getId(),
    2021                recruiter.getEmail(),
    2122                recruiter.getCompanyName(),
    2223                recruiter.getCompanyDescription(),
    23                 recruiter.getPhoneNumber()
     24                recruiter.getPhoneNumber(),
     25                recruiter.isHasAccess(),
     26                recruiter.getRegisteredOn()
    2427        );
    2528    }
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/service/impl/AuthServiceImpl.java

    r28b3398 rb248810  
    1818import org.springframework.stereotype.Service;
    1919
     20import java.time.LocalDateTime;
    2021import java.util.HashMap;
    2122
     
    3435    public User signUpJobSeeker(JobSeeker jobSeeker) {
    3536        jobSeeker.setPassword(passwordEncoder.encode(jobSeeker.getPassword()));
     37        jobSeeker.setHasAccess(true);
     38        jobSeeker.setRegisteredOn(LocalDateTime.now());
    3639        return jobSeekerRepository.save(jobSeeker);
    3740    }
     
    3942    public User signUpRecruiter(Recruiter recruiter) {
    4043        recruiter.setPassword(passwordEncoder.encode(recruiter.getPassword()));
     44        recruiter.setHasAccess(false);
     45        recruiter.setRegisteredOn(LocalDateTime.now());
    4146        return recruiterRepository.save(recruiter);
    4247    }
     
    4954        String refreshJwt = jwtService.generateRefreshToken(new HashMap<>(), user);
    5055
    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);
    5257    }
    5358   
     
    5863            String jwt = jwtService.generateToken(user);
    5964
    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());
    6166        }
    6267        return null;
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/service/impl/JwtServiceImpl.java

    r28b3398 rb248810  
    66import io.jsonwebtoken.io.Decoders;
    77import io.jsonwebtoken.security.Keys;
     8import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.User;
    89import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.service.intef.JwtService;
    910import org.springframework.security.core.userdetails.UserDetails;
     
    1920    private final static String SECRET_KEY = "7191b1d33668d4a2316a02f9a40798b77bccd22173bd882c93a0a916a5e921d1";
    2021
    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())
    2327                .setIssuedAt(new Date())
    2428                .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  
    11package mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.service.intef;
    22
     3import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.User;
    34import org.springframework.security.core.userdetails.UserDetails;
    45
     
    67
    78public interface JwtService {
    8     String generateToken(UserDetails userDetails);
     9    String generateToken(User user);
    910    String generateRefreshToken(Map<String, Object> extraClaims, UserDetails userDetails);
    1011    String extractUsername(String token);
Note: See TracChangeset for help on using the changeset viewer.