Package org.platformlayer.auth.client

Source Code of org.platformlayer.auth.client.PlatformLayerAuthenticationClientProvider

package org.platformlayer.auth.client;

import javax.inject.Inject;
import javax.inject.Provider;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.KeyManager;
import javax.net.ssl.TrustManager;

import org.platformlayer.http.HttpStrategy;
import org.platformlayer.http.SslConfiguration;
import org.platformlayer.rest.JreRestfulClient;
import org.platformlayer.rest.RestfulClient;

import com.fathomdb.Configuration;
import com.fathomdb.crypto.ssl.AcceptAllHostnameVerifier;
import com.fathomdb.crypto.ssl.PublicKeyTrustManager;
import com.google.common.base.Splitter;

public class PlatformLayerAuthenticationClientProvider implements Provider<PlatformLayerAuthenticationClient> {
  private static final int PORT_PLATFORMLAYER_AUTH_USER = 5001;

  @Inject
  Configuration configuration;

  @Inject
  HttpStrategy httpStrategy;

  @Override
  public PlatformLayerAuthenticationClient get() {
    String keystoneUserUrl = configuration.lookup("auth.user.url", "https://127.0.0.1:"
        + PORT_PLATFORMLAYER_AUTH_USER + "/v2.0/");

    HostnameVerifier hostnameVerifier = null;

    KeyManager keyManager = null;

    TrustManager trustManager = null;

    String trustKeys = configuration.lookup("auth.user.ssl.keys", null);

    if (trustKeys != null) {
      trustManager = new PublicKeyTrustManager(Splitter.on(',').trimResults().split(trustKeys));

      hostnameVerifier = new AcceptAllHostnameVerifier();
    }

    SslConfiguration sslConfiguration = new SslConfiguration(keyManager, trustManager, hostnameVerifier);
    RestfulClient restfulClient = new JreRestfulClient(httpStrategy, keystoneUserUrl, sslConfiguration);
    PlatformLayerAuthenticationClient authClient = new PlatformLayerAuthenticationClient(restfulClient);

    return authClient;
  }
}
TOP

Related Classes of org.platformlayer.auth.client.PlatformLayerAuthenticationClientProvider

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.