Package org.apache.jackrabbit.oak.api

Examples of org.apache.jackrabbit.oak.api.ContentSession


    @Test
    public void testSyncCreateUserAndGroups() throws Exception {

        options.put(ExternalLoginModule.PARAM_SYNC_MODE, new String[]{SyncMode.CREATE_USER, SyncMode.CREATE_GROUP});

        ContentSession cs = null;
        try {
            cs = login(new SimpleCredentials(USER_ID, USER_PWD.toCharArray()));

            root.refresh();
            Authorizable user = userManager.getAuthorizable(USER_ID);
            assertNotNull(user);
            assertTrue(user.hasProperty(USER_PROP));
            Authorizable group = userManager.getAuthorizable(GROUP_DN);
            assertTrue(group.hasProperty(GROUP_PROP));
            assertNotNull(group);
        } finally {
            if (cs != null) {
                cs.close();
            }
            options.clear();
        }
    }
View Full Code Here


    @Test
    public void testNoSync() throws Exception {

        options.put(ExternalLoginModule.PARAM_SYNC_MODE, "");

        ContentSession cs = null;
        try {
            cs = login(new SimpleCredentials(USER_ID, USER_PWD.toCharArray()));

            root.refresh();
            assertNull(userManager.getAuthorizable(USER_ID));
            assertNull(userManager.getAuthorizable(GROUP_DN));
        } finally {
            if (cs != null) {
                cs.close();
            }
            options.clear();
        }
    }
View Full Code Here

        // create user upfront in order to test update mode
        userManager.createUser(USER_ID, null);
        root.commit();

        ContentSession cs = null;
        try {
            cs = login(new SimpleCredentials(USER_ID, USER_PWD.toCharArray()));

            root.refresh();
            Authorizable user = userManager.getAuthorizable(USER_ID);
            assertNotNull(user);
            assertTrue(user.hasProperty(USER_PROP));
            Authorizable group = userManager.getAuthorizable(GROUP_DN);
            assertTrue(group.hasProperty(GROUP_PROP));
            assertNotNull(group);
        } finally {
            if (cs != null) {
                cs.close();
            }
            options.clear();
        }
    }
View Full Code Here

        // create user upfront in order to test update mode
        userManager.createUser(USER_ID, null);
        root.commit();

        ContentSession cs = null;
        try {
            cs = login(new SimpleCredentials(USER_ID, USER_PWD.toCharArray()));

            root.refresh();
            Authorizable user = userManager.getAuthorizable(USER_ID);
            assertNotNull(user);
            assertTrue(user.hasProperty(USER_PROP));
            assertNull(userManager.getAuthorizable(GROUP_DN));
        } finally {
            if (cs != null) {
                cs.close();
            }
            options.clear();
        }
    }
View Full Code Here

        // create user upfront in order to test update mode
        userManager.createUser(USER_ID, null);
        root.commit();

        ContentSession cs = null;
        try {
            cs = login(new SimpleCredentials(USER_ID, USER_PWD.toCharArray()));

            root.refresh();
            Authorizable user = userManager.getAuthorizable(USER_ID);
            assertNotNull(user);
            assertTrue(user.hasProperty(USER_PROP));
            Authorizable group = userManager.getAuthorizable(GROUP_DN);
            assertTrue(group.hasProperty(GROUP_PROP));
            assertNotNull(group);
        } finally {
            if (cs != null) {
                cs.close();
            }
            options.clear();
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testLoginSetsAuthInfo() throws Exception {
        ContentSession cs = null;
        try {
            SimpleCredentials sc = new SimpleCredentials(USER_ID, USER_PWD.toCharArray());
            sc.setAttribute("attr", "val");

            cs = login(sc);
            AuthInfo ai = cs.getAuthInfo();

            assertEquals(USER_ID, ai.getUserID());
            assertEquals("val", ai.getAttribute("attr"));
        } finally {
            if (cs != null) {
                cs.close();
            }
        }
    }
View Full Code Here

    @Test
    public void testPrincipalsFromAuthInfo() throws Exception {
        options.put(ExternalLoginModule.PARAM_SYNC_MODE, SyncMode.CREATE_USER);

        ContentSession cs = null;
        try {
            SimpleCredentials sc = new SimpleCredentials(USER_ID, USER_PWD.toCharArray());
            sc.setAttribute("attr", "val");

            cs = login(sc);
            AuthInfo ai = cs.getAuthInfo();

            root.refresh();
            PrincipalProvider pp = getSecurityProvider().getConfiguration(PrincipalConfiguration.class).getPrincipalProvider(root, NamePathMapper.DEFAULT);
            Set<? extends Principal> expected = pp.getPrincipals(USER_ID);
            assertEquals(2, expected.size());
            assertEquals(expected, ai.getPrincipals());

        } finally {
            if (cs != null) {
                cs.close();
            }
        }
    }
View Full Code Here

    @Test
    public void testPrincipalsFromAuthInfo2() throws Exception {
        options.put(ExternalLoginModule.PARAM_SYNC_MODE, new String[]{SyncMode.CREATE_USER, SyncMode.CREATE_GROUP});

        ContentSession cs = null;
        try {
            SimpleCredentials sc = new SimpleCredentials(USER_ID, USER_PWD.toCharArray());
            sc.setAttribute("attr", "val");

            cs = login(sc);
            AuthInfo ai = cs.getAuthInfo();

            root.refresh();
            PrincipalProvider pp = getSecurityProvider().getConfiguration(PrincipalConfiguration.class).getPrincipalProvider(root, NamePathMapper.DEFAULT);
            Set<? extends Principal> expected = pp.getPrincipals(USER_ID);
            assertEquals(3, expected.size());
            assertEquals(expected, ai.getPrincipals());

        } finally {
            if (cs != null) {
                cs.close();
            }
        }
    }
View Full Code Here

    @Test
    public void testReLogin() throws Exception {
        options.put(ExternalLoginModule.PARAM_SYNC_MODE, SyncMode.CREATE_USER);

        ContentSession cs = null;
        try {
            cs = login(new SimpleCredentials(USER_ID, USER_PWD.toCharArray()));

            root.refresh();
            Authorizable user = userManager.getAuthorizable(USER_ID);
            assertNotNull(user);
            assertFalse(root.getTree(user.getPath()).hasProperty(UserConstants.REP_PASSWORD));

            cs.close();
            // login again
            cs = login(new SimpleCredentials(USER_ID, USER_PWD.toCharArray()));
            assertEquals(USER_ID, cs.getAuthInfo().getUserID());
        } finally {
            if (cs != null) {
                cs.close();
            }
            options.clear();
        }
    }
View Full Code Here

        };
    }

    @Test
    public void testNullLogin() throws Exception {
        ContentSession cs = null;
        try {
            cs = login(null);
            fail("Null login should fail");
        } catch (LoginException e) {
            // success
        } finally {
            if (cs != null) {
                cs.close();
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.oak.api.ContentSession

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.