-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathAuthenticationServiceImpl.java
More file actions
39 lines (28 loc) · 1.12 KB
/
Copy pathAuthenticationServiceImpl.java
File metadata and controls
39 lines (28 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package mate.academy.service;
import java.util.Objects;
import mate.academy.exception.AuthenticationException;
import mate.academy.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AuthenticationServiceImpl implements AuthenticationService {
private static final Logger logger = LoggerFactory.getLogger(AuthenticationServiceImpl.class);
@Override
public User login(String login, String password) throws AuthenticationException {
logger.info("Method login was called for user: {}", login);
User user = findByLogin(login);
if (user == null || !Objects.equals(user.getPassword(), password)) {
logger.warn("Failed login attempt for user: {}", login);
throw new AuthenticationException("Username or password are incorrect");
}
logger.info("User {} successfully logged in.", login);
return user;
}
private User findByLogin(String login) {
if ("bob".equals(login)) {
User user = new User(login, "1234");
user.setUserId(2L);
return user;
}
return null;
}
}