-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* P4ADEV-510 storingUsers * setting collection name as collections * P4ADEV-510 storing users when login * fix unit tests
- Loading branch information
1 parent
d50cd57
commit 09a4dda
Showing
22 changed files
with
537 additions
and
16 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
12 changes: 10 additions & 2 deletions
12
...v/pagopa/payhub/auth/model/Operators.java → ...ov/pagopa/payhub/auth/model/Operator.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
12 changes: 10 additions & 2 deletions
12
...t/gov/pagopa/payhub/auth/model/Users.java → ...it/gov/pagopa/payhub/auth/model/User.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
7 changes: 7 additions & 0 deletions
7
src/main/java/it/gov/pagopa/payhub/auth/repository/OperatorsRepository.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,7 @@ | ||
package it.gov.pagopa.payhub.auth.repository; | ||
|
||
import it.gov.pagopa.payhub.auth.model.Operator; | ||
import org.springframework.data.mongodb.repository.MongoRepository; | ||
|
||
public interface OperatorsRepository extends MongoRepository<Operator, String> { | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/it/gov/pagopa/payhub/auth/repository/UsersRepository.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,7 @@ | ||
package it.gov.pagopa.payhub.auth.repository; | ||
|
||
import it.gov.pagopa.payhub.auth.model.User; | ||
import org.springframework.data.mongodb.repository.MongoRepository; | ||
|
||
public interface UsersRepository extends UsersRepositoryExt, MongoRepository<User, String> { | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/it/gov/pagopa/payhub/auth/repository/UsersRepositoryExt.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,7 @@ | ||
package it.gov.pagopa.payhub.auth.repository; | ||
|
||
import it.gov.pagopa.payhub.auth.model.User; | ||
|
||
public interface UsersRepositoryExt { | ||
User registerUser(User user); | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/it/gov/pagopa/payhub/auth/repository/UsersRepositoryExtImpl.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,35 @@ | ||
package it.gov.pagopa.payhub.auth.repository; | ||
|
||
import it.gov.pagopa.payhub.auth.model.User; | ||
import org.springframework.data.mongodb.core.FindAndModifyOptions; | ||
import org.springframework.data.mongodb.core.MongoTemplate; | ||
import org.springframework.data.mongodb.core.query.Criteria; | ||
import org.springframework.data.mongodb.core.query.Query; | ||
import org.springframework.data.mongodb.core.query.Update; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class UsersRepositoryExtImpl implements UsersRepositoryExt{ | ||
|
||
private final MongoTemplate mongoTemplate; | ||
|
||
public UsersRepositoryExtImpl(MongoTemplate mongoTemplate) { | ||
this.mongoTemplate = mongoTemplate; | ||
} | ||
|
||
@Override | ||
public User registerUser(User user) { | ||
return mongoTemplate.findAndModify( | ||
Query.query(Criteria.where(User.Fields.mappedExternalUserId).is(user.getMappedExternalUserId())), | ||
new Update() | ||
.setOnInsert(User.Fields.userCode, user.getUserCode()) | ||
.setOnInsert(User.Fields.iamIssuer, user.getIamIssuer()) | ||
.setOnInsert(User.Fields.tosAccepted, false) | ||
.set(User.Fields.lastLogin, LocalDateTime.now()), | ||
FindAndModifyOptions.options() | ||
.returnNew(true) | ||
.upsert(true), | ||
User.class | ||
); | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
src/main/java/it/gov/pagopa/payhub/auth/service/exchange/IamUserRegistrationService.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,31 @@ | ||
package it.gov.pagopa.payhub.auth.service.exchange; | ||
|
||
import it.gov.pagopa.payhub.auth.service.user.UserService; | ||
import it.gov.pagopa.payhub.model.generated.UserInfo; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class IamUserRegistrationService { | ||
|
||
private final boolean organizationAccessMode; | ||
|
||
private final UserService userService; | ||
|
||
public IamUserRegistrationService( | ||
@Value("${app.enable-access-organization-mode}") boolean organizationAccessMode, | ||
|
||
UserService userService | ||
) { | ||
this.organizationAccessMode = organizationAccessMode; | ||
this.userService = userService; | ||
} | ||
|
||
void registerUser(UserInfo userInfo){ | ||
userService.registerUser(userInfo.getUserId(), userInfo.getFiscalCode(), userInfo.getIssuer()); | ||
|
||
if(organizationAccessMode){ | ||
//store Operators | ||
} | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
src/main/java/it/gov/pagopa/payhub/auth/service/user/UserService.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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
package it.gov.pagopa.payhub.auth.service.user; | ||
|
||
import it.gov.pagopa.payhub.auth.model.User; | ||
import it.gov.pagopa.payhub.model.generated.UserInfo; | ||
|
||
public interface UserService { | ||
User registerUser(String externalUserId, String fiscalCode, String iamIssuer); | ||
UserInfo getUserInfo(String accessToken); | ||
} |
12 changes: 11 additions & 1 deletion
12
src/main/java/it/gov/pagopa/payhub/auth/service/user/UserServiceImpl.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
10 changes: 10 additions & 0 deletions
10
.../it/gov/pagopa/payhub/auth/service/user/registration/ExternalUserIdObfuscatorService.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,10 @@ | ||
package it.gov.pagopa.payhub.auth.service.user.registration; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class ExternalUserIdObfuscatorService { | ||
public String obfuscate(String externalUserId){ | ||
return externalUserId; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...java/it/gov/pagopa/payhub/auth/service/user/registration/FiscalCodeObfuscatorService.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,10 @@ | ||
package it.gov.pagopa.payhub.auth.service.user.registration; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class FiscalCodeObfuscatorService { | ||
public String obfuscate(String fiscalCode){ | ||
return fiscalCode; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...ain/java/it/gov/pagopa/payhub/auth/service/user/registration/UserRegistrationService.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,32 @@ | ||
package it.gov.pagopa.payhub.auth.service.user.registration; | ||
|
||
import it.gov.pagopa.payhub.auth.model.User; | ||
import it.gov.pagopa.payhub.auth.repository.UsersRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class UserRegistrationService { | ||
|
||
private final ExternalUserIdObfuscatorService externalUserIdObfuscatorService; | ||
private final FiscalCodeObfuscatorService fiscalCodeObfuscatorService; | ||
private final UsersRepository usersRepository; | ||
|
||
public UserRegistrationService(ExternalUserIdObfuscatorService externalUserIdObfuscatorService, FiscalCodeObfuscatorService fiscalCodeObfuscatorService, UsersRepository usersRepository) { | ||
this.externalUserIdObfuscatorService = externalUserIdObfuscatorService; | ||
this.fiscalCodeObfuscatorService = fiscalCodeObfuscatorService; | ||
this.usersRepository = usersRepository; | ||
} | ||
|
||
public User registerUser(String externalUserId, String fiscalCode, String iamIssuer){ | ||
User user = buildUser(externalUserId, fiscalCode, iamIssuer); | ||
return usersRepository.registerUser(user); | ||
} | ||
|
||
private User buildUser(String externalUserId, String fiscalCode, String iamIssuer){ | ||
return User.builder() | ||
.iamIssuer(iamIssuer) | ||
.mappedExternalUserId(externalUserIdObfuscatorService.obfuscate(externalUserId)) | ||
.userCode(fiscalCodeObfuscatorService.obfuscate(fiscalCode)) | ||
.build(); | ||
} | ||
} |
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,9 @@ | ||
package it.gov.pagopa.payhub.auth.utils; | ||
|
||
import java.time.ZoneId; | ||
|
||
public class Constants { | ||
private Constants(){} | ||
|
||
public static final ZoneId ZONEID = ZoneId.of("Europe/Rome"); | ||
} |
Oops, something went wrong.