-
Notifications
You must be signed in to change notification settings - Fork 5
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
Pieter Van Eeckhout
committed
Jun 26, 2023
1 parent
822b4a7
commit 9851cf1
Showing
51 changed files
with
981 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# .env_usermodule file | ||
|
||
# PostgreSQL | ||
POSTGRES_USER=edpn_usermodule | ||
POSTGRES_PASSWORD=hvWYDHqG3yXCKReH | ||
POSTGRES_DB=usermodule |
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
61 changes: 61 additions & 0 deletions
61
user-module/src/main/java/io/edpn/backend/user/application/model/EdpnUserDetails.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,61 @@ | ||
package io.edpn.backend.user.application.model; | ||
|
||
import io.edpn.backend.user.domain.model.EdpnUser; | ||
import io.edpn.backend.user.domain.model.UserRole; | ||
import java.time.LocalDateTime; | ||
import java.util.Collection; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import lombok.Data; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.GrantedAuthority; | ||
import org.springframework.security.core.authority.SimpleGrantedAuthority; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
|
||
@Data | ||
@RequiredArgsConstructor | ||
public class EdpnUserDetails implements UserDetails { | ||
|
||
private final EdpnUser user; | ||
|
||
@Override | ||
public Collection<? extends GrantedAuthority> getAuthorities() { | ||
return Stream.concat(user.getRoles().stream().map(UserRole::getName).map("ROLE_"::concat), | ||
Stream.concat(user.getRoles().stream().map(UserRole::getGrants).flatMap(Set::stream), | ||
user.getGrants().stream().map("GRANT_"::concat))) | ||
.map(SimpleGrantedAuthority::new) | ||
.collect(Collectors.toUnmodifiableSet()); | ||
} | ||
|
||
@Override | ||
public String getPassword() { | ||
return user.getPassword(); | ||
} | ||
|
||
@Override | ||
public String getUsername() { | ||
return user.getEmail(); | ||
} | ||
|
||
@Override | ||
public boolean isAccountNonExpired() { | ||
return Optional.ofNullable(user.getAccountExpiryTimestamp()).map(ts -> LocalDateTime.now().isBefore(ts)).orElse(false); | ||
} | ||
|
||
@Override | ||
public boolean isAccountNonLocked() { | ||
return !user.isLocked(); | ||
} | ||
|
||
@Override | ||
public boolean isCredentialsNonExpired() { | ||
return Optional.ofNullable(user.getPasswordExpiryTimestamp()).map(ts -> LocalDateTime.now().isBefore(ts)).orElse(false); | ||
} | ||
|
||
@Override | ||
public boolean isEnabled() { | ||
return user.isEnabled(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...module/src/main/java/io/edpn/backend/user/application/service/EdpnUserDetailsService.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,21 @@ | ||
package io.edpn.backend.user.application.service; | ||
|
||
import io.edpn.backend.user.application.model.EdpnUserDetails; | ||
import io.edpn.backend.user.domain.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
import org.springframework.security.core.userdetails.UserDetailsService; | ||
import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
|
||
@RequiredArgsConstructor | ||
public class EdpnUserDetailsService implements UserDetailsService { | ||
|
||
private final UserRepository userRepository; | ||
|
||
@Override | ||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { | ||
return userRepository.findByUsername(username) | ||
.map(EdpnUserDetails::new) | ||
.orElseThrow(() -> new UsernameNotFoundException("User not found")); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
user-module/src/main/java/io/edpn/backend/user/domain/model/ApiGrant.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,13 @@ | ||
package io.edpn.backend.user.domain.model; | ||
|
||
import java.util.UUID; | ||
import lombok.Builder; | ||
import lombok.Value; | ||
|
||
@Value | ||
@Builder | ||
public class ApiGrant { | ||
|
||
UUID id; | ||
String name; | ||
} |
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 |
---|---|---|
|
@@ -12,5 +12,5 @@ public class ApiRole { | |
|
||
UUID id; | ||
String name; | ||
Set<String> grants; | ||
Set<ApiGrant> grants; | ||
} |
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
13 changes: 13 additions & 0 deletions
13
user-module/src/main/java/io/edpn/backend/user/domain/model/UserGrant.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,13 @@ | ||
package io.edpn.backend.user.domain.model; | ||
|
||
import java.util.UUID; | ||
import lombok.Builder; | ||
import lombok.Value; | ||
|
||
@Value | ||
@Builder | ||
public class UserGrant { | ||
|
||
UUID id; | ||
String name; | ||
} |
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 |
---|---|---|
|
@@ -12,5 +12,5 @@ public class UserRole { | |
|
||
UUID id; | ||
String name; | ||
Set<String> grants; | ||
Set<UserGrant> grants; | ||
} |
20 changes: 20 additions & 0 deletions
20
.../src/main/java/io/edpn/backend/user/infrastructure/persistence/entity/ApiGrantEntity.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,20 @@ | ||
package io.edpn.backend.user.infrastructure.persistence.entity; | ||
|
||
import java.util.UUID; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
@Getter | ||
@Setter | ||
@ToString | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class ApiGrantEntity { | ||
private UUID id; | ||
private String name; | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...rastructure/entity/PricingPlanEntity.java → ...persistence/entity/PricingPlanEntity.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
20 changes: 20 additions & 0 deletions
20
...src/main/java/io/edpn/backend/user/infrastructure/persistence/entity/UserGrantEntity.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,20 @@ | ||
package io.edpn.backend.user.infrastructure.persistence.entity; | ||
|
||
import java.util.UUID; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
|
||
@Getter | ||
@Setter | ||
@ToString | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class UserGrantEntity { | ||
private UUID id; | ||
private String name; | ||
} |
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
23 changes: 23 additions & 0 deletions
23
...n/java/io/edpn/backend/user/infrastructure/persistence/mappers/entity/ApiGrantMapper.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,23 @@ | ||
package io.edpn.backend.user.infrastructure.persistence.mappers.entity; | ||
|
||
import io.edpn.backend.user.domain.model.ApiGrant; | ||
import io.edpn.backend.user.infrastructure.persistence.entity.ApiGrantEntity; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class ApiGrantMapper { | ||
|
||
public ApiGrant map(ApiGrantEntity entity) { | ||
return ApiGrant.builder() | ||
.id(entity.getId()) | ||
.name(entity.getName()) | ||
.build(); | ||
} | ||
|
||
public ApiGrantEntity map(ApiGrant key) { | ||
return ApiGrantEntity.builder() | ||
.id(key.getId()) | ||
.name(key.getName()) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.