Java 类javax.naming.directory.AttributeInUseException 实例源码

项目:plugin-id-ldap    文件:GroupLdapRepositoryTest.java   
/**
 * Mock a managed LDAP desynchronization
 */
@Test
public void removeUserSync() {
    final GroupLdapRepository groupRepository = new GroupLdapRepository() {
        @Override
        public GroupOrg findById(final String name) {
            // The group has only the user user we want to remove
            return new GroupOrg("dc=" + name, name, Collections.singleton("flast1"));
        }

    };
    groupRepository.setLdapCacheRepository(Mockito.mock(LdapCacheRepository.class));
    final LdapTemplate ldapTemplate = Mockito.mock(LdapTemplate.class);
    groupRepository.setTemplate(ldapTemplate);
    Mockito.doThrow(new org.springframework.ldap.AttributeInUseException(new AttributeInUseException("any"))).when(ldapTemplate)
            .modifyAttributes(ArgumentMatchers.any(LdapName.class), ArgumentMatchers.any());
    removeUser(groupRepository);
}
项目:plugin-id-ldap    文件:GroupLdapRepositoryTest.java   
/**
 * Mock a not managed LDAP desynchronization
 */
@Test(expected = org.springframework.ldap.AttributeInUseException.class)
public void addUserSyncError() {
    final GroupLdapRepository groupRepository = newGroupLdapRepository();
    final LdapTemplate ldapTemplate = Mockito.mock(LdapTemplate.class);
    groupRepository.setTemplate(ldapTemplate);
    Mockito.doThrow(new org.springframework.ldap.AttributeInUseException(new AttributeInUseException("any"))).when(ldapTemplate)
            .modifyAttributes(ArgumentMatchers.any(LdapName.class), ArgumentMatchers.any());

    addUser(groupRepository);
}
项目:plugin-id-ldap    文件:GroupLdapRepositoryTest.java   
/**
 * Mock a managed LDAP desynchronization
 */
@Test
public void addUserSync1() {
    final GroupLdapRepository groupRepository = newGroupLdapRepository();
    final LdapTemplate ldapTemplate = Mockito.mock(LdapTemplate.class);
    groupRepository.setTemplate(ldapTemplate);
    Mockito.doThrow(new org.springframework.ldap.AttributeInUseException(new AttributeInUseException("value #0 already exists")))
            .when(ldapTemplate).modifyAttributes(ArgumentMatchers.any(LdapName.class), ArgumentMatchers.any());

    addUser(groupRepository);
}
项目:plugin-id-ldap    文件:GroupLdapRepositoryTest.java   
/**
 * Mock a managed LDAP desynchronization
 */
@Test
public void addUserSync2() {
    final GroupLdapRepository groupRepository = newGroupLdapRepository();
    final LdapTemplate ldapTemplate = Mockito.mock(LdapTemplate.class);
    groupRepository.setTemplate(ldapTemplate);
    Mockito.doThrow(new org.springframework.ldap.AttributeInUseException(new AttributeInUseException("ATTRIBUTE_OR_VALUE_EXISTS")))
            .when(ldapTemplate).modifyAttributes(ArgumentMatchers.any(LdapName.class), ArgumentMatchers.any());

    addUser(groupRepository);
}
项目:msf4j    文件:LDAPUserStoreManager.java   
public void assignUser(String username, String groupName) throws NamingException {

        try {
            ModificationItem[] mods = new ModificationItem[1];
            Attribute mod = new BasicAttribute("member", getUserDN(username));
            mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE, mod);
            context.modifyAttributes(getGroupDN(groupName), mods);
        } catch (AttributeInUseException e) {
            // If user is already added, ignore exception
        }
    }
项目:GeoprocessingAppstore    文件:ManageUserServlet.java   
/**
 * Add attribute to ldap entry.
 * @param request HTTP request.
 * @param response HTTP response.
 * @param context request context
 * @throws IdentityException if a system error occurs preventing the action
 * @throws IOException if error writing to the buffer
 * @throws NamingException if an LDAP naming exception occurs
 * @throws SQLException 
 * @throws CredentialPolicyException 
 */
private void executeModifyUserAttribute(HttpServletRequest request,
        HttpServletResponse response,
        RequestContext context, boolean isAddAttributeRequest) throws IdentityException, IOException, NamingException, SQLException, CredentialPolicyException {
    String mimeType = "application/json";
    String filter = Val.chkStr(request.getParameter("q"));
    String attributeName = Val.chkStr(request.getParameter("an"));
    String attributeValue = Val.chkStr(request.getParameter("av"));
    if(filter.length() == 0) {
        response.getWriter().write("{ \"response\" : \"noResults\" }");
        return;
    } 
    IdentityAdapter idAdapter = context.newIdentityAdapter();
    Users users = idAdapter.readUsers(filter,null);
    for (User u : users.values()){      
        if(isAddAttributeRequest){
            try{
                idAdapter.addAttribute(u.getDistinguishedName(), attributeName, attributeValue);
            }catch(AttributeInUseException aiue){
                // TODO : do nothing if attribute exists ? or overwrite ?
            }
        }else {
            idAdapter.removeAttribute(u.getDistinguishedName(), attributeName, attributeValue);
        }           
    }
    writeCharacterResponse(response,"{ \"response\" : \"User attribute modification was successful.\" }","UTF-8",mimeType+";charset=UTF-8");
}
项目:GeoprocessingAppstore    文件:ManageUserServlet.java   
private void executeModifyGroupAttribute(HttpServletRequest request,
        HttpServletResponse response,
        RequestContext context, boolean isAddAttributeRequest) throws IdentityException, IOException, NamingException, SQLException, CredentialPolicyException {
    String mimeType = "application/json";
    String filter = Val.chkStr(request.getParameter("q"));
    String attributeName = Val.chkStr(request.getParameter("an"));
    String attributeValue = Val.chkStr(request.getParameter("av"));
    if(filter.length() == 0) {
        response.getWriter().write("{ \"response\" : \"noResults\" }");
        return;
    } 

    IdentityAdapter idAdapter = context.newIdentityAdapter();

    /*User selectableUser = new User();
    selectableUser.setDistinguishedName("*");
    idAdapter.readUserGroups(selectableUser);
    selectableGroups = selectableUser.getGroups();*/

    Groups groups = idAdapter.readGroups(filter);
    for (Group g : groups.values()){
        if(isAddAttributeRequest){
            try{
                idAdapter.addAttribute(g.getDistinguishedName(), attributeName, attributeValue);
            }catch(AttributeInUseException aiue){
                // TODO : do nothing if attribute exists ? or overwrite ?
            }
        }else {
            idAdapter.removeAttribute(g.getDistinguishedName(), attributeName, attributeValue);
        }
    }

     writeCharacterResponse(response,"{ \"response\" : \"Group attribute modification was successful.\" }","UTF-8",mimeType+";charset=UTF-8");
}
项目:cn1    文件:AttributeInUseExceptionTest.java   
public void testSetRemainingName() {
    AttributeInUseException ex = new AttributeInUseException("Test");
    ex.setRemainingName(null);
    assertNull(ex.getRemainingName());
}
项目:cn1    文件:AttributeInUseExceptionTest.java   
public void testSetResolvedName() {
    AttributeInUseException ex = new AttributeInUseException("Test");
    ex.setResolvedName(null);
    assertNull(ex.getResolvedName());
}
项目:freeVM    文件:AttributeInUseExceptionTest.java   
public void testSetRemainingName() {
    AttributeInUseException ex = new AttributeInUseException("Test");
    ex.setRemainingName(null);
    assertNull(ex.getRemainingName());
}
项目:freeVM    文件:AttributeInUseExceptionTest.java   
public void testSetResolvedName() {
    AttributeInUseException ex = new AttributeInUseException("Test");
    ex.setResolvedName(null);
    assertNull(ex.getResolvedName());
}
项目:freeVM    文件:AttributeInUseExceptionTest.java   
public void testSetRemainingName() {
    AttributeInUseException ex = new AttributeInUseException("Test");
    ex.setRemainingName(null);
    assertNull(ex.getRemainingName());
}
项目:freeVM    文件:AttributeInUseExceptionTest.java   
public void testSetResolvedName() {
    AttributeInUseException ex = new AttributeInUseException("Test");
    ex.setResolvedName(null);
    assertNull(ex.getResolvedName());
}