use of com.nexblocks.authguard.config.ConfigContext in project AuthGuard by AuthGuard.
the class OtpVerifierTest method setup.
void setup(final OtpConfig otpConfig) {
mockOtpRepository = Mockito.mock(OtpRepository.class);
final ConfigContext configContext = Mockito.mock(ConfigContext.class);
Mockito.when(configContext.asConfigBean(OtpConfig.class)).thenReturn(otpConfig);
otpVerifier = new OtpVerifier(mockOtpRepository, new ServiceMapperImpl());
}
use of com.nexblocks.authguard.config.ConfigContext in project AuthGuard by AuthGuard.
the class SecurePasswordProviderTest method parsesWithPreviousVersions.
@Test
void parsesWithPreviousVersions() {
final ObjectNode configRoot = new ObjectNode(JsonNodeFactory.instance).put("algorithm", "bcrypt").put("validFor", "5d").put("version", 2);
final ObjectNode bcryptConfig = new ObjectNode(JsonNodeFactory.instance);
configRoot.set("bcrypt", bcryptConfig);
final ObjectNode previousPasswordConfig = new ObjectNode(JsonNodeFactory.instance).put("algorithm", "scrypt").put("validFor", "5d").put("version", 1);
final ObjectNode scryptConfig = new ObjectNode(JsonNodeFactory.instance);
previousPasswordConfig.set("scrypt", scryptConfig);
final ArrayNode previousVersions = new ArrayNode(JsonNodeFactory.instance).add(previousPasswordConfig);
configRoot.set("previousVersions", previousVersions);
final ConfigContext configContext = new JacksonConfigContext(configRoot);
final SecurePasswordProvider provider = new SecurePasswordProvider(configContext);
assertThat(provider.getCurrentVersion()).isEqualTo(2);
assertThat(provider.getPreviousVersions().get(1)).isInstanceOf(SCryptPassword.class);
}
use of com.nexblocks.authguard.config.ConfigContext in project AuthGuard by AuthGuard.
the class SecurePasswordProviderTest method parsesWithoutPreviousVersions.
@Test
void parsesWithoutPreviousVersions() {
final ObjectNode configRoot = new ObjectNode(JsonNodeFactory.instance).put("algorithm", "bcrypt").put("validFor", "5d");
final ObjectNode bcryptConfig = new ObjectNode(JsonNodeFactory.instance);
configRoot.set("bcrypt", bcryptConfig);
final ConfigContext configContext = new JacksonConfigContext(configRoot);
final SecurePasswordProvider provider = new SecurePasswordProvider(configContext);
assertThat(provider.getCurrentVersion()).isEqualTo(1);
}
use of com.nexblocks.authguard.config.ConfigContext in project AuthGuard by AuthGuard.
the class ExternalProvidersBinder method configure.
@Override
protected void configure() {
final ConfigContext subContext = configContext.getSubContext("external");
Optional.ofNullable(subContext).map(context -> context.getAsBoolean("email")).filter(Boolean::booleanValue).ifPresentOrElse(ignored -> bindAndRegister(EmailProvider.class), () -> bind(EmailProvider.class).to(PlaceholderProviderSink.class));
Optional.ofNullable(subContext).map(context -> context.getAsBoolean("sms")).filter(Boolean::booleanValue).ifPresentOrElse(ignored -> bindAndRegister(SmsProvider.class), () -> bind(SmsProvider.class).to(PlaceholderProviderSink.class));
}
use of com.nexblocks.authguard.config.ConfigContext in project AuthGuard by AuthGuard.
the class AccountsServiceImplTest method setup.
@BeforeEach
void setup() {
accountsRepository = Mockito.mock(AccountsRepository.class);
permissionsService = Mockito.mock(PermissionsService.class);
rolesService = Mockito.mock(RolesService.class);
idempotencyService = Mockito.mock(IdempotencyService.class);
messageBus = Mockito.mock(MessageBus.class);
final ConfigContext configContext = Mockito.mock(ConfigContext.class);
final AccountConfig accountConfig = AccountConfig.builder().verifyEmail(true).verifyPhoneNumber(true).defaultRolesByDomain(ImmutableMap.of("unit", Collections.singleton("def-role"), "main", Collections.singleton("not-def-role"))).build();
Mockito.when(configContext.asConfigBean(AccountConfig.class)).thenReturn(accountConfig);
serviceMapper = new ServiceMapperImpl();
accountService = new AccountsServiceImpl(accountsRepository, permissionsService, rolesService, idempotencyService, serviceMapper, messageBus, configContext);
}
Aggregations