Package org.springframework.ldap.core

Examples of org.springframework.ldap.core.DirContextAdapter


    }

    @Test
    public void testMapUserToContext() throws Exception {
        User user = new UserImpl();
        DirContextAdapter adapter = new DirContextAdapter();

        contextMapper.mapUserToContext(user, adapter);

        assertTrue("Nothing happened", true);
    }
View Full Code Here


                public Object executeWithContext(DirContext ctx) throws NamingException {
                    Attributes attrs = ctx.getAttributes(dn, attributesToRetrieve);

                    // Object object = ctx.lookup(LdapUtils.getRelativeName(dn, ctx));

                    return new DirContextAdapter(attrs, new DistinguishedName(dn),
                            new DistinguishedName(ctx.getNameInNamespace()));
                }
            });
    }
View Full Code Here

        final HashSet<Map<String, List<String>>> set = new HashSet<Map<String, List<String>>>();

        ContextMapper roleMapper = new ContextMapper() {
            public Object mapFromContext(Object ctx) {
                DirContextAdapter adapter = (DirContextAdapter) ctx;
                Map<String, List<String>> record = new HashMap<String, List<String>>();
                if (attributeNames == null || attributeNames.length == 0) {
                    try {
                        for (NamingEnumeration ae = adapter.getAttributes().getAll(); ae.hasMore(); ) {
                            Attribute attr = (Attribute) ae.next();
                            extractStringAttributeValues(adapter, record, attr.getID());
                        }
                    } catch (NamingException x) {
                        org.springframework.ldap.support.LdapUtils.convertLdapException(x);
View Full Code Here

        Set<DirContextOperations> results = new HashSet<DirContextOperations>();
        try {
            while (resultsEnum.hasMore()) {
                SearchResult searchResult = resultsEnum.next();
                DirContextAdapter dca = (DirContextAdapter) searchResult.getObject();
                Assert.notNull(dca, "No object returned by search, DirContext is not correctly configured");

                if (logger.isDebugEnabled()) {
                    logger.debug("Found DN: " + dca.getDn());
                }
                results.add(dca);
            }
        } catch (PartialResultException e) {
            LdapUtils.closeEnumeration(resultsEnum);
View Full Code Here

    @Test
    public void successfulAuthenticationProducesExpectedAuthorities() throws Exception {
        DirContext ctx = mock(DirContext.class);
        when(ctx.getNameInNamespace()).thenReturn("");

        DirContextAdapter dca = new DirContextAdapter();
        SearchResult sr = new SearchResult("CN=Joe Jannsen,CN=Users", dca, dca.getAttributes());
        when(ctx.search(any(Name.class), any(String.class), any(Object[].class), any(SearchControls.class)))
                .thenReturn(new MockNamingEnumeration(sr))
                .thenReturn(new MockNamingEnumeration(sr));

        provider.contextFactory = createContextFactoryReturning(ctx);

        Authentication result = provider.authenticate(joe);

        assertEquals(0, result.getAuthorities().size());

        dca.addAttributeValue("memberOf","CN=Admin,CN=Users,DC=mydomain,DC=eu");

        result = provider.authenticate(joe);

        assertEquals(1, result.getAuthorities().size());
    }
View Full Code Here

    public void nullDomainIsSupportedIfAuthenticatingWithFullUserPrincipal() throws Exception {
        provider = new ActiveDirectoryLdapAuthenticationProvider(null, "ldap://192.168.1.200/");
        DirContext ctx = mock(DirContext.class);
        when(ctx.getNameInNamespace()).thenReturn("");

        DirContextAdapter dca = new DirContextAdapter();
        SearchResult sr = new SearchResult("CN=Joe Jannsen,CN=Users", dca, dca.getAttributes());
        when(ctx.search(eq(new DistinguishedName("DC=mydomain,DC=eu")), any(String.class), any(Object[].class), any(SearchControls.class)))
                .thenReturn(new MockNamingEnumeration(sr));
        provider.contextFactory = createContextFactoryReturning(ctx);

        try {
View Full Code Here

        DirContext ctx = mock(DirContext.class);
        when(ctx.getNameInNamespace()).thenReturn("");
        NamingEnumeration<SearchResult> searchResults = mock(NamingEnumeration.class);
        when(searchResults.hasMore()).thenReturn(true,true,false);
        SearchResult searchResult = mock(SearchResult.class);
        when(searchResult.getObject()).thenReturn(new DirContextAdapter("ou=1"),new DirContextAdapter("ou=2"));
        when(searchResults.next()).thenReturn(searchResult);
        when(ctx.search(any(Name.class), any(String.class), any(Object[].class), any(SearchControls.class)))
                .thenReturn(searchResults );

        provider.contextFactory = createContextFactoryReturning(ctx);
View Full Code Here

    //~ Inner Classes ==================================================================================================

    class MockAuthenticator implements LdapAuthenticator {

        public DirContextOperations authenticate(Authentication authentication) {
            DirContextAdapter ctx = new DirContextAdapter();
            ctx.setAttributeValue("ou", "FROM_ENTRY");
            String username = authentication.getName();
            String password = (String) authentication.getCredentials();


            if (username.equals("ben") && password.equals("benspassword")) {
                ctx.setDn(new DistinguishedName("cn=ben,ou=people,dc=springframework,dc=org"));
                ctx.setAttributeValue("userPassword","{SHA}nFCebWjxfaLbHHG1Qk5UU4trbvQ=");

                return ctx;
            } else if (username.equals("jen") && password.equals("")) {
                ctx.setDn(new DistinguishedName("cn=jen,ou=people,dc=springframework,dc=org"));

                return ctx;
            }

            throw new BadCredentialsException("Authentication failed.");
View Full Code Here

    public void searchForSingleEntryInternalAllowsReferrals() throws Exception {
        String base = "";
        String filter = "";
        String searchResultName = "ldap://example.com/dc=springframework,dc=org";
        Object[] params = new Object[] {};
        DirContextAdapter searchResultObject = mock(DirContextAdapter.class);

        when(ctx.search(any(DistinguishedName.class), eq(filter), eq(params), searchControls.capture())).thenReturn(resultsEnum);
        when(resultsEnum.hasMore()).thenReturn(true, false);
        when(resultsEnum.next()).thenReturn(searchResult);
        when(searchResult.getName()).thenReturn(searchResultName);
View Full Code Here

            logger.debug("Retrieving attributes...");

            Attributes attrs = ctx.getAttributes(userDn, getUserAttributes());

            DirContextAdapter result = new DirContextAdapter(attrs, userDn, ctxSource.getBaseLdapPath());

            if (ppolicy != null) {
                result.setAttributeValue(ppolicy.getID(), ppolicy);
            }

            return result;
        } catch (NamingException e) {
            // This will be thrown if an invalid user name is used and the method may
View Full Code Here

TOP

Related Classes of org.springframework.ldap.core.DirContextAdapter

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.