use of com.b2international.snowowl.core.setup.Environment in project snow-owl by b2ihealthcare.
the class IdentityPlugin method createProviders.
private List<IdentityProvider> createProviders(Environment env, List<IdentityProviderConfig> providerConfigurations) {
final List<IdentityProvider> providers = newArrayListWithExpectedSize(3);
env.plugins().getPlugins().stream().filter(IdentityProviderFactory.class::isInstance).map(IdentityProviderFactory.class::cast).forEach(factory -> {
Optional<IdentityProviderConfig> providerConfig = providerConfigurations.stream().filter(conf -> conf.getClass() == factory.getConfigType()).findFirst();
if (providerConfig.isPresent()) {
try {
providers.add(factory.create(env, providerConfig.get()));
} catch (Exception e) {
throw new SnowowlRuntimeException(String.format("Couldn't initialize '%s' identity provider", factory), e);
}
}
});
return providers;
}
use of com.b2international.snowowl.core.setup.Environment in project snow-owl by b2ihealthcare.
the class SnowOwlCommandProvider method _snowowl.
public void _snowowl(CommandInterpreter interpreter) throws Exception {
// first read all args into an array
List<String> args = newArrayList();
String arg;
while ((arg = interpreter.nextArgument()) != null) {
args.add(arg);
}
final Environment env = ApplicationContext.getServiceForClass(Environment.class);
final List<CommandLine> commands = cli(env).parse(args.toArray(new String[] {}));
try (InterpreterStream out = new InterpreterStream(interpreter)) {
// print help if requested for any command
if (CommandLine.printHelpIfRequested(commands, out, out, CommandLine.Help.Ansi.AUTO)) {
return;
}
// get the last command used in the cli
CommandLine cli = Iterables.getLast(commands, null);
if (cli == null) {
return;
}
// we should get an executable Snow Owl Command, so execute it
BaseCommand cmd = (BaseCommand) cli.getCommand();
final String authorizationToken = ApplicationContext.getServiceForClass(JWTGenerator.class).generate(User.SYSTEM);
final ServiceProvider context = env.inject().bind(IEventBus.class, new AuthorizedEventBus(ApplicationContext.getServiceForClass(IEventBus.class), ImmutableMap.of(AuthorizedRequest.AUTHORIZATION_HEADER, authorizationToken))).build();
cmd.setContext(context);
cmd.run(out);
} catch (Exception e) {
interpreter.println("Unknown error occured");
interpreter.printStackTrace(e);
}
}
Aggregations