From 009ca3fdf0dd77e2218f40d2fbbce2328e476ac5 Mon Sep 17 00:00:00 2001 From: Markus Eberl Date: Fri, 12 Aug 2022 11:19:48 +0200 Subject: [PATCH] chore: remove diakonie specifica in package name and fix sonar issues --- pom.xml | 2 +- .../onlineberatung/otp/OtpMailSender.java | 11 ---- .../otp/RandomDigitsCodeGenerator.java | 14 ----- .../RealmOtpResourceProvider.java | 32 +++++----- .../RealmOtpResourceProviderFactory.java | 20 +++---- .../BearerTokenSessionAuthenticator.java | 2 +- .../OtpAppAuthenticatorFactory.java | 5 +- .../authenticator/OtpMailAuthenticator.java | 27 ++++----- .../OtpMailAuthenticatorFactory.java | 15 +++-- .../OtpParameterAuthenticator.java | 12 ++-- .../authenticator/SessionAuthenticator.java | 2 +- .../credential/AppOtpCredentialService.java | 4 +- .../credential/CredentialContext.java | 2 +- .../credential/MailOtpCredentialData.java | 2 +- .../credential/MailOtpCredentialModel.java | 4 +- .../credential/MailOtpCredentialProvider.java | 7 +-- .../MailOtpCredentialProviderFactory.java | 2 +- .../credential/MailOtpCredentialService.java | 4 +- .../credential/MailOtpSecretData.java | 2 +- .../log/LoggingEventListenerProvider.java | 5 +- .../LoggingEventListenerProviderFactory.java | 5 +- .../mail/DefaultMailSender.java | 58 ++++++++++--------- .../mail/MailSendingException.java | 2 +- .../onlineberatung/otp/MemoryOtpService.java | 21 +++---- .../onlineberatung/otp/Otp.java | 2 +- .../onlineberatung/otp/OtpGenerator.java | 2 +- .../de/onlineberatung/otp/OtpMailSender.java | 11 ++++ .../onlineberatung/otp/OtpService.java | 2 +- .../otp/RandomDigitsCodeGenerator.java | 12 ++++ .../onlineberatung/otp/ValidationResult.java | 2 +- ...ycloak.authentication.AuthenticatorFactory | 4 +- ...ycloak.events.EventListenerProviderFactory | 2 +- ...ices.resource.RealmResourceProviderFactory | 2 +- ...mOtpResourceProviderParameterizedTest.java | 22 +++---- .../RealmOtpResourceProviderTest.java | 40 ++++++------- ...OtpMailAuthenticatorParameterizedTest.java | 21 +++---- .../OtpMailAuthenticatorTest.java | 44 +++++++------- .../OtpParameterAuthenticatorTest.java | 10 ++-- .../MailOtpCredentialServiceTest.java | 20 ++++--- .../otp/MemoryOtpServiceTest.java | 10 ++-- 40 files changed, 237 insertions(+), 229 deletions(-) delete mode 100644 src/main/java/de/diakonie/onlineberatung/otp/OtpMailSender.java delete mode 100644 src/main/java/de/diakonie/onlineberatung/otp/RandomDigitsCodeGenerator.java rename src/main/java/de/{diakonie => }/onlineberatung/RealmOtpResourceProvider.java (90%) rename src/main/java/de/{diakonie => }/onlineberatung/RealmOtpResourceProviderFactory.java (73%) rename src/main/java/de/{diakonie => }/onlineberatung/authenticator/BearerTokenSessionAuthenticator.java (94%) rename src/main/java/de/{diakonie => }/onlineberatung/authenticator/OtpAppAuthenticatorFactory.java (96%) rename src/main/java/de/{diakonie => }/onlineberatung/authenticator/OtpMailAuthenticator.java (87%) rename src/main/java/de/{diakonie => }/onlineberatung/authenticator/OtpMailAuthenticatorFactory.java (88%) rename src/main/java/de/{diakonie => }/onlineberatung/authenticator/OtpParameterAuthenticator.java (88%) rename src/main/java/de/{diakonie => }/onlineberatung/authenticator/SessionAuthenticator.java (73%) rename src/main/java/de/{diakonie => }/onlineberatung/credential/AppOtpCredentialService.java (97%) rename src/main/java/de/{diakonie => }/onlineberatung/credential/CredentialContext.java (96%) rename src/main/java/de/{diakonie => }/onlineberatung/credential/MailOtpCredentialData.java (95%) rename src/main/java/de/{diakonie => }/onlineberatung/credential/MailOtpCredentialModel.java (97%) rename src/main/java/de/{diakonie => }/onlineberatung/credential/MailOtpCredentialProvider.java (93%) rename src/main/java/de/{diakonie => }/onlineberatung/credential/MailOtpCredentialProviderFactory.java (91%) rename src/main/java/de/{diakonie => }/onlineberatung/credential/MailOtpCredentialService.java (96%) rename src/main/java/de/{diakonie => }/onlineberatung/credential/MailOtpSecretData.java (91%) rename src/main/java/de/{diakonie => }/onlineberatung/log/LoggingEventListenerProvider.java (99%) rename src/main/java/de/{diakonie => }/onlineberatung/log/LoggingEventListenerProviderFactory.java (95%) rename src/main/java/de/{diakonie => }/onlineberatung/mail/DefaultMailSender.java (88%) rename src/main/java/de/{diakonie => }/onlineberatung/mail/MailSendingException.java (79%) rename src/main/java/de/{diakonie => }/onlineberatung/otp/MemoryOtpService.java (77%) rename src/main/java/de/{diakonie => }/onlineberatung/otp/Otp.java (97%) rename src/main/java/de/{diakonie => }/onlineberatung/otp/OtpGenerator.java (62%) create mode 100644 src/main/java/de/onlineberatung/otp/OtpMailSender.java rename src/main/java/de/{diakonie => }/onlineberatung/otp/OtpService.java (76%) create mode 100644 src/main/java/de/onlineberatung/otp/RandomDigitsCodeGenerator.java rename src/main/java/de/{diakonie => }/onlineberatung/otp/ValidationResult.java (71%) rename src/test/java/de/{diakonie => }/onlineberatung/RealmOtpResourceProviderParameterizedTest.java (84%) rename src/test/java/de/{diakonie => }/onlineberatung/RealmOtpResourceProviderTest.java (90%) rename src/test/java/de/{diakonie => }/onlineberatung/authenticator/OtpMailAuthenticatorParameterizedTest.java (86%) rename src/test/java/de/{diakonie => }/onlineberatung/authenticator/OtpMailAuthenticatorTest.java (80%) rename src/test/java/de/{diakonie => }/onlineberatung/authenticator/OtpParameterAuthenticatorTest.java (90%) rename src/test/java/de/{diakonie => }/onlineberatung/credential/MailOtpCredentialServiceTest.java (80%) rename src/test/java/de/{diakonie => }/onlineberatung/otp/MemoryOtpServiceTest.java (93%) diff --git a/pom.xml b/pom.xml index db91c48..31ff26a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - de.diakonie.onlineberatung + de.onlineberatung keycloak-otp-config-spi 1.0-SNAPSHOT diff --git a/src/main/java/de/diakonie/onlineberatung/otp/OtpMailSender.java b/src/main/java/de/diakonie/onlineberatung/otp/OtpMailSender.java deleted file mode 100644 index 11e75fc..0000000 --- a/src/main/java/de/diakonie/onlineberatung/otp/OtpMailSender.java +++ /dev/null @@ -1,11 +0,0 @@ -package de.diakonie.onlineberatung.otp; - -import de.diakonie.onlineberatung.credential.CredentialContext; -import de.diakonie.onlineberatung.mail.MailSendingException; - -public interface OtpMailSender { - - void sendOtpCode(Otp otp, - CredentialContext credentialContext) throws MailSendingException; - -} \ No newline at end of file diff --git a/src/main/java/de/diakonie/onlineberatung/otp/RandomDigitsCodeGenerator.java b/src/main/java/de/diakonie/onlineberatung/otp/RandomDigitsCodeGenerator.java deleted file mode 100644 index 5b78062..0000000 --- a/src/main/java/de/diakonie/onlineberatung/otp/RandomDigitsCodeGenerator.java +++ /dev/null @@ -1,14 +0,0 @@ -package de.diakonie.onlineberatung.otp; - - -import java.security.SecureRandom; -import org.keycloak.common.util.RandomString; - -public class RandomDigitsCodeGenerator implements OtpGenerator { - - @Override - public String generate(int length) { - return new RandomString(length, new SecureRandom(), RandomString.digits).nextString(); - } - -} diff --git a/src/main/java/de/diakonie/onlineberatung/RealmOtpResourceProvider.java b/src/main/java/de/onlineberatung/RealmOtpResourceProvider.java similarity index 90% rename from src/main/java/de/diakonie/onlineberatung/RealmOtpResourceProvider.java rename to src/main/java/de/onlineberatung/RealmOtpResourceProvider.java index d2c93ce..562d9d1 100644 --- a/src/main/java/de/diakonie/onlineberatung/RealmOtpResourceProvider.java +++ b/src/main/java/de/onlineberatung/RealmOtpResourceProvider.java @@ -1,22 +1,22 @@ -package de.diakonie.onlineberatung; +package de.onlineberatung; import static java.util.Objects.isNull; import static java.util.Objects.nonNull; -import de.diakonie.onlineberatung.authenticator.SessionAuthenticator; -import de.diakonie.onlineberatung.credential.AppOtpCredentialService; -import de.diakonie.onlineberatung.credential.CredentialContext; -import de.diakonie.onlineberatung.credential.MailOtpCredentialService; -import de.diakonie.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.Error; -import de.diakonie.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.OtpInfoDTO; -import de.diakonie.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.OtpSetupDTO; -import de.diakonie.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.OtpType; -import de.diakonie.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.Success; -import de.diakonie.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.SuccessWithEmail; -import de.diakonie.onlineberatung.mail.MailSendingException; -import de.diakonie.onlineberatung.otp.Otp; -import de.diakonie.onlineberatung.otp.OtpMailSender; -import de.diakonie.onlineberatung.otp.OtpService; +import de.onlineberatung.authenticator.SessionAuthenticator; +import de.onlineberatung.credential.AppOtpCredentialService; +import de.onlineberatung.credential.CredentialContext; +import de.onlineberatung.credential.MailOtpCredentialService; +import de.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.Error; +import de.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.OtpInfoDTO; +import de.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.OtpSetupDTO; +import de.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.OtpType; +import de.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.Success; +import de.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.SuccessWithEmail; +import de.onlineberatung.mail.MailSendingException; +import de.onlineberatung.otp.Otp; +import de.onlineberatung.otp.OtpMailSender; +import de.onlineberatung.otp.OtpService; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -44,7 +44,7 @@ public class RealmOtpResourceProvider implements RealmResourceProvider { private static final String MISSING_CREDENTIAL_CONFIG = "no mail otp credentials configured"; private static final String MISSING_USERNAME_ERROR_DESCRIPTION = "username not found"; private static final String MISSING_EMAIL_ADDRESS_ERROR_DESCRIPTION = "email address of user not available"; - private final static String FAILED_TO_SENT = "failed to send otp verification email"; + private static final String FAILED_TO_SENT = "failed to send otp verification email"; private final KeycloakSession session; private final SessionAuthenticator sessionAuthenticator; diff --git a/src/main/java/de/diakonie/onlineberatung/RealmOtpResourceProviderFactory.java b/src/main/java/de/onlineberatung/RealmOtpResourceProviderFactory.java similarity index 73% rename from src/main/java/de/diakonie/onlineberatung/RealmOtpResourceProviderFactory.java rename to src/main/java/de/onlineberatung/RealmOtpResourceProviderFactory.java index 0f39b20..e77af11 100644 --- a/src/main/java/de/diakonie/onlineberatung/RealmOtpResourceProviderFactory.java +++ b/src/main/java/de/onlineberatung/RealmOtpResourceProviderFactory.java @@ -1,14 +1,14 @@ -package de.diakonie.onlineberatung; +package de.onlineberatung; -import static de.diakonie.onlineberatung.authenticator.OtpMailAuthenticatorFactory.OTP_CONFIG_ALIAS; +import static de.onlineberatung.authenticator.OtpMailAuthenticatorFactory.OTP_CONFIG_ALIAS; -import de.diakonie.onlineberatung.authenticator.BearerTokenSessionAuthenticator; -import de.diakonie.onlineberatung.credential.AppOtpCredentialService; -import de.diakonie.onlineberatung.credential.MailOtpCredentialProviderFactory; -import de.diakonie.onlineberatung.credential.MailOtpCredentialService; -import de.diakonie.onlineberatung.mail.DefaultMailSender; -import de.diakonie.onlineberatung.otp.MemoryOtpService; -import de.diakonie.onlineberatung.otp.RandomDigitsCodeGenerator; +import de.onlineberatung.authenticator.BearerTokenSessionAuthenticator; +import de.onlineberatung.credential.AppOtpCredentialService; +import de.onlineberatung.credential.MailOtpCredentialProviderFactory; +import de.onlineberatung.credential.MailOtpCredentialService; +import de.onlineberatung.mail.DefaultMailSender; +import de.onlineberatung.otp.MemoryOtpService; +import de.onlineberatung.otp.RandomDigitsCodeGenerator; import java.time.Clock; import org.keycloak.Config.Scope; import org.keycloak.models.KeycloakSession; @@ -55,4 +55,4 @@ public void close() { public String getId() { return ID; } -} \ No newline at end of file +} diff --git a/src/main/java/de/diakonie/onlineberatung/authenticator/BearerTokenSessionAuthenticator.java b/src/main/java/de/onlineberatung/authenticator/BearerTokenSessionAuthenticator.java similarity index 94% rename from src/main/java/de/diakonie/onlineberatung/authenticator/BearerTokenSessionAuthenticator.java rename to src/main/java/de/onlineberatung/authenticator/BearerTokenSessionAuthenticator.java index 293340f..842dfd6 100644 --- a/src/main/java/de/diakonie/onlineberatung/authenticator/BearerTokenSessionAuthenticator.java +++ b/src/main/java/de/onlineberatung/authenticator/BearerTokenSessionAuthenticator.java @@ -1,4 +1,4 @@ -package de.diakonie.onlineberatung.authenticator; +package de.onlineberatung.authenticator; import static java.util.Objects.isNull; diff --git a/src/main/java/de/diakonie/onlineberatung/authenticator/OtpAppAuthenticatorFactory.java b/src/main/java/de/onlineberatung/authenticator/OtpAppAuthenticatorFactory.java similarity index 96% rename from src/main/java/de/diakonie/onlineberatung/authenticator/OtpAppAuthenticatorFactory.java rename to src/main/java/de/onlineberatung/authenticator/OtpAppAuthenticatorFactory.java index 88e34ad..8218cb6 100644 --- a/src/main/java/de/diakonie/onlineberatung/authenticator/OtpAppAuthenticatorFactory.java +++ b/src/main/java/de/onlineberatung/authenticator/OtpAppAuthenticatorFactory.java @@ -1,4 +1,4 @@ -package de.diakonie.onlineberatung.authenticator; +package de.onlineberatung.authenticator; import static java.util.Arrays.asList; @@ -73,14 +73,17 @@ public Authenticator create(KeycloakSession session) { @Override public void init(Config.Scope config) { + // unused } @Override public void postInit(KeycloakSessionFactory factory) { + // unused } @Override public void close() { + // unused } diff --git a/src/main/java/de/diakonie/onlineberatung/authenticator/OtpMailAuthenticator.java b/src/main/java/de/onlineberatung/authenticator/OtpMailAuthenticator.java similarity index 87% rename from src/main/java/de/diakonie/onlineberatung/authenticator/OtpMailAuthenticator.java rename to src/main/java/de/onlineberatung/authenticator/OtpMailAuthenticator.java index 8aaf7ad..58e441c 100644 --- a/src/main/java/de/diakonie/onlineberatung/authenticator/OtpMailAuthenticator.java +++ b/src/main/java/de/onlineberatung/authenticator/OtpMailAuthenticator.java @@ -1,17 +1,18 @@ -package de.diakonie.onlineberatung.authenticator; +package de.onlineberatung.authenticator; -import static de.diakonie.onlineberatung.authenticator.OtpParameterAuthenticator.extractDecodedOtpParam; -import static de.diakonie.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.OtpType.EMAIL; +import static de.onlineberatung.authenticator.OtpParameterAuthenticator.extractDecodedOtpParam; import static java.util.Objects.isNull; import static java.util.Objects.nonNull; -import de.diakonie.onlineberatung.credential.CredentialContext; -import de.diakonie.onlineberatung.credential.MailOtpCredentialModel; -import de.diakonie.onlineberatung.credential.MailOtpCredentialService; -import de.diakonie.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.Challenge; -import de.diakonie.onlineberatung.mail.MailSendingException; -import de.diakonie.onlineberatung.otp.OtpMailSender; -import de.diakonie.onlineberatung.otp.OtpService; +import de.onlineberatung.credential.CredentialContext; +import de.onlineberatung.credential.MailOtpCredentialModel; +import de.onlineberatung.credential.MailOtpCredentialService; +import de.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.Challenge; +import de.onlineberatung.mail.MailSendingException; +import de.onlineberatung.otp.OtpMailSender; +import de.onlineberatung.otp.OtpService; +import de.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.OtpType; +import java.util.Collections; import java.util.List; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -74,7 +75,7 @@ public boolean requiresUser() { @Override public void setRequiredActions(KeycloakSession session, RealmModel realm, UserModel user) { - + // unused } private void sendOtpMail(MailOtpCredentialModel credentialModel, CredentialContext credContext, @@ -93,7 +94,7 @@ private void sendOtpMail(MailOtpCredentialModel credentialModel, CredentialConte try { mailSender.sendOtpCode(otp, credContext); var challengeResponse = new Challenge().error(INVALID_GRANT_ERROR) - .errorDescription("Missing totp").otpType(EMAIL); + .errorDescription("Missing totp").otpType(OtpType.EMAIL); context.failure(AuthenticationFlowError.INVALID_CREDENTIALS, Response.status(Status.BAD_REQUEST).entity(challengeResponse) .type(MediaType.APPLICATION_JSON_TYPE).build()); @@ -177,7 +178,7 @@ public String getHelpText() { @Override public List getConfigProperties() { - return null; + return Collections.emptyList(); } @Override diff --git a/src/main/java/de/diakonie/onlineberatung/authenticator/OtpMailAuthenticatorFactory.java b/src/main/java/de/onlineberatung/authenticator/OtpMailAuthenticatorFactory.java similarity index 88% rename from src/main/java/de/diakonie/onlineberatung/authenticator/OtpMailAuthenticatorFactory.java rename to src/main/java/de/onlineberatung/authenticator/OtpMailAuthenticatorFactory.java index 833ef52..7cf0b2a 100644 --- a/src/main/java/de/diakonie/onlineberatung/authenticator/OtpMailAuthenticatorFactory.java +++ b/src/main/java/de/onlineberatung/authenticator/OtpMailAuthenticatorFactory.java @@ -1,12 +1,12 @@ -package de.diakonie.onlineberatung.authenticator; +package de.onlineberatung.authenticator; import static java.util.Arrays.asList; -import de.diakonie.onlineberatung.credential.MailOtpCredentialProviderFactory; -import de.diakonie.onlineberatung.credential.MailOtpCredentialService; -import de.diakonie.onlineberatung.mail.DefaultMailSender; -import de.diakonie.onlineberatung.otp.MemoryOtpService; -import de.diakonie.onlineberatung.otp.RandomDigitsCodeGenerator; +import de.onlineberatung.credential.MailOtpCredentialProviderFactory; +import de.onlineberatung.credential.MailOtpCredentialService; +import de.onlineberatung.mail.DefaultMailSender; +import de.onlineberatung.otp.MemoryOtpService; +import de.onlineberatung.otp.RandomDigitsCodeGenerator; import java.time.Clock; import java.util.List; import org.keycloak.Config; @@ -89,14 +89,17 @@ public Authenticator create(KeycloakSession session) { @Override public void init(Config.Scope config) { + // unused } @Override public void postInit(KeycloakSessionFactory factory) { + // unused } @Override public void close() { + // unused } } diff --git a/src/main/java/de/diakonie/onlineberatung/authenticator/OtpParameterAuthenticator.java b/src/main/java/de/onlineberatung/authenticator/OtpParameterAuthenticator.java similarity index 88% rename from src/main/java/de/diakonie/onlineberatung/authenticator/OtpParameterAuthenticator.java rename to src/main/java/de/onlineberatung/authenticator/OtpParameterAuthenticator.java index c37f2a0..698b202 100644 --- a/src/main/java/de/diakonie/onlineberatung/authenticator/OtpParameterAuthenticator.java +++ b/src/main/java/de/onlineberatung/authenticator/OtpParameterAuthenticator.java @@ -1,9 +1,9 @@ -package de.diakonie.onlineberatung.authenticator; +package de.onlineberatung.authenticator; -import static de.diakonie.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.OtpType.APP; import static java.util.Objects.isNull; -import de.diakonie.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.Challenge; +import de.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.Challenge; +import de.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.OtpType; import java.util.Collections; import java.util.List; import javax.ws.rs.core.MediaType; @@ -24,7 +24,7 @@ public class OtpParameterAuthenticator extends AbstractDirectGrantAuthenticator public static final String ID = "otp-parameter-authenticator"; - final AuthenticationExecutionModel.Requirement[] REQUIREMENT_CHOICES = { + static final AuthenticationExecutionModel.Requirement[] REQUIREMENT_CHOICES = { AuthenticationExecutionModel.Requirement.REQUIRED}; @Override @@ -38,7 +38,7 @@ public void authenticate(AuthenticationFlowContext context) { if (otpOfRequest == null) { Challenge challengeResponse = new Challenge().error("invalid_grant") - .errorDescription("Missing totp").otpType(APP); + .errorDescription("Missing totp").otpType(OtpType.APP); context.failure(AuthenticationFlowError.INVALID_CREDENTIALS, Response.status(Status.BAD_REQUEST).entity(challengeResponse) .type(MediaType.APPLICATION_JSON_TYPE).build()); @@ -106,4 +106,4 @@ static String extractDecodedOtpParam(AuthenticationFlowContext context) { otpParam = (isNull(otpParam)) ? inputData.getFirst("totp") : otpParam; return otpParam; } -} \ No newline at end of file +} diff --git a/src/main/java/de/diakonie/onlineberatung/authenticator/SessionAuthenticator.java b/src/main/java/de/onlineberatung/authenticator/SessionAuthenticator.java similarity index 73% rename from src/main/java/de/diakonie/onlineberatung/authenticator/SessionAuthenticator.java rename to src/main/java/de/onlineberatung/authenticator/SessionAuthenticator.java index 75d4d82..0dafd1d 100644 --- a/src/main/java/de/diakonie/onlineberatung/authenticator/SessionAuthenticator.java +++ b/src/main/java/de/onlineberatung/authenticator/SessionAuthenticator.java @@ -1,4 +1,4 @@ -package de.diakonie.onlineberatung.authenticator; +package de.onlineberatung.authenticator; import org.keycloak.models.KeycloakSession; diff --git a/src/main/java/de/diakonie/onlineberatung/credential/AppOtpCredentialService.java b/src/main/java/de/onlineberatung/credential/AppOtpCredentialService.java similarity index 97% rename from src/main/java/de/diakonie/onlineberatung/credential/AppOtpCredentialService.java rename to src/main/java/de/onlineberatung/credential/AppOtpCredentialService.java index 4735f65..4f8d5ea 100644 --- a/src/main/java/de/diakonie/onlineberatung/credential/AppOtpCredentialService.java +++ b/src/main/java/de/onlineberatung/credential/AppOtpCredentialService.java @@ -1,4 +1,4 @@ -package de.diakonie.onlineberatung.credential; +package de.onlineberatung.credential; import org.keycloak.models.credential.OTPCredentialModel; import org.keycloak.models.utils.CredentialValidation; @@ -47,4 +47,4 @@ public void deleteCredentials(CredentialContext context) { credentialModel -> CredentialHelper.deleteOTPCredential(context.getSession(), context.getRealm(), context.getUser(), credentialModel.getId())); } -} \ No newline at end of file +} diff --git a/src/main/java/de/diakonie/onlineberatung/credential/CredentialContext.java b/src/main/java/de/onlineberatung/credential/CredentialContext.java similarity index 96% rename from src/main/java/de/diakonie/onlineberatung/credential/CredentialContext.java rename to src/main/java/de/onlineberatung/credential/CredentialContext.java index b7e7366..2d138b3 100644 --- a/src/main/java/de/diakonie/onlineberatung/credential/CredentialContext.java +++ b/src/main/java/de/onlineberatung/credential/CredentialContext.java @@ -1,4 +1,4 @@ -package de.diakonie.onlineberatung.credential; +package de.onlineberatung.credential; import java.util.Objects; import org.keycloak.authentication.AuthenticationFlowContext; diff --git a/src/main/java/de/diakonie/onlineberatung/credential/MailOtpCredentialData.java b/src/main/java/de/onlineberatung/credential/MailOtpCredentialData.java similarity index 95% rename from src/main/java/de/diakonie/onlineberatung/credential/MailOtpCredentialData.java rename to src/main/java/de/onlineberatung/credential/MailOtpCredentialData.java index 3da7679..341391b 100644 --- a/src/main/java/de/diakonie/onlineberatung/credential/MailOtpCredentialData.java +++ b/src/main/java/de/onlineberatung/credential/MailOtpCredentialData.java @@ -1,4 +1,4 @@ -package de.diakonie.onlineberatung.credential; +package de.onlineberatung.credential; public class MailOtpCredentialData { diff --git a/src/main/java/de/diakonie/onlineberatung/credential/MailOtpCredentialModel.java b/src/main/java/de/onlineberatung/credential/MailOtpCredentialModel.java similarity index 97% rename from src/main/java/de/diakonie/onlineberatung/credential/MailOtpCredentialModel.java rename to src/main/java/de/onlineberatung/credential/MailOtpCredentialModel.java index 07a1c02..fe3621b 100644 --- a/src/main/java/de/diakonie/onlineberatung/credential/MailOtpCredentialModel.java +++ b/src/main/java/de/onlineberatung/credential/MailOtpCredentialModel.java @@ -1,8 +1,8 @@ -package de.diakonie.onlineberatung.credential; +package de.onlineberatung.credential; import static org.keycloak.util.JsonSerialization.writeValueAsString; -import de.diakonie.onlineberatung.otp.Otp; +import de.onlineberatung.otp.Otp; import java.io.IOException; import java.time.Clock; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/de/diakonie/onlineberatung/credential/MailOtpCredentialProvider.java b/src/main/java/de/onlineberatung/credential/MailOtpCredentialProvider.java similarity index 93% rename from src/main/java/de/diakonie/onlineberatung/credential/MailOtpCredentialProvider.java rename to src/main/java/de/onlineberatung/credential/MailOtpCredentialProvider.java index 3fffabe..a1abdfd 100644 --- a/src/main/java/de/diakonie/onlineberatung/credential/MailOtpCredentialProvider.java +++ b/src/main/java/de/onlineberatung/credential/MailOtpCredentialProvider.java @@ -1,7 +1,6 @@ -package de.diakonie.onlineberatung.credential; +package de.onlineberatung.credential; -import de.diakonie.onlineberatung.RealmOtpResourceProvider; -import de.diakonie.onlineberatung.authenticator.OtpMailAuthenticator; +import de.onlineberatung.authenticator.OtpMailAuthenticator; import java.time.Clock; import org.jboss.logging.Logger; import org.keycloak.credential.CredentialInput; @@ -19,7 +18,7 @@ public class MailOtpCredentialProvider implements CredentialProvider, CredentialInputValidator { - private static final Logger logger = Logger.getLogger(RealmOtpResourceProvider.class); + private static final Logger logger = Logger.getLogger(MailOtpCredentialProvider.class); private final KeycloakSession session; private final Clock clock; diff --git a/src/main/java/de/diakonie/onlineberatung/credential/MailOtpCredentialProviderFactory.java b/src/main/java/de/onlineberatung/credential/MailOtpCredentialProviderFactory.java similarity index 91% rename from src/main/java/de/diakonie/onlineberatung/credential/MailOtpCredentialProviderFactory.java rename to src/main/java/de/onlineberatung/credential/MailOtpCredentialProviderFactory.java index 83171d8..5bae742 100644 --- a/src/main/java/de/diakonie/onlineberatung/credential/MailOtpCredentialProviderFactory.java +++ b/src/main/java/de/onlineberatung/credential/MailOtpCredentialProviderFactory.java @@ -1,4 +1,4 @@ -package de.diakonie.onlineberatung.credential; +package de.onlineberatung.credential; import java.time.Clock; import org.keycloak.credential.CredentialProviderFactory; diff --git a/src/main/java/de/diakonie/onlineberatung/credential/MailOtpCredentialService.java b/src/main/java/de/onlineberatung/credential/MailOtpCredentialService.java similarity index 96% rename from src/main/java/de/diakonie/onlineberatung/credential/MailOtpCredentialService.java rename to src/main/java/de/onlineberatung/credential/MailOtpCredentialService.java index 9b8daf4..17ecd88 100644 --- a/src/main/java/de/diakonie/onlineberatung/credential/MailOtpCredentialService.java +++ b/src/main/java/de/onlineberatung/credential/MailOtpCredentialService.java @@ -1,9 +1,9 @@ -package de.diakonie.onlineberatung.credential; +package de.onlineberatung.credential; import static java.util.Objects.isNull; import static java.util.Objects.nonNull; -import de.diakonie.onlineberatung.otp.Otp; +import de.onlineberatung.otp.Otp; import java.time.Clock; public class MailOtpCredentialService { diff --git a/src/main/java/de/diakonie/onlineberatung/credential/MailOtpSecretData.java b/src/main/java/de/onlineberatung/credential/MailOtpSecretData.java similarity index 91% rename from src/main/java/de/diakonie/onlineberatung/credential/MailOtpSecretData.java rename to src/main/java/de/onlineberatung/credential/MailOtpSecretData.java index 3a30b88..f4a394a 100644 --- a/src/main/java/de/diakonie/onlineberatung/credential/MailOtpSecretData.java +++ b/src/main/java/de/onlineberatung/credential/MailOtpSecretData.java @@ -1,4 +1,4 @@ -package de.diakonie.onlineberatung.credential; +package de.onlineberatung.credential; public class MailOtpSecretData { diff --git a/src/main/java/de/diakonie/onlineberatung/log/LoggingEventListenerProvider.java b/src/main/java/de/onlineberatung/log/LoggingEventListenerProvider.java similarity index 99% rename from src/main/java/de/diakonie/onlineberatung/log/LoggingEventListenerProvider.java rename to src/main/java/de/onlineberatung/log/LoggingEventListenerProvider.java index 8f1dc28..8ca90b4 100644 --- a/src/main/java/de/diakonie/onlineberatung/log/LoggingEventListenerProvider.java +++ b/src/main/java/de/onlineberatung/log/LoggingEventListenerProvider.java @@ -1,4 +1,4 @@ -package de.diakonie.onlineberatung.log; +package de.onlineberatung.log; import java.util.Map; import javax.ws.rs.core.Cookie; @@ -145,6 +145,7 @@ private void logAdminEvent(AdminEvent adminEvent, boolean includeRepresentation) @Override public void close() { + // unused } private void setKeycloakContext(StringBuilder sb) { @@ -173,4 +174,4 @@ private void setKeycloakContext(StringBuilder sb) { sb.append("]"); } -} \ No newline at end of file +} diff --git a/src/main/java/de/diakonie/onlineberatung/log/LoggingEventListenerProviderFactory.java b/src/main/java/de/onlineberatung/log/LoggingEventListenerProviderFactory.java similarity index 95% rename from src/main/java/de/diakonie/onlineberatung/log/LoggingEventListenerProviderFactory.java rename to src/main/java/de/onlineberatung/log/LoggingEventListenerProviderFactory.java index 914b15e..2b264bd 100644 --- a/src/main/java/de/diakonie/onlineberatung/log/LoggingEventListenerProviderFactory.java +++ b/src/main/java/de/onlineberatung/log/LoggingEventListenerProviderFactory.java @@ -1,4 +1,4 @@ -package de.diakonie.onlineberatung.log; +package de.onlineberatung.log; import org.jboss.logging.Logger; import org.keycloak.Config; @@ -29,11 +29,12 @@ public void init(Config.Scope config) { @Override public void postInit(KeycloakSessionFactory factory) { - + // unused } @Override public void close() { + // unused } @Override diff --git a/src/main/java/de/diakonie/onlineberatung/mail/DefaultMailSender.java b/src/main/java/de/onlineberatung/mail/DefaultMailSender.java similarity index 88% rename from src/main/java/de/diakonie/onlineberatung/mail/DefaultMailSender.java rename to src/main/java/de/onlineberatung/mail/DefaultMailSender.java index a2bd0fe..84b3869 100644 --- a/src/main/java/de/diakonie/onlineberatung/mail/DefaultMailSender.java +++ b/src/main/java/de/onlineberatung/mail/DefaultMailSender.java @@ -1,10 +1,12 @@ -package de.diakonie.onlineberatung.mail; +package de.onlineberatung.mail; import static java.util.Collections.emptyList; +import static java.util.Collections.emptyMap; +import static java.util.Collections.emptySet; -import de.diakonie.onlineberatung.credential.CredentialContext; -import de.diakonie.onlineberatung.otp.Otp; -import de.diakonie.onlineberatung.otp.OtpMailSender; +import de.onlineberatung.credential.CredentialContext; +import de.onlineberatung.otp.Otp; +import de.onlineberatung.otp.OtpMailSender; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -79,7 +81,7 @@ public String getUsername() { @Override public void setUsername(String username) { - + // unused } @Override @@ -89,7 +91,7 @@ public Long getCreatedTimestamp() { @Override public void setCreatedTimestamp(Long timestamp) { - + // unused } @Override @@ -99,22 +101,22 @@ public boolean isEnabled() { @Override public void setEnabled(boolean enabled) { - + // unused } @Override public void setSingleAttribute(String name, String value) { - + // unused } @Override public void setAttribute(String name, List values) { - + // unused } @Override public void removeAttribute(String name) { - + // unused } @Override @@ -124,27 +126,27 @@ public String getFirstAttribute(String name) { @Override public List getAttribute(String name) { - return null; + return emptyList(); } @Override public Map> getAttributes() { - return null; + return emptyMap(); } @Override public Set getRequiredActions() { - return null; + return emptySet(); } @Override public void addRequiredAction(String action) { - + // unused } @Override public void removeRequiredAction(String action) { - + // unused } @Override @@ -154,7 +156,7 @@ public String getFirstName() { @Override public void setFirstName(String firstName) { - + // unused } @Override @@ -164,7 +166,7 @@ public String getLastName() { @Override public void setLastName(String lastName) { - + // unused } @Override @@ -184,22 +186,22 @@ public boolean isEmailVerified() { @Override public void setEmailVerified(boolean verified) { - + // unused } @Override public Set getGroups() { - return null; + return emptySet(); } @Override public void joinGroup(GroupModel group) { - + // unused } @Override public void leaveGroup(GroupModel group) { - + // unused } @Override @@ -214,7 +216,7 @@ public String getFederationLink() { @Override public void setFederationLink(String link) { - + // unused } @Override @@ -224,17 +226,17 @@ public String getServiceAccountClientLink() { @Override public void setServiceAccountClientLink(String clientInternalId) { - + // unused } @Override public Set getRealmRoleMappings() { - return null; + return emptySet(); } @Override public Set getClientRoleMappings(ClientModel app) { - return null; + return emptySet(); } @Override @@ -244,17 +246,17 @@ public boolean hasRole(RoleModel role) { @Override public void grantRole(RoleModel role) { - + // unused } @Override public Set getRoleMappings() { - return null; + return emptySet(); } @Override public void deleteRoleMapping(RoleModel role) { - + // unused } } } diff --git a/src/main/java/de/diakonie/onlineberatung/mail/MailSendingException.java b/src/main/java/de/onlineberatung/mail/MailSendingException.java similarity index 79% rename from src/main/java/de/diakonie/onlineberatung/mail/MailSendingException.java rename to src/main/java/de/onlineberatung/mail/MailSendingException.java index 3a149e9..03e54af 100644 --- a/src/main/java/de/diakonie/onlineberatung/mail/MailSendingException.java +++ b/src/main/java/de/onlineberatung/mail/MailSendingException.java @@ -1,4 +1,4 @@ -package de.diakonie.onlineberatung.mail; +package de.onlineberatung.mail; public class MailSendingException extends RuntimeException { diff --git a/src/main/java/de/diakonie/onlineberatung/otp/MemoryOtpService.java b/src/main/java/de/onlineberatung/otp/MemoryOtpService.java similarity index 77% rename from src/main/java/de/diakonie/onlineberatung/otp/MemoryOtpService.java rename to src/main/java/de/onlineberatung/otp/MemoryOtpService.java index 252e248..4d5e649 100644 --- a/src/main/java/de/diakonie/onlineberatung/otp/MemoryOtpService.java +++ b/src/main/java/de/onlineberatung/otp/MemoryOtpService.java @@ -1,14 +1,9 @@ -package de.diakonie.onlineberatung.otp; +package de.onlineberatung.otp; -import static de.diakonie.onlineberatung.otp.ValidationResult.EXPIRED; -import static de.diakonie.onlineberatung.otp.ValidationResult.INVALID; -import static de.diakonie.onlineberatung.otp.ValidationResult.NOT_PRESENT; -import static de.diakonie.onlineberatung.otp.ValidationResult.TOO_MANY_FAILED_ATTEMPTS; -import static de.diakonie.onlineberatung.otp.ValidationResult.VALID; import static java.util.Objects.isNull; import static java.util.Objects.nonNull; -import de.diakonie.onlineberatung.credential.MailOtpCredentialModel; +import de.onlineberatung.credential.MailOtpCredentialModel; import java.time.Clock; import javax.annotation.Nullable; import org.jboss.logging.Logger; @@ -55,27 +50,27 @@ public Otp createOtp(String emailAddress) { @Override public ValidationResult validate(String currentCode, Otp storedOtp) { if (isNull(currentCode) || currentCode.isBlank()) { - return INVALID; + return ValidationResult.INVALID; } if (isNull(storedOtp) || isNull(storedOtp.getCode()) || MailOtpCredentialModel.INVALIDATED.equals(storedOtp.getCode())) { - return NOT_PRESENT; + return ValidationResult.NOT_PRESENT; } if (storedOtp.getFailedVerifications() >= MAX_FAILED_VALIDATIONS) { - return TOO_MANY_FAILED_ATTEMPTS; + return ValidationResult.TOO_MANY_FAILED_ATTEMPTS; } if (isExpired(storedOtp.getExpiry())) { - return EXPIRED; + return ValidationResult.EXPIRED; } if (!storedOtp.getCode().equals(currentCode)) { - return INVALID; + return ValidationResult.INVALID; } - return VALID; + return ValidationResult.VALID; } private boolean isExpired(long expiry) { diff --git a/src/main/java/de/diakonie/onlineberatung/otp/Otp.java b/src/main/java/de/onlineberatung/otp/Otp.java similarity index 97% rename from src/main/java/de/diakonie/onlineberatung/otp/Otp.java rename to src/main/java/de/onlineberatung/otp/Otp.java index 6b5e8da..e44fc57 100644 --- a/src/main/java/de/diakonie/onlineberatung/otp/Otp.java +++ b/src/main/java/de/onlineberatung/otp/Otp.java @@ -1,4 +1,4 @@ -package de.diakonie.onlineberatung.otp; +package de.onlineberatung.otp; import java.util.Objects; diff --git a/src/main/java/de/diakonie/onlineberatung/otp/OtpGenerator.java b/src/main/java/de/onlineberatung/otp/OtpGenerator.java similarity index 62% rename from src/main/java/de/diakonie/onlineberatung/otp/OtpGenerator.java rename to src/main/java/de/onlineberatung/otp/OtpGenerator.java index 40edfa8..04549c1 100644 --- a/src/main/java/de/diakonie/onlineberatung/otp/OtpGenerator.java +++ b/src/main/java/de/onlineberatung/otp/OtpGenerator.java @@ -1,4 +1,4 @@ -package de.diakonie.onlineberatung.otp; +package de.onlineberatung.otp; public interface OtpGenerator { diff --git a/src/main/java/de/onlineberatung/otp/OtpMailSender.java b/src/main/java/de/onlineberatung/otp/OtpMailSender.java new file mode 100644 index 0000000..802d43a --- /dev/null +++ b/src/main/java/de/onlineberatung/otp/OtpMailSender.java @@ -0,0 +1,11 @@ +package de.onlineberatung.otp; + +import de.onlineberatung.credential.CredentialContext; +import de.onlineberatung.mail.MailSendingException; + +public interface OtpMailSender { + + void sendOtpCode(Otp otp, + CredentialContext credentialContext) throws MailSendingException; + +} diff --git a/src/main/java/de/diakonie/onlineberatung/otp/OtpService.java b/src/main/java/de/onlineberatung/otp/OtpService.java similarity index 76% rename from src/main/java/de/diakonie/onlineberatung/otp/OtpService.java rename to src/main/java/de/onlineberatung/otp/OtpService.java index 316aa10..bbb360c 100644 --- a/src/main/java/de/diakonie/onlineberatung/otp/OtpService.java +++ b/src/main/java/de/onlineberatung/otp/OtpService.java @@ -1,4 +1,4 @@ -package de.diakonie.onlineberatung.otp; +package de.onlineberatung.otp; public interface OtpService { diff --git a/src/main/java/de/onlineberatung/otp/RandomDigitsCodeGenerator.java b/src/main/java/de/onlineberatung/otp/RandomDigitsCodeGenerator.java new file mode 100644 index 0000000..aeaf67d --- /dev/null +++ b/src/main/java/de/onlineberatung/otp/RandomDigitsCodeGenerator.java @@ -0,0 +1,12 @@ +package de.onlineberatung.otp; + +import org.keycloak.common.util.SecretGenerator; + +public class RandomDigitsCodeGenerator implements OtpGenerator { + + @Override + public String generate(int length) { + return SecretGenerator.getInstance().randomString(length, SecretGenerator.DIGITS); + } + +} diff --git a/src/main/java/de/diakonie/onlineberatung/otp/ValidationResult.java b/src/main/java/de/onlineberatung/otp/ValidationResult.java similarity index 71% rename from src/main/java/de/diakonie/onlineberatung/otp/ValidationResult.java rename to src/main/java/de/onlineberatung/otp/ValidationResult.java index 9fe232c..ccefd44 100644 --- a/src/main/java/de/diakonie/onlineberatung/otp/ValidationResult.java +++ b/src/main/java/de/onlineberatung/otp/ValidationResult.java @@ -1,4 +1,4 @@ -package de.diakonie.onlineberatung.otp; +package de.onlineberatung.otp; public enum ValidationResult { diff --git a/src/main/resources/META-INF/services/org.keycloak.authentication.AuthenticatorFactory b/src/main/resources/META-INF/services/org.keycloak.authentication.AuthenticatorFactory index e484881..1844b8a 100644 --- a/src/main/resources/META-INF/services/org.keycloak.authentication.AuthenticatorFactory +++ b/src/main/resources/META-INF/services/org.keycloak.authentication.AuthenticatorFactory @@ -1,2 +1,2 @@ -de.diakonie.onlineberatung.authenticator.OtpMailAuthenticatorFactory -de.diakonie.onlineberatung.authenticator.OtpAppAuthenticatorFactory \ No newline at end of file +de.onlineberatung.authenticator.OtpMailAuthenticatorFactory +de.onlineberatung.authenticator.OtpAppAuthenticatorFactory diff --git a/src/main/resources/META-INF/services/org.keycloak.events.EventListenerProviderFactory b/src/main/resources/META-INF/services/org.keycloak.events.EventListenerProviderFactory index 0b1cfad..5a55fb4 100755 --- a/src/main/resources/META-INF/services/org.keycloak.events.EventListenerProviderFactory +++ b/src/main/resources/META-INF/services/org.keycloak.events.EventListenerProviderFactory @@ -1 +1 @@ -de.diakonie.onlineberatung.log.LoggingEventListenerProviderFactory \ No newline at end of file +de.onlineberatung.log.LoggingEventListenerProviderFactory diff --git a/src/main/resources/META-INF/services/org.keycloak.services.resource.RealmResourceProviderFactory b/src/main/resources/META-INF/services/org.keycloak.services.resource.RealmResourceProviderFactory index 312f48b..0b219e2 100644 --- a/src/main/resources/META-INF/services/org.keycloak.services.resource.RealmResourceProviderFactory +++ b/src/main/resources/META-INF/services/org.keycloak.services.resource.RealmResourceProviderFactory @@ -1 +1 @@ -de.diakonie.onlineberatung.RealmOtpResourceProviderFactory \ No newline at end of file +de.onlineberatung.RealmOtpResourceProviderFactory diff --git a/src/test/java/de/diakonie/onlineberatung/RealmOtpResourceProviderParameterizedTest.java b/src/test/java/de/onlineberatung/RealmOtpResourceProviderParameterizedTest.java similarity index 84% rename from src/test/java/de/diakonie/onlineberatung/RealmOtpResourceProviderParameterizedTest.java rename to src/test/java/de/onlineberatung/RealmOtpResourceProviderParameterizedTest.java index ea2aee6..66aea71 100644 --- a/src/test/java/de/diakonie/onlineberatung/RealmOtpResourceProviderParameterizedTest.java +++ b/src/test/java/de/onlineberatung/RealmOtpResourceProviderParameterizedTest.java @@ -1,19 +1,19 @@ -package de.diakonie.onlineberatung; +package de.onlineberatung; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import de.diakonie.onlineberatung.authenticator.SessionAuthenticator; -import de.diakonie.onlineberatung.credential.AppOtpCredentialService; -import de.diakonie.onlineberatung.credential.MailOtpCredentialModel; -import de.diakonie.onlineberatung.credential.MailOtpCredentialService; -import de.diakonie.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.OtpSetupDTO; -import de.diakonie.onlineberatung.otp.Otp; -import de.diakonie.onlineberatung.otp.OtpMailSender; -import de.diakonie.onlineberatung.otp.OtpService; -import de.diakonie.onlineberatung.otp.ValidationResult; +import de.onlineberatung.authenticator.SessionAuthenticator; +import de.onlineberatung.credential.AppOtpCredentialService; +import de.onlineberatung.credential.MailOtpCredentialModel; +import de.onlineberatung.credential.MailOtpCredentialService; +import de.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.OtpSetupDTO; +import de.onlineberatung.otp.Otp; +import de.onlineberatung.otp.OtpMailSender; +import de.onlineberatung.otp.OtpService; +import de.onlineberatung.otp.ValidationResult; import java.time.Clock; import java.util.Arrays; import java.util.Collection; @@ -94,4 +94,4 @@ public void setupOtpMail_response_on_validation_result() { assertThat(response.getStatus()).isEqualTo(httpStatusExpected); } -} \ No newline at end of file +} diff --git a/src/test/java/de/diakonie/onlineberatung/RealmOtpResourceProviderTest.java b/src/test/java/de/onlineberatung/RealmOtpResourceProviderTest.java similarity index 90% rename from src/test/java/de/diakonie/onlineberatung/RealmOtpResourceProviderTest.java rename to src/test/java/de/onlineberatung/RealmOtpResourceProviderTest.java index 0afc9c3..f44e4b8 100644 --- a/src/test/java/de/diakonie/onlineberatung/RealmOtpResourceProviderTest.java +++ b/src/test/java/de/onlineberatung/RealmOtpResourceProviderTest.java @@ -1,7 +1,5 @@ -package de.diakonie.onlineberatung; +package de.onlineberatung; -import static de.diakonie.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.OtpType.APP; -import static de.diakonie.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.OtpType.EMAIL; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doThrow; @@ -9,19 +7,20 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import de.diakonie.onlineberatung.authenticator.SessionAuthenticator; -import de.diakonie.onlineberatung.credential.AppOtpCredentialService; -import de.diakonie.onlineberatung.credential.CredentialContext; -import de.diakonie.onlineberatung.credential.MailOtpCredentialModel; -import de.diakonie.onlineberatung.credential.MailOtpCredentialService; -import de.diakonie.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.OtpInfoDTO; -import de.diakonie.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.OtpSetupDTO; -import de.diakonie.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.SuccessWithEmail; -import de.diakonie.onlineberatung.mail.MailSendingException; -import de.diakonie.onlineberatung.otp.Otp; -import de.diakonie.onlineberatung.otp.OtpMailSender; -import de.diakonie.onlineberatung.otp.OtpService; -import de.diakonie.onlineberatung.otp.ValidationResult; +import de.onlineberatung.authenticator.SessionAuthenticator; +import de.onlineberatung.credential.AppOtpCredentialService; +import de.onlineberatung.credential.CredentialContext; +import de.onlineberatung.credential.MailOtpCredentialModel; +import de.onlineberatung.credential.MailOtpCredentialService; +import de.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.OtpInfoDTO; +import de.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.OtpSetupDTO; +import de.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.SuccessWithEmail; +import de.onlineberatung.mail.MailSendingException; +import de.onlineberatung.otp.Otp; +import de.onlineberatung.otp.OtpMailSender; +import de.onlineberatung.otp.OtpService; +import de.onlineberatung.otp.ValidationResult; +import de.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.OtpType; import java.time.Clock; import org.junit.Before; import org.junit.Test; @@ -31,6 +30,7 @@ import org.keycloak.models.UserModel; import org.keycloak.models.UserProvider; import org.keycloak.models.credential.OTPCredentialModel; +import org.mockito.Mockito; public class RealmOtpResourceProviderTest { @@ -124,7 +124,7 @@ public void sendVerificationMail_should_invalidate_otp_if_sending_fails() { mailSetup.setEmail("hk@test.de"); var otp = new Otp("123", 450L, 1234567L, "hk@test.de", 0); when(otpService.createOtp("hk@test.de")).thenReturn(otp); - doThrow(MailSendingException.class).when(mailSender).sendOtpCode(any(), any()); + Mockito.doThrow(MailSendingException.class).when(mailSender).sendOtpCode(any(), any()); var credentialModel = MailOtpCredentialModel.createOtpModel(otp, Clock.systemDefaultZone()); when(mailCredentialService.createCredential(otp, credentialContext)).thenReturn( credentialModel); @@ -242,7 +242,7 @@ public void getOtpSetupInfo_should_return_type_app_if_app_2fa_is_configured() { assertThat(response.getStatus()).isEqualTo(200); var otpInfo = response.readEntity(OtpInfoDTO.class); assertThat(otpInfo.getOtpSetup()).isTrue(); - assertThat(otpInfo.getOtpType()).isEqualTo(APP); + assertThat(otpInfo.getOtpType()).isEqualTo(OtpType.APP); } @Test @@ -254,7 +254,7 @@ public void getOtpSetupInfo_should_return_type_mail_if_mail_2fa_is_configured() assertThat(response.getStatus()).isEqualTo(200); var otpInfo = response.readEntity(OtpInfoDTO.class); assertThat(otpInfo.getOtpSetup()).isTrue(); - assertThat(otpInfo.getOtpType()).isEqualTo(EMAIL); + assertThat(otpInfo.getOtpType()).isEqualTo(OtpType.EMAIL); } @Test @@ -334,4 +334,4 @@ public void deleteOtp_should_delete_all_otps() { verify(appCredentialService).deleteCredentials(credentialContext); verify(mailCredentialService).deleteCredential(credentialContext); } -} \ No newline at end of file +} diff --git a/src/test/java/de/diakonie/onlineberatung/authenticator/OtpMailAuthenticatorParameterizedTest.java b/src/test/java/de/onlineberatung/authenticator/OtpMailAuthenticatorParameterizedTest.java similarity index 86% rename from src/test/java/de/diakonie/onlineberatung/authenticator/OtpMailAuthenticatorParameterizedTest.java rename to src/test/java/de/onlineberatung/authenticator/OtpMailAuthenticatorParameterizedTest.java index 80ca02e..37ca493 100644 --- a/src/test/java/de/diakonie/onlineberatung/authenticator/OtpMailAuthenticatorParameterizedTest.java +++ b/src/test/java/de/onlineberatung/authenticator/OtpMailAuthenticatorParameterizedTest.java @@ -1,6 +1,6 @@ -package de.diakonie.onlineberatung.authenticator; +package de.onlineberatung.authenticator; -import static de.diakonie.onlineberatung.credential.MailOtpCredentialModel.createOtpModel; +import static de.onlineberatung.credential.MailOtpCredentialModel.createOtpModel; import static java.time.Clock.systemDefaultZone; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.mockito.ArgumentMatchers.eq; @@ -8,13 +8,13 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import de.diakonie.onlineberatung.credential.CredentialContext; -import de.diakonie.onlineberatung.credential.MailOtpCredentialModel; -import de.diakonie.onlineberatung.credential.MailOtpCredentialService; -import de.diakonie.onlineberatung.otp.Otp; -import de.diakonie.onlineberatung.otp.OtpMailSender; -import de.diakonie.onlineberatung.otp.OtpService; -import de.diakonie.onlineberatung.otp.ValidationResult; +import de.onlineberatung.credential.CredentialContext; +import de.onlineberatung.credential.MailOtpCredentialModel; +import de.onlineberatung.credential.MailOtpCredentialService; +import de.onlineberatung.otp.Otp; +import de.onlineberatung.otp.OtpMailSender; +import de.onlineberatung.otp.OtpService; +import de.onlineberatung.otp.ValidationResult; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -90,7 +90,8 @@ public void setUp() { @Test public void authenticate_otp_validation() { var otp = new Otp("765432", 11L, 112L, null, 0); - MailOtpCredentialModel credentialModel = createOtpModel(otp, systemDefaultZone()); + MailOtpCredentialModel credentialModel = MailOtpCredentialModel + .createOtpModel(otp, systemDefaultZone()); when(credentialService.getCredential(credentialContext)).thenReturn(credentialModel); when(otpService.validate("765432", otp)).thenReturn(input); diff --git a/src/test/java/de/diakonie/onlineberatung/authenticator/OtpMailAuthenticatorTest.java b/src/test/java/de/onlineberatung/authenticator/OtpMailAuthenticatorTest.java similarity index 80% rename from src/test/java/de/diakonie/onlineberatung/authenticator/OtpMailAuthenticatorTest.java rename to src/test/java/de/onlineberatung/authenticator/OtpMailAuthenticatorTest.java index 7b2af67..e574019 100644 --- a/src/test/java/de/diakonie/onlineberatung/authenticator/OtpMailAuthenticatorTest.java +++ b/src/test/java/de/onlineberatung/authenticator/OtpMailAuthenticatorTest.java @@ -1,7 +1,6 @@ -package de.diakonie.onlineberatung.authenticator; +package de.onlineberatung.authenticator; -import static de.diakonie.onlineberatung.credential.MailOtpCredentialModel.createOtpModel; -import static de.diakonie.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.OtpType.EMAIL; +import static de.onlineberatung.credential.MailOtpCredentialModel.createOtpModel; import static java.time.Clock.systemDefaultZone; import static java.util.Collections.singletonList; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @@ -12,14 +11,16 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import de.diakonie.onlineberatung.credential.CredentialContext; -import de.diakonie.onlineberatung.credential.MailOtpCredentialService; -import de.diakonie.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.Challenge; -import de.diakonie.onlineberatung.mail.MailSendingException; -import de.diakonie.onlineberatung.otp.Otp; -import de.diakonie.onlineberatung.otp.OtpMailSender; -import de.diakonie.onlineberatung.otp.OtpService; -import de.diakonie.onlineberatung.otp.ValidationResult; +import de.onlineberatung.credential.CredentialContext; +import de.onlineberatung.credential.MailOtpCredentialService; +import de.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.Challenge; +import de.onlineberatung.mail.MailSendingException; +import de.onlineberatung.otp.Otp; +import de.onlineberatung.otp.OtpMailSender; +import de.onlineberatung.otp.OtpService; +import de.onlineberatung.otp.ValidationResult; +import de.onlineberatung.credential.MailOtpCredentialModel; +import de.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.OtpType; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.Response; import org.jboss.resteasy.spi.HttpRequest; @@ -31,6 +32,7 @@ import org.keycloak.models.RealmModel; import org.keycloak.models.UserModel; import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; public class OtpMailAuthenticatorTest { @@ -68,7 +70,7 @@ public void setUp() { @Test public void isConfigured_should_be_true_if_credential_is_active() { var otp = new Otp("1234", 300, 1000L, "someemail@test.de", 0); - var credentialModel = createOtpModel(otp, systemDefaultZone(), true); + var credentialModel = MailOtpCredentialModel.createOtpModel(otp, systemDefaultZone(), true); when(credentialService.getCredential(credentialContext)).thenReturn(credentialModel); var configured = authenticator.configuredFor(session, realm, user); @@ -79,7 +81,7 @@ public void isConfigured_should_be_true_if_credential_is_active() { @Test public void isConfigured_should_be_false_if_credential_is_inactive() { var otp = new Otp("1234", 300, 1000L, "someemail@test.de", 0); - var credentialModel = createOtpModel(otp, systemDefaultZone(), false); + var credentialModel = MailOtpCredentialModel.createOtpModel(otp, systemDefaultZone(), false); when(credentialService.getCredential(credentialContext)).thenReturn(credentialModel); var configured = authenticator.configuredFor(session, realm, user); @@ -99,7 +101,7 @@ public void authenticate_should_send_mail_if_otp_param_is_missing() { when(user.getUsername()).thenReturn("Karen"); when(user.getEmail()).thenReturn("mymail@test.de"); var expectedOtp = new Otp("123", 200L, 123456L, "mymail@test.de", 0); - var credentialModel = createOtpModel(expectedOtp, systemDefaultZone()); + var credentialModel = MailOtpCredentialModel.createOtpModel(expectedOtp, systemDefaultZone()); when(credentialService.getCredential(credentialContext)).thenReturn(credentialModel); when(otpService.createOtp("mymail@test.de")).thenReturn(expectedOtp); @@ -110,7 +112,7 @@ public void authenticate_should_send_mail_if_otp_param_is_missing() { responseCaptor.capture()); assertThat(responseCaptor.getValue().getStatus()).isEqualTo(400); var challenge = responseCaptor.getValue().readEntity(Challenge.class); - assertThat(challenge.getOtpType()).isEqualTo(EMAIL); + assertThat(challenge.getOtpType()).isEqualTo(OtpType.EMAIL); verify(mailSender).sendOtpCode(expectedOtp, credentialContext); } @@ -118,7 +120,7 @@ public void authenticate_should_send_mail_if_otp_param_is_missing() { public void authenticate_should_use_email_address_from_stored_credentials_if_user_has_none() { when(user.getUsername()).thenReturn("Karen"); var expectedOtp = new Otp("123", 200L, 123456L, "mymail@test.de", 0); - var credentialModel = createOtpModel(expectedOtp, systemDefaultZone()); + var credentialModel = MailOtpCredentialModel.createOtpModel(expectedOtp, systemDefaultZone()); when(credentialService.getCredential(credentialContext)).thenReturn(credentialModel); when(otpService.createOtp("mymail@test.de")).thenReturn(expectedOtp); @@ -129,7 +131,7 @@ public void authenticate_should_use_email_address_from_stored_credentials_if_use responseCaptor.capture()); assertThat(responseCaptor.getValue().getStatus()).isEqualTo(400); var challenge = responseCaptor.getValue().readEntity(Challenge.class); - assertThat(challenge.getOtpType()).isEqualTo(EMAIL); + assertThat(challenge.getOtpType()).isEqualTo(OtpType.EMAIL); verify(mailSender).sendOtpCode(expectedOtp, credentialContext); } @@ -139,9 +141,9 @@ public void authenticate_should_invalidate_otp_if_mail_sending_fails() { when(user.getEmail()).thenReturn("mymail@test.de"); var expectedOtp = new Otp("123", 200L, 123456L, "mymail@test.de", 0); when(otpService.createOtp("mymail@test.de")).thenReturn(expectedOtp); - var credentialModel = createOtpModel(expectedOtp, systemDefaultZone()); + var credentialModel = MailOtpCredentialModel.createOtpModel(expectedOtp, systemDefaultZone()); when(credentialService.getCredential(credentialContext)).thenReturn(credentialModel); - doThrow(MailSendingException.class).when(mailSender).sendOtpCode(any(), any()); + Mockito.doThrow(MailSendingException.class).when(mailSender).sendOtpCode(any(), any()); authenticator.authenticate(authFlow); @@ -157,7 +159,7 @@ public void authenticate_should_increase_number_of_failed_attempts_if_otp_is_inv when(user.getUsername()).thenReturn("Karen"); when(user.getEmail()).thenReturn("mymail@test.de"); var storedOtp = new Otp("123", 200L, 123456L, "mymail@test.de", 0); - var credentialModel = createOtpModel(storedOtp, systemDefaultZone()); + var credentialModel = MailOtpCredentialModel.createOtpModel(storedOtp, systemDefaultZone()); when(credentialService.getCredential(credentialContext)).thenReturn(credentialModel); decodedFormParams.put("otp", singletonList("86767")); when(otpService.validate("86767", storedOtp)).thenReturn(ValidationResult.INVALID); @@ -166,4 +168,4 @@ public void authenticate_should_increase_number_of_failed_attempts_if_otp_is_inv verify(credentialService).incrementFailedAttempts(credentialModel, credentialContext, 0); } -} \ No newline at end of file +} diff --git a/src/test/java/de/diakonie/onlineberatung/authenticator/OtpParameterAuthenticatorTest.java b/src/test/java/de/onlineberatung/authenticator/OtpParameterAuthenticatorTest.java similarity index 90% rename from src/test/java/de/diakonie/onlineberatung/authenticator/OtpParameterAuthenticatorTest.java rename to src/test/java/de/onlineberatung/authenticator/OtpParameterAuthenticatorTest.java index 061872e..aab877f 100644 --- a/src/test/java/de/diakonie/onlineberatung/authenticator/OtpParameterAuthenticatorTest.java +++ b/src/test/java/de/onlineberatung/authenticator/OtpParameterAuthenticatorTest.java @@ -1,13 +1,13 @@ -package de.diakonie.onlineberatung.authenticator; +package de.onlineberatung.authenticator; -import static de.diakonie.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.OtpType.APP; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import de.diakonie.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.Challenge; +import de.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.Challenge; +import de.onlineberatung.keycloak_otp_config_spi.keycloakextension.generated.web.model.OtpType; import java.util.Collections; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.Response; @@ -79,7 +79,7 @@ public void should_fail_if_request_contains_no_form_params() { responseCaptor.capture()); assertThat(responseCaptor.getValue().getStatus()).isEqualTo(400); var challenge = responseCaptor.getValue().readEntity(Challenge.class); - assertThat(challenge.getOtpType()).isEqualTo(APP); + assertThat(challenge.getOtpType()).isEqualTo(OtpType.APP); } @Test @@ -90,4 +90,4 @@ public void should_be_successful_if_form_params_contain_otp() { authenticator.authenticate(authFlow); verify(authFlow).success(); } -} \ No newline at end of file +} diff --git a/src/test/java/de/diakonie/onlineberatung/credential/MailOtpCredentialServiceTest.java b/src/test/java/de/onlineberatung/credential/MailOtpCredentialServiceTest.java similarity index 80% rename from src/test/java/de/diakonie/onlineberatung/credential/MailOtpCredentialServiceTest.java rename to src/test/java/de/onlineberatung/credential/MailOtpCredentialServiceTest.java index 3657b8d..82c738d 100644 --- a/src/test/java/de/diakonie/onlineberatung/credential/MailOtpCredentialServiceTest.java +++ b/src/test/java/de/onlineberatung/credential/MailOtpCredentialServiceTest.java @@ -1,6 +1,5 @@ -package de.diakonie.onlineberatung.credential; +package de.onlineberatung.credential; -import static de.diakonie.onlineberatung.credential.MailOtpCredentialModel.INVALIDATED; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; @@ -8,8 +7,9 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import de.diakonie.onlineberatung.otp.Otp; +import de.onlineberatung.otp.Otp; import java.time.Clock; +import org.assertj.core.api.AssertionsForClassTypes; import org.junit.Before; import org.junit.Test; import org.keycloak.models.KeycloakSession; @@ -49,8 +49,9 @@ public void activate_should_activate_and_reset_failed_verifications() { credentialService.activate(credential, credentialContext); assertThat(credential.isActive()).isTrue(); - assertThat(credential.getOtp().getFailedVerifications()).isEqualTo(0); - assertThat(credential.getOtp().getCode()).isEqualTo(INVALIDATED); + AssertionsForClassTypes.assertThat(credential.getOtp().getFailedVerifications()).isZero(); + AssertionsForClassTypes + .assertThat(credential.getOtp().getCode()).isEqualTo(MailOtpCredentialModel.INVALIDATED); verify(credentialProvider).updateCredential(realm, user, credential); } @@ -61,8 +62,9 @@ public void invalidate_should_invalidate_code_and_reset_failed_verifications() { credentialService.invalidate(credential, credentialContext); - assertThat(credential.getOtp().getFailedVerifications()).isEqualTo(0); - assertThat(credential.getOtp().getCode()).isEqualTo(INVALIDATED); + AssertionsForClassTypes.assertThat(credential.getOtp().getFailedVerifications()).isZero(); + AssertionsForClassTypes + .assertThat(credential.getOtp().getCode()).isEqualTo(MailOtpCredentialModel.INVALIDATED); verify(credentialProvider).updateCredential(realm, user, credential); } @@ -74,7 +76,7 @@ public void incrementFailedAttempts_should_increment_failed_attempts() { credentialService.incrementFailedAttempts(credential, credentialContext, otp.getFailedVerifications()); - assertThat(credential.getOtp().getFailedVerifications()).isEqualTo(1); + AssertionsForClassTypes.assertThat(credential.getOtp().getFailedVerifications()).isEqualTo(1); verify(credentialProvider).updateCredential(realm, user, credential); } -} \ No newline at end of file +} diff --git a/src/test/java/de/diakonie/onlineberatung/otp/MemoryOtpServiceTest.java b/src/test/java/de/onlineberatung/otp/MemoryOtpServiceTest.java similarity index 93% rename from src/test/java/de/diakonie/onlineberatung/otp/MemoryOtpServiceTest.java rename to src/test/java/de/onlineberatung/otp/MemoryOtpServiceTest.java index eec0efe..63a972d 100644 --- a/src/test/java/de/diakonie/onlineberatung/otp/MemoryOtpServiceTest.java +++ b/src/test/java/de/onlineberatung/otp/MemoryOtpServiceTest.java @@ -1,8 +1,8 @@ -package de.diakonie.onlineberatung.otp; +package de.onlineberatung.otp; -import static de.diakonie.onlineberatung.otp.ValidationResult.INVALID; -import static de.diakonie.onlineberatung.otp.ValidationResult.NOT_PRESENT; -import static de.diakonie.onlineberatung.otp.ValidationResult.TOO_MANY_FAILED_ATTEMPTS; +import static de.onlineberatung.otp.ValidationResult.INVALID; +import static de.onlineberatung.otp.ValidationResult.NOT_PRESENT; +import static de.onlineberatung.otp.ValidationResult.TOO_MANY_FAILED_ATTEMPTS; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -118,4 +118,4 @@ public void validate_should_not_be_valid_if_too_may_attempts_were_made_even_if_c assertThat(result).isEqualTo(TOO_MANY_FAILED_ATTEMPTS); } -} \ No newline at end of file +}