/*
 * Copyright 2017-2018, EnMasse authors.
 * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
 */
package io.enmasse.controller.common;

import io.enmasse.address.model.AuthenticationService;
import io.enmasse.address.model.AuthenticationServiceResolver;

import java.util.Optional;

/**
 * Resolves the none authentication service host name.
 */
public class StandardAuthenticationServiceResolver implements AuthenticationServiceResolver {
    private final String host;
    private final int port;

    public StandardAuthenticationServiceResolver(String host, int port) {
        this.host = host;
        this.port = port;
    }

    @Override
    public String getHost(AuthenticationService authService) {
        return host;
    }

    @Override
    public int getPort(AuthenticationService authService) {
        return port;
    }

    @Override
    public Optional<String> getCaSecretName(AuthenticationService authService) {
        return Optional.of("standard-authservice-cert");
    }

    @Override
    public Optional<String> getClientSecretName(AuthenticationService authService) {
        return Optional.empty();
    }

    @Override
    public Optional<String> getSaslInitHost(String addressSpaceName, AuthenticationService authService) {
        return Optional.of(addressSpaceName);
    }
}

@@ -748,32 +748,199 @@
  authService) %7B%0A
+        String overrideHost = (String) authService.getDetails().get(%22host%22);%0A        if (overrideHost != null) %7B%0A            return overrideHost;%0A        %7D else %7B%0A    
         return h
@@ -940,24 +940,34 @@
 eturn host;%0A
+        %7D%0A
     %7D%0A%0A    @
@@ -1027,32 +1027,217 @@
  authService) %7B%0A
+        String overridePort = (String) authService.getDetails().get(%22port%22);%0A        if (overridePort != null) %7B%0A            return Integer.parseInt(overridePort);%0A        %7D else %7B%0A    
         return p
@@ -1237,24 +1237,34 @@
 eturn port;%0A
+        %7D%0A
     %7D%0A%0A    @

Allow standard authservice host port to be overridden