use of org.infinispan.server.configuration.endpoint.EndpointConfigurationBuilder in project infinispan by infinispan.
the class Server method parseConfiguration.
private void parseConfiguration(List<Path> configurationFiles) {
ParserRegistry parser = new ParserRegistry(classLoader, false, properties);
try {
// load the defaults first
URL defaults = this.getClass().getClassLoader().getResource(SERVER_DEFAULTS);
defaultsHolder = parser.parse(defaults);
// Set a default audit logger
defaultsHolder.getGlobalConfigurationBuilder().security().authorization().auditLogger(new LoggingAuditLogger());
// base the global configuration to the default
configurationBuilderHolder = new ConfigurationBuilderHolder(classLoader);
GlobalConfigurationBuilder global = configurationBuilderHolder.getGlobalConfigurationBuilder();
global.read(defaultsHolder.getGlobalConfigurationBuilder().build());
// Copy all default templates
for (Map.Entry<String, ConfigurationBuilder> entry : defaultsHolder.getNamedConfigurationBuilders().entrySet()) {
configurationBuilderHolder.newConfigurationBuilder(entry.getKey()).read(entry.getValue().build());
}
// then load the user configurations
for (Path configurationFile : configurationFiles) {
if (!configurationFile.isAbsolute()) {
configurationFile = serverConf.toPath().resolve(configurationFile);
}
parser.parse(configurationFile.toUri().toURL(), configurationBuilderHolder);
}
if (log.isDebugEnabled()) {
StringBuilderWriter sw = new StringBuilderWriter();
try (ConfigurationWriter w = ConfigurationWriter.to(sw).build()) {
Map<String, Configuration> configs = configurationBuilderHolder.getNamedConfigurationBuilders().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().build()));
parser.serialize(w, global.build(), configs);
}
log.debugf("Actual configuration: %s", sw);
}
// Amend the named caches configurations with the defaults
for (Map.Entry<String, ConfigurationBuilder> entry : configurationBuilderHolder.getNamedConfigurationBuilders().entrySet()) {
Configuration cfg = entry.getValue().build();
ConfigurationBuilder defaultCfg = defaultsHolder.getNamedConfigurationBuilders().get("org.infinispan." + cfg.clustering().cacheMode().name());
ConfigurationBuilder rebased = new ConfigurationBuilder().read(defaultCfg.build());
rebased.read(cfg);
entry.setValue(rebased);
}
// Process the server configuration
ServerConfigurationBuilder serverBuilder = global.module(ServerConfigurationBuilder.class);
// Set up transport security
TransportSecurityConfiguration transportSecurityConfiguration = serverBuilder.security().transport().create();
if (transportSecurityConfiguration.securityRealm() != null) {
String securityRealm = transportSecurityConfiguration.securityRealm();
Supplier<SSLContext> serverSSLContextSupplier = serverBuilder.serverSSLContextSupplier(securityRealm);
Supplier<SSLContext> clientSSLContextSupplier = serverBuilder.clientSSLContextSupplier(securityRealm);
NamedSocketFactory namedSocketFactory = new NamedSocketFactory(() -> clientSSLContextSupplier.get().getSocketFactory(), () -> serverSSLContextSupplier.get().getServerSocketFactory());
global.transport().addProperty(JGroupsTransport.SOCKET_FACTORY, namedSocketFactory);
Server.log.sslTransport(securityRealm);
}
// Set the operation handler on all endpoints
ServerAdminOperationsHandler adminOperationsHandler = new ServerAdminOperationsHandler(defaultsHolder);
ServerConfigurationBuilder serverConfigurationBuilder = global.module(ServerConfigurationBuilder.class);
for (EndpointConfigurationBuilder endpoint : serverConfigurationBuilder.endpoints().endpoints().values()) {
for (ProtocolServerConfigurationBuilder<?, ?> connector : endpoint.connectors()) {
connector.adminOperationsHandler(adminOperationsHandler);
}
}
configurationBuilderHolder.validate();
} catch (IOException e) {
throw new CacheConfigurationException(e);
}
}
use of org.infinispan.server.configuration.endpoint.EndpointConfigurationBuilder in project infinispan by infinispan.
the class RespServerConfigurationParser method parseResp.
private void parseResp(ConfigurationReader reader, ServerConfigurationBuilder serverBuilder) {
boolean dedicatedSocketBinding = false;
String securityRealm = null;
EndpointConfigurationBuilder endpoint = serverBuilder.endpoints().current();
RespServerConfigurationBuilder builder = endpoint.addConnector(RespServerConfigurationBuilder.class);
for (int i = 0; i < reader.getAttributeCount(); i++) {
ParseUtils.requireNoNamespaceAttribute(reader, i);
String value = replaceProperties(reader.getAttributeValue(i));
Attribute attribute = Attribute.forName(reader.getAttributeName(i));
switch(attribute) {
case CACHE:
{
builder.defaultCacheName(value);
break;
}
case NAME:
{
builder.name(value);
break;
}
case SOCKET_BINDING:
{
builder.socketBinding(value);
builder.startTransport(true);
dedicatedSocketBinding = true;
break;
}
case SECURITY_REALM:
{
securityRealm = value;
}
default:
{
ServerConfigurationParser.parseCommonConnectorAttributes(reader, i, serverBuilder, builder);
}
}
}
if (!dedicatedSocketBinding) {
builder.socketBinding(endpoint.singlePort().socketBinding()).startTransport(false);
}
while (reader.inTag()) {
Element element = Element.forName(reader.getLocalName());
switch(element) {
case AUTHENTICATION:
{
parseAuthentication(reader, serverBuilder, builder.authentication().enable(), securityRealm);
break;
}
case ENCRYPTION:
{
if (!dedicatedSocketBinding) {
throw Server.log.cannotConfigureProtocolEncryptionUnderSinglePort();
}
parseEncryption(reader, serverBuilder, builder.encryption(), securityRealm);
break;
}
default:
{
ServerConfigurationParser.parseCommonConnectorElements(reader, builder);
}
}
}
}
use of org.infinispan.server.configuration.endpoint.EndpointConfigurationBuilder in project infinispan by infinispan.
the class RestServerConfigurationParser method parseRest.
private void parseRest(ConfigurationReader reader, ServerConfigurationBuilder serverBuilder) {
boolean dedicatedSocketBinding = false;
String securityRealm = null;
EndpointConfigurationBuilder endpoint = serverBuilder.endpoints().current();
RestServerConfigurationBuilder builder = endpoint.addConnector(RestServerConfigurationBuilder.class);
ServerConfigurationParser.configureEndpoint(reader.getProperties(), endpoint, builder);
for (int i = 0; i < reader.getAttributeCount(); i++) {
ParseUtils.requireNoNamespaceAttribute(reader, i);
String value = replaceProperties(reader.getAttributeValue(i));
Attribute attribute = Attribute.forName(reader.getAttributeName(i));
switch(attribute) {
case CONTEXT_PATH:
{
builder.contextPath(value);
break;
}
case EXTENDED_HEADERS:
{
builder.extendedHeaders(ExtendedHeaders.valueOf(value));
break;
}
case NAME:
{
builder.name(value);
break;
}
case MAX_CONTENT_LENGTH:
{
builder.maxContentLength(Integer.parseInt(value));
break;
}
case COMPRESSION_LEVEL:
{
builder.compressionLevel(Integer.parseInt(value));
break;
}
case SOCKET_BINDING:
{
builder.socketBinding(value);
builder.startTransport(true);
dedicatedSocketBinding = true;
break;
}
case SECURITY_REALM:
{
securityRealm = value;
}
default:
{
ServerConfigurationParser.parseCommonConnectorAttributes(reader, i, serverBuilder, builder);
}
}
}
if (!dedicatedSocketBinding) {
builder.socketBinding(endpoint.singlePort().socketBinding()).startTransport(false);
}
while (reader.inTag()) {
Element element = Element.forName(reader.getLocalName());
switch(element) {
case AUTHENTICATION:
{
parseAuthentication(reader, serverBuilder, builder.authentication().enable(), securityRealm);
break;
}
case ENCRYPTION:
{
if (!dedicatedSocketBinding) {
throw Server.log.cannotConfigureProtocolEncryptionUnderSinglePort();
}
parseEncryption(reader, serverBuilder, builder.encryption(), securityRealm);
break;
}
case CORS_RULES:
{
parseCorsRules(reader, builder);
break;
}
default:
{
ServerConfigurationParser.parseCommonConnectorElements(reader, builder);
}
}
}
}
use of org.infinispan.server.configuration.endpoint.EndpointConfigurationBuilder in project infinispan by infinispan.
the class ServerConfigurationParser method parseEndpoints.
private void parseEndpoints(ConfigurationReader reader, ConfigurationBuilderHolder holder, ServerConfigurationBuilder builder) {
String defaultSocketBinding = null;
String defaultSecurityRealm = null;
for (int i = 0; i < reader.getAttributeCount(); i++) {
Attribute attribute = Attribute.forName(reader.getAttributeName(i));
String value = reader.getAttributeValue(i);
switch(attribute) {
case SOCKET_BINDING:
defaultSocketBinding = value;
break;
case SECURITY_REALM:
defaultSecurityRealm = value;
break;
default:
throw ParseUtils.unexpectedElement(reader);
}
}
while (reader.inTag()) {
Element element = Element.forName(reader.getLocalName());
if (element == Element.ENDPOINT || element == Element.ENDPOINTS) {
parseEndpoint(reader, holder, builder, element, defaultSocketBinding, defaultSecurityRealm);
} else {
throw ParseUtils.unexpectedElement(reader);
}
}
if (builder.endpoints().endpoints().isEmpty()) {
if (defaultSocketBinding == null) {
throw ParseUtils.missingRequired(reader, Collections.singleton(Attribute.SOCKET_BINDING));
}
EndpointConfigurationBuilder endpoint = builder.endpoints().addEndpoint(defaultSocketBinding);
if (defaultSecurityRealm != null) {
endpoint.securityRealm(defaultSecurityRealm).implicitConnectorSecurity(true);
}
configureDefaultEndpoint(reader, defaultSocketBinding, endpoint);
}
}
use of org.infinispan.server.configuration.endpoint.EndpointConfigurationBuilder in project infinispan by infinispan.
the class ServerConfigurationParser method parseEndpoint.
private void parseEndpoint(ConfigurationReader reader, ConfigurationBuilderHolder holder, ServerConfigurationBuilder builder, Element endpointElement, String defaultSocketBinding, String defaultSecurityRealm) {
final String socketBinding;
if (defaultSocketBinding == null) {
socketBinding = ParseUtils.requireAttributes(reader, Attribute.SOCKET_BINDING)[0];
} else {
String binding = reader.getAttributeValue(Attribute.SOCKET_BINDING);
socketBinding = binding != null ? binding : defaultSocketBinding;
}
EndpointConfigurationBuilder endpoint = builder.endpoints().addEndpoint(socketBinding);
String realm = reader.getAttributeValue(Attribute.SECURITY_REALM);
final String securityRealm = realm != null ? realm : defaultSecurityRealm;
if (securityRealm != null) {
endpoint.securityRealm(securityRealm).implicitConnectorSecurity(reader.getSchema().since(11, 0));
}
for (int i = 0; i < reader.getAttributeCount(); i++) {
Attribute attribute = Attribute.forName(reader.getAttributeName(i));
String value = reader.getAttributeValue(i);
switch(attribute) {
case SOCKET_BINDING:
case SECURITY_REALM:
// Already seen
break;
case ADMIN:
endpoint.admin(Boolean.parseBoolean(value));
break;
case METRICS_AUTH:
endpoint.metricsAuth(Boolean.parseBoolean(value));
break;
default:
parseCommonConnectorAttributes(reader, i, builder, endpoint.singlePort());
break;
}
}
while (reader.inTag(endpointElement)) {
Element element = Element.forName(reader.getLocalName());
switch(element) {
case IP_FILTER:
{
parseConnectorIpFilter(reader, endpoint.singlePort().ipFilter());
break;
}
case CONNECTORS:
// Wrapping element for YAML/JSON
parseConnectors(reader, holder);
break;
default:
reader.handleAny(holder);
break;
}
}
configureDefaultEndpoint(reader, socketBinding, endpoint);
}
Aggregations