Search in sources :

Example 1 with URIParameter

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);
    }
}
Also used : URIParameter(java.security.URIParameter) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) URISyntaxException(java.net.URISyntaxException) URL(java.net.URL) SuppressForbidden(org.elasticsearch.common.SuppressForbidden)

Example 2 with URIParameter

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");
    }
}
Also used : URIParameter(java.security.URIParameter) FileNotFoundException(java.io.FileNotFoundException) LoginConfigImpl(sun.security.jgss.LoginConfigImpl) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) URI(java.net.URI) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 3 with URIParameter

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);
}
Also used : lombok.val(lombok.val) URIParameter(java.security.URIParameter) LoginContext(javax.security.auth.login.LoginContext) Configuration(javax.security.auth.login.Configuration)

Example 4 with URIParameter

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;
}
Also used : URIParameter(java.security.URIParameter) Configuration(javax.security.auth.login.Configuration) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) URI(java.net.URI) File(java.io.File) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 5 with URIParameter

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;
}
Also used : URIParameter(java.security.URIParameter) Configuration(javax.security.auth.login.Configuration) File(java.io.File) URI(java.net.URI) IOException(java.io.IOException)

Aggregations

URIParameter (java.security.URIParameter)9 File (java.io.File)5 IOException (java.io.IOException)5 URI (java.net.URI)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 Configuration (javax.security.auth.login.Configuration)5 FileNotFoundException (java.io.FileNotFoundException)3 FileOutputStream (java.io.FileOutputStream)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 Permission (java.security.Permission)1 PermissionCollection (java.security.PermissionCollection)1 Permissions (java.security.Permissions)1 Policy (java.security.Policy)1 UnresolvedPermission (java.security.UnresolvedPermission)1 LoginContext (javax.security.auth.login.LoginContext)1 lombok.val (lombok.val)1 SuppressForbidden (org.elasticsearch.common.SuppressForbidden)1 LoginConfigImpl (sun.security.jgss.LoginConfigImpl)1