View Javadoc
1   /*
2    * Copyright (C) 2021 B3Partners B.V.
3    *
4    * SPDX-License-Identifier: MIT
5    */
6   package org.tailormap.api.repository;
7   
8   import java.util.Collection;
9   import java.util.Optional;
10  import org.springframework.data.jpa.repository.EntityGraph;
11  import org.springframework.data.jpa.repository.JpaRepository;
12  import org.springframework.data.rest.core.annotation.RepositoryRestResource;
13  import org.springframework.lang.NonNull;
14  import org.springframework.security.access.prepost.PreAuthorize;
15  import org.tailormap.api.persistence.User;
16  import org.tailormap.api.security.annotation.PreAuthorizeAdmin;
17  
18  @PreAuthorizeAdmin
19  @RepositoryRestResource()
20  public interface UserRepository extends JpaRepository<User, String> {
21    @Override
22    @PreAuthorize("permitAll()")
23    @EntityGraph(attributePaths = {"groups"})
24    @NonNull
25    Optional<User> findById(@NonNull String username);
26  
27    boolean existsByGroupsNameIn(Collection<String> groupNames);
28  }