@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()); } };
@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(); } }
/** * This will do a basic replace. * * @see UpdateOp#update(org.identityconnectors.framework.common.objects.ObjectClass, * org.identityconnectors.framework.common.objects.Uid, java.util.Set, * org.identityconnectors.framework.common.objects.OperationOptions) */ public Uid update( ObjectClass objectClass, Uid uid, Set<Attribute> attrs, OperationOptions options) { String val = AttributeUtil.getAsStringValue(uid); int idx = Integer.valueOf(val).intValue(); // get out the object.. ConnectorObject base = objects.get(idx); ConnectorObjectBuilder bld = new ConnectorObjectBuilder(); bld.add(base); bld.addAttributes(attrs); ConnectorObject obj = bld.build(); objects.set(idx, obj); return obj.getUid(); }
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; } }
public void executeQuery( ObjectClass objClass, String query, ResultsHandler handler, OperationOptions options) { // TODO Auto-generated method stub LOG.ok("Query {0} ", query); if (!isAccount(objClass)) { throw new UnsupportedOperationException( "Could not execute query. Object class not supported: " + objClass); } try { String repoId = getFoundationRepoId(); String template = "<Templates>" + "<Person>" + "</Person>" + "</Templates>"; int flags = MdOMIUtil.OMI_GET_METADATA | MdOMIUtil.OMI_ALL | MdOMIUtil.OMI_TEMPLATE; List objects = connection .getFactory() .getOMIUtil() .getMetadataObjects(repoId, MetadataObjects.PERSON, flags, template); Iterator iterator = objects.iterator(); while (iterator.hasNext()) { Object obj = iterator.next(); RootImpl p = (RootImpl) obj; ConnectorObjectBuilder cob = new ConnectorObjectBuilder(); cob.addAttribute(Name.NAME, p.getName()); cob.addAttribute(Uid.NAME, p.getId()); Set<Entry<String, String>> attrs = p.getAttrs().entrySet(); Iterator<Entry<String, String>> attrIterator = attrs.iterator(); while (attrIterator.hasNext()) { Entry<String, String> attr = attrIterator.next(); // skip id and name..it was set before (icf_name and icf_uid) if (attr.getKey().equals(CMetadata.ATTRIBUTE_ID_NAME)) { continue; } if (attr.getKey().equals(CMetadata.ATTRIBUTE_NAME_NAME)) { continue; } if (StringUtil.isEmpty(attr.getValue())) { LOG.ok("Skipping setting attribute {0}. Attribute value is blank", attr.getKey()); } else { LOG.ok("Setting attribute {0} with value {1}", attr.getKey(), attr.getValue()); cob.addAttribute(attr.getKey(), attr.getValue()); } } handler.handle(cob.build()); } } catch (RemoteException e) { // TODO Auto-generated catch block throw new ConnectorException(e); } catch (MdException e) { // TODO Auto-generated catch block throw new ConnectorException(e); } }