-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #269 from Longwater1234/version_three
Version three
- Loading branch information
Showing
50 changed files
with
302 additions
and
217 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
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
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
83 changes: 83 additions & 0 deletions
83
src/main/java/com/davistiba/wedemyserver/config/MainUserDetails.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,83 @@ | ||
package com.davistiba.wedemyserver.config; | ||
|
||
import com.davistiba.wedemyserver.models.User; | ||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import lombok.Getter; | ||
import org.springframework.security.core.GrantedAuthority; | ||
import org.springframework.security.core.authority.SimpleGrantedAuthority; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
|
||
import java.io.Serial; | ||
import java.io.Serializable; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Objects; | ||
|
||
@Getter | ||
public class MainUserDetails implements UserDetails, Serializable { | ||
|
||
@Serial | ||
private static final long serialVersionUID = 3733936374876008250L; | ||
|
||
private final User user; | ||
|
||
public MainUserDetails(User user) { | ||
this.user = user; | ||
} | ||
|
||
@Override | ||
@JsonIgnore | ||
public Collection<? extends GrantedAuthority> getAuthorities() { | ||
SimpleGrantedAuthority authority = new SimpleGrantedAuthority(user.getUserRole()); | ||
return Collections.singletonList(authority); | ||
} | ||
|
||
@Override | ||
@JsonIgnore | ||
public String getPassword() { | ||
return user.getPassword(); | ||
} | ||
|
||
@Override | ||
@JsonIgnore | ||
public String getUsername() { | ||
return user.getEmail(); | ||
} | ||
|
||
@Override | ||
@JsonIgnore | ||
public boolean isAccountNonExpired() { | ||
return true; | ||
} | ||
|
||
@Override | ||
@JsonIgnore | ||
public boolean isAccountNonLocked() { | ||
return true; | ||
} | ||
|
||
@Override | ||
@JsonIgnore | ||
public boolean isCredentialsNonExpired() { | ||
return true; | ||
} | ||
|
||
@Override | ||
@JsonIgnore | ||
public boolean isEnabled() { | ||
return user.getEnabled(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
MainUserDetails that = (MainUserDetails) o; | ||
return Objects.equals(user.getEmail(), that.user.getEmail()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(user.getEmail()); | ||
} | ||
} |
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
Oops, something went wrong.