use of com.nexblocks.authguard.config.ConfigContext in project AuthGuard by AuthGuard.
the class ExchangesBinderTest method unsupportedExchange.
@Test
void unsupportedExchange() {
final ConfigContext rootContext = Mockito.mock(ConfigContext.class);
final ConfigContext exchangeContext = Mockito.mock(ConfigContext.class);
final ExchangesBinder.ExchangeConfig allowedExchange = new ExchangesBinder.ExchangeConfig();
allowedExchange.setFrom("unsupported");
allowedExchange.setTo("random");
Mockito.when(rootContext.getSubContext("exchange")).thenReturn(exchangeContext);
Mockito.when(exchangeContext.getAsCollection("allowed", ExchangesBinder.ExchangeConfig.class)).thenReturn(Collections.singletonList(allowedExchange));
final Collection<String> searchPackages = Collections.singletonList("com.nexblocks.authguard.bindings");
assertThatThrownBy(() -> Guice.createInjector(new ExchangesBinder(rootContext, searchPackages))).isInstanceOf(CreationException.class).extracting("cause").isInstanceOf(ConfigurationException.class);
}
use of com.nexblocks.authguard.config.ConfigContext in project AuthGuard by AuthGuard.
the class MessageBusTest method setup.
@BeforeAll
void setup() {
final ObjectNode configNode = new ObjectNode(JsonNodeFactory.instance);
configNode.set("channels", new ArrayNode(JsonNodeFactory.instance).add("accounts").add("auth"));
final ConfigContext configContext = new JacksonConfigContext(configNode);
messageBus = new MessageBus(new RxPublisherFactory(), configContext);
}
use of com.nexblocks.authguard.config.ConfigContext in project AuthGuard by AuthGuard.
the class VerificationSubscriberTest method setup.
@BeforeEach
void setup() {
emailProvider = Mockito.mock(EmailProvider.class);
accountTokensRepository = Mockito.mock(AccountTokensRepository.class);
final ConfigContext configContext = Mockito.mock(ConfigContext.class);
final ImmutableVerificationConfig verificationConfig = ImmutableVerificationConfig.builder().emailVerificationLife("1d").build();
Mockito.when(configContext.asConfigBean(ImmutableVerificationConfig.class)).thenReturn(verificationConfig);
verificationSubscriber = new VerificationSubscriber(emailProvider, accountTokensRepository, configContext);
}
use of com.nexblocks.authguard.config.ConfigContext in project AuthGuard by AuthGuard.
the class AuthGuardCli method execute.
public int execute(final String[] args) {
final Options options = cliOption();
final CommandLine cmd = parseCommandLineOptions(options, args);
if (cmd == null) {
return 1;
}
// help
if (cmd.hasOption("help")) {
new HelpFormatter().printHelp("authguard", options);
return 0;
}
// config
final ConfigContext configContext;
if (cmd.hasOption("config")) {
configContext = configurationLoader.loadFromFile(cmd.getOptionValue("config"));
} else {
configContext = configurationLoader.loadFromResources();
}
log.info("Initialized configuration context");
log.debug("Loaded configuration: {}", configContext);
// run the server
try {
serverRunner.run(configContext);
} catch (final ProvisionException | CreationException e) {
if (e.getCause() != null) {
if (e.getCause().getMessage() != null) {
log.error("Failed to initialize the server. Error: {}", e.getCause().getMessage());
} else {
log.error("Failed to initialize the server. Error: ", e.getCause());
}
} else {
log.error("Failed to initialize the server. Error: ", e);
}
return 1;
} catch (final ConfigurationException e) {
log.error("Configuration error: {}", e.getMessage());
return 2;
} catch (final InitializationException e) {
log.error("Failed to initialize the server. Error: {}", e.getMessage());
return 3;
}
return 0;
}
use of com.nexblocks.authguard.config.ConfigContext in project AuthGuard by AuthGuard.
the class ServerRunner method run.
public void run(final ConfigContext configContext) {
// class search
final Collection<String> searchPackages = configContext.getSubContext("injection").getAsCollection("packages", String.class);
final ClassSearch classSearch = new ClassSearch(searchPackages);
// injectors
final Injector injector = Guice.createInjector(new MappersBinder(), new ConfigBinder(configContext), new ExchangesBinder(configContext, searchPackages), new ApiKeysExchangeBinder(configContext, searchPackages), new ApiRoutesBinder(searchPackages, configContext), new ServicesBinder(configContext), new JwtBinder(configContext), new DalBinder(configContext, searchPackages), new EmbBinder(searchPackages), new ExternalProvidersBinder(configContext, searchPackages));
log.info("Initialed injection binders");
// run bootstraps
new BootstrapRunner(classSearch, injector).runAll();
log.info("Completed bootstrap");
// run the server
final ImmutableServerConfig serverConfig = Optional.ofNullable(configContext.getAsConfigBean("server", ImmutableServerConfig.class)).orElseGet(() -> ImmutableServerConfig.builder().port(3000).build());
new AuthGuardServer(injector).start(Javalin.create(config -> {
config.enforceSsl = serverConfig.enforceSsl();
config.server(() -> new JettyServerProvider(serverConfig).get());
config.accessManager(new RolesAccessManager());
}));
}
Aggregations