Search in sources :

Example 1 with NetPermission

use of java.net.NetPermission in project languagetool by languagetool-org.

the class Tools method setPasswordAuthenticator.

/**
   * Calls {@code Authenticator.setDefault()} with a password
   * authenticator so that it's possible to use URLs of the
   * format {@code http://username:password@server} when loading XML files.
   * If the password manager doesn't allow calling {@code Authenticator.setDefault()},
   * this will be silently ignored and the feature of using these URLs
   * will not be available.
   * @since 3.0
   */
public static void setPasswordAuthenticator() {
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        try {
            security.checkPermission(new NetPermission("setDefaultAuthenticator"));
            Authenticator.setDefault(new PasswordAuthenticator());
        } catch (SecurityException e) {
        // ignore, but the feature to use user:password in the URL cannot be used now,
        // see https://github.com/languagetool-org/languagetool/issues/255
        }
    } else {
        Authenticator.setDefault(new PasswordAuthenticator());
    }
}
Also used : PasswordAuthenticator(org.languagetool.rules.patterns.PasswordAuthenticator) NetPermission(java.net.NetPermission)

Aggregations

NetPermission (java.net.NetPermission)1 PasswordAuthenticator (org.languagetool.rules.patterns.PasswordAuthenticator)1