Package java.net

Examples of java.net.PasswordAuthentication


        final String password = "password";

        Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(login, password.toCharArray());
            }
        });

        URL postUrl = new URL(SERVER_URL + "/");
        HttpURLConnection connection = (HttpURLConnection)postUrl.openConnection();
View Full Code Here


        // Authentication test
        // set up a very simple authenticator
        Authenticator.setDefault(new Authenticator() {
            public PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("test", "password"
                        .toCharArray());
            }
        });
        try {
            client.open(authTestUrl);
View Full Code Here

    public void testProxyAuthorization() throws Exception {
        // Set up test Authenticator
        Authenticator.setDefault(new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("user", "password"
                        .toCharArray());
            }
        });

        try {
View Full Code Here

            }
        }
    }
   
    protected PasswordAuthentication getPasswordAuthentication() {
        PasswordAuthentication auth = null;
        Message m = PhaseInterceptorChain.getCurrentMessage();
        if (m != null) {
            Exchange exchange = m.getExchange();
            Conduit conduit = exchange.getConduit(m);
            if (conduit instanceof HTTPConduit) {
                HTTPConduit httpConduit = (HTTPConduit)conduit;
                if (getRequestorType() == RequestorType.PROXY
                    && httpConduit.getProxyAuthorization() != null) {
                    String un = httpConduit.getProxyAuthorization().getUserName();
                    String pwd =  httpConduit.getProxyAuthorization().getPassword();
                    if (un != null && pwd != null) {
                        auth = new PasswordAuthentication(un, pwd.toCharArray());
                    }
                } else if (getRequestorType() == RequestorType.SERVER
                    && httpConduit.getAuthorization() != null) {
                   
                    if ("basic".equals(getRequestingScheme()) || "digest".equals(getRequestingScheme())) {
                        return null;
                    }
                   
                    String un = httpConduit.getAuthorization().getUserName();
                    String pwd =  httpConduit.getAuthorization().getPassword();
                    if (un != null && pwd != null) {
                        auth = new PasswordAuthentication(un, pwd.toCharArray());
                    }
                }
            }
        }
        // else PhaseInterceptorChain.getCurrentMessage() is null,
View Full Code Here

                    && !StringUtils.isEmpty(proxy.getPassword())) {
                    final String authUser = proxy.getUsername();
                    final String authPassword = proxy.getPassword();
                    Authenticator.setDefault(new Authenticator() {
                        public PasswordAuthentication getPasswordAuthentication() {
                            return new PasswordAuthentication(authUser, authPassword.toCharArray());
                        }
                    });

                    System.setProperty(HTTP_PROXY_USER, authUser);
                    System.setProperty(HTTP_PROXY_PORT, authPassword);
View Full Code Here

                prompt = challenge.substring(realm, end);
            }
        }
        // The following will use the user-defined authenticator to get
        // the password
        PasswordAuthentication pa = Authenticator
                .requestPasswordAuthentication(getHostAddress(), getHostPort(),
                        url.getProtocol(), prompt, scheme);
        if (pa == null) {
            // could not retrieve the credentials
            return null;
        }
        // base64 encode the username and password
        byte[] bytes = (pa.getUserName() + ":" + new String(pa.getPassword())) //$NON-NLS-1$
                .getBytes("ISO8859_1"); //$NON-NLS-1$
        String encoded = Base64.encode(bytes, "ISO8859_1"); //$NON-NLS-1$
        return scheme + " " + encoded; //$NON-NLS-1$
    }
View Full Code Here

    // Authentication test
    try {
      // set up a very simple authenticator
      Authenticator.setDefault(new Authenticator() {
        public PasswordAuthentication getPasswordAuthentication() {
          return new PasswordAuthentication("test", "password"
              .toCharArray());
        }
      });
      try {
        client.open(authTestUrl);
View Full Code Here

      catch (IOException ex) {
        System.out.println("Caught exception " + ex);
        System.exit(1);
      }

      return new PasswordAuthentication(username, password.toCharArray());
    }
View Full Code Here

public class ProxyAuthenticator extends Authenticator {

    private String userName, password;

    protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication(userName, password.toCharArray());
    }
View Full Code Here

     */
    private static final class ProxyAuth extends Authenticator {
        private PasswordAuthentication auth;

        private ProxyAuth(String user, String pass) {
            auth = new PasswordAuthentication(user, pass.toCharArray());
        }
View Full Code Here

TOP

Related Classes of java.net.PasswordAuthentication

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.