-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathAuthenticationServiceImpl.java
More file actions
29 lines (25 loc) · 1.06 KB
/
Copy pathAuthenticationServiceImpl.java
File metadata and controls
29 lines (25 loc) · 1.06 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
package mate.academy.service;
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. Params: login={}", login);
User user = findByLogin(login);
if (!user.getPassword().equals(password)) {
logger.error("Attempt of user {} to authenticate with wrong credentials", login);
throw new AuthenticationException("Username or password are incorrect");
}
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;
}
}