@Test // @Ignore public void testEnableDisable() throws Exception { SpmlConfiguration config = createConfiguration(); SpmlConnector info = createConnector(config); try { Set<Attribute> attrs = fillInSampleUser(TEST_USER); // Delete the account if it already exists // deleteUser(TEST_USER, info); // Create the account // Uid newUid = info.create(ObjectClass.ACCOUNT, attrs, null); System.out.println(newUid.getValue() + " created"); // Test disabling the user { ConnectorObjectBuilder builder = new ConnectorObjectBuilder(); builder.setUid(newUid); Attribute password = AttributeBuilder.build(OperationalAttributes.ENABLE_NAME, Boolean.FALSE); builder.addAttribute(password); builder.addAttribute(new Name(TEST_USER)); ConnectorObject newUser = builder.build(); info.update(newUser.getObjectClass(), newUser.getAttributes(), null); Map map = new HashMap<String, Object>(); map.put( OperationOptions.OP_ATTRIBUTES_TO_GET, new String[] {OperationalAttributes.ENABLE_NAME}); OperationOptions options = new OperationOptions(map); ConnectorObject user = getUser(TEST_USER, options); Attribute enabled = user.getAttributeByName(OperationalAttributes.ENABLE_NAME); Assert.assertNotNull(enabled); Assert.assertFalse(AttributeUtil.getBooleanValue(enabled)); } // Test enabling the user { ConnectorObjectBuilder builder = new ConnectorObjectBuilder(); builder.setUid(newUid); Attribute password = AttributeBuilder.build(OperationalAttributes.ENABLE_NAME, Boolean.TRUE); builder.addAttribute(password); builder.addAttribute(new Name(TEST_USER)); ConnectorObject newUser = builder.build(); info.update(newUser.getObjectClass(), newUser.getAttributes(), null); Attribute enabled = newUser.getAttributeByName(OperationalAttributes.ENABLE_NAME); Assert.assertNotNull(enabled); Assert.assertTrue(AttributeUtil.getBooleanValue(enabled)); } } finally { info.dispose(); } }
@Test // @Ignore public void testChangePassword() throws Exception { SpmlConfiguration config = createConfiguration(); SpmlConnector info = createConnector(config); try { Set<Attribute> attrs = fillInSampleUser(TEST_USER); // Delete the account if it already exists // deleteUser(TEST_USER, info); // Create the account // Uid newUid = info.create(ObjectClass.ACCOUNT, attrs, null); System.out.println(newUid.getValue() + " created"); ConnectorObjectBuilder builder = new ConnectorObjectBuilder(); builder.setUid(newUid); Attribute password = AttributeBuilder.build( OperationalAttributes.PASSWORD_NAME, new GuardedString("xyzzy123".toCharArray())); builder.addAttribute(password); builder.addAttribute(new Name(TEST_USER)); ConnectorObject newUser = builder.build(); info.update(newUser.getObjectClass(), newUser.getAttributes(), null); } finally { info.dispose(); } }
/** Searches for objects to return based on the filter provided with offset and limit features. */ public void executeQuery( ObjectClass oclass, String query, ResultsHandler handler, OperationOptions options) { /** Track the number of lines processed. */ long lines = 0; /** Text qualifier character. */ final char textQualifier = cfg.getTextQualifier(); /** Field delimiter. */ final char fieldSeparator = cfg.getFieldDelimiter(); /** Unique identifier field. */ final String uniqueIdField = cfg.getUniqueAttributeName(); /** Internal reader initialized in the constructor. */ BufferedReader rdr = null; try { rdr = cfg.newFileReader(); /** Fields names read from the header. */ List<String> fieldNames = FlatFileConnector.readHeader(rdr, fieldSeparator, textQualifier, uniqueIdField); String line; while ((line = rdr.readLine()) != null) { ++lines; if (line.trim().length() == 0) { LOG.info(MSG_SKIPPING); continue; } LOG.ok("Processing Data Line: {0}", line); List<String> fieldValues = StringUtil.parseLine(line, fieldSeparator, textQualifier); if (fieldValues == null) { LOG.error("Error: {0}", line); break; } else { ConnectorObjectBuilder bld = new ConnectorObjectBuilder(); for (int i = 0; i < fieldValues.size(); ++i) { String name = fieldNames.get(i); String value = fieldValues.get(i); if (name.equals(uniqueIdField)) { bld.setUid(value); bld.setName(value); } else { bld.addAttribute(name, value); } } // create the connector object.. ConnectorObject ret = bld.build(); if (!handler.handle(ret)) { break; } } } } catch (IOException e) { throw new ConnectorIOException(e); } finally { IOUtil.quietClose(rdr); } }
static { ConnectorObjectBuilder bld = new ConnectorObjectBuilder(); for (int i = 0; i < 100; i++) { bld.setUid(Integer.toString(i)); bld.setName(Integer.toString(i)); objects.add(bld.build()); } };
static { boolean enabled = true; for (int i = 0; i < 100; i++) { ConnectorObjectBuilder builder = new ConnectorObjectBuilder(); builder.setUid(String.valueOf(i)); builder.setName(String.format("user%03d", i)); builder.addAttribute(AttributeBuilder.buildEnabled(enabled)); Map<String, Object> mapAttribute = new HashMap<String, Object>(); mapAttribute.put("email", "*****@*****.**"); mapAttribute.put("primary", true); mapAttribute.put("usage", Arrays.asList("home", "work")); builder.addAttribute(AttributeBuilder.build("emails", mapAttribute)); ConnectorObject co = builder.build(); collection.put(co.getName().getNameValue(), co); enabled = !enabled; } }