Skip to content

Commit df96379

Browse files
authored
Merge pull request #80 from JEstebanCDev/version6.5
Version6.5
2 parents f565f64 + 53f9566 commit df96379

File tree

6 files changed

+16
-13
lines changed

6 files changed

+16
-13
lines changed

src/main/java/JEstebanC/FastFoodApp/controller/AdditionalController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ public ResponseEntity<Response> getadditional() {
7878
@PreAuthorize("hasRole('ROLE_ADMIN') OR hasRole('ROLE_EMPLOYEE')")
7979
@PutMapping(value = "/{id}")
8080
public ResponseEntity<Response> updateAdditional(@PathVariable("id") Long id,
81-
@RequestParam("request") @Valid String strAddiotional,
81+
@RequestParam("strAdditional") @Valid String strAdditional,
8282
@RequestParam("additionalImage") @Nullable MultipartFile file) {
8383
try {
8484
if (serviceImp.exist(id)) {
85-
Additional additional= serviceImp.update(id,new ObjectMapper().readValue(strAddiotional, Additional.class), file);
85+
Additional additional= serviceImp.update(id,new ObjectMapper().readValue(strAdditional, Additional.class), file);
8686
if (additional!=null) {
8787
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now())
8888
.data(Map.of("additional", additional))

src/main/java/JEstebanC/FastFoodApp/controller/RefreshTokenController.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ public ResponseEntity<Response> refreshToken(HttpServletRequest request) {
8686

8787
Map<String, Object> tokens = new HashMap<>();
8888
tokens.put("valid", true);
89-
tokens.put("userRoles", user.getUserRoles().getAuthority());
9089
tokens.put("access_token", access_token);
9190
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now())
9291
.data(Map.of("tokens", tokens)).message("tokens").status(HttpStatus.OK)

src/main/java/JEstebanC/FastFoodApp/controller/UserController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public ResponseEntity<Response> getUserByName(@PathVariable("name") String name)
208208
}
209209
}
210210

211-
@PreAuthorize("hasRole('ROLE_ADMIN')")
211+
@PreAuthorize("hasRole('ROLE_ADMIN') OR hasRole('ROLE_EMPLOYEE')")
212212
@GetMapping(value = "/admin/{name}")
213213
public ResponseEntity<Response> getUserAdminByName(@PathVariable("name") String name) {
214214

src/main/java/JEstebanC/FastFoodApp/repository/IUserRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
@Repository
1919
public interface IUserRepository extends JpaRepository<User, Long> {
20-
@Query(value = "select * from user_app where user_roles=2 and name=:name order by name", nativeQuery = true)
20+
@Query(value = "select * from user_app where user_roles=2 and name like :name order by name", nativeQuery = true)
2121
Collection<User> findByNameStartsWith(@Param("name")String name);
2222

2323

src/main/java/JEstebanC/FastFoodApp/security/CustomAuthenticationFilter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ protected void successfulAuthentication(HttpServletRequest request, HttpServletR
7676

7777
Map<String, Object> tokens = new HashMap<>();
7878
tokens.put("valid", true);
79-
tokens.put("userRoles", user.getAuthorities().stream().map(GrantedAuthority::getAuthority).findAny().get());
8079
tokens.put("access_token", access_token);
8180
tokens.put("refresh_token", refresh_token);
8281
response.setStatus(200);

src/main/java/JEstebanC/FastFoodApp/service/UserServiceImp.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,16 @@ public UserDetails loadUserByUsername(String username) throws UsernameNotFoundEx
6262
log.error("User with username: " + username + " not found");
6363
throw new UsernameNotFoundException("User with username: " + username + " not found");
6464
} else {
65-
log.info("User found " + username);
66-
Collection<SimpleGrantedAuthority> authorities = new ArrayList<>();
67-
authorities.add(new SimpleGrantedAuthority(user.getUserRoles().getAuthority()));
68-
return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(),
69-
authorities);
65+
if (user.getStatus().equals(Status.ACTIVE)){
66+
log.info("User found " + username);
67+
Collection<SimpleGrantedAuthority> authorities = new ArrayList<>();
68+
authorities.add(new SimpleGrantedAuthority(user.getUserRoles().getAuthority()));
69+
return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(),
70+
authorities);
71+
}else{
72+
log.error("User with username: " + username + " is inactive");
73+
throw new UsernameNotFoundException("User with username: " + username + " is inactive");
74+
}
7075
}
7176
}
7277

@@ -249,15 +254,15 @@ public Boolean exist(String username) {
249254
public Collection<UserDTO> findByName(String name) {
250255
log.info("Searching user by name: " + name);
251256

252-
return userRepository.findByNameStartsWith(name).stream().map(this::convertUserToDTO)
257+
return userRepository.findByNameStartsWith(name+"%").stream().map(this::convertUserToDTO)
253258
.collect(Collectors.toList());
254259

255260
}
256261

257262
public Collection<UserDTO> findByNameAdmin(String name) {
258263
log.info("Searching user-admin by name: " + name);
259264

260-
return userRepository.findByNameAdminStartsWith(name).stream().map(this::convertUserToDTO)
265+
return userRepository.findByNameAdminStartsWith(name+"%").stream().map(this::convertUserToDTO)
261266
.collect(Collectors.toList());
262267

263268
}

0 commit comments

Comments
 (0)