Changes in / [0c049e9:80ddcae]
- Location:
- sources/app/src/main/java/parkup
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sources/app/src/main/java/parkup/ParkUpApplication.java
r0c049e9 r80ddcae 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;8 5 9 6 @SpringBootApplication … … 15 12 SpringApplication.run(ParkUpApplication.class, args); 16 13 } 17 18 @Bean19 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 }27 14 } -
sources/app/src/main/java/parkup/services/ParkingZoneService.java
r0c049e9 r80ddcae 2 2 3 3 import org.springframework.beans.factory.annotation.Autowired; 4 import org.springframework.security.core.Authentication;5 4 import org.springframework.stereotype.Service; 6 import parkup.ParkUpApplication;7 5 import parkup.data.ParkingZoneAdminView; 8 6 import parkup.data.ParkingZoneLocation; … … 15 13 import parkup.repositories.ParkingZoneRepository; 16 14 import parkup.repositories.WorkerRepository; 17 import static parkup.ParkUpApplication.getToken; 15 18 16 import javax.transaction.Transactional; 19 17 import java.util.ArrayList; … … 39 37 40 38 public List<ParkingZone> getAllParkingZones() { 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(); 39 List<ParkingZone> parkingZones= parkingZoneRepository.findAll(); 54 40 for(ParkingZone pz:parkingZones){ 55 41 setTransientVariables(pz);
Note:
See TracChangeset
for help on using the changeset viewer.