Changeset 950fa0d for src/main/java/edu
- Timestamp:
- 05/24/23 23:18:47 (18 months ago)
- Branches:
- master
- Children:
- 77205be
- Parents:
- 8bcd64c
- Location:
- src/main/java/edu/gjoko/schedlr
- Files:
-
- 6 added
- 12 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/edu/gjoko/schedlr/config/AppFilter.java
r8bcd64c r950fa0d 10 10 import org.springframework.web.filter.GenericFilterBean; 11 11 12 import javax.servlet.FilterChain; 13 import javax.servlet.ServletException; 14 import javax.servlet.ServletRequest; 15 import javax.servlet.ServletResponse; 12 import javax.servlet.*; 16 13 import javax.servlet.http.HttpServletRequest; 17 14 import javax.servlet.http.HttpServletResponse; … … 75 72 break; 76 73 } 77 if(page != null && !page.trim().isEmpty() ) {74 if(page != null && !page.trim().isEmpty() && !DispatcherType.ERROR.equals(servletRequest.getDispatcherType())) { 78 75 servletRequest.getRequestDispatcher(page).forward(servletRequest, servletResponse); 79 76 return; -
src/main/java/edu/gjoko/schedlr/config/AppSecurityConfig.java
r8bcd64c r950fa0d 10 10 import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 11 11 import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 12 import org.springframework.security.config.core.GrantedAuthorityDefaults;13 12 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 14 import org.springframework.security.web.access.AccessDeniedHandler;15 13 import org.springframework.security.web.authentication.AuthenticationFailureHandler; 16 14 import org.springframework.security.web.authentication.AuthenticationSuccessHandler; 15 import org.springframework.security.web.authentication.logout.HeaderWriterLogoutHandler; 16 import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler; 17 17 import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; 18 import org.springframework.security.web.header.writers.ClearSiteDataHeaderWriter; 19 20 import static org.springframework.security.web.header.writers.ClearSiteDataHeaderWriter.Directive.*; 18 21 19 22 @Configuration … … 21 24 @AllArgsConstructor 22 25 public class AppSecurityConfig extends WebSecurityConfigurerAdapter { 26 27 private static final ClearSiteDataHeaderWriter.Directive[] SOURCE = 28 {CACHE, COOKIES, STORAGE, EXECUTION_CONTEXTS}; 23 29 24 30 private final PostgresUserDetailsService userDetailsService; … … 55 61 .defaultSuccessUrl("/homepage") 56 62 .and() 63 .logout(logout -> logout 64 .logoutUrl("/logout") 65 .logoutSuccessUrl("/login") 66 .addLogoutHandler(new SecurityContextLogoutHandler()) 67 .addLogoutHandler(new HeaderWriterLogoutHandler(new ClearSiteDataHeaderWriter(SOURCE)))) 57 68 .authorizeRequests() 58 69 .antMatchers("/login").permitAll() 70 .antMatchers("/logout").permitAll() 59 71 .antMatchers("/register_customer").permitAll() 60 72 .antMatchers("/register_business").permitAll() 61 73 .antMatchers("/api/nomenclatures/*").permitAll() 74 .antMatchers("/api/user/me").permitAll() 62 75 .antMatchers("/api/business").permitAll() 76 .antMatchers("/api/appointment").permitAll() 63 77 .antMatchers("/homepage").permitAll() 64 78 .antMatchers("/css/**").permitAll() -
src/main/java/edu/gjoko/schedlr/controllers/rest/BusinessController.java
r8bcd64c r950fa0d 2 2 3 3 import edu.gjoko.schedlr.entity.Business; 4 import edu.gjoko.schedlr.entity.BusinessType; 4 5 import edu.gjoko.schedlr.services.BusinessService; 5 6 import lombok.AllArgsConstructor; 6 import org.springframework.security.core.Authentication;7 import org.springframework.security.core.context.SecurityContextHolder;8 7 import org.springframework.web.bind.annotation.*; 9 8 … … 38 37 return businessService.findByOwner(businessOwnerId); 39 38 } 39 40 @GetMapping(path = "/{businessTypeId}") 41 public List<Business> getBusinessesByBusinessType(@PathVariable("businessTypeId") Long id) { 42 BusinessType businessType = new BusinessType(); 43 businessType.setId(id); 44 return businessService.findByBusinessTypeAndActiveStatus(businessType); 45 } 40 46 } -
src/main/java/edu/gjoko/schedlr/controllers/rest/NomenclatureController.java
r8bcd64c r950fa0d 2 2 3 3 import edu.gjoko.schedlr.entity.BusinessType; 4 import edu.gjoko.schedlr.repositories.BusinessTypeRepository;5 4 import edu.gjoko.schedlr.services.NomenclaturesService; 6 5 import lombok.AllArgsConstructor; … … 14 13 @RequestMapping("api/nomenclatures") 15 14 @AllArgsConstructor 16 public class Nomenclature sController {15 public class NomenclatureController { 17 16 18 17 private final NomenclaturesService nomenclaturesService; -
src/main/java/edu/gjoko/schedlr/entity/Appointment.java
r8bcd64c r950fa0d 24 24 private Long id; 25 25 26 @Column(name = "start_t ype")26 @Column(name = "start_time") 27 27 private LocalDateTime startTime; 28 28 … … 30 30 private LocalDateTime endTime; 31 31 32 @Column(name = "price") 33 private Float price; 32 @OneToOne 33 @JoinColumn(name = "customer_id", referencedColumnName = "id") 34 private Stakeholder customer; 35 36 @ManyToOne 37 @JoinColumn(name = "business_id") 38 private Business business; 39 40 @ManyToOne 41 @JoinColumn(name = "service_id") 42 private Service service; 34 43 35 44 @Column(name = "created") -
src/main/java/edu/gjoko/schedlr/entity/Business.java
r8bcd64c r950fa0d 37 37 private BusinessType businessType; 38 38 39 @ManyToOne( cascade = CascadeType.PERSIST)39 @ManyToOne() 40 40 @JoinColumn(name = "owner_id", referencedColumnName = "id", nullable = false) 41 41 @JsonProperty("owner") -
src/main/java/edu/gjoko/schedlr/entity/Service.java
r8bcd64c r950fa0d 33 33 private Integer price; 34 34 35 @OneToOne(cascade = CascadeType. MERGE)35 @OneToOne(cascade = CascadeType.PERSIST) 36 36 @JoinColumn(name = "service_type_id", referencedColumnName = "id") 37 37 private ServiceType serviceType; 38 38 39 39 @ManyToOne 40 @JoinColumn(name = "business_ fk")40 @JoinColumn(name = "business_id") 41 41 @JsonBackReference 42 42 private Business business; -
src/main/java/edu/gjoko/schedlr/entity/ServiceType.java
r8bcd64c r950fa0d 30 30 private String name; 31 31 32 33 32 @ManyToOne 34 33 @JoinColumn(name = "business_type_id") -
src/main/java/edu/gjoko/schedlr/entity/Stakeholder.java
r8bcd64c r950fa0d 43 43 44 44 @Column(name = "password") 45 @JsonIgnore46 45 private String password; 47 46 -
src/main/java/edu/gjoko/schedlr/repositories/BusinessRepository.java
r8bcd64c r950fa0d 3 3 import edu.gjoko.schedlr.entity.Business; 4 4 import edu.gjoko.schedlr.entity.BusinessStatus; 5 import edu.gjoko.schedlr.entity.BusinessType; 5 6 import edu.gjoko.schedlr.entity.Stakeholder; 7 import org.hibernate.Session; 6 8 import org.springframework.data.jpa.repository.JpaRepository; 7 9 import org.springframework.stereotype.Repository; … … 12 14 public interface BusinessRepository extends JpaRepository<Business, Long> { 13 15 14 List<Business> findBusinessesByBusinessStatus(BusinessStatus status);16 Business findBusinessByOwner(Stakeholder owner); 15 17 16 Business findBusinessByOwner(Stakeholder owner);18 List<Business> findBusinessesByBusinessTypeAndBusinessStatus(BusinessType businessType, BusinessStatus businessStatus); 17 19 } -
src/main/java/edu/gjoko/schedlr/services/BusinessService.java
r8bcd64c r950fa0d 1 1 package edu.gjoko.schedlr.services; 2 2 3 import edu.gjoko.schedlr.entity.Business; 4 import edu.gjoko.schedlr.entity.ServiceType; 5 import edu.gjoko.schedlr.entity.Stakeholder; 6 import edu.gjoko.schedlr.entity.StakeholderType; 3 import edu.gjoko.schedlr.entity.*; 7 4 import edu.gjoko.schedlr.repositories.BusinessRepository; 5 import edu.gjoko.schedlr.repositories.ServiceRepository; 8 6 import edu.gjoko.schedlr.repositories.ServiceTypeRepository; 7 import edu.gjoko.schedlr.repositories.StakeholderRepository; 9 8 import lombok.AllArgsConstructor; 10 9 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; … … 13 12 import java.util.List; 14 13 14 import static edu.gjoko.schedlr.entity.BusinessStatus.ACTIVE; 15 15 import static edu.gjoko.schedlr.entity.BusinessStatus.NEW; 16 16 … … 21 21 private final BusinessRepository businessRepository; 22 22 private final ServiceTypeRepository serviceTypeRepository; 23 private final ServiceRepository serviceRepository; 24 25 private final StakeholderRepository stakeholderRepository; 23 26 private BCryptPasswordEncoder bCryptPasswordEncoder; 24 27 … … 51 54 .stream() 52 55 .forEach(business -> { 56 stakeholderRepository.save(business.getOwner()); 57 serviceRepository.saveAll(business.getServices()); 53 58 businessRepository.save(business); 54 59 }); … … 60 65 return businessRepository.findBusinessByOwner(owner); 61 66 } 67 68 public List<Business> findByBusinessTypeAndActiveStatus(BusinessType businessType) { 69 return businessRepository.findBusinessesByBusinessTypeAndBusinessStatus(businessType, ACTIVE); 70 } 62 71 } -
src/main/java/edu/gjoko/schedlr/services/PostgresUserDetailsService.java
r8bcd64c r950fa0d 8 8 import edu.gjoko.schedlr.repositories.StakeholderRepository; 9 9 import lombok.RequiredArgsConstructor; 10 import org.springframework.security.access.AccessDeniedException;11 10 import org.springframework.security.core.GrantedAuthority; 12 11 import org.springframework.security.core.authority.SimpleGrantedAuthority; … … 15 14 import org.springframework.security.core.userdetails.UserDetailsService; 16 15 import org.springframework.security.core.userdetails.UsernameNotFoundException; 17 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;18 16 import org.springframework.stereotype.Service; 19 17 … … 26 24 27 25 private final StakeholderRepository stakeholderRepository; 28 private final BCryptPasswordEncoder bCryptPasswordEncoder;29 30 26 private final BusinessRepository businessRepository; 31 27 … … 33 29 public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 34 30 Stakeholder user = stakeholderRepository.findStakeholderByUsername(username); 35 if (user == null) {31 if (user == null) { 36 32 throw new UsernameNotFoundException("Non existing user"); 37 33 } 38 34 39 if (user.getStakeholderType() == StakeholderType.BUSINESS_OWNER) {35 if (user.getStakeholderType() == StakeholderType.BUSINESS_OWNER) { 40 36 Business business = businessRepository.findBusinessByOwner(user); 41 37 if (business.getBusinessStatus() != BusinessStatus.ACTIVE) { -
src/main/java/edu/gjoko/schedlr/services/StakeholderService.java
r8bcd64c r950fa0d 24 24 return stakeholderRepository.save(stakeholder); 25 25 } 26 27 public Stakeholder findById(Long id) { 28 return stakeholderRepository.findById(id).get(); 29 } 26 30 }
Note:
See TracChangeset
for help on using the changeset viewer.