-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1a0ec4
commit bbd911e
Showing
10 changed files
with
113 additions
and
95 deletions.
There are no files selected for viewing
This file contains 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
74 changes: 74 additions & 0 deletions
74
src/main/java/by/petrovich/eshop/entity/model/CustomUserDetail.java
This file contains 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,74 @@ | ||
package by.petrovich.eshop.entity.model; | ||
|
||
import by.petrovich.eshop.entity.User; | ||
import org.springframework.security.core.GrantedAuthority; | ||
import org.springframework.security.core.authority.SimpleGrantedAuthority; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
|
||
import java.math.BigDecimal; | ||
import java.time.LocalDate; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
||
public class CustomUserDetail implements UserDetails { | ||
private final User user; | ||
|
||
public CustomUserDetail(User user) { | ||
this.user = user; | ||
} | ||
|
||
@Override | ||
public Collection<? extends GrantedAuthority> getAuthorities() { | ||
return Collections.singletonList(new SimpleGrantedAuthority(user.getRole().getName())); | ||
} | ||
|
||
@Override | ||
public String getPassword() { | ||
return user.getPassword(); | ||
} | ||
|
||
@Override | ||
public String getUsername() { | ||
return user.getName(); | ||
} | ||
|
||
@Override | ||
public boolean isAccountNonExpired() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isAccountNonLocked() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isCredentialsNonExpired() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isEnabled() { | ||
return true; | ||
} | ||
|
||
public Integer getUserId() { | ||
return user.getUserId(); | ||
} | ||
|
||
public String getEmail() { | ||
return user.getEmail(); | ||
} | ||
|
||
public String getRole() { | ||
return user.getRole().getName(); | ||
} | ||
|
||
public BigDecimal getBalance() { | ||
return user.getBalance(); | ||
} | ||
|
||
public LocalDate getBirthDate() { | ||
return user.getBirthDate(); | ||
} | ||
} |
59 changes: 0 additions & 59 deletions
59
src/main/java/by/petrovich/eshop/security/CustomUserDetails.java
This file was deleted.
Oops, something went wrong.
This file contains 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 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 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,7 @@ | ||
INSERT INTO roles (name) | ||
VALUES ('ROLE_USER'), | ||
('ROLE_ADMIN'); | ||
|
||
INSERT INTO users (name, password, email, birth_date, balance, role_id) | ||
values ('Wade', '$2a$10$0ZrU1zZA2gx9lBm2MQ1Id.gN7Itm8a8Xi3AComXN2CZXZzHCclh..', '[email protected]', '01-01-1990', 0.5, 1), | ||
('Dave', '$2a$10$XtGZF/tA.hNaFsDN6MEKYOTcFS.52OFv0U0UZUWjCl34SgDJVenBG', '[email protected]', '01-01-1990', 0.5, 1), | ||
|
@@ -65,15 +69,14 @@ VALUES ('product name1', | |
16.50, 5); | ||
|
||
INSERT INTO orders (price, user_id, created_at) | ||
VALUES (0.10, 1, CURRENT_TIMESTAMP), | ||
(0.20, 2, CURRENT_TIMESTAMP), | ||
VALUES (100.00, 1, CURRENT_TIMESTAMP), | ||
(19.99, 1, CURRENT_TIMESTAMP), | ||
(200.00, 2, CURRENT_TIMESTAMP), | ||
(25.00, 2, CURRENT_TIMESTAMP), | ||
(50.00, 2, CURRENT_TIMESTAMP), | ||
(0.30, 3, CURRENT_TIMESTAMP); | ||
|
||
INSERT INTO carts (price, created_at, user_id) | ||
VALUES (50.55, CURRENT_TIMESTAMP, 1), | ||
(10.99, CURRENT_TIMESTAMP, 2), | ||
(0.5, CURRENT_TIMESTAMP, 3); | ||
|
||
INSERT INTO roles (name) | ||
VALUES ('ROLE_USER'), | ||
('ROLE_ADMIN'); | ||
(0.5, CURRENT_TIMESTAMP, 3); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 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 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