Skip to content

Commit 7ce8bc8

Browse files
committed
feat(FilterTaskAuth): checking if the password is correct and the user exists
1 parent e48eb9f commit 7ce8bc8

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/main/java/br/com/leticiamangueira/todolist/filter/FilterTaskAuth.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import java.io.IOException;
44
import java.util.Base64;
55

6+
import org.springframework.beans.factory.annotation.Autowired;
67
import org.springframework.stereotype.Component;
78
import org.springframework.web.filter.OncePerRequestFilter;
89

10+
import br.com.leticiamangueira.todolist.user.IUserRepository;
911
import jakarta.servlet.FilterChain;
1012
import jakarta.servlet.ServletException;
1113
import jakarta.servlet.http.HttpServletRequest;
@@ -14,7 +16,8 @@
1416
@Component
1517
public class FilterTaskAuth extends OncePerRequestFilter {
1618

17-
19+
@Autowired
20+
private IUserRepository userRepository;
1821

1922
@Override
2023
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
@@ -29,24 +32,21 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
2932

3033
var authString = new String(authDecoded);
3134

32-
33-
3435
String[] credentials = authString.split(":");
3536
String username = credentials[0];
3637
String password = credentials[1];
3738

38-
System.out.println("Authorization");
39-
System.out.println(username);
40-
System.out.println(password);
41-
42-
43-
4439
// Validar usuário
40+
var user = this.userRepository.findByUsername(username);
41+
if (user == null) {
42+
response.sendError(401);
43+
} else {
44+
// Validar senha
4545

46-
// Validar senha
46+
// Segue viagem
47+
filterChain.doFilter(request, response);
48+
}
4749

48-
// Segue viagem
4950

50-
filterChain.doFilter(request, response);
5151
}
5252
}

0 commit comments

Comments
 (0)