Package java.net

Examples of java.net.Authenticator


    @Test
    public void runCleanupTestStrongRef() throws Exception {
        final List<Integer> traceLengths = new ArrayList<Integer>();
       
        //create a chain of CXFAuthenticators, strongly referenced to prevent cleanups
        Authenticator.setDefault(new Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                traceLengths.add(Thread.currentThread().getStackTrace().length);
                return super.getPasswordAuthentication();
            }
        });
View Full Code Here


    @Test
    public void runCleanupTestWeakRef() throws Exception {
        InetAddress add = InetAddress.getLocalHost();
        final List<Integer> traceLengths = new ArrayList<Integer>();
        //create a chain of CXFAuthenticators, strongly referenced to prevent cleanups
        Authenticator.setDefault(new Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                traceLengths.add(Thread.currentThread().getStackTrace().length);
                return super.getPasswordAuthentication();
            }
        });
View Full Code Here

    }
   
    public static synchronized void addAuthenticator() {
        if (instance == null) {
            instance = new CXFAuthenticator();
            Authenticator wrapped = null;
            for (final Field f : Authenticator.class.getDeclaredFields()) {
                if (f.getType().equals(Authenticator.class)) {
                    ReflectionUtil.setAccessible(f);
                    try {
                        wrapped = (Authenticator)f.get(null);
                        if (wrapped != null
                            && wrapped.getClass().getName().equals(ReferencingAuthenticator.class.getName())) {
                            Method m = wrapped.getClass().getMethod("check");
                            m.setAccessible(true);
                            m.invoke(wrapped);
                        }
                        wrapped = (Authenticator)f.get(null);
                    } catch (Exception e) {
                        //ignore
                    }
                }
            }
           
            try {
                ClassLoader loader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
                        public ClassLoader run() {
                            return new URLClassLoader(new URL[0], ClassLoader.getSystemClassLoader());
                        }
                    }, null);
               
               
                Method m = ClassLoader.class.getDeclaredMethod("defineClass", String.class,
                                                               byte[].class, Integer.TYPE, Integer.TYPE);
               
                InputStream ins = ReferencingAuthenticator.class
                        .getResourceAsStream("ReferencingAuthenticator.class");
                byte b[] = IOUtils.readBytesFromStream(ins);
               
                ReflectionUtil.setAccessible(m).invoke(loader, ReferencingAuthenticator.class.getName(),
                                                       b, 0, b.length);
                Class<?> cls = loader.loadClass(ReferencingAuthenticator.class.getName());
                final Authenticator auth = (Authenticator)cls.getConstructor(Authenticator.class, Authenticator.class)
                    .newInstance(instance, wrapped);
               
                if (System.getSecurityManager() == null) {
                    Authenticator.setDefault(auth);
                } else {
View Full Code Here

        this.wrapped = wrapped;
    }

    @Override
    protected PasswordAuthentication getPasswordAuthentication() {
        Authenticator cxfauth = auth.get();
        if (cxfauth == null) {
            remove();
        }
        PasswordAuthentication pauth = null;
        if (wrapped != null) {
View Full Code Here

        }
        return pauth;
    }
   
    public final void check() {
        Authenticator cxfauth = auth.get();
        if (cxfauth == null) {
            remove();
        }
        if (wrapped != null && wrapped.getClass().getName().equals(ReferencingAuthenticator.class.getName())) {
            try {
View Full Code Here

        try {
            for (final Field f : Authenticator.class.getDeclaredFields()) {
                if (f.getType().equals(Authenticator.class)) {
                    try {
                        f.setAccessible(true);
                        Authenticator o = (Authenticator)f.get(null);
                        if (o == this) {
                            //this is at the root of any chain of authenticators
                            Authenticator.setDefault(wrapped);
                        } else {
                            removeFromChain(o);
View Full Code Here

        try {
            if (a.getClass().getName().equals(ReferencingAuthenticator.class.getName())) {
                //multiple referencing authenticators, we can remove ourself
                Field f2 = a.getClass().getDeclaredField("wrapped");
                f2.setAccessible(true);
                Authenticator a2 = (Authenticator)f2.get(a);
                if (a2 == this) {
                    f2.set(a, wrapped);
                } else {
                    removeFromChain(a2);
                }
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());
            }
View Full Code Here

    final String authTestUrl = "http://localhost:" + server.getPort()
        + Support_HttpServer.AUTHTEST;

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

    private void connect(Map<String, String> sessionParameters) {
        this.sessionParameters = sessionParameters;

        // set a new dummy authenticator
        // don't send previous credentials to another server
        Authenticator.setDefault(new Authenticator() {
        });

        if (Boolean.parseBoolean(sessionParameters.get(ACCEPT_SELF_SIGNED_CERTIFICATES))) {
            acceptSelfSignedCertificates();
        }
View Full Code Here

TOP

Related Classes of java.net.Authenticator

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.