Search in sources :

Example 41 with Config

use of io.helidon.config.Config in project helidon by oracle.

the class SmokeTest method testPropertiesParser.

@Test
public void testPropertiesParser() {
    Config config = Config.builder().sources(ConfigSources.create("key=value", "text/x-java-properties")).build();
    assertThat(config.get("key").asString(), is(ConfigValues.simpleValue("value")));
}
Also used : Config(io.helidon.config.Config) Test(org.junit.jupiter.api.Test)

Example 42 with Config

use of io.helidon.config.Config in project helidon by oracle.

the class ConfigCreateDefaultFromPropertiesTest method testCreateKeyFromSysProps.

@Test
@ExtendWith(RestoreSystemPropertiesExt.class)
public void testCreateKeyFromSysProps() {
    System.setProperty(KEY, PROP_VALUE);
    Config config = Config.create();
    assertThat(config.get(KEY).asString(), is(ConfigValues.simpleValue(PROP_VALUE)));
}
Also used : Config(io.helidon.config.Config) Test(org.junit.jupiter.api.Test) ExtendWith(org.junit.jupiter.api.extension.ExtendWith)

Example 43 with Config

use of io.helidon.config.Config in project helidon by oracle.

the class ConfigCreateDefaultFromPropertiesTest method testCreate.

@Test
@ExtendWith(RestoreSystemPropertiesExt.class)
public void testCreate() {
    Config config = Config.create();
    assertThat(config.get(KEY).asString().get(), is(CONFIG_VALUE));
}
Also used : Config(io.helidon.config.Config) Test(org.junit.jupiter.api.Test) ExtendWith(org.junit.jupiter.api.extension.ExtendWith)

Example 44 with Config

use of io.helidon.config.Config in project helidon by oracle.

the class AtnProvider method syncAuthenticate.

@Override
protected AuthenticationResponse syncAuthenticate(ProviderRequest providerRequest) {
    EndpointConfig endpointConfig = providerRequest.endpointConfig();
    Config atnConfig = endpointConfig.config(CONFIG_KEY).orElse(null);
    Subject user = null;
    Subject service = null;
    List<Auth> list;
    Optional<AtnConfig> optional = providerRequest.endpointConfig().instance(AtnConfig.class);
    if (optional.isPresent()) {
        list = optional.get().auths();
    } else if (atnConfig != null && !atnConfig.isLeaf()) {
        list = atnConfig.asNodeList().map(this::fromConfig).orElse(Collections.emptyList());
    } else {
        list = fromAnnotations(endpointConfig);
    }
    for (Auth authentication : list) {
        if (authentication.type() == SubjectType.USER) {
            user = buildSubject(authentication);
        } else {
            service = buildSubject(authentication);
        }
    }
    return AuthenticationResponse.success(user, service);
}
Also used : Config(io.helidon.config.Config) EndpointConfig(io.helidon.security.EndpointConfig) EndpointConfig(io.helidon.security.EndpointConfig) Subject(io.helidon.security.Subject)

Example 45 with Config

use of io.helidon.config.Config in project helidon by oracle.

the class SecureGreetClient method main.

/**
 * Program entry point.
 *
 * @param args  program arguments
 */
public static void main(String[] args) {
    Channel channel = ManagedChannelBuilder.forAddress("localhost", 1408).usePlaintext().build();
    Config config = Config.create();
    // configure Helidon security and add the basic auth provider
    Security security = Security.builder().addProvider(HttpBasicAuthProvider.create(config.get("http-basic-auth"))).build();
    // create the gRPC client security call credentials
    // setting the properties used by the basic auth provider for user name and password
    GrpcClientSecurity clientSecurity = GrpcClientSecurity.builder(security.createContext("test.client")).property(HttpBasicAuthProvider.EP_PROPERTY_OUTBOUND_USER, "Bob").property(HttpBasicAuthProvider.EP_PROPERTY_OUTBOUND_PASSWORD, "password").build();
    // create the GreetService client stub and use the GrpcClientSecurity call credentials
    GreetServiceGrpc.GreetServiceBlockingStub stub = GreetServiceGrpc.newBlockingStub(channel).withCallCredentials(clientSecurity);
    Greet.GreetResponse greetResponse = stub.greet(Greet.GreetRequest.newBuilder().setName("Bob").build());
    System.out.println(greetResponse.getMessage());
    Greet.SetGreetingResponse setGreetingResponse = stub.setGreeting(Greet.SetGreetingRequest.newBuilder().setGreeting("Merhaba").build());
    System.out.println("Greeting set to: " + setGreetingResponse.getGreeting());
    greetResponse = stub.greet(Greet.GreetRequest.newBuilder().setName("Bob").build());
    System.out.println(greetResponse.getMessage());
}
Also used : GrpcClientSecurity(io.helidon.security.integration.grpc.GrpcClientSecurity) Greet(io.helidon.grpc.examples.common.Greet) Config(io.helidon.config.Config) Channel(io.grpc.Channel) GreetServiceGrpc(io.helidon.grpc.examples.common.GreetServiceGrpc) Security(io.helidon.security.Security) GrpcClientSecurity(io.helidon.security.integration.grpc.GrpcClientSecurity)

Aggregations

Config (io.helidon.config.Config)329 Test (org.junit.jupiter.api.Test)169 LogConfig (io.helidon.common.LogConfig)56 WebServer (io.helidon.webserver.WebServer)54 Routing (io.helidon.webserver.Routing)51 BeforeAll (org.junit.jupiter.api.BeforeAll)24 Security (io.helidon.security.Security)20 HealthSupport (io.helidon.health.HealthSupport)18 Single (io.helidon.common.reactive.Single)17 MetricsSupport (io.helidon.metrics.MetricsSupport)16 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)16 ConfigSources (io.helidon.config.ConfigSources)15 JsonpSupport (io.helidon.media.jsonp.JsonpSupport)15 SecurityContext (io.helidon.security.SecurityContext)15 Optional (java.util.Optional)15 TimeUnit (java.util.concurrent.TimeUnit)15 WebSecurity (io.helidon.security.integration.webserver.WebSecurity)13 HealthChecks (io.helidon.health.checks.HealthChecks)12 WebClient (io.helidon.webclient.WebClient)12 GrpcRouting (io.helidon.grpc.server.GrpcRouting)11