-
Notifications
You must be signed in to change notification settings - Fork 1.1k
1 #1245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
VadimN637
wants to merge
5
commits into
mate-academy:master
Choose a base branch
from
VadimN637:new
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
1 #1245
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| .idea/* | ||
| *.iml | ||
| target/* | ||
| *.log | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <configuration> | ||
|
|
||
| <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> | ||
| <encoder> | ||
| <pattern>%d{HH:mm:ss} %-5level %logger{36} - %msg%n</pattern> | ||
| </encoder> | ||
| </appender> | ||
|
|
||
| <appender name="FILE" class="ch.qos.logback.core.FileAppender"> | ||
| <file>app.log</file> | ||
| <append>true</append> | ||
| <encoder> | ||
| <pattern>%d %-5level %logger - %msg%n</pattern> | ||
| </encoder> | ||
| </appender> | ||
|
|
||
| <root level="INFO"> | ||
| <appender-ref ref="CONSOLE"/> | ||
| <appender-ref ref="FILE"/> | ||
| </root> | ||
|
|
||
| </configuration> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 21 additions & 13 deletions
34
src/main/java/mate/academy/service/AuthenticationServiceImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,31 @@ | ||
| package mate.academy.service; | ||
|
|
||
| import mate.academy.exception.AuthenticationException; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import mate.academy.model.User; | ||
|
|
||
|
|
||
| public class AuthenticationServiceImpl implements AuthenticationService { | ||
| private static final Logger logger = | ||
| LoggerFactory.getLogger(AuthenticationServiceImpl.class); | ||
|
|
||
| @Override | ||
| public User login(String login, String password) throws AuthenticationException { | ||
| //TODO: add corresponding log message about method login was called | ||
| User user = findByLogin(login); | ||
| if (!user.getPassword().equals(password)) { | ||
| throw new AuthenticationException("Username or password are incorrect"); | ||
| public User login(String login, String password) { | ||
| logger.trace("Enter login method: login={}", login); | ||
|
|
||
| if (login == null || password == null) { | ||
| logger.error("Login or password is null"); | ||
| throw new IllegalArgumentException("Login/password is null"); | ||
| } | ||
|
|
||
| logger.debug("Checking credentials for user={}", login); | ||
| if ("admin".equals(login) && "1234".equals(password)) { | ||
| logger.info("User logged in successfully: {}", login); | ||
| return new User(login, password); | ||
| } | ||
| 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; | ||
| logger.warn("Login failed for user={}", login); | ||
| throw new RuntimeException("Invalid credentials"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing: There is no logback.xml (or log4j2.xml) configuration file that configures File and Console appenders. The task explicitly requires adding appenders for File and Console. You need to create a configuration file in
src/main/resources/to define these appenders.