-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathAuthenticationServiceImpl.java
More file actions
33 lines (26 loc) · 1.12 KB
/
Copy pathAuthenticationServiceImpl.java
File metadata and controls
33 lines (26 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
package mate.academy.service;
import mate.academy.exception.AuthenticationException;
import mate.academy.model.User;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class AuthenticationServiceImpl implements AuthenticationService {
private static final Logger logger =
LogManager.getLogger(AuthenticationServiceImpl.class);
@Override
public User login(String login, String password) throws AuthenticationException {
logger.info("Login method was called. Login: {}", login);
User user = findByLogin(login);
if (!user.getPassword().equals(password)) {
logger.error("Authentication failed for user: {}", login);
throw new AuthenticationException("Username or password are incorrect");
}
logger.info("User {} successfully authenticated", login);
return user;
}
private User findByLogin(String login) {
User user = new User(login, "1234");
// this user identifier should be set by DB. We will use dummy data for this example
user.setUserId(2L);
return user;
}
}