Package org.springframework.ldap.core

Examples of org.springframework.ldap.core.DistinguishedName


     */
    public DirContextOperations searchForSingleEntry(final String base, final String filter, final Object[] params) {

        return (DirContextOperations) executeReadOnly(new ContextExecutor() {
                public Object executeWithContext(DirContext ctx) throws NamingException {
                    DistinguishedName ctxBaseDn = new DistinguishedName(ctx.getNameInNamespace());
                    NamingEnumeration<SearchResult> resultsEnum = ctx.search(base, filter, params, searchControls);
                    Set<DirContextOperations> results = new HashSet<DirContextOperations>();
                    try {
                        while (resultsEnum.hasMore()) {

                            SearchResult searchResult = resultsEnum.next();
                            // Work out the DN of the matched entry
                            StringBuilder dn = new StringBuilder(searchResult.getName());

                            if (base.length() > 0) {
                                dn.append(",");
                                dn.append(base);
                            }

                            results.add(new DirContextAdapter(searchResult.getAttributes(),
                                    new DistinguishedName(dn.toString()), ctxBaseDn));
                        }
                    } catch (PartialResultException e) {
                        logger.info("Ignoring PartialResultException");
                    }

View Full Code Here


        return user;
    }

    private DirContextOperations bindWithDn(String userDn, String username, String password) {
        BaseLdapPathContextSource ctxSource = (BaseLdapPathContextSource) getContextSource();
        DistinguishedName fullDn = new DistinguishedName(userDn);
        fullDn.prepend(ctxSource.getBaseLdapPath());

        logger.debug("Attempting to bind as " + fullDn);

        DirContext ctx = null;
        try {
            ctx = getContextSource().getContext(fullDn.toString(), password);
            // Check for password policy control
            PasswordPolicyControl ppolicy = PasswordPolicyControlExtractor.extractControl(ctx);

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

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

            if (ppolicy != null) {
                result.setAttributeValue(ppolicy.getID(), ppolicy);
            }
View Full Code Here

        if (baseDn.length() == 0) {
            return fullDn;
        }

        DistinguishedName base = new DistinguishedName(baseDn);
        DistinguishedName full = new DistinguishedName(fullDn);

        if(base.equals(full)) {
            return "";
        }

        Assert.isTrue(full.startsWith(base), "Full DN does not start with base DN");

        full.removeFirst(base);

        return full.toString();
    }
View Full Code Here

     * Gets the full dn of a name by prepending the name of the context it is relative to.
     * If the name already contains the base name, it is returned unaltered.
     */
    public static DistinguishedName getFullDn(DistinguishedName dn, Context baseCtx)
            throws NamingException {
        DistinguishedName baseDn = new DistinguishedName(baseCtx.getNameInNamespace());

        if(dn.contains(baseDn)) {
            return dn;
        }

        baseDn.append(dn);

        return baseDn;
    }
View Full Code Here

    /**
     * Assembles the Distinguished Name that should be used the given username.
     */
    public DistinguishedName buildDn(String username) {
        DistinguishedName dn = new DistinguishedName(userDnBase);

        dn.add(usernameAttribute, username);

        return dn;
    }
View Full Code Here

    //must set these as part of the Person creation assertions
    p.setSn(user.getFullName().split(" ")[1]);
    p.setCn(new String[]{user.getFullName()});

    DistinguishedName newDn = new DistinguishedName();
    newDn.add("ou", "Users");
    newDn.add("cn", user.getFullName());
    p.setDn(newDn);

    return p.createUserDetails();
  }
View Full Code Here

     * Test.
     */
    @Test
    public void test()
    {
        DistinguishedName dn = new DistinguishedName();
        LdapGroup sut = new LdapGroup(dn);
        ArrayList<String> source = new ArrayList<String>(Arrays.asList("blah"));
        sut.setSourceList(source);

        assertEquals(dn, sut.getDistinguishedName());
View Full Code Here

        DirContextAdapter dir = (DirContextAdapter) inCtx;
       
        //This is the callback for the PagedLdapSearch, getNameInNamespace returns the fully qualified
        //dn for the result.  This is preferred over getDn which just returns the relative dn without
        //the base path if it was supplied by the ldaptemplate during search.
        return new LdapGroup(new DistinguishedName(dir.getNameInNamespace()));
    }
View Full Code Here

            attrValue = toEntity.getId();
        }
        Attribute relationAttribute = fromEntity.getAttribute(this.relationAttribute);
        if (relationAttribute.getDefinition().isMultiValue())
        {
            DistinguishedName attrib = new DistinguishedName(attrValue);
            if (attributeContainsInternalId)
            {
                boolean found = false;
                String attribValue = null;
                Iterator<String> iterator = relationAttribute.getValues().iterator();
                while(iterator.hasNext() && !found)
                {
                    attribValue = iterator.next();
                    DistinguishedName ldapAttr = new DistinguishedName(attribValue);
                    if (ldapAttr.equals(attrib))
                    {
                        relationAttribute.getValues().remove(attribValue);
                        found = true;
                    }
                }
View Full Code Here

   
    public SpringLDAPEntityDAO(LDAPEntityDAOConfiguration configuration)
    {
        super();
        this.configuration = configuration;
        searchDN = new DistinguishedName(getConfiguration().getSearchDN());
        this.entityFactory = new EntityFactoryImpl(configuration);
        this.contextMapper = new DefaultEntityContextMapper(entityFactory);
    }
View Full Code Here

TOP

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

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.