use of java.security.URIParameter in project elasticsearch by elastic.
the class Security method readPolicy.
/**
* Reads and returns the specified {@code policyFile}.
* <p>
* Resources (e.g. jar files and directories) listed in {@code codebases} location
* will be provided to the policy file via a system property of the short name:
* e.g. <code>${codebase.joda-convert-1.2.jar}</code> would map to full URL.
*/
@SuppressForbidden(reason = "accesses fully qualified URLs to configure security")
static Policy readPolicy(URL policyFile, URL[] codebases) {
try {
try {
// set codebase properties
for (URL url : codebases) {
String shortName = PathUtils.get(url.toURI()).getFileName().toString();
System.setProperty("codebase." + shortName, url.toString());
}
return Policy.getInstance("JavaPolicy", new URIParameter(policyFile.toURI()));
} finally {
// clear codebase properties
for (URL url : codebases) {
String shortName = PathUtils.get(url.toURI()).getFileName().toString();
System.clearProperty("codebase." + shortName);
}
}
} catch (NoSuchAlgorithmException | URISyntaxException e) {
throw new IllegalArgumentException("unable to parse policy file `" + policyFile + "`", e);
}
}
use of java.security.URIParameter in project jdk8u_jdk by JetBrains.
the class DefaultGssConfig method main.
public static void main(String[] argv) throws Exception {
// 1. Make sure the FileNotFoundException is hidden
try {
Configuration.getInstance("JavaLoginConfig", new URIParameter(new URI("file:///no/such/file")));
} catch (NoSuchAlgorithmException nsae) {
if (nsae.getCause() instanceof IOException && !(nsae.getCause() instanceof FileNotFoundException)) {
// ignore
} else {
throw nsae;
}
}
// 2. Make sure there's always a Configuration even if no config file exists
Configuration.getConfiguration();
// 3. Make sure there're default entries for GSS krb5 client/server
LoginConfigImpl lc = new LoginConfigImpl(GSSCaller.CALLER_INITIATE, GSSUtil.GSS_KRB5_MECH_OID);
if (lc.getAppConfigurationEntry("").length == 0) {
throw new Exception("No default config for GSS krb5 client");
}
lc = new LoginConfigImpl(GSSCaller.CALLER_ACCEPT, GSSUtil.GSS_KRB5_MECH_OID);
if (lc.getAppConfigurationEntry("").length == 0) {
throw new Exception("No default config for GSS krb5 server");
}
}
use of java.security.URIParameter in project cas by apereo.
the class JaasAuthenticationHandler method getLoginContext.
/**
* Gets login context.
*
* @param credential the credential
* @return the login context
* @throws GeneralSecurityException the general security exception
*/
protected LoginContext getLoginContext(final UsernamePasswordCredential credential) throws GeneralSecurityException {
val callbackHandler = new UsernamePasswordCallbackHandler(credential.getUsername(), credential.getPassword());
if (this.loginConfigurationFile != null && StringUtils.isNotBlank(this.loginConfigType) && this.loginConfigurationFile.exists() && this.loginConfigurationFile.canRead()) {
final Configuration.Parameters parameters = new URIParameter(loginConfigurationFile.toURI());
val loginConfig = Configuration.getInstance(this.loginConfigType, parameters);
return new LoginContext(this.realm, null, callbackHandler, loginConfig);
}
return new LoginContext(this.realm, callbackHandler);
}
use of java.security.URIParameter in project storm by nathanmarz.
the class AuthUtils method GetConfiguration.
/**
* Construct a JAAS configuration object per storm configuration file
* @param storm_conf Storm configuration
* @return JAAS configuration object
*/
public static Configuration GetConfiguration(Map storm_conf) {
Configuration login_conf = null;
// find login file configuration from Storm configuration
String loginConfigurationFile = (String) storm_conf.get("java.security.auth.login.config");
if ((loginConfigurationFile != null) && (loginConfigurationFile.length() > 0)) {
try {
URI config_uri = new File(loginConfigurationFile).toURI();
login_conf = Configuration.getInstance("JavaLoginConfig", new URIParameter(config_uri));
} catch (NoSuchAlgorithmException ex1) {
if (ex1.getCause() instanceof FileNotFoundException)
throw new RuntimeException("configuration file " + loginConfigurationFile + " could not be found");
else
throw new RuntimeException(ex1);
} catch (Exception ex2) {
throw new RuntimeException(ex2);
}
}
return login_conf;
}
use of java.security.URIParameter in project storm by apache.
the class AuthUtils method GetConfiguration.
/**
* Construct a JAAS configuration object per storm configuration file
* @param storm_conf Storm configuration
* @return JAAS configuration object
*/
public static Configuration GetConfiguration(Map storm_conf) {
Configuration login_conf = null;
//find login file configuration from Storm configuration
String loginConfigurationFile = (String) storm_conf.get("java.security.auth.login.config");
if ((loginConfigurationFile != null) && (loginConfigurationFile.length() > 0)) {
File config_file = new File(loginConfigurationFile);
if (!config_file.canRead()) {
throw new RuntimeException("File " + loginConfigurationFile + " cannot be read.");
}
try {
URI config_uri = config_file.toURI();
login_conf = Configuration.getInstance("JavaLoginConfig", new URIParameter(config_uri));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
return login_conf;
}
Aggregations