From: elgekko Date: Sun, 2 Jul 2023 23:14:01 +0000 (+0200) Subject: Plenty of bugs fixed X-Git-Url: http://git.useribm.hu/?a=commitdiff_plain;h=6bc7aaa5fc33ac5a70538e6df143bd00caa775f4;p=sly-crm.git Plenty of bugs fixed --- diff --git a/KB.md b/KB.md index 7668341..4aa1b8f 100644 --- a/KB.md +++ b/KB.md @@ -58,6 +58,8 @@ https://www.zkoss.org/documentation#References https://www.zkoss.org/wiki/ZK_Spring_Essentials/Working_with_ZK_Spring/Working_with_ZK_Spring_Security/Secure_a_ZK_Application_with_Spring_Security https://www.zkoss.org/wiki/ZK_Spring_Essentials/Working_with_ZK_Spring/Working_with_ZK_Spring_Security/Add_Security_in_the_View_Layer (To enable remove @SpringBootApplication with exludes and @ComponentScan) +https://www.baeldung.com/get-user-in-spring-security +https://www.baeldung.com/spring-security-authentication-provider ##### ZK Style diff --git a/lis-app/pom.xml b/lis-app/pom.xml index 7935481..e64e7d2 100644 --- a/lis-app/pom.xml +++ b/lis-app/pom.xml @@ -2,9 +2,8 @@ 4.0.0 - hu.user lis-app - 0.1.1-SNAPSHOT + 0.1.2-SNAPSHOT hu.user lis diff --git a/lis-app/src/main/resources/application.yaml b/lis-app/src/main/resources/application.yaml index 4f0ccb0..3f2d8e4 100644 --- a/lis-app/src/main/resources/application.yaml +++ b/lis-app/src/main/resources/application.yaml @@ -9,7 +9,7 @@ spring: jpa: hibernate: use-new-id-generator-mappings: false - show-sql: false + show-sql: true properties: hibernate: format_sql: true @@ -24,7 +24,8 @@ spring: logging: level: org.hibernate.engine.jdbc.spi.SqlExceptionHelper: ERROR - org.springframework.security.web: DEBUG + org.springframework.security: DEBUG + org.springframework.security.web: INFO # pattern: # console: "%d %-5level %logger : %msg%n" # file: "%d %-5level [%thread] %logger : %msg%n" \ No newline at end of file diff --git a/lis-app/src/test/java/hu/user/lis/AssociatesDataModelIT.java b/lis-app/src/test/java/hu/user/lis/AssociatesDataModelIT.java new file mode 100644 index 0000000..7617378 --- /dev/null +++ b/lis-app/src/test/java/hu/user/lis/AssociatesDataModelIT.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) $today.year-$today.month-24. + * By elGekko + */ + +package hu.user.lis; + +import hu.user.lis.ui.data.AssociatesDataModel; +import lombok.extern.log4j.Log4j2; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.junit4.SpringRunner; + + +@Log4j2 +@RunWith(SpringRunner.class) +@ComponentScan("hu.user.lis") +@SpringBootTest +//@TestPropertySource("classpath:application.yaml") +//@AutoConfigureMockMvc +public class AssociatesDataModelIT { + @Autowired + private AssociatesDataModel associatesDataModel; + + @Test + public void testRepositoryCapabilities() { + associatesDataModel.search("lé"); + log.info("Found {} items", associatesDataModel.getResultSetCount()); + associatesDataModel.getResultSet(0, 10, null) + .forEach(c -> log.info("{}", c.getName())); + } + +} diff --git a/lis-app/src/test/java/hu/user/lis/ITRepository.java b/lis-app/src/test/java/hu/user/lis/RepositoryIT.java similarity index 98% rename from lis-app/src/test/java/hu/user/lis/ITRepository.java rename to lis-app/src/test/java/hu/user/lis/RepositoryIT.java index b45fb5b..af2701c 100644 --- a/lis-app/src/test/java/hu/user/lis/ITRepository.java +++ b/lis-app/src/test/java/hu/user/lis/RepositoryIT.java @@ -24,7 +24,7 @@ import java.util.List; @SpringBootTest //@TestPropertySource("classpath:application.yaml") //@AutoConfigureMockMvc -public class ITRepository { +public class RepositoryIT { @Autowired private ServiceRecordRepository serviceRecordRepository; diff --git a/lis-db/migrations/scripts/003_add_remotely_authenticated_to_associate.sql b/lis-db/migrations/scripts/003_add_remotely_authenticated_to_associate.sql new file mode 100644 index 0000000..bd50d37 --- /dev/null +++ b/lis-db/migrations/scripts/003_add_remotely_authenticated_to_associate.sql @@ -0,0 +1,12 @@ +-- // add_remotely_authenticated_to_associate +-- Migration SQL that makes the change goes here. + +ALTER TABLE associate + ADD COLUMN remotely_authenticated SMALLINT NOT NULL DEFAULT 0; + +-- //@UNDO +-- SQL to undo the change goes here. + +ALTER TABLE associate + DROP COLUMN remotely_authenticated; + diff --git a/lis-db/pom.xml b/lis-db/pom.xml index 24a52da..15486c6 100644 --- a/lis-db/pom.xml +++ b/lis-db/pom.xml @@ -4,7 +4,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"> 4.0.0 - hu.user lis-db hu.user diff --git a/lis-db/src/main/java/hu/user/lis/db/Associate.java b/lis-db/src/main/java/hu/user/lis/db/Associate.java index d2cbcc6..6561526 100644 --- a/lis-db/src/main/java/hu/user/lis/db/Associate.java +++ b/lis-db/src/main/java/hu/user/lis/db/Associate.java @@ -22,4 +22,5 @@ public class Associate { String password; double monthlyCost; boolean active; + boolean remotelyAuthenticated; } diff --git a/lis-db/src/main/java/hu/user/lis/db/repository/AssociateRepository.java b/lis-db/src/main/java/hu/user/lis/db/repository/AssociateRepository.java index 380e10b..5716df0 100644 --- a/lis-db/src/main/java/hu/user/lis/db/repository/AssociateRepository.java +++ b/lis-db/src/main/java/hu/user/lis/db/repository/AssociateRepository.java @@ -4,5 +4,7 @@ import hu.user.lis.db.Associate; import org.springframework.data.jpa.repository.JpaRepository; public interface AssociateRepository extends JpaRepository, AssociateRepositorySearch { + Associate findByLoginAndPassword(String login, String password); + Associate findByLogin(String login); } diff --git a/lis-db/src/main/java/hu/user/lis/db/repository/AssociateRepositorySearchImpl.java b/lis-db/src/main/java/hu/user/lis/db/repository/AssociateRepositorySearchImpl.java index 783055b..1cafe75 100644 --- a/lis-db/src/main/java/hu/user/lis/db/repository/AssociateRepositorySearchImpl.java +++ b/lis-db/src/main/java/hu/user/lis/db/repository/AssociateRepositorySearchImpl.java @@ -34,26 +34,14 @@ public class AssociateRepositorySearchImpl implements AssociateRepositorySearch return predicates.toArray(new Predicate[]{}); } -// Predicate[] getPredicates(CriteriaBuilder cb, Root root, String partialName, boolean filterShowActive) { -// List predicates = new ArrayList<>(); -// if (StringUtils.isNotBlank(partialName)) { -// predicates.add(cb.like(root.get("name"), "%" + partialName + "%")); -// } -// if (filterShowActive) { -// predicates.add(cb.isTrue(root.get("active"))); -// } else { -// predicates.add(cb.isFalse(root.get("active"))); -// } -// return predicates.toArray(new Predicate[]{}); -// } - @Override public List search(String partialName, boolean filterShowActive, boolean filterShowInActive, Pageable pageable) { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(Associate.class); Root root = cq.from(Associate.class); - TypedQuery query = entityManager.createQuery(cq); + cq.where(getPredicates(cb, root, partialName, filterShowActive, filterShowInActive)); + TypedQuery query = entityManager.createQuery(cq); query.setMaxResults(pageable.getPageSize()); query.setFirstResult(pageable.getPageSize() * pageable.getPageNumber()); return query.getResultList(); @@ -64,30 +52,10 @@ public class AssociateRepositorySearchImpl implements AssociateRepositorySearch CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(Long.class); Root root = cq.from(Associate.class); + cq.select(cb.count(root)); cq.where(getPredicates(cb, root, partialName, filterShowActive, filterShowInActive)); return entityManager.createQuery(cq).getSingleResult(); } -// @Override -// public List search(String partialName, boolean filterShowActive, Pageable pageable) { -// CriteriaBuilder cb = entityManager.getCriteriaBuilder(); -// CriteriaQuery cq = cb.createQuery(Associate.class); -// Root root = cq.from(Associate.class); -// TypedQuery query = entityManager.createQuery(cq); -// cq.where(getPredicates(cb, root, partialName, filterShowActive)); -// query.setMaxResults(pageable.getPageSize()); -// query.setFirstResult(pageable.getPageSize() * pageable.getPageNumber()); -// return query.getResultList(); -// } -// -// @Override -// public long count(String partialName, boolean filterShowActive) { -// CriteriaBuilder cb = entityManager.getCriteriaBuilder(); -// CriteriaQuery cq = cb.createQuery(Long.class); -// Root root = cq.from(Associate.class); -// cq.select(cb.count(root)); -// cq.where(getPredicates(cb, root, partialName, filterShowActive)); -// return entityManager.createQuery(cq).getSingleResult(); -// } } diff --git a/lis-db/src/main/java/hu/user/lis/db/repository/PartnerRepositorySearchImpl.java b/lis-db/src/main/java/hu/user/lis/db/repository/PartnerRepositorySearchImpl.java index adf75db..7266539 100644 --- a/lis-db/src/main/java/hu/user/lis/db/repository/PartnerRepositorySearchImpl.java +++ b/lis-db/src/main/java/hu/user/lis/db/repository/PartnerRepositorySearchImpl.java @@ -63,6 +63,7 @@ public class PartnerRepositorySearchImpl implements PartnerRepositorySearch { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(Partner.class); Root root = cq.from(Partner.class); + cq.where(getPredicates(cb, root, partialName, partialVatNr, partialAddress, filterShowActive, filterShowInActive)); TypedQuery query = entityManager.createQuery(cq); query.setMaxResults(pageable.getPageSize()); @@ -75,6 +76,7 @@ public class PartnerRepositorySearchImpl implements PartnerRepositorySearch { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(Long.class); Root root = cq.from(Partner.class); + cq.select(cb.count(root)); cq.where(getPredicates(cb, root, partialName, partialVatNr, partialAddress, filterShowActive, filterShowInActive)); return entityManager.createQuery(cq).getSingleResult(); diff --git a/lis-db/src/main/java/hu/user/lis/db/repository/ProjectAssociateRepository.java b/lis-db/src/main/java/hu/user/lis/db/repository/ProjectAssociateRepository.java index ad74956..721c76c 100644 --- a/lis-db/src/main/java/hu/user/lis/db/repository/ProjectAssociateRepository.java +++ b/lis-db/src/main/java/hu/user/lis/db/repository/ProjectAssociateRepository.java @@ -1,7 +1,13 @@ package hu.user.lis.db.repository; import hu.user.lis.db.ProjectAssociate; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; public interface ProjectAssociateRepository extends JpaRepository { + Page findAllByProjectId(Long projectId, Pageable pageable); + + Long countByProjectId(Long projectId); + } diff --git a/lis-db/src/main/java/hu/user/lis/db/repository/ProjectRepositorySearch.java b/lis-db/src/main/java/hu/user/lis/db/repository/ProjectRepositorySearch.java index c6c5420..b39dfe2 100644 --- a/lis-db/src/main/java/hu/user/lis/db/repository/ProjectRepositorySearch.java +++ b/lis-db/src/main/java/hu/user/lis/db/repository/ProjectRepositorySearch.java @@ -6,8 +6,8 @@ import org.springframework.data.domain.Pageable; import java.util.List; public interface ProjectRepositorySearch { - List search(String partialName, boolean filterShowActive, boolean filterShowInActive, Pageable pageable); + List search(String partialSearch, boolean filterShowActive, boolean filterShowInActive, Pageable pageable); - long count(String partialName, boolean filterShowActive, boolean filterShowInActive); + long count(String partialSearch, boolean filterShowActive, boolean filterShowInActive); } diff --git a/lis-db/src/main/java/hu/user/lis/db/repository/ProjectRepositorySearchImpl.java b/lis-db/src/main/java/hu/user/lis/db/repository/ProjectRepositorySearchImpl.java index 3cf5311..6d7a4ef 100644 --- a/lis-db/src/main/java/hu/user/lis/db/repository/ProjectRepositorySearchImpl.java +++ b/lis-db/src/main/java/hu/user/lis/db/repository/ProjectRepositorySearchImpl.java @@ -20,13 +20,13 @@ public class ProjectRepositorySearchImpl implements ProjectRepositorySearch { @PersistenceContext EntityManager entityManager; - Predicate[] getPredicates(CriteriaBuilder cb, Root root, String partialName, boolean filterShowActive, boolean filterShowInActive) { + Predicate[] getPredicates(CriteriaBuilder cb, Root root, String partialSearch, boolean filterShowActive, boolean filterShowInActive) { List predicates = new ArrayList<>(); - if (StringUtils.isNotBlank(partialName)) { + if (StringUtils.isNotBlank(partialSearch)) { List orPredicates = new ArrayList<>(); - orPredicates.add(cb.like(cb.lower(root.get("name")), "%" + partialName.toLowerCase() + "%")); - orPredicates.add(cb.like(cb.lower(root.get("humanId")), "%" + partialName.toLowerCase() + "%")); - orPredicates.add(cb.like(cb.lower(root.join("partner").get("name")), "%" + partialName.toLowerCase() + "%")); + orPredicates.add(cb.like(cb.lower(root.get("name")), "%" + partialSearch.toLowerCase() + "%")); + orPredicates.add(cb.like(cb.lower(root.get("humanId")), "%" + partialSearch.toLowerCase() + "%")); + orPredicates.add(cb.like(cb.lower(root.join("partner").get("name")), "%" + partialSearch.toLowerCase() + "%")); predicates.add(cb.or(orPredicates.toArray(new Predicate[]{}))); } @@ -40,24 +40,26 @@ public class ProjectRepositorySearchImpl implements ProjectRepositorySearch { } @Override - public List search(String partialName, boolean filterShowActive, boolean filterShowInActive, Pageable pageable) { + public List search(String partialSearch, boolean filterShowActive, boolean filterShowInActive, Pageable pageable) { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(Project.class); Root root = cq.from(Project.class); + + cq.where(getPredicates(cb, root, partialSearch, filterShowActive, filterShowInActive)); TypedQuery query = entityManager.createQuery(cq); - cq.where(getPredicates(cb, root, partialName, filterShowActive, filterShowInActive)); query.setMaxResults(pageable.getPageSize()); query.setFirstResult(pageable.getPageSize() * pageable.getPageNumber()); return query.getResultList(); } @Override - public long count(String partialName, boolean filterShowActive, boolean filterShowInActive) { + public long count(String partialSearch, boolean filterShowActive, boolean filterShowInActive) { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(Long.class); Root root = cq.from(Project.class); + cq.select(cb.count(root)); - cq.where(getPredicates(cb, root, partialName, filterShowActive, filterShowInActive)); + cq.where(getPredicates(cb, root, partialSearch, filterShowActive, filterShowInActive)); return entityManager.createQuery(cq).getSingleResult(); } } diff --git a/lis-db/src/main/java/hu/user/lis/db/repository/ServiceRecordRepositorySearchImpl.java b/lis-db/src/main/java/hu/user/lis/db/repository/ServiceRecordRepositorySearchImpl.java index 4b5f7a0..8d89ebe 100644 --- a/lis-db/src/main/java/hu/user/lis/db/repository/ServiceRecordRepositorySearchImpl.java +++ b/lis-db/src/main/java/hu/user/lis/db/repository/ServiceRecordRepositorySearchImpl.java @@ -34,6 +34,7 @@ public class ServiceRecordRepositorySearchImpl implements ServiceRecordRepositor CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(ServiceRecord.class); Root root = cq.from(ServiceRecord.class); + cq.where(getPredicates(cb, root, filterProjectId, filterAssociateId)); TypedQuery query = entityManager.createQuery(cq); query.setMaxResults(pageable.getPageSize()); @@ -46,6 +47,7 @@ public class ServiceRecordRepositorySearchImpl implements ServiceRecordRepositor CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(Long.class); Root root = cq.from(ServiceRecord.class); + cq.select(cb.count(root)); cq.where(getPredicates(cb, root, filterProjectId, filterAssociateId)); return entityManager.createQuery(cq).getSingleResult(); diff --git a/lis-services/pom.xml b/lis-services/pom.xml index a22a4f6..d7a3958 100644 --- a/lis-services/pom.xml +++ b/lis-services/pom.xml @@ -2,7 +2,6 @@ 4.0.0 - hu.user lis-services hu.user diff --git a/lis-ui/pom.xml b/lis-ui/pom.xml index 3d2a7e1..91ebb28 100644 --- a/lis-ui/pom.xml +++ b/lis-ui/pom.xml @@ -3,7 +3,6 @@ xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - hu.user lis-ui hu.user @@ -30,6 +29,14 @@ org.springframework.boot spring-boot-starter-security + + org.springframework.security + spring-security-ldap + + + org.springframework.ldap + spring-ldap-core + org.javassist javassist diff --git a/lis-ui/src/main/java/hu/user/lis/ui/auth/CurrentProfile.java b/lis-ui/src/main/java/hu/user/lis/ui/auth/CurrentProfile.java new file mode 100644 index 0000000..a8700fe --- /dev/null +++ b/lis-ui/src/main/java/hu/user/lis/ui/auth/CurrentProfile.java @@ -0,0 +1,16 @@ +package hu.user.lis.ui.auth; + +import hu.user.lis.db.Associate; +import lombok.Getter; +import lombok.Setter; +import org.springframework.stereotype.Service; + +@Service +@Getter +@Setter +public class CurrentProfile { + + private Associate associate; + + +} diff --git a/lis-ui/src/main/java/hu/user/lis/ui/auth/Guard.java b/lis-ui/src/main/java/hu/user/lis/ui/auth/Guard.java new file mode 100644 index 0000000..4dbac67 --- /dev/null +++ b/lis-ui/src/main/java/hu/user/lis/ui/auth/Guard.java @@ -0,0 +1,25 @@ +package hu.user.lis.ui.auth; + +import lombok.extern.log4j.Log4j2; +import org.springframework.security.authentication.AnonymousAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.zkoss.zk.ui.Executions; +import org.zkoss.zk.ui.Page; +import org.zkoss.zk.ui.util.Initiator; + +import java.util.Map; + +@Log4j2 +public class Guard implements Initiator { + @Override + public void doInit(Page page, Map args) throws Exception { + //HttpServletRequest request = (HttpServletRequest) Executions.getCurrent().getNativeRequest(); + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + + if (authentication == null || authentication instanceof AnonymousAuthenticationToken) { + Executions.sendRedirect("/login"); + } + } + +} \ No newline at end of file diff --git a/lis-ui/src/main/java/hu/user/lis/ui/auth/LdapUserDetailsContextMapper.java b/lis-ui/src/main/java/hu/user/lis/ui/auth/LdapUserDetailsContextMapper.java new file mode 100644 index 0000000..2cb9dfe --- /dev/null +++ b/lis-ui/src/main/java/hu/user/lis/ui/auth/LdapUserDetailsContextMapper.java @@ -0,0 +1,54 @@ +package hu.user.lis.ui.auth; + +import hu.user.lis.db.Associate; +import hu.user.lis.db.repository.AssociateRepository; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.ldap.core.DirContextOperations; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.ldap.userdetails.LdapUserDetailsImpl; +import org.springframework.security.ldap.userdetails.LdapUserDetailsMapper; +import org.springframework.security.ldap.userdetails.UserDetailsContextMapper; +import org.springframework.stereotype.Service; + +import java.util.Collection; +import java.util.Objects; + +@Service +@Log4j2 +public class LdapUserDetailsContextMapper extends LdapUserDetailsMapper implements UserDetailsContextMapper { + @Autowired + AssociateRepository associateRepository; + + @Autowired + CurrentProfile currentProfile; + + @Override + public UserDetails mapUserFromContext(DirContextOperations ctx, String username, Collection authorities) { + LdapUserDetailsImpl ldapUserDetailsImpl = (LdapUserDetailsImpl) super.mapUserFromContext(ctx, username, authorities); +// String dn = ldapDetails.getDn(); +// int beginIndex = dn.indexOf("cn=") + 3; +// int endIndex = dn.indexOf(","); +// String username = dn.substring(beginIndex, endIndex); +// myUserDetails.setAccountNonExpired(ldapUserDetailsImpl.isAccountNonExpired()); +// myUserDetails.setAccountNonLocked(ldapUserDetailsImpl.isAccountNonLocked()); +// myUserDetails.setCredentialsNonExpired(ldapUserDetailsImpl.isCredentialsNonExpired()); +// myUserDetails.setEnabled(ldapUserDetailsImpl.isEnabled()); +// myUserDetails.setAuthorities(ldapUserDetailsImpl.getAuthorities()); +// myUserDetails.setUsername(); + Associate associate = associateRepository.findByLogin(ldapUserDetailsImpl.getUsername()); + if (Objects.isNull(associate)) { + associate = Associate.builder() + .login(ldapUserDetailsImpl.getUsername()) + .name(ctx.getObjectAttribute("displayname").toString()) + .active(true) + .remotelyAuthenticated(true) + .build(); +// ctx.getObjectAttribute("mail") + associateRepository.save(associate); + } + currentProfile.setAssociate(associate); + return ldapUserDetailsImpl; + } +} \ No newline at end of file diff --git a/lis-ui/src/main/java/hu/user/lis/ui/auth/LocalAuthProvider.java b/lis-ui/src/main/java/hu/user/lis/ui/auth/LocalAuthProvider.java new file mode 100644 index 0000000..7aa5944 --- /dev/null +++ b/lis-ui/src/main/java/hu/user/lis/ui/auth/LocalAuthProvider.java @@ -0,0 +1,48 @@ +package hu.user.lis.ui.auth; + +import hu.user.lis.db.Associate; +import hu.user.lis.db.repository.AssociateRepository; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.authentication.AuthenticationProvider; +import org.springframework.security.authentication.BadCredentialsException; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.AuthenticationException; +import org.springframework.stereotype.Component; + +import java.util.Arrays; +import java.util.Objects; + +@Component +public class LocalAuthProvider implements AuthenticationProvider { + @Autowired + AssociateRepository associateRepository; + + @Autowired + CurrentProfile currentProfile; + + @Override + public Authentication authenticate(Authentication authentication) throws AuthenticationException { + UsernamePasswordAuthenticationToken result; + String name = authentication.getName(); + String password = authentication.getCredentials().toString(); + + Associate associate = null; + if (StringUtils.isNotBlank(password)) { + associate = associateRepository.findByLoginAndPassword(name, password); + } + if (Objects.nonNull(associate)) { + result = new UsernamePasswordAuthenticationToken(name, password, Arrays.asList()); + currentProfile.setAssociate(associate); + } else { + throw new BadCredentialsException("Local authentication failed!"); + } + return result; + } + + @Override + public boolean supports(Class authentication) { + return authentication.equals(UsernamePasswordAuthenticationToken.class); + } +} diff --git a/lis-ui/src/main/java/hu/user/lis/ui/config/WebSecurityConfig.java b/lis-ui/src/main/java/hu/user/lis/ui/config/WebSecurityConfig.java index 0dc146f..bde12a7 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/config/WebSecurityConfig.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/config/WebSecurityConfig.java @@ -1,29 +1,32 @@ package hu.user.lis.ui.config; -import org.springframework.context.annotation.Bean; +import hu.user.lis.ui.auth.LdapUserDetailsContextMapper; +import hu.user.lis.ui.auth.LocalAuthProvider; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.core.userdetails.User; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.provisioning.InMemoryUserDetailsManager; import static hu.user.lis.ui.view.IndexViewModel.NAVIGATION; -/** - * This is an example of minimal configuration for ZK + Spring Security, we open as less access as possible to run a ZK-based application. - * Please understand the configuration and modify it upon your requirement. - */ @Configuration @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { + public static final String ZUL_FILES = "/zkau/web/**/*.zul"; + public static final String[] ZK_RESOURCES = {"/zkau/web/**/js/**", "/zkau/web/**/zul/css/**", "/zkau/web/**/img/**"}; + // allow desktop cleanup after logout or when reloading login page public static final String REMOVE_DESKTOP_REGEX = "/zkau\\?dtid=.*&cmd_0=rmDesktop&.*"; + @Autowired + LocalAuthProvider localAuthProvider; + + @Autowired + LdapUserDetailsContextMapper ldapUserDetailsContextMapper; @Override protected void configure(HttpSecurity http) throws Exception { @@ -35,7 +38,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { .regexMatchers(HttpMethod.GET, REMOVE_DESKTOP_REGEX).permitAll() // allow desktop cleanup .requestMatchers(req -> "rmDesktop".equals(req.getParameter("cmd_0"))).permitAll() // allow desktop cleanup from ZATS .mvcMatchers("/", "/login", "/logout").permitAll() - .mvcMatchers(navigation).hasRole("USER") + //mvcMatchers(navigation).hasRole("USER") .anyRequest().authenticated() .and() .formLogin() @@ -44,16 +47,20 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { .logout().logoutUrl("/logout").logoutSuccessUrl("/"); } - @Bean - @Override - public UserDetailsService userDetailsService() { - UserDetails user = - User.withDefaultPasswordEncoder() - .username("user") - .password("password") - .roles("USER") - .build(); - - return new InMemoryUserDetailsManager(user); + @Autowired + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + auth.ldapAuthentication() + .userDnPatterns("uid={0},ou=people") + .groupSearchBase("ou=groups") + .userDetailsContextMapper(ldapUserDetailsContextMapper) + .contextSource() +// .url("ldap://fds.in.useribm.hu:389/dc=user,dc=hu") + .url("ldaps://fds.useribm.hu:636/dc=user,dc=hu") +// .and() +// .passwordCompare() +// .passwordEncoder(new BCryptPasswordEncoder()) +// .passwordAttribute("userPassword") + ; + auth.authenticationProvider(localAuthProvider); } } \ No newline at end of file diff --git a/lis-ui/src/main/java/hu/user/lis/ui/data/AssociateSelectorDataModel.java b/lis-ui/src/main/java/hu/user/lis/ui/data/AssociateSelectorDataModel.java index 46ae165..608c434 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/data/AssociateSelectorDataModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/data/AssociateSelectorDataModel.java @@ -23,15 +23,10 @@ public class AssociateSelectorDataModel extends CachedSpringDataModel private String partialName; @Override - protected List getResultSet(int page, int pageSize, FieldComparator sortComparator) { + public List getResultSet(int page, int pageSize, FieldComparator sortComparator) { Pageable pageable = createPageable(0, SEARCH_LIMIT, null); List result = StringUtils.isBlank(partialName) ? associateRepository.findAll(pageable).toList() : associateRepository.search(partialName, true, false, pageable); - - log.info("Associate filter: {}", partialName); - result.forEach(a -> { - log.info("Associate: {}", a.getName()); - }); return result; } @@ -40,8 +35,6 @@ public class AssociateSelectorDataModel extends CachedSpringDataModel int result = StringUtils.isBlank(partialName) ? (int) associateRepository.count() : (int) associateRepository.count(partialName, true, false); - log.info("Associate filter: {}", partialName); - log.info("Associate count: {}", result); return result > SEARCH_LIMIT ? SEARCH_LIMIT : result; } diff --git a/lis-ui/src/main/java/hu/user/lis/ui/data/AssociatesDataModel.java b/lis-ui/src/main/java/hu/user/lis/ui/data/AssociatesDataModel.java index aecb9c8..11c283d 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/data/AssociatesDataModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/data/AssociatesDataModel.java @@ -27,7 +27,7 @@ public class AssociatesDataModel extends CachedSpringDataModel { private boolean filterShowActive; @Override - protected List getResultSet(int page, int pageSize, FieldComparator sortComparator) { + public List getResultSet(int page, int pageSize, FieldComparator sortComparator) { Pageable pageable = createPageable(page, pageSize, sortComparator); List result = listAll ? associateRepository.findAll(pageable).toList() : associateRepository.search(partialName, filterShowActive, filterShowInActive, pageable); diff --git a/lis-ui/src/main/java/hu/user/lis/ui/data/CachedDataModel.java b/lis-ui/src/main/java/hu/user/lis/ui/data/CachedDataModel.java index 198aaf4..2704ac1 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/data/CachedDataModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/data/CachedDataModel.java @@ -36,8 +36,12 @@ public abstract class CachedDataModel extends ListModelList { this.cacheEnd = 0; clearCache(); - fireEvent(ListDataEvent.STRUCTURE_CHANGED, -1, -1); - BindUtils.postNotifyChange(null, null, this, "*"); + try { + fireEvent(ListDataEvent.STRUCTURE_CHANGED, -1, -1); + BindUtils.postNotifyChange(null, null, this, "*"); + } catch (Exception e) { + log.warn(e.getMessage()); + } } public void clearCache() { @@ -166,7 +170,7 @@ public abstract class CachedDataModel extends ListModelList { } } - abstract protected List getResultSet(int page, int pageSize, FieldComparator sortComparator); + abstract public List getResultSet(int page, int pageSize, FieldComparator sortComparator); abstract public int getResultSetCount(); diff --git a/lis-ui/src/main/java/hu/user/lis/ui/data/PartnerSelectorDataModel.java b/lis-ui/src/main/java/hu/user/lis/ui/data/PartnerSelectorDataModel.java index 4542b19..689b750 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/data/PartnerSelectorDataModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/data/PartnerSelectorDataModel.java @@ -1,63 +1,49 @@ package hu.user.lis.ui.data; import hu.user.lis.db.Partner; -import hu.user.lis.services.data.PartnerService; +import hu.user.lis.db.repository.PartnerRepository; import lombok.extern.log4j.Log4j2; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Scope; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Component; -import org.zkoss.bind.BindUtils; import org.zkoss.zul.FieldComparator; -import java.util.Comparator; import java.util.List; -import java.util.stream.Collectors; @Component @Log4j2 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class PartnerSelectorDataModel extends CachedDataModel { +public class PartnerSelectorDataModel extends CachedSpringDataModel { static private final int SEARCH_LIMIT = 10; + @Autowired - PartnerService partnerService; - private String partialName; + PartnerRepository partnerRepository; - private boolean filter(Partner partner) { - if (StringUtils.isBlank(partialName)) { - return true; - } else { - if (partner.getName().toLowerCase().startsWith(partialName.toLowerCase())) { - return true; - } - } - return false; - } + private String partialName; @Override - protected List getResultSet(int page, int pageSize, FieldComparator sortComparator) { - List result = partnerService.getAll().stream() - .sorted(Comparator.comparing(Partner::getName)) - .filter(s -> filter(s)) - .limit(SEARCH_LIMIT) - .collect(Collectors.toList()); + public List getResultSet(int page, int pageSize, FieldComparator sortComparator) { + Pageable pageable = createPageable(page, pageSize, sortComparator); + List result = StringUtils.isBlank(partialName) ? partnerRepository.findAll() : + partnerRepository.search(partialName, partialName, partialName, true, false, pageable); return result; } + @Override public int getResultSetCount() { - int result = (int) partnerService.getAll().stream() - .filter(s -> filter(s)) - .limit(SEARCH_LIMIT) - .count(); - return result; + int result = StringUtils.isBlank(partialName) ? + (int) partnerRepository.count() : + (int) partnerRepository.count(partialName, partialName, partialName, true, false); + return result > SEARCH_LIMIT ? SEARCH_LIMIT : result; } public void search(String partialName) { log.info("Searching partner using filter {}", partialName); this.partialName = partialName; super.reset(); - BindUtils.postNotifyChange(null, null, this, "*"); } } diff --git a/lis-ui/src/main/java/hu/user/lis/ui/data/PartnersDataModel.java b/lis-ui/src/main/java/hu/user/lis/ui/data/PartnersDataModel.java index a76defe..23b3e2c 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/data/PartnersDataModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/data/PartnersDataModel.java @@ -19,18 +19,25 @@ import java.util.List; public class PartnersDataModel extends CachedSpringDataModel { @Autowired PartnerRepository partnerRepository; + @Autowired PartnerService partnerService; + private String partialName; + private String partialAddress; + private String partialVatNr; + private boolean listAll; + private boolean filterShowInActive; + private boolean filterShowActive; @Override - protected List getResultSet(int page, int pageSize, FieldComparator sortComparator) { + public List getResultSet(int page, int pageSize, FieldComparator sortComparator) { Pageable pageable = createPageable(page, pageSize, sortComparator); List result = listAll ? partnerRepository.findAll() : partnerRepository.search(partialName, partialVatNr, partialAddress, filterShowActive, filterShowInActive, pageable); diff --git a/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectAssociatesDataModel.java b/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectAssociatesDataModel.java index b52a6a6..b9498e7 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectAssociatesDataModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectAssociatesDataModel.java @@ -1,73 +1,49 @@ package hu.user.lis.ui.data; import hu.user.lis.db.ProjectAssociate; +import hu.user.lis.db.repository.ProjectAssociateRepository; import hu.user.lis.services.data.ProjectAssociateService; -import lombok.Getter; import lombok.extern.log4j.Log4j2; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Scope; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Component; -import org.zkoss.bind.BindUtils; import org.zkoss.zul.FieldComparator; import java.util.List; -import java.util.stream.Collectors; @Component @Log4j2 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class ProjectAssociatesDataModel extends CachedDataModel { - @Getter +public class ProjectAssociatesDataModel extends CachedSpringDataModel { + + @Autowired + ProjectAssociateRepository projectAssociateRepository; + @Autowired ProjectAssociateService projectAssociateService; - private String projectId; + private Long projectId; - private boolean canExecuteSearch() { - boolean result = StringUtils.isNotBlank(projectId); - log.info("Can execute search: {}", result); - return result; - } - - private boolean filter(ProjectAssociate projectAssociate) { - boolean result = true; - if (StringUtils.isNotBlank(projectId)) { - if (!projectAssociate.getProject().getId().equals(projectId)) { - result = false; - } - } - return result; - } @Override - protected List getResultSet(int page, int pageSize, FieldComparator sortComparator) { - List result = null; - if (canExecuteSearch()) { - result = projectAssociateService.getAll().stream() - .filter(s -> filter(s)) - .collect(Collectors.toList()); - } + public List getResultSet(int page, int pageSize, FieldComparator sortComparator) { + Pageable pageable = createPageable(page, pageSize, sortComparator); + List result = projectAssociateRepository.findAllByProjectId(projectId, pageable).getContent(); return result; } @Override public int getResultSetCount() { - int result = 0; - if (canExecuteSearch()) { - result = (int) projectAssociateService.getAll().stream() - .filter(s -> filter(s)) - .count(); - } - return result; + long result = projectAssociateRepository.countByProjectId(projectId); + return (int) result; } - public void search(String projectId) { - log.info("Searching project associate using filters: projectId LIKE {}", projectId); + public void search(Long projectId) { + log.info("Searching project associate using filter: projectId LIKE {}", projectId); this.projectId = projectId; super.reset(); - BindUtils.postNotifyChange(null, null, this, "*"); } } diff --git a/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectSelectorDataModel.java b/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectSelectorDataModel.java index 1da8cec..058b714 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectSelectorDataModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectSelectorDataModel.java @@ -23,7 +23,7 @@ public class ProjectSelectorDataModel extends CachedSpringDataModel { private String partialSearch; @Override - protected List getResultSet(int page, int pageSize, FieldComparator sortComparator) { + public List getResultSet(int page, int pageSize, FieldComparator sortComparator) { Pageable pageable = createPageable(0, SEARCH_LIMIT, null); List result = StringUtils.isBlank(partialSearch) ? projectRepository.findAll(pageable).toList() : projectRepository.search(partialSearch, true, false, pageable); diff --git a/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectStatusDataModel.java b/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectStatusDataModel.java index fba594f..f1ce273 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectStatusDataModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectStatusDataModel.java @@ -24,7 +24,7 @@ public class ProjectStatusDataModel extends CachedSpringDataModel private boolean activeOnly; @Override - protected List getResultSet(int page, int pageSize, FieldComparator sortComparator) { + public List getResultSet(int page, int pageSize, FieldComparator sortComparator) { List result; if (activeOnly) { result = projectStatusRepository.findByActiveIsTrue(Sort.by(Sort.Direction.ASC, "order")); @@ -51,10 +51,12 @@ public class ProjectStatusDataModel extends CachedSpringDataModel } public void moveUp(ProjectStatus entity) { - projectStatusService.getAll().stream().anyMatch(s -> { + projectStatusRepository.findAll(Sort.by(Sort.Direction.ASC, "order")).stream().anyMatch(s -> { if (s.getOrder() == entity.getOrder() + 1) { s.setOrder(s.getOrder() - 1); + projectStatusRepository.save(s); entity.setOrder(entity.getOrder() + 1); + projectStatusRepository.save(entity); return true; } return false; @@ -62,10 +64,12 @@ public class ProjectStatusDataModel extends CachedSpringDataModel } public void moveDown(ProjectStatus entity) { - projectStatusService.getAll().stream().anyMatch(s -> { + projectStatusRepository.findAll(Sort.by(Sort.Direction.ASC, "order")).stream().anyMatch(s -> { if (s.getOrder() == entity.getOrder() - 1) { s.setOrder(s.getOrder() + 1); + projectStatusRepository.save(s); entity.setOrder(entity.getOrder() - 1); + projectStatusRepository.save(entity); return true; } return false; @@ -78,4 +82,8 @@ public class ProjectStatusDataModel extends CachedSpringDataModel entity.setOrder((int) currentCount + 1); projectStatusRepository.save(entity); } + + public void save(ProjectStatus entity) { + projectStatusRepository.save(entity); + } } diff --git a/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectsDataModel.java b/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectsDataModel.java index f16eb13..8f6a15b 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectsDataModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectsDataModel.java @@ -1,98 +1,56 @@ package hu.user.lis.ui.data; import hu.user.lis.db.Project; +import hu.user.lis.db.repository.ProjectRepository; import hu.user.lis.services.data.ProjectService; -import lombok.Getter; import lombok.extern.log4j.Log4j2; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Scope; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Component; -import org.zkoss.bind.BindUtils; import org.zkoss.zul.FieldComparator; -import java.util.Comparator; import java.util.List; -import java.util.stream.Collectors; @Component @Log4j2 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class ProjectsDataModel extends CachedDataModel { - @Getter +public class ProjectsDataModel extends CachedSpringDataModel { + @Autowired + ProjectRepository projectRepository; + @Autowired ProjectService projectService; + private String partialName; - private String partialHumanId; - private boolean listAll; - private boolean filterShowInActive; - private boolean filterShowActive; + private boolean listAll; - private boolean canExecuteSearch() { - boolean result = listAll || filterShowActive || filterShowInActive || - StringUtils.isNotBlank(partialName) || - StringUtils.isNotBlank(partialHumanId); - log.info("Can execute search: {}", result); - return result; - } + private boolean filterShowInActive; - private boolean filter(Project entity) { - if (listAll) { - return true; - } - boolean result = true; - if (StringUtils.isNotBlank(partialName)) { - if (!entity.getName().toLowerCase().startsWith(partialName.toLowerCase())) { - result = false; - } - } - if (StringUtils.isNotBlank(partialHumanId)) { - if (!entity.getHumanId().toLowerCase().startsWith(partialHumanId.toLowerCase())) { - result = false; - } - } - if (!filterShowActive && entity.isActive()) { - result = false; - } - if (!filterShowInActive && !entity.isActive()) { - result = false; - } - return result; - } + private boolean filterShowActive; @Override - protected List getResultSet(int page, int pageSize, FieldComparator sortComparator) { - List result = null; - if (canExecuteSearch()) { - result = projectService.getAll().stream() - .filter(s -> filter(s)) - .sorted(Comparator.comparing(Project::getName, String.CASE_INSENSITIVE_ORDER)) - .collect(Collectors.toList()); - } + public List getResultSet(int page, int pageSize, FieldComparator sortComparator) { + Pageable pageable = createPageable(page, pageSize, sortComparator); + List result = listAll ? projectRepository.findAll() : + projectRepository.search(partialName, filterShowActive, filterShowInActive, pageable); return result; } @Override public int getResultSetCount() { - int result = 0; - if (canExecuteSearch()) { - result = (int) projectService.getAll().stream() - .filter(s -> filter(s)) - .count(); - } - return result; + long result = listAll ? projectRepository.count() : + projectRepository.count(partialName, filterShowActive, filterShowInActive); + return (int) result; } - public void search(String partialName, String partialHumanId) { - log.info("Searching partner using filters: name LIKE {}, VAT human ID LIKE {}", - partialName, partialHumanId); + public void search(String partialName) { + log.info("Searching partner using filters: name LIKE {}"); listAll = false; this.partialName = partialName; - this.partialHumanId = partialHumanId; super.reset(); - BindUtils.postNotifyChange(null, null, this, "*"); } @@ -103,13 +61,27 @@ public class ProjectsDataModel extends CachedDataModel { this.filterShowInActive = filterShowInActive; listAll = false; super.reset(); - BindUtils.postNotifyChange(null, null, this, "*"); } public void listAll() { log.info("List all projects"); listAll = true; super.reset(); - BindUtils.postNotifyChange(null, null, this, "*"); + } + + public Project createNew() { + return projectService.createNew(); + } + + public void addNew(Project entity) { + projectRepository.save(entity); + } + + public Project copy(Project selectedEntity) { + return projectService.copy(selectedEntity); + } + + public Project save(Project selectedEntity) { + return projectRepository.save(selectedEntity); } } diff --git a/lis-ui/src/main/java/hu/user/lis/ui/data/ServiceRecordsDataModel.java b/lis-ui/src/main/java/hu/user/lis/ui/data/ServiceRecordsDataModel.java index 39e80a9..62e8f86 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/data/ServiceRecordsDataModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/data/ServiceRecordsDataModel.java @@ -40,7 +40,7 @@ public class ServiceRecordsDataModel extends CachedSpringDataModel getResultSet(int page, int pageSize, FieldComparator sortComparator) { + public List getResultSet(int page, int pageSize, FieldComparator sortComparator) { Pageable pageable = createPageable(page, pageSize, sortComparator); List result = listAll ? serviceRecordRepository.findAll(pageable).toList() : serviceRecordRepository.search(filterProjectId, filterAssociateId, pageable); diff --git a/lis-ui/src/main/java/hu/user/lis/ui/data/SuppliersDataModel.java b/lis-ui/src/main/java/hu/user/lis/ui/data/SuppliersDataModel.java index cd3f7ee..79c7672 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/data/SuppliersDataModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/data/SuppliersDataModel.java @@ -51,7 +51,7 @@ public class SuppliersDataModel extends CachedDataModel { } @Override - protected List getResultSet(int page, int pageSize, FieldComparator sortComparator) { + public List getResultSet(int page, int pageSize, FieldComparator sortComparator) { List result = null; if (canExecuteSearch()) { result = supplierService.getAll().stream() diff --git a/lis-ui/src/main/java/hu/user/lis/ui/data/SuppliersSimpleDataModel.java b/lis-ui/src/main/java/hu/user/lis/ui/data/SuppliersSimpleDataModel.java index 7b9b897..5e6d6b9 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/data/SuppliersSimpleDataModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/data/SuppliersSimpleDataModel.java @@ -36,7 +36,7 @@ public class SuppliersSimpleDataModel extends CachedDataModel { } @Override - protected List getResultSet(int page, int pageSize, FieldComparator sortComparator) { + public List getResultSet(int page, int pageSize, FieldComparator sortComparator) { List result = supplierService.getAll().stream() .sorted(Comparator.comparing(Supplier::getName)) .filter(s -> filter(s)) diff --git a/lis-ui/src/main/java/hu/user/lis/ui/editor/AssociateEditorModel.java b/lis-ui/src/main/java/hu/user/lis/ui/editor/AssociateEditorModel.java index 67f9417..fd29d54 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/editor/AssociateEditorModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/editor/AssociateEditorModel.java @@ -66,7 +66,7 @@ public class AssociateEditorModel extends AbstractValidator { } if (StringUtils.isBlank(newData.getName()) || StringUtils.isBlank(newData.getLogin()) || - StringUtils.isBlank(newData.getPassword()) || + (!newData.isRemotelyAuthenticated() && StringUtils.isBlank(newData.getPassword())) || newData.getMonthlyCost() < 1 ) { log.info("Document is not valid"); diff --git a/lis-ui/src/main/java/hu/user/lis/ui/view/IndexViewModel.java b/lis-ui/src/main/java/hu/user/lis/ui/view/IndexViewModel.java index f00bcad..1080759 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/view/IndexViewModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/view/IndexViewModel.java @@ -2,6 +2,7 @@ package hu.user.lis.ui.view; import com.google.common.collect.ImmutableMap; import hu.user.lis.ui.Constants; +import hu.user.lis.ui.auth.CurrentProfile; import hu.user.lis.ui.event.EventBus; import hu.user.lis.ui.session.SessionSettings; import lombok.Getter; @@ -48,7 +49,12 @@ public class IndexViewModel implements EventListener { SessionSettings sessionSettings; @WireVariable EventBus eventBus; + + @WireVariable + CurrentProfile currentProfile; + String searchPhrase; + String page; @Init @@ -60,6 +66,9 @@ public class IndexViewModel implements EventListener { //project editor route(path); +// Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); +// if (authentication != null && !(authentication instanceof AnonymousAuthenticationToken)) { +// } log.info("Init {}", path); } diff --git a/lis-ui/src/main/java/hu/user/lis/ui/view/PartnersViewModel.java b/lis-ui/src/main/java/hu/user/lis/ui/view/PartnersViewModel.java index b81f636..cff9f54 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/view/PartnersViewModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/view/PartnersViewModel.java @@ -41,7 +41,7 @@ public class PartnersViewModel extends AsyncBaseModel { @Init public void init() { setFilterShowActive(true); - Clients.evalJavaScript("pushNav('/')"); + Clients.evalJavaScript("pushNav('/partners')"); log.info("Initialized"); } @@ -84,7 +84,7 @@ public class PartnersViewModel extends AsyncBaseModel { editorWindow.addEventListener("onClose", e -> { if (e.getData() != null) { log.info("Partner popup result {}", e.getData()); - partnersDataModel.add(newEntity); + partnersDataModel.addNew(newEntity); partnersDataModel.clearSelection(); refresh(); partnersDataModel.addToSelection(newEntity); diff --git a/lis-ui/src/main/java/hu/user/lis/ui/view/ProjectsViewModel.java b/lis-ui/src/main/java/hu/user/lis/ui/view/ProjectsViewModel.java index 97eff60..2459dd6 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/view/ProjectsViewModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/view/ProjectsViewModel.java @@ -77,7 +77,7 @@ public class ProjectsViewModel extends AsyncBaseModel implements EventListener { @Command public void onAdd() { - Project newEntity = projectsDataModel.getProjectService().createNew(); + Project newEntity = projectsDataModel.createNew(); // eventBus.showProjectEditor(ImmutableMap.of("formDocument", newEntity)); eventBus.showProjectEditor(null); } @@ -137,9 +137,9 @@ public class ProjectsViewModel extends AsyncBaseModel implements EventListener { Project formDocument = args.get("formDocument"); if (args.containsKey("origDocument")) { Project origDocument = args.get("origDocument"); - projectsDataModel.getProjectService().replace(origDocument, formDocument); + projectsDataModel.save(formDocument); } else { - projectsDataModel.getProjectService().add(formDocument); + projectsDataModel.addNew(formDocument); } refresh(); projectsDataModel.addToSelection(formDocument); diff --git a/lis-ui/src/main/java/hu/user/lis/ui/view/ServiceRecordsViewModel.java b/lis-ui/src/main/java/hu/user/lis/ui/view/ServiceRecordsViewModel.java index f77889c..0b7e927 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/view/ServiceRecordsViewModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/view/ServiceRecordsViewModel.java @@ -119,7 +119,7 @@ public class ServiceRecordsViewModel implements EventListener { editorWindow.addEventListener("onClose", e -> { if (e.getData() != null) { log.info("Partner popup result {}", e.getData()); - serviceRecordsDataModel.add(newEntity); + serviceRecordsDataModel.addNew(newEntity); serviceRecordsDataModel.clearSelection(); refresh(); serviceRecordsDataModel.addToSelection(newEntity); diff --git a/lis-ui/src/main/java/hu/user/lis/ui/view/SettingsViewModel.java b/lis-ui/src/main/java/hu/user/lis/ui/view/SettingsViewModel.java index f29e80f..4bba82d 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/view/SettingsViewModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/view/SettingsViewModel.java @@ -1,12 +1,13 @@ package hu.user.lis.ui.view; -import com.fasterxml.jackson.core.JsonProcessingException; import hu.user.lis.db.ProjectStatus; import hu.user.lis.ui.data.ProjectStatusDataModel; import lombok.Getter; -import lombok.Setter; import lombok.extern.log4j.Log4j2; +import org.zkoss.bind.BindContext; import org.zkoss.bind.annotation.Command; +import org.zkoss.bind.annotation.ContextParam; +import org.zkoss.bind.annotation.ContextType; import org.zkoss.bind.annotation.Init; import org.zkoss.zk.ui.select.annotation.VariableResolver; import org.zkoss.zk.ui.select.annotation.WireVariable; @@ -20,7 +21,6 @@ public class SettingsViewModel extends AsyncBaseModel { @Getter ProjectStatusDataModel projectStatusDataModel; @Getter - @Setter private ProjectStatus selectedProjectStatus; @Init @@ -54,10 +54,20 @@ public class SettingsViewModel extends AsyncBaseModel { } @Command - public void onAppend() throws JsonProcessingException { + public void onAppend() { projectStatusDataModel.append(); projectStatusDataModel.listAll(); } + @Command + public void onActiveChecked(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) { +// CheckEvent evt = (CheckEvent) ctx.getTriggerEvent(); +// ProjectStatus entity = (ProjectStatus) evt.getData(); +// projectStatusDataModel.save(entity); + } + public void setSelectedProjectStatus(ProjectStatus selectedProjectStatus) { + log.info("Sekected {}", selectedProjectStatus.getName()); + this.selectedProjectStatus = selectedProjectStatus; + } } diff --git a/lis-ui/src/main/resources/metainfo/zk/zk.xml b/lis-ui/src/main/resources/metainfo/zk/zk.xml index 632cf95..861c2fa 100644 --- a/lis-ui/src/main/resources/metainfo/zk/zk.xml +++ b/lis-ui/src/main/resources/metainfo/zk/zk.xml @@ -5,6 +5,10 @@ 300 /timeout + + + + diff --git a/lis-ui/src/main/resources/web/associate-editor.zul b/lis-ui/src/main/resources/web/associate-editor.zul index aa484cd..c28b92f 100644 --- a/lis-ui/src/main/resources/web/associate-editor.zul +++ b/lis-ui/src/main/resources/web/associate-editor.zul @@ -22,6 +22,7 @@