use of org.apache.knox.gateway.services.security.AliasServiceException in project knox by apache.
the class CredentialResource method getCredentialsList.
/**
* @return
*/
private List<String> getCredentialsList() {
GatewayServices services = (GatewayServices) request.getServletContext().getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
String clusterName = (String) request.getServletContext().getAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE);
AliasService as = services.getService(GatewayServices.ALIAS_SERVICE);
List<String> aliases = null;
try {
aliases = as.getAliasesForCluster(clusterName);
} catch (AliasServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return aliases;
}
use of org.apache.knox.gateway.services.security.AliasServiceException in project knox by apache.
the class RemoteConfigurationRegistryJAASConfig method createEntry.
private AppConfigurationEntry createEntry(RemoteConfigurationRegistryConfig config) {
AppConfigurationEntry entry = null;
Map<String, String> opts = new HashMap<>();
SASLMechanism saslMechanism = getSASLMechanism(config.getAuthType());
switch(saslMechanism) {
case Digest:
// Digest auth options
opts.put("username", config.getPrincipal());
char[] credential = null;
if (aliasService != null) {
try {
credential = aliasService.getPasswordFromAliasForGateway(config.getCredentialAlias());
} catch (AliasServiceException e) {
log.unresolvedCredentialAlias(config.getCredentialAlias());
}
} else {
throw new IllegalArgumentException("The AliasService is required to resolve credential aliases.");
}
if (credential != null) {
opts.put("password", new String(credential));
}
break;
case Kerberos:
opts.put("isUseTicketCache", String.valueOf(config.isUseTicketCache()));
opts.put("isUseKeyTab", String.valueOf(config.isUseKeyTab()));
opts.put("keyTab", config.getKeytab());
opts.put("principal", config.getPrincipal());
}
if (!opts.isEmpty()) {
entry = new AppConfigurationEntry(getLoginModuleName(config.getRegistryType(), saslMechanism), AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, opts);
}
return entry;
}
use of org.apache.knox.gateway.services.security.AliasServiceException in project knox by apache.
the class DefaultHttpClientFactory method createHttpClient.
@Override
public HttpClient createHttpClient(FilterConfig filterConfig) {
HttpClientBuilder builder = null;
GatewayConfig gatewayConfig = (GatewayConfig) filterConfig.getServletContext().getAttribute(GatewayConfig.GATEWAY_CONFIG_ATTRIBUTE);
GatewayServices services = (GatewayServices) filterConfig.getServletContext().getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
if (gatewayConfig != null && gatewayConfig.isMetricsEnabled()) {
MetricsService metricsService = services.getService(GatewayServices.METRICS_SERVICE);
builder = metricsService.getInstrumented(HttpClientBuilder.class);
} else {
builder = HttpClients.custom();
}
if (Boolean.parseBoolean(filterConfig.getInitParameter("useTwoWaySsl"))) {
char[] keypass = null;
MasterService ms = services.getService("MasterService");
AliasService as = services.getService(GatewayServices.ALIAS_SERVICE);
try {
keypass = as.getGatewayIdentityPassphrase();
} catch (AliasServiceException e) {
// nop - default passphrase will be used
}
if (keypass == null) {
// there has been no alias created for the key - let's assume it is the same as the keystore password
keypass = ms.getMasterSecret();
}
KeystoreService ks = services.getService(GatewayServices.KEYSTORE_SERVICE);
final SSLContext sslcontext;
try {
KeyStore keystoreForGateway = ks.getKeystoreForGateway();
sslcontext = SSLContexts.custom().loadTrustMaterial(keystoreForGateway, new TrustSelfSignedStrategy()).loadKeyMaterial(keystoreForGateway, keypass).build();
} catch (Exception e) {
throw new IllegalArgumentException("Unable to create SSLContext", e);
}
builder.setSSLSocketFactory(new SSLConnectionSocketFactory(sslcontext));
}
if ("true".equals(System.getProperty(GatewayConfig.HADOOP_KERBEROS_SECURED))) {
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UseJaasCredentials());
Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create().register(AuthSchemes.SPNEGO, new KnoxSpnegoAuthSchemeFactory(true)).build();
builder = builder.setDefaultAuthSchemeRegistry(authSchemeRegistry).setDefaultCookieStore(new HadoopAuthCookieStore()).setDefaultCredentialsProvider(credentialsProvider);
} else {
builder = builder.setDefaultCookieStore(new NoCookieStore());
}
builder.setKeepAliveStrategy(DefaultConnectionKeepAliveStrategy.INSTANCE);
builder.setConnectionReuseStrategy(DefaultConnectionReuseStrategy.INSTANCE);
builder.setRedirectStrategy(new NeverRedirectStrategy());
builder.setRetryHandler(new NeverRetryHandler());
int maxConnections = getMaxConnections(filterConfig);
builder.setMaxConnTotal(maxConnections);
builder.setMaxConnPerRoute(maxConnections);
builder.setDefaultRequestConfig(getRequestConfig(filterConfig));
HttpClient client = builder.build();
return client;
}
use of org.apache.knox.gateway.services.security.AliasServiceException in project knox by apache.
the class CredentialResource method getCredentialValueForAlias.
/**
* @param alias
* @return
*/
private CredentialValue getCredentialValueForAlias(String alias) {
GatewayServices services = (GatewayServices) request.getServletContext().getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
String clusterName = (String) request.getServletContext().getAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE);
AliasService as = services.getService(GatewayServices.ALIAS_SERVICE);
char[] credential = null;
try {
credential = as.getPasswordFromAliasForCluster(clusterName, alias);
} catch (AliasServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (credential != null) {
return new CredentialValue(alias, new String(credential));
}
return null;
}
use of org.apache.knox.gateway.services.security.AliasServiceException in project knox by apache.
the class KnoxLdapContextFactory method setSystemPassword.
@Override
public void setSystemPassword(String systemPass) {
if (systemPass == null) {
return;
}
systemPass = systemPass.trim();
if (systemPass.length() == 0) {
return;
}
if (!systemPass.startsWith("S{ALIAS=")) {
super.setSystemPassword(systemPass);
return;
}
systemPass = systemPass.substring("S{ALIAS=".length(), systemPass.length() - 1);
String aliasName = systemPass;
GatewayServices services = GatewayServer.getGatewayServices();
AliasService aliasService = (AliasService) services.getService(GatewayServices.ALIAS_SERVICE);
String clusterName = getClusterName();
// System.err.println("FACTORY systempass 30: " + systemPass);
// System.err.println("FACTORY clustername 40: " + clusterName);
// System.err.println("FACTORY SystemProperty GatewayHome 50: " + System.getProperty(GatewayConfig.GATEWAY_HOME_VAR));
char[] password = null;
try {
password = aliasService.getPasswordFromAliasForCluster(clusterName, systemPass);
} catch (AliasServiceException e) {
LOG.unableToGetPassword(e);
}
// System.err.println("FACTORY password: " + ((password == null) ? "NULL" : new String(password)));
if (password != null) {
// System.err.println("FACTORY SUCCESS 20 system password :" + new String(password));
super.setSystemPassword(new String(password));
} else {
// System.err.println("FACTORY FORCING system password to blank");
super.setSystemPassword("");
LOG.aliasValueNotFound(clusterName, aliasName);
}
}
Aggregations