Java源码示例:org.apache.atlas.security.SecurityProperties
示例1
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();
}
示例2
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();
}
示例3
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;
}
示例4
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;
}
}
示例5
@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");
}
示例6
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;
}
示例7
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;
}
}
示例8
@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");
}
示例9
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);
}
示例10
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);
}
示例11
/**
* 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;
}
示例12
/**
* 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;
}