Search in sources :

Example 1 with ConfigContext

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());
}
Also used : OtpRepository(com.nexblocks.authguard.dal.cache.OtpRepository) ServiceMapperImpl(com.nexblocks.authguard.service.mappers.ServiceMapperImpl) ConfigContext(com.nexblocks.authguard.config.ConfigContext)

Example 2 with ConfigContext

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);
}
Also used : JacksonConfigContext(com.nexblocks.authguard.config.JacksonConfigContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) JacksonConfigContext(com.nexblocks.authguard.config.JacksonConfigContext) ConfigContext(com.nexblocks.authguard.config.ConfigContext) Test(org.junit.jupiter.api.Test)

Example 3 with ConfigContext

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);
}
Also used : JacksonConfigContext(com.nexblocks.authguard.config.JacksonConfigContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JacksonConfigContext(com.nexblocks.authguard.config.JacksonConfigContext) ConfigContext(com.nexblocks.authguard.config.ConfigContext) Test(org.junit.jupiter.api.Test)

Example 4 with ConfigContext

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));
}
Also used : EmailProvider(com.nexblocks.authguard.external.email.EmailProvider) SmsProvider(com.nexblocks.authguard.external.sms.SmsProvider) ConfigContext(com.nexblocks.authguard.config.ConfigContext)

Example 5 with ConfigContext

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);
}
Also used : MessageBus(com.nexblocks.authguard.emb.MessageBus) AccountsRepository(com.nexblocks.authguard.dal.persistence.AccountsRepository) ServiceMapperImpl(com.nexblocks.authguard.service.mappers.ServiceMapperImpl) RolesService(com.nexblocks.authguard.service.RolesService) IdempotencyService(com.nexblocks.authguard.service.IdempotencyService) PermissionsService(com.nexblocks.authguard.service.PermissionsService) ConfigContext(com.nexblocks.authguard.config.ConfigContext) AccountConfig(com.nexblocks.authguard.service.config.AccountConfig) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ConfigContext (com.nexblocks.authguard.config.ConfigContext)16 Test (org.junit.jupiter.api.Test)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 JacksonConfigContext (com.nexblocks.authguard.config.JacksonConfigContext)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 ServiceMapperImpl (com.nexblocks.authguard.service.mappers.ServiceMapperImpl)3 Injector (com.google.inject.Injector)2 OtpRepository (com.nexblocks.authguard.dal.cache.OtpRepository)2 MessageBus (com.nexblocks.authguard.emb.MessageBus)2 EmailProvider (com.nexblocks.authguard.external.email.EmailProvider)2 ExchangeService (com.nexblocks.authguard.service.ExchangeService)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 CreationException (com.google.inject.CreationException)1 Guice (com.google.inject.Guice)1 ProvisionException (com.google.inject.ProvisionException)1 Named (com.google.inject.name.Named)1 com.nexblocks.authguard.bindings (com.nexblocks.authguard.bindings)1 BootstrapRunner (com.nexblocks.authguard.bootstrap.BootstrapRunner)1 EmptyConfigContext (com.nexblocks.authguard.config.EmptyConfigContext)1