当前位置: 首页>>代码示例>>Java>>正文


Java Authenticator类代码示例

本文整理汇总了Java中java.net.Authenticator的典型用法代码示例。如果您正苦于以下问题:Java Authenticator类的具体用法?Java Authenticator怎么用?Java Authenticator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Authenticator类属于java.net包,在下文中一共展示了Authenticator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: authenticateProxy

import java.net.Authenticator; //导入依赖的package包/类
@Override public Credential authenticateProxy(
    Proxy proxy, URL url, List<Challenge> challenges) throws IOException {
  for (Challenge challenge : challenges) {
    if (!"Basic".equalsIgnoreCase(challenge.getScheme())) {
      continue;
    }

    InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
    PasswordAuthentication auth = Authenticator.requestPasswordAuthentication(
        proxyAddress.getHostName(), getConnectToInetAddress(proxy, url), proxyAddress.getPort(),
        url.getProtocol(), challenge.getRealm(), challenge.getScheme(), url,
        Authenticator.RequestorType.PROXY);
    if (auth != null) {
      return Credential.basic(auth.getUserName(), new String(auth.getPassword()));
    }
  }
  return null;
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:19,代码来源:HttpAuthenticator.java

示例2: testIsAuthenticationDialogSuppressed

import java.net.Authenticator; //导入依赖的package包/类
public void testIsAuthenticationDialogSuppressed() throws Exception {
    final boolean[] suppressed = new boolean[1];
    Authenticator.setDefault(new Authenticator() {

        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            suppressed[0] = NetworkSettings.isAuthenticationDialogSuppressed();
            return super.getPasswordAuthentication();
        }
    });

    Callable<Void> callable = new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            Authenticator.requestPasswordAuthentication("wher.ev.er", Inet4Address.getByName("1.2.3.4"), 1234, "http", null, "http");
            return null;
        }
    };
    NetworkSettings.suppressAuthenticationDialog(callable);
    assertTrue(suppressed[0]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:NetworkSettingsTest.java

示例3: getSystemCreds

import java.net.Authenticator; //导入依赖的package包/类
private static PasswordAuthentication getSystemCreds(
        final AuthScope authscope,
        final Authenticator.RequestorType requestorType) {
    final String hostname = authscope.getHost();
    final int port = authscope.getPort();
    final String protocol = port == 443 ? "https" : "http";
    return Authenticator.requestPasswordAuthentication(
            hostname,
            null,
            port,
            protocol,
            null,
            translateScheme(authscope.getScheme()),
            null,
            requestorType);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:17,代码来源:SystemDefaultCredentialsProvider.java

示例4: privilegedRequestPasswordAuthentication

import java.net.Authenticator; //导入依赖的package包/类
private static PasswordAuthentication
privilegedRequestPasswordAuthentication(
                        final String host,
                        final InetAddress addr,
                        final int port,
                        final String protocol,
                        final String prompt,
                        final String scheme,
                        final URL url,
                        final RequestorType authType) {
    return java.security.AccessController.doPrivileged(
        new java.security.PrivilegedAction<PasswordAuthentication>() {
            public PasswordAuthentication run() {
                if (logger.isLoggable(PlatformLogger.Level.FINEST)) {
                    logger.finest("Requesting Authentication: host =" + host + " url = " + url);
                }
                PasswordAuthentication pass = Authenticator.requestPasswordAuthentication(
                    host, addr, port, protocol,
                    prompt, scheme, url, authType);
                if (logger.isLoggable(PlatformLogger.Level.FINEST)) {
                    logger.finest("Authentication returned: " + (pass != null ? pass.toString() : "null"));
                }
                return pass;
            }
        });
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:HttpURLConnection.java

示例5: getAnswer

import java.net.Authenticator; //导入依赖的package包/类
private void getAnswer() {
    if (!answered) {
        answered = true;
        PasswordAuthentication passAuth =
                Authenticator.requestPasswordAuthentication(
                hci.host, hci.addr, hci.port, hci.protocol,
                hci.prompt, hci.scheme, hci.url, hci.authType);
        /**
         * To be compatible with existing callback handler implementations,
         * when the underlying Authenticator is canceled, username and
         * password are assigned null. No exception is thrown.
         */
        if (passAuth != null) {
            username = passAuth.getUserName();
            password = passAuth.getPassword();
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:NegotiateCallbackHandler.java

示例6: HttpCallerInfo

import java.net.Authenticator; //导入依赖的package包/类
/**
 * Constructor an un-schemed object for site access.
 */
public HttpCallerInfo(URL url, Authenticator a) {
    this.url= url;
    prompt = "";
    host = url.getHost();

    int p = url.getPort();
    if (p == -1) {
        port = url.getDefaultPort();
    } else {
        port = p;
    }

    InetAddress ia;
    try {
        ia = InetAddress.getByName(url.getHost());
    } catch (Exception e) {
        ia = null;
    }
    addr = ia;

    protocol = url.getProtocol();
    authType = RequestorType.SERVER;
    scheme = "";
    authenticator = a;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:HttpCallerInfo.java

示例7: getAnswer

import java.net.Authenticator; //导入依赖的package包/类
private void getAnswer() {
    if (!answered) {
        answered = true;
        PasswordAuthentication passAuth =
                Authenticator.requestPasswordAuthentication(
                hci.authenticator,
                hci.host, hci.addr, hci.port, hci.protocol,
                hci.prompt, hci.scheme, hci.url, hci.authType);
        /**
         * To be compatible with existing callback handler implementations,
         * when the underlying Authenticator is canceled, username and
         * password are assigned null. No exception is thrown.
         */
        if (passAuth != null) {
            username = passAuth.getUserName();
            password = passAuth.getPassword();
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:NegotiateCallbackHandler.java

示例8: main

import java.net.Authenticator; //导入依赖的package包/类
public static void main (String args[]) throws Exception {
    Authenticator defaultAuth = Authenticator.getDefault();
    if (defaultAuth != null) {
        throw new RuntimeException("Unexpected authenticator: null expected");
    }
    MyAuthenticator auth = new MyAuthenticator();
    Authenticator.setDefault(auth);
    defaultAuth = Authenticator.getDefault();
    if (defaultAuth != auth) {
        throw new RuntimeException("Unexpected authenticator: auth expected");
    }
    System.setSecurityManager(new SecurityManager());
    try {
        defaultAuth = Authenticator.getDefault();
        throw new RuntimeException("Expected security exception not raised");
    } catch (AccessControlException s) {
        System.out.println("Got expected exception: " + s);
        if (!s.getPermission().equals(new NetPermission("requestPasswordAuthentication"))) {
            throw new RuntimeException("Unexpected permission check: " + s.getPermission());
        }
    }
    System.out.println("Test passed with default authenticator "
                       + defaultAuth);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:GetAuthenticatorTest.java

示例9: setupProxy

import java.net.Authenticator; //导入依赖的package包/类
private static ProxyTunnelServer setupProxy() throws IOException {
    ProxyTunnelServer pserver = new ProxyTunnelServer();

    /*
     * register a system wide authenticator and setup the proxy for
     * authentication
     */
    Authenticator.setDefault(new TestAuthenticator());

    // register with the username and password
    pserver.needUserAuth(true);
    pserver.setUserAuth("Test", "test123");

    pserver.start();
    return pserver;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:ProxyAuthTest.java

示例10: runWithAuthenticator

import java.net.Authenticator; //导入依赖的package包/类
@Override
public void
runWithAuthenticator(
	Authenticator	authenticator,
	Runnable		target )
{
	try{
		Authenticator.setDefault( authenticator );

		target.run();

	}finally{

		SESecurityManager.installAuthenticator();
	}
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:17,代码来源:SESecurityManagerImpl.java

示例11: GitAuth

import java.net.Authenticator; //导入依赖的package包/类
/**
 * Constructor.
 * 
 * @param oldAuth The wrapped authenticator.
 * 
 * @throws NoSuchFieldException Unable to access wrapped authenticator data.
 */
private GitAuth(Authenticator oldAuth) throws NoSuchFieldException {
	this.oldAuth = oldAuth;

	// Getting the fields with java reflection
	requestingHost = Authenticator.class.getDeclaredField("requestingHost");
	requestingSite = Authenticator.class.getDeclaredField("requestingSite");
	requestingPort = Authenticator.class.getDeclaredField("requestingPort");
	requestingProtocol = Authenticator.class.getDeclaredField("requestingProtocol");
	requestingPrompt = Authenticator.class.getDeclaredField("requestingPrompt");
	requestingScheme = Authenticator.class.getDeclaredField("requestingScheme");
	requestingURL = Authenticator.class.getDeclaredField("requestingURL");
	requestingAuthType = Authenticator.class.getDeclaredField("requestingAuthType");

	// Making the fields accessible
	requestingHost.setAccessible(true);
	requestingSite.setAccessible(true);
	requestingPort.setAccessible(true);
	requestingProtocol.setAccessible(true);
	requestingPrompt.setAccessible(true);
	requestingScheme.setAccessible(true);
	requestingURL.setAccessible(true);
	requestingAuthType.setAccessible(true);
}
 
开发者ID:oxygenxml,项目名称:oxygen-git-plugin,代码行数:31,代码来源:AuthenticationInterceptor.java

示例12: install

import java.net.Authenticator; //导入依赖的package包/类
/**
 * Installs my custom authenticator. Gets the current authenticator by
 * reflection and compares it with the previous one. If they are not the same
 * instance, then my authenticator will be installed. If not, then it means
 * that my authenticator is already installed
 */
public static void install() {
	final Authenticator[] currentAuth = new Authenticator[1];
	try {

		Field declaredField = Authenticator.class.getDeclaredField("theAuthenticator");
		declaredField.setAccessible(true);
		currentAuth[0] = (Authenticator) declaredField.get(null);

		if (currentAuth[0] == null || currentAuth[0] != installedAuthenticator) {
		  GitAuth oldInstalledAuth = installedAuthenticator;

			installedAuthenticator = new GitAuth(currentAuth[0]);
			installedAuthenticator.setBoundHosts(oldInstalledAuth.getBoundHosts());

			Authenticator.setDefault(installedAuthenticator);
		}

	} catch (Throwable e) {
		if (logger.isDebugEnabled()) {
			logger.debug(e, e);
		}
	}
}
 
开发者ID:oxygenxml,项目名称:oxygen-git-plugin,代码行数:30,代码来源:AuthenticationInterceptor.java

示例13: testUserPassword

import java.net.Authenticator; //导入依赖的package包/类
@Test
public void testUserPassword() throws Exception {
  startServer(buildUserPasswordConfig());

  Authenticator.setDefault(new Authenticator() {
    @Override
    protected PasswordAuthentication getPasswordAuthentication() {
      return new PasswordAuthentication("oryx", "pass".toCharArray());
    }
  });

  try {
    String response = Resources.toString(
        new URL("http://localhost:" + getHTTPPort() + "/helloWorld"),
        StandardCharsets.UTF_8);
    assertEquals("Hello, World", response);
  } finally {
    Authenticator.setDefault(null);
  }
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:21,代码来源:SecureAPIConfigIT.java

示例14: privilegedRequestPasswordAuthentication

import java.net.Authenticator; //导入依赖的package包/类
private static PasswordAuthentication
privilegedRequestPasswordAuthentication(
                        final String host,
                        final InetAddress addr,
                        final int port,
                        final String protocol,
                        final String prompt,
                        final String scheme,
                        final URL url,
                        final RequestorType authType) {
    return java.security.AccessController.doPrivileged(
        new java.security.PrivilegedAction<>() {
            public PasswordAuthentication run() {
                if (logger.isLoggable(PlatformLogger.Level.FINEST)) {
                    logger.finest("Requesting Authentication: host =" + host + " url = " + url);
                }
                PasswordAuthentication pass = Authenticator.requestPasswordAuthentication(
                    host, addr, port, protocol,
                    prompt, scheme, url, authType);
                if (logger.isLoggable(PlatformLogger.Level.FINEST)) {
                    logger.finest("Authentication returned: " + (pass != null ? pass.toString() : "null"));
                }
                return pass;
            }
        });
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:27,代码来源:HttpURLConnection.java

示例15: authenticate

import java.net.Authenticator; //导入依赖的package包/类
@Test public void authenticate() throws Exception {
  server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_UNAUTHORIZED)
      .addHeader("www-authenticate: Basic realm=\"protected area\"")
      .setBody("Please authenticate."));
  server.enqueue(new MockResponse().setBody("Successful auth!"));

  Authenticator.setDefault(new RecordingAuthenticator());
  urlFactory.setClient(urlFactory.client().newBuilder()
      .authenticator(new JavaNetAuthenticator())
      .build());
  connection = urlFactory.open(server.url("/").url());
  assertEquals("Successful auth!", readAscii(connection.getInputStream(), Integer.MAX_VALUE));

  RecordedRequest denied = server.takeRequest();
  assertNull(denied.getHeader("Authorization"));
  RecordedRequest accepted = server.takeRequest();
  assertEquals("GET / HTTP/1.1", accepted.getRequestLine());
  assertEquals("Basic " + RecordingAuthenticator.BASE_64_CREDENTIALS,
      accepted.getHeader("Authorization"));
}
 
开发者ID:lizhangqu,项目名称:PriorityOkHttp,代码行数:21,代码来源:HttpOverSpdyTest.java


注:本文中的java.net.Authenticator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。