CPD Results

The following document contains the results of PMD's CPD 4.3.

Duplications

File Line
pt/digitalis/utils/ldap/impl/AbstractLDAPUtils.java 3126
pt/digitalis/utils/ldap/impl/openldap/LDAPUtilsOpenLDAPImpl.java 273
                        getUserLoginAttributeName(), userToUpdate.getLoginName())));

            // '"mainGroup"'
            if (userToUpdate.getParentGroupDN() != null
                    && !userToUpdate.getParentGroupDN().equals(existingUser.getParentGroupDN()))
                items.add(new ModificationItem(LdapContext.REPLACE_ATTRIBUTE, new BasicAttribute(
                        getUserParentGroupAttributeName(), userToUpdate.getParentGroupDN())));

            // Parameters
            Map<String, String> bulkParameters = new HashMap<String, String>();
            for (String parameterName: userToUpdate.getParameters().keySet())
            {
                if (getConfigurations().getAttributesMapping().containsKey(parameterName))
                {
                    items.add(new ModificationItem(LdapContext.REPLACE_ATTRIBUTE, new BasicAttribute(
                            getConfigurations().getAttributesMapping().get(parameterName), userToUpdate
                                    .getParameter(parameterName))));
                }
                else
                {
                    if (existingUser.getParameter(parameterName) != null)
                    {
                        if (!getUnchangeableLDAPAttributes().contains(parameterName.toUpperCase())
                                && !userToUpdate.getParameter(parameterName).equalsIgnoreCase(
                                        existingUser.getParameter(parameterName)))
                            items.add(new ModificationItem(LdapContext.REPLACE_ATTRIBUTE, new BasicAttribute(
                                    parameterName, userToUpdate.getParameter(parameterName))));
                    }
                    else
                    {
                        bulkParameters.put(parameterName, userToUpdate.getParameter(parameterName));
                    }
                }
            }

            for (String parameterName: userToUpdate.getParametersToRemove())
            {
                if (getConfigurations().getAttributesMapping().containsKey(parameterName))
                {
                    items.add(new ModificationItem(LdapContext.REMOVE_ATTRIBUTE, new BasicAttribute(getConfigurations()
                            .getAttributesMapping().get(parameterName))));
                }
                else
                {
                    bulkParameters.remove(parameterName);
                }
            }

            // The value of the Bulk parameters to commit
            StringBuilder bulkParameterAttributeValue = new StringBuilder();
            for (Entry<String, String> entry: bulkParameters.entrySet())
            {
                bulkParameterAttributeValue.append(entry.getKey() + "=" + entry.getValue() + ";");
            }

            if (bulkParameterAttributeValue.length() == 0)
            {
                /* LDAP doesn't like empty strings on REPLACE_ATTRIBUTE */
                bulkParameterAttributeValue.append(" ");
            }

            items.add(new ModificationItem(LdapContext.REPLACE_ATTRIBUTE, new BasicAttribute(getConfigurations()
                    .getBulkParametersAttributeName(), bulkParameterAttributeValue.toString())));

            // Persist changes
            if (items.size() > 0)
            {
                ModificationItem mods[] = new ModificationItem[items.size()];
                for (int i = 0; i < items.size(); i++)
                {
                    mods[i] = items.get(i);
                }

                modifyAttributes(existingUser.getDistinguishedName(), mods, false);
            }

            /* Group modification must be made after all other attributes since it can cause DN changes. */
            // Main group
            if (ldapConfigurations.getAllowDistinguishedNameModifications() && userToUpdate.getParentGroupDN() != null
                    && !userToUpdate.getParentGroupDN().equals(existingUser.getParentGroupDN()))
File Line
pt/digitalis/utils/ldap/impl/AbstractLDAPUtils.java 3086
pt/digitalis/utils/ldap/impl/openldap/LDAPUtilsOpenLDAPImpl.java 237
    public void updateUser(LDAPUser userToUpdate, String userLogin) throws LDAPOperationException
    {
        if (this.isReadOnly())
            throw new LDAPOperationReadOnlyException();

        // Retrieve old user data to get the old data
        LDAPUser existingUser = findUserByLogin(userLogin, false);

        if (existingUser != null)
        {
            ArrayList<ModificationItem> items = new ArrayList<ModificationItem>();

            // 'displayName'
            if (userToUpdate.getDisplayName() != null
                    && !userToUpdate.getDisplayName().equalsIgnoreCase(existingUser.getDisplayName()))
            {
                items.add(new ModificationItem(LdapContext.REPLACE_ATTRIBUTE, new BasicAttribute(
                        getDisplayNameAttributeName(), userToUpdate.getDisplayName())));
            }

            // 'e-mail'
            if (userToUpdate.getEmail() != null && !userToUpdate.getEmail().equals(existingUser.getEmail()))
                items.add(new ModificationItem(LdapContext.REPLACE_ATTRIBUTE, new BasicAttribute(
                        getMailAttributeName(), userToUpdate.getEmail())));
            // 'givenName'
            if (userToUpdate.getGivenName() != null && !userToUpdate.getGivenName().equals(existingUser.getGivenName()))
                items.add(new ModificationItem(LdapContext.REPLACE_ATTRIBUTE, new BasicAttribute(
                        getGivenNameAttributeName(), userToUpdate.getGivenName())));

            /*
             * Password change method is implementation dependent so it's not done through ModificationItem. Password
             * does not come from LDAP server, so it's ALWAYS changed!!! Done before login change to assure that the
             * former login name still works.
             */
            if (userToUpdate.getPassword() != null)
                changePassword(userLogin, userToUpdate.getPassword());

            // '"login"'
            if (userToUpdate.getLoginName() != null && !userToUpdate.getLoginName().equals(existingUser.getLoginName()))
File Line
pt/digitalis/utils/ldap/impl/AbstractLDAPUtils.java 1689
pt/digitalis/utils/ldap/impl/AbstractLDAPUtils.java 1752
                    .getBaseSearchDN(), query.toString());

            for (SearchResult searchResult: returnedUsers)
            {
                LDAPUser user = convertFromSearchResultToLDAPUser(searchResult);

                if (searchResult != null && (searchResult.getObject() instanceof Context))
                {
                    ((Context) searchResult.getObject()).close();
                }

                users.add(user);

            }
        }
        catch (NamingException namingException)
        {
            throw new LDAPOperationException("Could not get users using query " + query.toString(), namingException);
        }
        catch (IOException e)
        {
            throw new LDAPOperationException("Could not get users using query " + query.toString(), e);
        }
        finally
        {
            try
            {
                context.close();
            }
            catch (NamingException e)
            {
                throw new LDAPOperationException("Error closing context!", e);
            }
        }

        return users;
    }

    /**
     * @see pt.digitalis.utils.ldap.ILDAPUtils#findUsersByAttributes(java.util.Map, int, int)
     */
    public Set<LDAPUser> findUsersByAttributes(Map<String, String> attributes, int rowsPerPage, int pageToReturn)
File Line
pt/digitalis/utils/ldap/impl/ad/LDAPUtilsActiveDirectoryImpl.java 82
pt/digitalis/utils/ldap/impl/openldap/LDAPUtilsOpenLDAPImpl.java 53
    @Override
    protected String calculateDistinguishedName(String commonName, String mainGroupDN) throws LDAPOperationException
    {

        if (commonName == null)
            throw new LDAPOperationException(
                    "The supplied CN was null! Cannot calculate the entity's DN without a valid CN...");
        if (mainGroupDN == null)
        {
            throw new LDAPOperationException(
                    "The supplied parent group name was null!! Cannot calculate the entity's DN without a valid parent group name...");
        }

        // Create user CN part
        StringBuffer newDistinguishedName = new StringBuffer(AbstractLDAPUtils.CN_TAG + commonName);

        // Get group DN
        StringBuffer groupDistinguishedName = new StringBuffer(mainGroupDN);

        // Discard group's CN
        groupDistinguishedName.trimToSize();
        groupDistinguishedName.replace(0, groupDistinguishedName.capacity(),
                groupDistinguishedName.substring(groupDistinguishedName.indexOf(",")));

        // Append the group's DN to user's DN
        newDistinguishedName.append(groupDistinguishedName);

        // Return result
        return newDistinguishedName.toString();
    }

    /**
     * @see pt.digitalis.utils.ldap.ILDAPUtils#changePassword(java.lang.String, java.lang.String)
     */
    @Override
    public void changePassword(String loginName, String newPassword) throws LDAPOperationException
    {
        if (this.isReadOnly())
            throw new LDAPOperationReadOnlyException();
File Line
pt/digitalis/utils/ldap/impl/AbstractLDAPUtils.java 1206
pt/digitalis/utils/ldap/impl/AbstractLDAPUtils.java 1341
                    .getBaseSearchDN(), search);

            for (SearchResult searchResult: returnedGroups)
            {
                LDAPGroup group = convertFromSearchResultToLDAPGroup(searchResult);

                if (searchResult != null && (searchResult.getObject() instanceof Context))
                {
                    ((Context) searchResult.getObject()).close();
                }

                groups.add(group);
            }

        }
        catch (NamingException namingException)
        {
            throw new LDAPOperationException("Could not get all groups!", namingException);
        }
        catch (IOException e)
        {
            throw new LDAPOperationException("Could not get all groups!", e);
        }
        finally
        {
            try
            {
                context.close();
            }
            catch (NamingException e)
            {
                throw new LDAPOperationException("Error closing context!", e);
            }
        }
        return groups;

    }

    /**
     * @see pt.digitalis.utils.ldap.ILDAPUtils#findAllUsers()
     */
    public Set<LDAPUser> findAllUsers() throws LDAPOperationException
File Line
pt/digitalis/utils/ldap/impl/AbstractLDAPUtils.java 1259
pt/digitalis/utils/ldap/impl/AbstractLDAPUtils.java 1578
                    .getBaseSearchDN(), search);

            for (SearchResult searchResult: returnedUsers)
            {
                LDAPUser user = convertFromSearchResultToLDAPUser(searchResult);

                if (searchResult != null && (searchResult.getObject() instanceof Context))
                {
                    ((Context) searchResult.getObject()).close();
                }

                users.add(user);
            }
        }
        catch (NamingException namingException)
        {
            throw new LDAPOperationException("Could not get all users!", namingException);
        }
        catch (IOException e)
        {
            throw new LDAPOperationException("Could not get all users!", e);
        }
        finally
        {
            try
            {
                context.close();
            }
            catch (NamingException e)
            {
                throw new LDAPOperationException("Error closing context!", e);
            }
        }
        return users;
    }

    /**
     * @see pt.digitalis.utils.ldap.ILDAPUtils#findGroupByCommonName(java.lang.String)
     */
    public LDAPGroup findGroupByCommonName(String cn) throws LDAPOperationException
File Line
pt/digitalis/utils/ldap/impl/AbstractLDAPUtils.java 780
pt/digitalis/utils/ldap/impl/AbstractLDAPUtils.java 1735
        StringBuffer query = new StringBuffer("(&" + "(" + getObjectClassName() + "=" + getUserClassName() + ")");
        for (String attributeKey: attributes.keySet())
        {
            String attributeValue = "";
            if (this.getUserParentGroupAttributeName().equals(attributeKey))
                attributeValue = findGroupByCommonName(attributes.get(attributeKey)).getDistinguishedName();
            else
                attributeValue = attributes.get(attributeKey);

            query.append("(" + attributeKey + "=" + attributeValue + ")");
        }
        query.append(")");

        LdapContext context = getLDAPContext();
        try
        {
            List<SearchResult> returnedUsers = doLDAPCount(context, getConfigurations().getBaseSearchDN(),