Changes in / [80ddcae:0c049e9]
- Location:
- sources/app/src/main/java/parkup
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sources/app/src/main/java/parkup/ParkUpApplication.java
r80ddcae r0c049e9 3 3 import org.springframework.boot.SpringApplication; 4 4 import org.springframework.boot.autoconfigure.SpringBootApplication; 5 import org.springframework.context.annotation.Bean; 6 import org.springframework.security.core.Authentication; 7 import org.springframework.security.core.context.SecurityContextHolder; 5 8 6 9 @SpringBootApplication … … 12 15 SpringApplication.run(ParkUpApplication.class, args); 13 16 } 17 18 @Bean 19 public static Authentication getToken() { 20 Authentication token = null; 21 Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); 22 if (authentication != null && !authentication.getAuthorities().stream().findFirst().get().getAuthority().equals("ROLE_ANONYMOUS")) { 23 token = authentication; 24 } 25 return token; 26 } 14 27 } -
sources/app/src/main/java/parkup/services/ParkingZoneService.java
r80ddcae r0c049e9 2 2 3 3 import org.springframework.beans.factory.annotation.Autowired; 4 import org.springframework.security.core.Authentication; 4 5 import org.springframework.stereotype.Service; 6 import parkup.ParkUpApplication; 5 7 import parkup.data.ParkingZoneAdminView; 6 8 import parkup.data.ParkingZoneLocation; … … 13 15 import parkup.repositories.ParkingZoneRepository; 14 16 import parkup.repositories.WorkerRepository; 15 17 import static parkup.ParkUpApplication.getToken; 16 18 import javax.transaction.Transactional; 17 19 import java.util.ArrayList; … … 37 39 38 40 public List<ParkingZone> getAllParkingZones() { 39 List<ParkingZone> parkingZones= parkingZoneRepository.findAll(); 41 Authentication user = getToken(); 42 String role =user.getAuthorities().stream().findFirst().get().getAuthority(); 43 String email = user.getName(); 44 List<ParkingZone> parkingZones; 45 if(role.equals("ROLE_REG_USER")) 46 parkingZones= parkingZoneRepository.findAll(); 47 else if(role.equals("ROLE_WORKER")){ 48 Worker loggedInWorker = workerRepository.findWorkerByEmail(email).orElseThrow(null); 49 parkingZones= parkingZoneRepository.findAll().stream().filter(pz->loggedInWorker.getParkingZones().contains(pz)).collect(Collectors.toList()); 50 }else if(role.equals("ROLE_ADMIN")) 51 parkingZones= parkingZoneRepository.findAll(); 52 else 53 parkingZones=parkingZoneRepository.findAll(); 40 54 for(ParkingZone pz:parkingZones){ 41 55 setTransientVariables(pz);
Note:
See TracChangeset
for help on using the changeset viewer.