org.apache.atlas.security.SecurityProperties Java Examples

The following examples show how to use org.apache.atlas.security.SecurityProperties. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Atlas.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    CommandLine cmd = parseArgs(args);
    PropertiesConfiguration buildConfiguration = new PropertiesConfiguration("atlas-buildinfo.properties");
    String appPath = "webapp/target/atlas-webapp-" + getProjectVersion(buildConfiguration);

    if (cmd.hasOption(APP_PATH)) {
        appPath = cmd.getOptionValue(APP_PATH);
    }

    setApplicationHome();
    Configuration configuration = ApplicationProperties.get();
    final String enableTLSFlag = configuration.getString(SecurityProperties.TLS_ENABLED);
    final int appPort = getApplicationPort(cmd, enableTLSFlag, configuration);
    System.setProperty(AtlasConstants.SYSTEM_PROPERTY_APP_PORT, String.valueOf(appPort));
    final boolean enableTLS = isTLSEnabled(enableTLSFlag, appPort);
    configuration.setProperty(SecurityProperties.TLS_ENABLED, String.valueOf(enableTLS));

    showStartupInfo(buildConfiguration, enableTLS, appPort);

    server = EmbeddedServer.newServer(appPort, appPath, enableTLS);
    installLogBridge();

    server.start();
}
 
Example #2
Source File: Atlas.java    From atlas with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    CommandLine cmd = parseArgs(args);
    PropertiesConfiguration buildConfiguration = new PropertiesConfiguration("atlas-buildinfo.properties");
    String appPath = "webapp/target/atlas-webapp-" + getProjectVersion(buildConfiguration);

    if (cmd.hasOption(APP_PATH)) {
        appPath = cmd.getOptionValue(APP_PATH);
    }

    setApplicationHome();
    Configuration configuration = ApplicationProperties.get();
    final String enableTLSFlag = configuration.getString(SecurityProperties.TLS_ENABLED);
    final String appHost = configuration.getString(SecurityProperties.BIND_ADDRESS, EmbeddedServer.ATLAS_DEFAULT_BIND_ADDRESS);

    if (!isLocalAddress(InetAddress.getByName(appHost))) {
        String msg =
            "Failed to start Atlas server. Address " + appHost
                + " does not belong to this host. Correct configuration parameter: "
                + SecurityProperties.BIND_ADDRESS;
        LOG.error(msg);
        throw new IOException(msg);
    }

    final int appPort = getApplicationPort(cmd, enableTLSFlag, configuration);
    System.setProperty(AtlasConstants.SYSTEM_PROPERTY_APP_PORT, String.valueOf(appPort));
    final boolean enableTLS = isTLSEnabled(enableTLSFlag, appPort);
    configuration.setProperty(SecurityProperties.TLS_ENABLED, String.valueOf(enableTLS));

    showStartupInfo(buildConfiguration, enableTLS, appPort);

    server = EmbeddedServer.newServer(appHost, appPort, appPath, enableTLS);
    installLogBridge();

    server.start();
}
 
Example #3
Source File: LoginProcessor.java    From atlas with Apache License 2.0 5 votes vote down vote up
private String getHostname(org.apache.commons.configuration.Configuration configuration) {
    String bindAddress = configuration.getString(SecurityProperties.BIND_ADDRESS);
    if (bindAddress == null) {
        LOG.info("No host name configured.  Defaulting to local host name.");
        try {
            bindAddress = InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException e) {
            throw new IllegalStateException(e);
        }
    }
    return bindAddress;
}
 
Example #4
Source File: BaseSSLAndKerberosTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
protected void setupCredentials() throws Exception {
    Configuration conf = new Configuration(false);

    File file = new File(jksPath.toUri().getPath());
    file.delete();
    conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, providerUrl);

    CredentialProvider provider = CredentialProviderFactory.getProviders(conf).get(0);

    // create new aliases
    try {

        char[] storepass = {'k', 'e', 'y', 'p', 'a', 's', 's'};
        provider.createCredentialEntry(SecurityProperties.KEYSTORE_PASSWORD_KEY, storepass);

        char[] trustpass = {'k', 'e', 'y', 'p', 'a', 's', 's'};
        provider.createCredentialEntry(SecurityProperties.TRUSTSTORE_PASSWORD_KEY, trustpass);

        char[] trustpass2 = {'k', 'e', 'y', 'p', 'a', 's', 's'};
        provider.createCredentialEntry("ssl.client.truststore.password", trustpass2);

        char[] certpass = {'k', 'e', 'y', 'p', 'a', 's', 's'};
        provider.createCredentialEntry(SecurityProperties.SERVER_CERT_PASSWORD_KEY, certpass);

        // write out so that it can be found in checks
        provider.flush();
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
}
 
Example #5
Source File: HAConfigurationTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testShouldReturnHTTPSBoundAddress() {
    when(configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX +"id1")).thenReturn("127.0.0.1:21443");
    when(configuration.getBoolean(SecurityProperties.TLS_ENABLED)).thenReturn(true);

    String address = HAConfiguration.getBoundAddressForId(configuration, "id1");

    assertEquals(address, "https://127.0.0.1:21443");
}
 
Example #6
Source File: LoginProcessor.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private String getHostname(org.apache.commons.configuration.Configuration configuration) {
    String bindAddress = configuration.getString(SecurityProperties.BIND_ADDRESS);
    if (bindAddress == null) {
        LOG.info("No host name configured.  Defaulting to local host name.");
        try {
            bindAddress = InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException e) {
            throw new IllegalStateException(e);
        }
    }
    return bindAddress;
}
 
Example #7
Source File: BaseSSLAndKerberosTest.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
protected void setupCredentials() throws Exception {
    Configuration conf = new Configuration(false);

    File file = new File(jksPath.toUri().getPath());
    file.delete();
    conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, providerUrl);

    CredentialProvider provider = CredentialProviderFactory.getProviders(conf).get(0);

    // create new aliases
    try {

        char[] storepass = {'k', 'e', 'y', 'p', 'a', 's', 's'};
        provider.createCredentialEntry(SecurityProperties.KEYSTORE_PASSWORD_KEY, storepass);

        char[] trustpass = {'k', 'e', 'y', 'p', 'a', 's', 's'};
        provider.createCredentialEntry(SecurityProperties.TRUSTSTORE_PASSWORD_KEY, trustpass);

        char[] trustpass2 = {'k', 'e', 'y', 'p', 'a', 's', 's'};
        provider.createCredentialEntry("ssl.client.truststore.password", trustpass2);

        char[] certpass = {'k', 'e', 'y', 'p', 'a', 's', 's'};
        provider.createCredentialEntry(SecurityProperties.SERVER_CERT_PASSWORD_KEY, certpass);

        // write out so that it can be found in checks
        provider.flush();
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
}
 
Example #8
Source File: HAConfigurationTest.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testShouldReturnHTTPSBoundAddress() {
    when(configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX +"id1")).thenReturn("127.0.0.1:21443");
    when(configuration.getBoolean(SecurityProperties.TLS_ENABLED)).thenReturn(true);

    String address = HAConfiguration.getBoundAddressForId(configuration, "id1");

    assertEquals(address, "https://127.0.0.1:21443");
}
 
Example #9
Source File: Atlas.java    From atlas with Apache License 2.0 4 votes vote down vote up
private static boolean isTLSEnabled(String enableTLSFlag, int appPort) {
    return Boolean.valueOf(StringUtils.isEmpty(enableTLSFlag) ?
            System.getProperty(SecurityProperties.TLS_ENABLED, (appPort % 1000) == 443 ? "true" : "false") : enableTLSFlag);
}
 
Example #10
Source File: Atlas.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
private static boolean isTLSEnabled(String enableTLSFlag, int appPort) {
    return Boolean.valueOf(StringUtils.isEmpty(enableTLSFlag) ?
            System.getProperty(SecurityProperties.TLS_ENABLED, (appPort % 1000) == 443 ? "true" : "false") : enableTLSFlag);
}
 
Example #11
Source File: HAConfiguration.java    From atlas with Apache License 2.0 3 votes vote down vote up
/**
 * Get the web server address that a server instance with the passed ID is bound to.
 *
 * This method uses the property {@link SecurityProperties#TLS_ENABLED} to determine whether
 * the URL is http or https.
 *
 * @param configuration underlying configuration
 * @param serverId serverId whose host:port property is picked to build the web server address.
 * @return
 */
public static String getBoundAddressForId(Configuration configuration, String serverId) {
    String hostPort = configuration.getString(ATLAS_SERVER_ADDRESS_PREFIX +serverId);
    boolean isSecure = configuration.getBoolean(SecurityProperties.TLS_ENABLED);
    String protocol = (isSecure) ? "https://" : "http://";
    return protocol + hostPort;
}
 
Example #12
Source File: HAConfiguration.java    From incubator-atlas with Apache License 2.0 3 votes vote down vote up
/**
 * Get the web server address that a server instance with the passed ID is bound to.
 *
 * This method uses the property {@link SecurityProperties#TLS_ENABLED} to determine whether
 * the URL is http or https.
 *
 * @param configuration underlying configuration
 * @param serverId serverId whose host:port property is picked to build the web server address.
 * @return
 */
public static String getBoundAddressForId(Configuration configuration, String serverId) {
    String hostPort = configuration.getString(ATLAS_SERVER_ADDRESS_PREFIX +serverId);
    boolean isSecure = configuration.getBoolean(SecurityProperties.TLS_ENABLED);
    String protocol = (isSecure) ? "https://" : "http://";
    return protocol + hostPort;
}