This is an automated email from the ASF dual-hosted git repository.
ilgrosso pushed a commit to branch 3_0_X
in repository https://gitbox.apache.org/repos/asf/syncope.git
The following commit(s) were added to refs/heads/3_0_X by this push:
new 70e6206e9d [SYNCOPE-1883] Storing username along with
GoogleMfaAuthAccount (#1082)
70e6206e9d is described below
commit 70e6206e9de54c7632cad813d07c29b479c1e4e1
Author: Francesco Chicchiriccò <[email protected]>
AuthorDate: Fri May 16 09:10:00 2025 +0200
[SYNCOPE-1883] Storing username along with GoogleMfaAuthAccount (#1082)
---
.../common/lib/wa/GoogleMfaAuthAccount.java | 104 ++++++++++++---------
.../syncope/common/lib/wa/GoogleMfaAuthToken.java | 24 ++---
.../service/wa/GoogleMfaAuthAccountService.java | 42 ++++-----
.../core/logic/wa/GoogleMfaAuthAccountLogic.java | 13 +--
.../wa/GoogleMfaAuthAccountServiceImpl.java | 10 +-
.../persistence/jpa/inner/AuthProfileTest.java | 4 +-
.../fit/core/wa/GoogleMfaAuthAccountITCase.java | 25 ++---
.../gauth/WAGoogleMfaAuthCredentialRepository.java | 72 ++++++--------
.../gauth/WAGoogleMfaAuthTokenRepository.java | 23 ++---
9 files changed, 161 insertions(+), 156 deletions(-)
diff --git
a/common/am/lib/src/main/java/org/apache/syncope/common/lib/wa/GoogleMfaAuthAccount.java
b/common/am/lib/src/main/java/org/apache/syncope/common/lib/wa/GoogleMfaAuthAccount.java
index fc01b3d5e4..abfa3cd370 100644
---
a/common/am/lib/src/main/java/org/apache/syncope/common/lib/wa/GoogleMfaAuthAccount.java
+++
b/common/am/lib/src/main/java/org/apache/syncope/common/lib/wa/GoogleMfaAuthAccount.java
@@ -18,7 +18,7 @@
*/
package org.apache.syncope.common.lib.wa;
-import java.time.OffsetDateTime;
+import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.builder.EqualsBuilder;
@@ -34,13 +34,18 @@ public class GoogleMfaAuthAccount implements BaseBean {
private final GoogleMfaAuthAccount instance = new
GoogleMfaAuthAccount();
- public GoogleMfaAuthAccount.Builder registrationDate(final
OffsetDateTime date) {
- instance.setRegistrationDate(date);
+ public GoogleMfaAuthAccount.Builder id(final Long id) {
+ instance.setId(id);
return this;
}
- public GoogleMfaAuthAccount.Builder scratchCodes(final List<Integer>
codes) {
- instance.setScratchCodes(codes);
+ public GoogleMfaAuthAccount.Builder name(final String name) {
+ instance.setName(name);
+ return this;
+ }
+
+ public GoogleMfaAuthAccount.Builder username(final String username) {
+ instance.setUsername(username);
return this;
}
@@ -54,13 +59,13 @@ public class GoogleMfaAuthAccount implements BaseBean {
return this;
}
- public GoogleMfaAuthAccount.Builder id(final Long id) {
- instance.setId(id);
+ public GoogleMfaAuthAccount.Builder scratchCodes(final List<Integer>
codes) {
+ instance.setScratchCodes(codes);
return this;
}
- public GoogleMfaAuthAccount.Builder name(final String name) {
- instance.setName(name);
+ public GoogleMfaAuthAccount.Builder registrationDate(final
ZonedDateTime date) {
+ instance.setRegistrationDate(date);
return this;
}
@@ -69,17 +74,27 @@ public class GoogleMfaAuthAccount implements BaseBean {
}
}
- private String secretKey;
+ private long id;
private String name;
- private int validationCode;
+ private String username;
- private long id;
+ private String secretKey;
+
+ private int validationCode;
private List<Integer> scratchCodes = new ArrayList<>(0);
- private OffsetDateTime registrationDate;
+ private ZonedDateTime registrationDate;
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(final long id) {
+ this.id = id;
+ }
public String getName() {
return name;
@@ -89,12 +104,12 @@ public class GoogleMfaAuthAccount implements BaseBean {
this.name = name;
}
- public long getId() {
- return id;
+ public String getUsername() {
+ return username;
}
- public void setId(final long id) {
- this.id = id;
+ public void setUsername(final String username) {
+ this.username = username;
}
public String getSecretKey() {
@@ -121,24 +136,25 @@ public class GoogleMfaAuthAccount implements BaseBean {
this.scratchCodes = scratchCodes;
}
- public OffsetDateTime getRegistrationDate() {
+ public ZonedDateTime getRegistrationDate() {
return registrationDate;
}
- public void setRegistrationDate(final OffsetDateTime registrationDate) {
+ public void setRegistrationDate(final ZonedDateTime registrationDate) {
this.registrationDate = registrationDate;
}
@Override
public int hashCode() {
- return new HashCodeBuilder()
- .append(secretKey)
- .append(name)
- .append(id)
- .append(scratchCodes)
- .append(validationCode)
- .append(registrationDate)
- .toHashCode();
+ return new HashCodeBuilder().
+ append(id).
+ append(name).
+ append(username).
+ append(secretKey).
+ append(validationCode).
+ append(scratchCodes).
+ append(registrationDate).
+ build();
}
@Override
@@ -153,25 +169,27 @@ public class GoogleMfaAuthAccount implements BaseBean {
return false;
}
GoogleMfaAuthAccount other = (GoogleMfaAuthAccount) obj;
- return new EqualsBuilder()
- .append(this.secretKey, other.secretKey)
- .append(this.name, other.name)
- .append(this.id, other.id)
- .append(this.scratchCodes, other.scratchCodes)
- .append(this.registrationDate, other.registrationDate)
- .append(this.validationCode, other.validationCode)
- .isEquals();
+ return new EqualsBuilder().
+ append(id, other.id).
+ append(name, other.name).
+ append(username, other.username).
+ append(secretKey, other.secretKey).
+ append(validationCode, other.validationCode).
+ append(scratchCodes, other.scratchCodes).
+ append(registrationDate, other.registrationDate).
+ build();
}
@Override
public String toString() {
- return new ToStringBuilder(this)
- .append("name", name)
- .append("secretKey", secretKey)
- .append("id", id)
- .append("scratchCodes", scratchCodes)
- .append("registrationDate", registrationDate)
- .append("validationCode", validationCode)
- .toString();
+ return new ToStringBuilder(this).
+ append(id).
+ append(name).
+ append(username).
+ append(secretKey).
+ append(validationCode).
+ append(scratchCodes).
+ append(registrationDate).
+ build();
}
}
diff --git
a/common/am/lib/src/main/java/org/apache/syncope/common/lib/wa/GoogleMfaAuthToken.java
b/common/am/lib/src/main/java/org/apache/syncope/common/lib/wa/GoogleMfaAuthToken.java
index 470103a598..9e4d266349 100644
---
a/common/am/lib/src/main/java/org/apache/syncope/common/lib/wa/GoogleMfaAuthToken.java
+++
b/common/am/lib/src/main/java/org/apache/syncope/common/lib/wa/GoogleMfaAuthToken.java
@@ -69,10 +69,10 @@ public class GoogleMfaAuthToken implements BaseBean {
@Override
public int hashCode() {
- return new HashCodeBuilder()
- .append(otp)
- .append(issueDate)
- .toHashCode();
+ return new HashCodeBuilder().
+ append(otp).
+ append(issueDate).
+ build();
}
@Override
@@ -87,17 +87,17 @@ public class GoogleMfaAuthToken implements BaseBean {
return false;
}
GoogleMfaAuthToken other = (GoogleMfaAuthToken) obj;
- return new EqualsBuilder()
- .append(this.otp, other.otp)
- .append(this.issueDate, other.issueDate)
- .isEquals();
+ return new EqualsBuilder().
+ append(otp, other.otp).
+ append(issueDate, other.issueDate).
+ build();
}
@Override
public String toString() {
- return new ToStringBuilder(this)
- .append("token", otp)
- .append("issueDate", issueDate)
- .toString();
+ return new ToStringBuilder(this).
+ append("token", otp).
+ append("issueDate", issueDate).
+ build();
}
}
diff --git
a/common/am/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/wa/GoogleMfaAuthAccountService.java
b/common/am/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/wa/GoogleMfaAuthAccountService.java
index 201a871bfa..4e9d359e6a 100644
---
a/common/am/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/wa/GoogleMfaAuthAccountService.java
+++
b/common/am/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/wa/GoogleMfaAuthAccountService.java
@@ -40,54 +40,50 @@ import
org.apache.syncope.common.rest.api.service.JAXRSService;
@SecurityRequirements({
@SecurityRequirement(name = "BasicAuthentication"),
@SecurityRequirement(name = "Bearer") })
-@Path("wa/gauth")
+@Path("wa/gauth/accts")
public interface GoogleMfaAuthAccountService extends JAXRSService {
- @DELETE
+ @GET
@Consumes({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML,
MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML,
MediaType.APPLICATION_XML })
- @Path("accts/{owner}")
- void delete(@NotNull @PathParam("owner") String owner);
+ PagedResult<GoogleMfaAuthAccount> list();
- @DELETE
+ @GET
@Consumes({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML,
MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML,
MediaType.APPLICATION_XML })
- @Path("accts/devices/{id}")
- void delete(@NotNull @PathParam("id") long id);
+ @Path("{owner}")
+ PagedResult<GoogleMfaAuthAccount> read(@NotNull @PathParam("owner") String
owner);
- @DELETE
+ @GET
+ @Path("devices/{id}")
@Consumes({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML,
MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML,
MediaType.APPLICATION_XML })
- @Path("accts")
- void deleteAll();
+ GoogleMfaAuthAccount read(@NotNull @PathParam("id") long id);
@POST
- @Path("accts/{owner}")
@Consumes({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML,
MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML,
MediaType.APPLICATION_XML })
- void create(@NotNull @PathParam("owner") String owner, @NotNull
GoogleMfaAuthAccount acct);
+ void create(@NotNull GoogleMfaAuthAccount acct);
@PUT
- @Path("accts/{owner}")
@Consumes({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML,
MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML,
MediaType.APPLICATION_XML })
- void update(@NotNull @PathParam("owner") String owner, @NotNull
GoogleMfaAuthAccount acct);
+ void update(@NotNull GoogleMfaAuthAccount acct);
- @GET
+ @DELETE
@Consumes({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML,
MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML,
MediaType.APPLICATION_XML })
- @Path("accts/{owner}")
- PagedResult<GoogleMfaAuthAccount> read(@NotNull @PathParam("owner") String
owner);
+ @Path("{owner}")
+ void delete(@NotNull @PathParam("owner") String owner);
- @GET
- @Path("accts/id/{id}")
+ @DELETE
@Consumes({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML,
MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML,
MediaType.APPLICATION_XML })
- GoogleMfaAuthAccount read(@NotNull @PathParam("id") long id);
+ @Path("devices/{id}")
+ void delete(@NotNull @PathParam("id") long id);
- @GET
- @Path("accts")
+ @DELETE
@Consumes({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML,
MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, RESTHeaders.APPLICATION_YAML,
MediaType.APPLICATION_XML })
- PagedResult<GoogleMfaAuthAccount> list();
+ void deleteAll();
}
diff --git
a/core/am/logic/src/main/java/org/apache/syncope/core/logic/wa/GoogleMfaAuthAccountLogic.java
b/core/am/logic/src/main/java/org/apache/syncope/core/logic/wa/GoogleMfaAuthAccountLogic.java
index e0de66a054..23cbaeed40 100644
---
a/core/am/logic/src/main/java/org/apache/syncope/core/logic/wa/GoogleMfaAuthAccountLogic.java
+++
b/core/am/logic/src/main/java/org/apache/syncope/core/logic/wa/GoogleMfaAuthAccountLogic.java
@@ -94,10 +94,10 @@ public class GoogleMfaAuthAccountLogic extends
AbstractAuthProfileLogic {
}
@PreAuthorize("hasRole('" + IdRepoEntitlement.ANONYMOUS + "')")
- public void create(final String owner, final GoogleMfaAuthAccount account)
{
- AuthProfile profile = authProfileDAO.findByOwner(owner).orElseGet(()
-> {
+ public void create(final GoogleMfaAuthAccount account) {
+ AuthProfile profile =
authProfileDAO.findByOwner(account.getUsername()).orElseGet(() -> {
AuthProfile authProfile =
entityFactory.newEntity(AuthProfile.class);
- authProfile.setOwner(owner);
+ authProfile.setOwner(account.getUsername());
return authProfile;
});
@@ -108,9 +108,10 @@ public class GoogleMfaAuthAccountLogic extends
AbstractAuthProfileLogic {
}
@PreAuthorize("hasRole('" + IdRepoEntitlement.ANONYMOUS + "')")
- public void update(final String owner, final GoogleMfaAuthAccount account)
{
- AuthProfile authProfile = authProfileDAO.findByOwner(owner).
- orElseThrow(() -> new NotFoundException("Could not find
account for Owner " + owner));
+ public void update(final GoogleMfaAuthAccount account) {
+ AuthProfile authProfile =
authProfileDAO.findByOwner(account.getUsername()).
+ orElseThrow(() -> new NotFoundException("Could not find
account for Owner " + account.getUsername()));
+
List<GoogleMfaAuthAccount> accounts =
authProfile.getGoogleMfaAuthAccounts();
if (accounts.removeIf(acct -> acct.getId() == account.getId())) {
accounts.add(account);
diff --git
a/core/am/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/wa/GoogleMfaAuthAccountServiceImpl.java
b/core/am/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/wa/GoogleMfaAuthAccountServiceImpl.java
index 2c8d95b981..41223a240f 100644
---
a/core/am/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/wa/GoogleMfaAuthAccountServiceImpl.java
+++
b/core/am/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/service/wa/GoogleMfaAuthAccountServiceImpl.java
@@ -51,16 +51,16 @@ public class GoogleMfaAuthAccountServiceImpl extends
AbstractService implements
}
@Override
- public void create(final String owner, final GoogleMfaAuthAccount acct) {
- logic.create(owner, acct);
+ public void create(final GoogleMfaAuthAccount acct) {
+ logic.create(acct);
}
@Override
- public void update(final String owner, final GoogleMfaAuthAccount acct) {
- logic.update(owner, acct);
+ public void update(final GoogleMfaAuthAccount acct) {
+ logic.update(acct);
}
- private PagedResult<GoogleMfaAuthAccount> build(final
List<GoogleMfaAuthAccount> read) {
+ protected PagedResult<GoogleMfaAuthAccount> build(final
List<GoogleMfaAuthAccount> read) {
PagedResult<GoogleMfaAuthAccount> result = new PagedResult<>();
result.setPage(1);
result.setSize(read.size());
diff --git
a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AuthProfileTest.java
b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AuthProfileTest.java
index bc54c790bd..19101d0913 100644
---
a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AuthProfileTest.java
+++
b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AuthProfileTest.java
@@ -24,6 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
+import java.time.ZonedDateTime;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -212,11 +213,12 @@ public class AuthProfileTest extends AbstractTest {
AuthProfile profile = entityFactory.newEntity(AuthProfile.class);
profile.setOwner(owner);
GoogleMfaAuthAccount account = new GoogleMfaAuthAccount.Builder()
- .registrationDate(OffsetDateTime.now())
+ .registrationDate(ZonedDateTime.now())
.scratchCodes(List.of(1, 2, 3, 4, 5))
.secretKey(SecureRandomUtils.generateRandomUUID().toString())
.validationCode(123456)
.name(SecureRandomUtils.generateRandomUUID().toString())
+ .username(owner)
.build();
profile.setGoogleMfaAuthAccounts(List.of(account));
return authProfileDAO.save(profile);
diff --git
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/wa/GoogleMfaAuthAccountITCase.java
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/wa/GoogleMfaAuthAccountITCase.java
index 21cd0d822c..86e06344a6 100644
---
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/wa/GoogleMfaAuthAccountITCase.java
+++
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/wa/GoogleMfaAuthAccountITCase.java
@@ -23,7 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import java.time.OffsetDateTime;
+import java.time.ZonedDateTime;
import java.util.List;
import java.util.UUID;
import org.apache.syncope.common.lib.SyncopeClientException;
@@ -36,9 +36,10 @@ import org.junit.jupiter.api.Test;
public class GoogleMfaAuthAccountITCase extends AbstractITCase {
- private static GoogleMfaAuthAccount createGoogleMfaAuthAccount() {
+ private static GoogleMfaAuthAccount createGoogleMfaAuthAccount(final
String username) {
return new GoogleMfaAuthAccount.Builder()
- .registrationDate(OffsetDateTime.now())
+ .username(username)
+ .registrationDate(ZonedDateTime.now())
.scratchCodes(List.of(1, 2, 3, 4, 5))
.secretKey(SecureRandomUtils.generateRandomUUID().toString())
.validationCode(123456)
@@ -53,15 +54,15 @@ public class GoogleMfaAuthAccountITCase extends
AbstractITCase {
@Test
public void create() {
- GoogleMfaAuthAccount acct = createGoogleMfaAuthAccount();
- assertDoesNotThrow(() ->
GOOGLE_MFA_AUTH_ACCOUNT_SERVICE.create(UUID.randomUUID().toString(), acct));
+ GoogleMfaAuthAccount acct =
createGoogleMfaAuthAccount(UUID.randomUUID().toString());
+ assertDoesNotThrow(() -> GOOGLE_MFA_AUTH_ACCOUNT_SERVICE.create(acct));
}
@Test
public void count() {
String owner = UUID.randomUUID().toString();
- GoogleMfaAuthAccount acct = createGoogleMfaAuthAccount();
- GOOGLE_MFA_AUTH_ACCOUNT_SERVICE.create(owner, acct);
+ GoogleMfaAuthAccount acct = createGoogleMfaAuthAccount(owner);
+ GOOGLE_MFA_AUTH_ACCOUNT_SERVICE.create(acct);
PagedResult<GoogleMfaAuthAccount> list =
GOOGLE_MFA_AUTH_ACCOUNT_SERVICE.list();
assertFalse(list.getResult().isEmpty());
assertEquals(1, list.getTotalCount());
@@ -74,8 +75,8 @@ public class GoogleMfaAuthAccountITCase extends
AbstractITCase {
@Test
public void delete() {
String owner = UUID.randomUUID().toString();
- GoogleMfaAuthAccount acct = createGoogleMfaAuthAccount();
- GOOGLE_MFA_AUTH_ACCOUNT_SERVICE.create(owner, acct);
+ GoogleMfaAuthAccount acct = createGoogleMfaAuthAccount(owner);
+ GOOGLE_MFA_AUTH_ACCOUNT_SERVICE.create(acct);
GOOGLE_MFA_AUTH_ACCOUNT_SERVICE.delete(owner);
assertThrows(SyncopeClientException.class, () ->
GOOGLE_MFA_AUTH_ACCOUNT_SERVICE.read(owner));
}
@@ -83,12 +84,12 @@ public class GoogleMfaAuthAccountITCase extends
AbstractITCase {
@Test
public void update() {
String owner = UUID.randomUUID().toString();
- GoogleMfaAuthAccount acct = createGoogleMfaAuthAccount();
- GOOGLE_MFA_AUTH_ACCOUNT_SERVICE.create(owner, acct);
+ GoogleMfaAuthAccount acct = createGoogleMfaAuthAccount(owner);
+ GOOGLE_MFA_AUTH_ACCOUNT_SERVICE.create(acct);
acct = GOOGLE_MFA_AUTH_ACCOUNT_SERVICE.read(acct.getId());
acct.setSecretKey("NewSecret");
acct.setScratchCodes(List.of(9, 8, 7, 6, 5));
- GOOGLE_MFA_AUTH_ACCOUNT_SERVICE.update(owner, acct);
+ GOOGLE_MFA_AUTH_ACCOUNT_SERVICE.update(acct);
assertEquals(1,
GOOGLE_MFA_AUTH_ACCOUNT_SERVICE.list().getTotalCount());
acct = GOOGLE_MFA_AUTH_ACCOUNT_SERVICE.read(owner).getResult().get(0);
assertEquals(acct.getSecretKey(), acct.getSecretKey());
diff --git
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/gauth/WAGoogleMfaAuthCredentialRepository.java
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/gauth/WAGoogleMfaAuthCredentialRepository.java
index 85951b6eab..e5626187dd 100644
---
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/gauth/WAGoogleMfaAuthCredentialRepository.java
+++
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/gauth/WAGoogleMfaAuthCredentialRepository.java
@@ -19,7 +19,7 @@
package org.apache.syncope.wa.starter.gauth;
import com.warrenstrange.googleauth.IGoogleAuthenticator;
-import java.time.OffsetDateTime;
+import java.time.ZonedDateTime;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
@@ -48,37 +48,22 @@ public class WAGoogleMfaAuthCredentialRepository extends
BaseGoogleAuthenticator
this.waRestClient = waRestClient;
}
- protected GoogleMfaAuthAccount mapGoogleMfaAuthAccount(final
OneTimeTokenAccount otta) {
- return new GoogleMfaAuthAccount.Builder().
- registrationDate(OffsetDateTime.now()).
-
scratchCodes(otta.getScratchCodes().stream().map(Number::intValue).collect(Collectors.toList())).
- validationCode(otta.getValidationCode()).
- secretKey(otta.getSecretKey()).
- id(otta.getId()).
- build();
- }
-
protected GoogleAuthenticatorAccount mapGoogleMfaAuthAccount(final
GoogleMfaAuthAccount gmfaa) {
return GoogleAuthenticatorAccount.builder().
+ id(gmfaa.getId()).
+ name(gmfaa.getName()).
+ username(gmfaa.getUsername()).
secretKey(gmfaa.getSecretKey()).
validationCode(gmfaa.getValidationCode()).
scratchCodes(gmfaa.getScratchCodes().stream().map(Number::intValue).collect(Collectors.toList())).
- name(gmfaa.getName()).
- id(gmfaa.getId()).
+ registrationDate(gmfaa.getRegistrationDate()).
build();
}
- protected GoogleMfaAuthAccountService service() {
- return waRestClient.getService(GoogleMfaAuthAccountService.class);
- }
-
@Override
public OneTimeTokenAccount get(final long id) {
try {
- GoogleMfaAuthAccount account = service().read(id);
- if (account != null) {
- return mapGoogleMfaAuthAccount(account);
- }
+ return
mapGoogleMfaAuthAccount(waRestClient.getService(GoogleMfaAuthAccountService.class).read(id));
} catch (SyncopeClientException e) {
if (e.getType() == ClientExceptionType.NotFound) {
LOG.info("Could not locate account for id {}", id);
@@ -92,7 +77,7 @@ public class WAGoogleMfaAuthCredentialRepository extends
BaseGoogleAuthenticator
@Override
public OneTimeTokenAccount get(final String username, final long id) {
try {
- return service().read(username).
+ return
waRestClient.getService(GoogleMfaAuthAccountService.class).read(username).
getResult().stream().
filter(account -> account.getId() == id).
map(this::mapGoogleMfaAuthAccount).
@@ -111,7 +96,7 @@ public class WAGoogleMfaAuthCredentialRepository extends
BaseGoogleAuthenticator
@Override
public Collection<? extends OneTimeTokenAccount> get(final String
username) {
try {
- return service().read(username).
+ return
waRestClient.getService(GoogleMfaAuthAccountService.class).read(username).
getResult().stream().
map(this::mapGoogleMfaAuthAccount).
collect(Collectors.toList());
@@ -127,42 +112,47 @@ public class WAGoogleMfaAuthCredentialRepository extends
BaseGoogleAuthenticator
@Override
public Collection<? extends OneTimeTokenAccount> load() {
- return service().list().
+ return
waRestClient.getService(GoogleMfaAuthAccountService.class).list().
getResult().stream().
map(this::mapGoogleMfaAuthAccount).
collect(Collectors.toList());
}
- @Override
- public OneTimeTokenAccount save(final OneTimeTokenAccount otta) {
- GoogleMfaAuthAccount account = new GoogleMfaAuthAccount.Builder().
- registrationDate(OffsetDateTime.now()).
-
scratchCodes(otta.getScratchCodes().stream().map(Number::intValue).collect(Collectors.toList())).
- validationCode(otta.getValidationCode()).
- secretKey(otta.getSecretKey()).
- name(otta.getName()).
+ protected GoogleMfaAuthAccount mapOneTimeTokenAccount(final
OneTimeTokenAccount otta) {
+ return new GoogleMfaAuthAccount.Builder().
id(otta.getId()).
+ name(otta.getName()).
+ username(otta.getUsername()).
+ secretKey(otta.getSecretKey()).
+ validationCode(otta.getValidationCode()).
+
scratchCodes(otta.getScratchCodes().stream().map(Number::intValue).collect(Collectors.toList())).
+ registrationDate(ZonedDateTime.now()).
build();
- service().create(otta.getUsername(), account);
- return mapGoogleMfaAuthAccount(account);
+ }
+
+ @Override
+ public OneTimeTokenAccount save(final OneTimeTokenAccount otta) {
+ GoogleMfaAuthAccount account = mapOneTimeTokenAccount(otta);
+
waRestClient.getService(GoogleMfaAuthAccountService.class).create(account);
+ return otta;
}
@Override
public OneTimeTokenAccount update(final OneTimeTokenAccount tokenAccount) {
- GoogleMfaAuthAccount acct = mapGoogleMfaAuthAccount(tokenAccount);
- service().update(tokenAccount.getUsername(), acct);
+ GoogleMfaAuthAccount acct = mapOneTimeTokenAccount(tokenAccount);
+
waRestClient.getService(GoogleMfaAuthAccountService.class).update(acct);
return tokenAccount;
}
@Override
public void deleteAll() {
- service().deleteAll();
+ waRestClient.getService(GoogleMfaAuthAccountService.class).deleteAll();
}
@Override
public void delete(final String username) {
try {
- service().delete(username);
+
waRestClient.getService(GoogleMfaAuthAccountService.class).delete(username);
} catch (SyncopeClientException e) {
if (e.getType() == ClientExceptionType.NotFound) {
LOG.info("Could not locate account for owner {}", username);
@@ -174,18 +164,18 @@ public class WAGoogleMfaAuthCredentialRepository extends
BaseGoogleAuthenticator
@Override
public void delete(final long id) {
- service().delete(id);
+ waRestClient.getService(GoogleMfaAuthAccountService.class).delete(id);
}
@Override
public long count() {
- return service().list().getTotalCount();
+ return
waRestClient.getService(GoogleMfaAuthAccountService.class).list().getTotalCount();
}
@Override
public long count(final String username) {
try {
- return service().read(username).getTotalCount();
+ return
waRestClient.getService(GoogleMfaAuthAccountService.class).read(username).getTotalCount();
} catch (SyncopeClientException e) {
if (e.getType() == ClientExceptionType.NotFound) {
LOG.info("Could not locate account for owner {}", username);
diff --git
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/gauth/WAGoogleMfaAuthTokenRepository.java
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/gauth/WAGoogleMfaAuthTokenRepository.java
index edb1d8b2e5..35a47f7724 100644
---
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/gauth/WAGoogleMfaAuthTokenRepository.java
+++
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/gauth/WAGoogleMfaAuthTokenRepository.java
@@ -40,13 +40,10 @@ public class WAGoogleMfaAuthTokenRepository extends
BaseOneTimeTokenRepository<G
this.expireTokensInSeconds = expireTokensInSeconds;
}
- protected GoogleMfaAuthTokenService service() {
- return waRestClient.getService(GoogleMfaAuthTokenService.class);
- }
-
@Override
protected void cleanInternal() {
-
service().delete(LocalDateTime.now().minusSeconds(expireTokensInSeconds));
+ waRestClient.getService(GoogleMfaAuthTokenService.class).
+
delete(LocalDateTime.now().minusSeconds(expireTokensInSeconds));
}
@Override
@@ -55,13 +52,13 @@ public class WAGoogleMfaAuthTokenRepository extends
BaseOneTimeTokenRepository<G
token(token.getToken()).
issueDate(token.getIssuedDateTime()).
build();
- service().store(token.getUserId(), tokenTO);
+
waRestClient.getService(GoogleMfaAuthTokenService.class).store(token.getUserId(),
tokenTO);
}
@Override
public GoogleAuthenticatorToken get(final String username, final Integer
otp) {
try {
- GoogleMfaAuthToken tokenTO = service().read(username, otp);
+ GoogleMfaAuthToken tokenTO =
waRestClient.getService(GoogleMfaAuthTokenService.class).read(username, otp);
GoogleAuthenticatorToken token = new
GoogleAuthenticatorToken(tokenTO.getOtp(), username);
token.setIssuedDateTime(tokenTO.getIssueDate());
return token;
@@ -73,31 +70,31 @@ public class WAGoogleMfaAuthTokenRepository extends
BaseOneTimeTokenRepository<G
@Override
public void remove(final String username, final Integer otp) {
- service().delete(username, otp);
+
waRestClient.getService(GoogleMfaAuthTokenService.class).delete(username, otp);
}
@Override
public void remove(final String username) {
- service().delete(username);
+
waRestClient.getService(GoogleMfaAuthTokenService.class).delete(username);
}
@Override
public void remove(final Integer otp) {
- service().delete(otp);
+ waRestClient.getService(GoogleMfaAuthTokenService.class).delete(otp);
}
@Override
public void removeAll() {
- service().delete((LocalDateTime) null);
+
waRestClient.getService(GoogleMfaAuthTokenService.class).delete((LocalDateTime)
null);
}
@Override
public long count(final String username) {
- return service().read(username).getTotalCount();
+ return
waRestClient.getService(GoogleMfaAuthTokenService.class).read(username).getTotalCount();
}
@Override
public long count() {
- return service().list().getTotalCount();
+ return
waRestClient.getService(GoogleMfaAuthTokenService.class).list().getTotalCount();
}
}