Commit a1739694 authored by Adrian Damian's avatar Adrian Damian
Browse files

Added check if group exists

parent 47274109
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -118,10 +118,13 @@ public abstract interface GroupPersistence<T extends Principal>
     * @throws TransientException If an temporary, unexpected problem occurred.
     * @throws AccessControlException If the operation is not permitted.
     * @throws UserNotFoundException If owner or a member not valid user.
     * @throws GroupNotFoundException if one of the groups in group members or
     * group admins does not exist in the server.
     */
    public abstract Group addGroup(Group group)
        throws GroupAlreadyExistsException, TransientException,
               AccessControlException, UserNotFoundException;
               AccessControlException, UserNotFoundException, 
               GroupNotFoundException;

    /**
     * Deletes the group.
+31 −3
Original line number Diff line number Diff line
@@ -135,10 +135,12 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO
     *                                     exists.
     * @throws TransientException If an temporary, unexpected problem occurred.
     * @throws UserNotFoundException If owner or a member not valid user.
     * @throws GroupNotFoundException 
     */
    public Group addGroup(final Group group)
        throws GroupAlreadyExistsException, TransientException,
               UserNotFoundException, AccessControlException
               UserNotFoundException, AccessControlException, 
               GroupNotFoundException
    {
        if (group.getOwner() == null)
        {
@@ -205,7 +207,8 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO
                                final DN ownerDN, final String description, 
                                final Set<User<? extends Principal>> users, 
                                final Set<Group> groups)
        throws UserNotFoundException, LDAPException, TransientException, AccessControlException
        throws UserNotFoundException, LDAPException, TransientException, 
        AccessControlException, GroupNotFoundException
    {
        // add new group
        List<Attribute> attributes = new ArrayList<Attribute>();
@@ -228,6 +231,10 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO
        }
        for (Group groupMember : groups)
        {
            if (!checkGroupExists(groupID))
            {
                throw new GroupNotFoundException(groupID);
            }
            DN memberDN = getGroupDN(groupMember.getID());
            members.add(memberDN.toNormalizedString());
        }
@@ -316,7 +323,7 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO
     * @throws TransientException If an temporary, unexpected problem occurred.
     */
    public Collection<String> getGroupNames()
        throws TransientException, AccessControlException
        throws TransientException
    {
        try
        {
@@ -604,6 +611,10 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO
        }
        for (Group gr : group.getGroupMembers())
        {
            if (!checkGroupExists(gr.getID()))
            {
                throw new GroupNotFoundException(gr.getID());
            }
            DN grDN = getGroupDN(gr.getID());
            newMembers.add(grDN.toNormalizedString());
        }
@@ -615,6 +626,10 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO
        }
        for (Group gr : group.getGroupAdmins())
        {
            if (!checkGroupExists(gr.getID()))
            {
                throw new GroupNotFoundException(gr.getID());
            }
            DN grDN = getGroupDN(gr.getID());
            newAdmins.add(grDN.toNormalizedString());
        }
@@ -1002,4 +1017,17 @@ public class LdapGroupDAO<T extends Principal> extends LdapDAO
        }
    }
    
    private boolean checkGroupExists(String groupID) 
            throws TransientException
    {
        for (String groupName : getGroupNames())
        {
            if (groupName.equalsIgnoreCase(groupID))
            {
                return true;
            }
        }
        return false;
    }

}
+2 −1
Original line number Diff line number Diff line
@@ -147,7 +147,8 @@ public class LdapGroupPersistence<T extends Principal>

    public Group addGroup(Group group)
        throws GroupAlreadyExistsException, TransientException, 
               AccessControlException, UserNotFoundException
               AccessControlException, UserNotFoundException, 
               GroupNotFoundException
    {
        LdapGroupDAO<T> groupDAO = null;
        LdapUserDAO<T> userDAO = null;
+1 −1
Original line number Diff line number Diff line
@@ -182,7 +182,7 @@ public class LdapDAOTest
    private void testConnection(final LDAPConnection ldapCon)
    {
        assertTrue("Not connected but should be.", ldapCon.isConnected());
        assertFalse("Should be SSLSocketFactory.",
        assertTrue("Should be SSLSocketFactory.",
                   (ldapCon.getSocketFactory() instanceof SSLSocketFactory));
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -65,9 +65,9 @@ public class LdapGroupDAOTest
{
    private static final Logger log = Logger.getLogger(LdapGroupDAOTest.class);

    static String usersDN = "ou=Users,ou=ds,dc=canfartest,dc=net";
    static String groupsDN = "ou=Groups,ou=ds,dc=canfartest,dc=net";
    static String adminGroupsDN = "ou=adminGroups,ou=ds,dc=canfartest,dc=net";
    static String usersDN = "ou=Users,ou=ds,dc=testcanfar";
    static String groupsDN = "ou=Groups,ou=ds,dc=testcanfar";
    static String adminGroupsDN = "ou=adminGroups,ou=ds,dc=testcanfar";
    
    static String daoTestDN1 = "cn=cadcdaotest1,ou=cadc,o=hia,c=ca";
    static String daoTestDN2 = "cn=cadcdaotest2,ou=cadc,o=hia,c=ca";
Loading