use of io.helidon.config.metadata.Configured in project helidon by oracle.
the class HttpBasicAuthProvider method syncOutbound.
@Override
protected OutboundSecurityResponse syncOutbound(ProviderRequest providerRequest, SecurityEnvironment outboundEnv, EndpointConfig outboundEp) {
// explicit username in request properties
Optional<Object> maybeUsername = outboundEp.abacAttribute(EP_PROPERTY_OUTBOUND_USER);
if (maybeUsername.isPresent()) {
String username = maybeUsername.get().toString();
char[] password = passwordFromEndpoint(outboundEp);
return toBasicAuthOutbound(outboundEnv, HttpBasicOutboundConfig.DEFAULT_TOKEN_HANDLER, username, password);
}
var target = outboundConfig.findTargetCustomObject(outboundEnv, HttpBasicOutboundConfig.class, HttpBasicOutboundConfig::create, HttpBasicOutboundConfig::create);
if (target.isEmpty()) {
return OutboundSecurityResponse.abstain();
}
HttpBasicOutboundConfig outboundConfig = target.get();
if (outboundConfig.hasExplicitUser()) {
// use configured user
return toBasicAuthOutbound(outboundEnv, outboundConfig.tokenHandler(), outboundConfig.explicitUser(), outboundConfig.explicitPassword());
} else {
// propagate current user (if possible)
SecurityContext secContext = providerRequest.securityContext();
// first try user
Optional<BasicPrivateCredentials> creds = secContext.user().flatMap(this::credentialsFromSubject);
if (creds.isEmpty()) {
// if not present, try service
creds = secContext.service().flatMap(this::credentialsFromSubject);
}
Optional<char[]> overridePassword = outboundEp.abacAttribute(EP_PROPERTY_OUTBOUND_PASSWORD).map(String::valueOf).map(String::toCharArray);
return creds.map(credentials -> {
char[] password = overridePassword.orElse(credentials.password);
return toBasicAuthOutbound(outboundEnv, outboundConfig.tokenHandler(), credentials.username, password);
}).orElseGet(OutboundSecurityResponse::abstain);
}
}
use of io.helidon.config.metadata.Configured in project helidon by oracle.
the class OutboundConfig method createFromConfig.
static OutboundConfig createFromConfig(Config providerConfig, OutboundTarget[] defaults) {
Config config = providerConfig.get(CONFIG_OUTBOUND);
List<OutboundTarget> configuredTargets = config.asList(OutboundTarget::create).orElse(List.of());
boolean useDefaults = configuredTargets.stream().noneMatch(targetConfig -> "default".equals(targetConfig.name())) && (null != defaults);
Builder builder = OutboundConfig.builder();
if (useDefaults) {
// first add default values
Arrays.stream(defaults).forEach(builder::addTarget);
}
// then add configured values
configuredTargets.forEach(builder::addTarget);
return builder.build();
}
Aggregations