Package org.apache.harmony.auth.module

Examples of org.apache.harmony.auth.module.KeyStoreLoginModule


            + Support_Resources.getAbsoluteResourcePath("fault_pass");

    private final String KEYSTORE_ALIAS = "mykey";

    public void test_abort() throws LoginException {
        KeyStoreLoginModule ksm = new KeyStoreLoginModule();
        try {
            assertFalse("Should return false if login failed or no login", ksm
                    .abort());
        } catch (LoginException e) {
            fail("Abort failed");
        }
        Subject subject = new Subject();
        subject.setReadOnly();
        ksm.initialize(subject, null, null, options);
        try {
            assertFalse("Should return false if login failed or no login", ksm
                    .abort());
        } catch (Exception e) {
            fail("Not any exception here");
        }
        options.remove("keyStorePasswordURL");
        options.put("keyStorePasswordURL", KEYSTORE_FAULTPASSWORD_URL);
        subject = new Subject();
        ksm.initialize(subject, null, null, options);
        try {
            ksm.login();
            fail("login should fail");
        } catch (LoginException e) {
            assertFalse("Should return false because of login failure", ksm
                    .abort());
        }
        options.remove("keyStorePasswordURL");
        options.put("keyStorePasswordURL", KEYSTORE_PASSWORD_URL);
        subject = new Subject();
        ksm.initialize(subject, null, null, options);
        ksm.login();
        assertTrue("Should return true if login was successful", ksm
                .abort());
    }
View Full Code Here


        assertTrue("Should return true if login was successful", ksm
                .abort());
    }

    public void test_commit() {
        KeyStoreLoginModule module = new KeyStoreLoginModule();
        Subject subject = new Subject();
        module.initialize(subject, null, null, options);
        try {
            assertTrue("Login should be successful", module.login());
            module.commit();
        } catch (LoginException e) {
            e.printStackTrace();
            fail("Login shouldn't fail");
        }
        Set<Principal> principals = subject.getPrincipals();
        assertFalse("Should get at least one principal", principals.isEmpty());
        Set<Object> subjects = subject.getPrivateCredentials();
        assertFalse("Should get at least one private credential", subjects
                .isEmpty());
        Set<Object> subjects2 = subject.getPublicCredentials();
        assertFalse("Should get at least one public credential", subjects2
                .isEmpty());
        subject = new Subject();
        subject.setReadOnly();
        module.initialize(subject, null, null, options);
        try {
            assertFalse("Commit shouldn't be successful", module.commit());
            fail("Should throw LoginException here because of trying to clear read-only subject");
        } catch (LoginException e) {
            // expected LoginException here
        }
View Full Code Here

        }

    }

    public void test_initialize() {
        KeyStoreLoginModule module = new KeyStoreLoginModule();
        try {
            module.initialize(null, null, null, null);
            fail("Should throw NullPointerException here.");
        } catch (NullPointerException e) {
            // expected NullPointerException
        }
    }
View Full Code Here

            // expected NullPointerException
        }
    }

    public void test_login() {
        KeyStoreLoginModule module = new KeyStoreLoginModule();
        HashMap<String, String> emptyOptions = new HashMap<String, String>();
        module.initialize(null, null, null, emptyOptions);
        try {
            module.login();
            fail("Should throw LoginException here.");
        } catch (LoginException e) {
            // expected LoginException
        }

        Subject subject = new Subject();
        module.initialize(subject, null, null, options);
        try {
            assertTrue("Login should be successful", module.login());
        } catch (LoginException e) {
            fail("Login shouldn't fail");
        }
        options.put("keyStorePasswordURL", KEYSTORE_FAULTPASSWORD_URL);
        module.initialize(subject, null, null, options);
        try {
            assertFalse("Login shouldn't be successful", module.login());
            fail("Login should fail");
        } catch (LoginException e) {
            // expected Loginexception here
        }
    }
View Full Code Here

            // expected Loginexception here
        }
    }

    public void test_logout() {
        KeyStoreLoginModule module = new KeyStoreLoginModule();
        Subject subject = new Subject();
        module.initialize(subject, null, null, options);
        try {
            assertTrue("Login should be successful", module.login());
            module.commit();
        } catch (LoginException e) {
            fail("Login shouldn't fail");
        }
        Set<Principal> principals = subject.getPrincipals();
        assertFalse("Should get at least one principal", principals.isEmpty());
        Set<Object> subjects = subject.getPrivateCredentials();
        assertFalse("Should get at least one private credential", subjects
                .isEmpty());
        Set<Object> subjects2 = subject.getPublicCredentials();
        assertFalse("Should get at least one public credential", subjects2
                .isEmpty());
        try {
            assertTrue("Should be true", module.logout());
        } catch (LoginException e) {
            fail("Logout failed");
        }
        principals = subject.getPrincipals();
        assertTrue("Principals should be cleared", principals.isEmpty());
View Full Code Here

            + Support_Resources.getAbsoluteResourcePath("fault_pass");

    private final String KEYSTORE_ALIAS = "mykey";

    public void test_abort() throws LoginException {
        KeyStoreLoginModule ksm = new KeyStoreLoginModule();
        try {
            assertFalse("Should return false if login failed or no login", ksm
                    .abort());
        } catch (LoginException e) {
            fail("Abort failed");
        }
        Subject subject = new Subject();
        subject.setReadOnly();
        ksm.initialize(subject, null, null, options);

        assertFalse("Should return false if login failed or no login", ksm.abort());

        options.remove("keyStorePasswordURL");
        options.put("keyStorePasswordURL", KEYSTORE_FAULTPASSWORD_URL);
        subject = new Subject();
        ksm.initialize(subject, null, null, options);
        try {
            ksm.login();
            fail("login should fail");
        } catch (LoginException e) {
            assertFalse("Should return false because of login failure", ksm
                    .abort());
        }
        options.remove("keyStorePasswordURL");
        options.put("keyStorePasswordURL", KEYSTORE_PASSWORD_URL);
        subject = new Subject();
        ksm.initialize(subject, null, null, options);
        ksm.login();
        assertTrue("Should return true if login was successful", ksm
                .abort());
    }
View Full Code Here

        assertTrue("Should return true if login was successful", ksm
                .abort());
    }

    public void test_commit() {
        KeyStoreLoginModule module = new KeyStoreLoginModule();
        Subject subject = new Subject();
        module.initialize(subject, null, null, options);
        try {
            assertTrue("Login should be successful", module.login());
            module.commit();
        } catch (LoginException e) {
            e.printStackTrace();
            fail("Login shouldn't fail");
        }
        Set<Principal> principals = subject.getPrincipals();
        assertFalse("Should get at least one principal", principals.isEmpty());
        Set<Object> subjects = subject.getPrivateCredentials();
        assertFalse("Should get at least one private credential", subjects
                .isEmpty());
        Set<Object> subjects2 = subject.getPublicCredentials();
        assertFalse("Should get at least one public credential", subjects2
                .isEmpty());
        subject = new Subject();
        subject.setReadOnly();
        module.initialize(subject, null, null, options);
        try {
            assertFalse("Commit shouldn't be successful", module.commit());
            fail("Should throw LoginException here because of trying to clear read-only subject");
        } catch (LoginException e) {
            // expected LoginException here
        }
View Full Code Here

        }

    }

    public void test_initialize() {
        KeyStoreLoginModule module = new KeyStoreLoginModule();
        try {
            module.initialize(null, null, null, null);
            fail("Should throw NullPointerException here.");
        } catch (NullPointerException e) {
            // expected NullPointerException
        }
    }
View Full Code Here

            // expected NullPointerException
        }
    }

    public void test_login() {
        KeyStoreLoginModule module = new KeyStoreLoginModule();
        HashMap<String, String> emptyOptions = new HashMap<String, String>();
        module.initialize(null, null, null, emptyOptions);
        try {
            module.login();
            fail("Should throw LoginException here.");
        } catch (LoginException e) {
            // expected LoginException
        }

        Subject subject = new Subject();
        module.initialize(subject, null, null, options);
        try {
            assertTrue("Login should be successful", module.login());
        } catch (LoginException e) {
            fail("Login shouldn't fail");
        }
        options.put("keyStorePasswordURL", KEYSTORE_FAULTPASSWORD_URL);
        module.initialize(subject, null, null, options);
        try {
            assertFalse("Login shouldn't be successful", module.login());
            fail("Login should fail");
        } catch (LoginException e) {
            // expected Loginexception here
        }
    }
View Full Code Here

            // expected Loginexception here
        }
    }

    public void test_logout() {
        KeyStoreLoginModule module = new KeyStoreLoginModule();
        Subject subject = new Subject();
        module.initialize(subject, null, null, options);
        try {
            assertTrue("Login should be successful", module.login());
            module.commit();
        } catch (LoginException e) {
            fail("Login shouldn't fail");
        }
        Set<Principal> principals = subject.getPrincipals();
        assertFalse("Should get at least one principal", principals.isEmpty());
        Set<Object> subjects = subject.getPrivateCredentials();
        assertFalse("Should get at least one private credential", subjects
                .isEmpty());
        Set<Object> subjects2 = subject.getPublicCredentials();
        assertFalse("Should get at least one public credential", subjects2
                .isEmpty());
        try {
            assertTrue("Should be true", module.logout());
        } catch (LoginException e) {
            fail("Logout failed");
        }
        principals = subject.getPrincipals();
        assertTrue("Principals should be cleared", principals.isEmpty());
View Full Code Here

TOP

Related Classes of org.apache.harmony.auth.module.KeyStoreLoginModule

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.