use of com.evolveum.icf.dummy.resource.DummyGroup in project midpoint by Evolveum.
the class DummyConnector method removeAttributeValues.
/**
* {@inheritDoc}
*/
public Uid removeAttributeValues(ObjectClass objectClass, Uid uid, Set<Attribute> valuesToRemove, OperationOptions options) {
validate(objectClass);
validate(uid);
try {
if (ObjectClass.ACCOUNT.is(objectClass.getObjectClassValue())) {
DummyAccount account;
if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
account = resource.getAccountByUsername(uid.getUidValue());
} else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
account = resource.getAccountById(uid.getUidValue());
} else {
throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
}
if (account == null) {
throw new UnknownUidException("Account with UID " + uid + " does not exist on resource");
}
for (Attribute attr : valuesToRemove) {
if (attr.is(OperationalAttributeInfos.PASSWORD.getName())) {
throw new UnsupportedOperationException("Removing password value is not supported");
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
throw new IllegalArgumentException("Attempt to remove value from enable attribute");
} else if (PredefinedAttributes.AUXILIARY_OBJECT_CLASS_NAME.equalsIgnoreCase(attr.getName())) {
account.deleteAuxiliaryObjectClassNames(attr.getValue());
} else {
String name = attr.getName();
try {
account.removeAttributeValues(name, attr.getValue());
log.ok("Removed attribute {0} values {1} from {2}, resulting values: {3}", name, attr.getValue(), account, account.getAttributeValues(name, Object.class));
} catch (SchemaViolationException e) {
// The framework should deal with it ... somehow
throw new IllegalArgumentException(e.getMessage(), e);
}
}
}
} else if (ObjectClass.GROUP.is(objectClass.getObjectClassValue())) {
DummyGroup group;
if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
group = resource.getGroupByName(uid.getUidValue());
} else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
group = resource.getGroupById(uid.getUidValue());
} else {
throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
}
if (group == null) {
throw new UnknownUidException("Group with UID " + uid + " does not exist on resource");
}
for (Attribute attr : valuesToRemove) {
if (attr.is(OperationalAttributeInfos.PASSWORD.getName())) {
throw new IllegalArgumentException("Attempt to change password on group");
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
throw new IllegalArgumentException("Attempt to remove value from enable attribute");
} else {
String name = attr.getName();
List<Object> values = attr.getValue();
if (attr.is(DummyGroup.ATTR_MEMBERS_NAME) && values != null && configuration.getUpCaseName()) {
List<Object> newValues = new ArrayList<Object>(values.size());
for (Object val : values) {
newValues.add(StringUtils.upperCase((String) val));
}
values = newValues;
}
try {
group.removeAttributeValues(name, values);
log.ok("Removed attribute {0} values {1} from {2}, resulting values: {3}", name, attr.getValue(), group, group.getAttributeValues(name, Object.class));
} catch (SchemaViolationException e) {
// The framework should deal with it ... somehow
throw new IllegalArgumentException(e.getMessage(), e);
}
}
}
} else if (objectClass.is(OBJECTCLASS_PRIVILEGE_NAME)) {
DummyPrivilege priv;
if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
priv = resource.getPrivilegeByName(uid.getUidValue());
} else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
priv = resource.getPrivilegeById(uid.getUidValue());
} else {
throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
}
if (priv == null) {
throw new UnknownUidException("Privilege with UID " + uid + " does not exist on resource");
}
for (Attribute attr : valuesToRemove) {
if (attr.is(OperationalAttributeInfos.PASSWORD.getName())) {
throw new IllegalArgumentException("Attempt to change password on privilege");
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
throw new IllegalArgumentException("Attempt to remove value from enable attribute");
} else {
String name = attr.getName();
try {
priv.removeAttributeValues(name, attr.getValue());
log.ok("Removed attribute {0} values {1} from {2}, resulting values: {3}", name, attr.getValue(), priv, priv.getAttributeValues(name, Object.class));
} catch (SchemaViolationException e) {
// The framework should deal with it ... somehow
throw new IllegalArgumentException(e.getMessage(), e);
}
}
}
} else if (objectClass.is(OBJECTCLASS_ORG_NAME)) {
DummyOrg org;
if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
org = resource.getOrgByName(uid.getUidValue());
} else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
org = resource.getOrgById(uid.getUidValue());
} else {
throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
}
if (org == null) {
throw new UnknownUidException("Org with UID " + uid + " does not exist on resource");
}
for (Attribute attr : valuesToRemove) {
if (attr.is(OperationalAttributeInfos.PASSWORD.getName())) {
throw new IllegalArgumentException("Attempt to change password on org");
} else if (attr.is(OperationalAttributes.ENABLE_NAME)) {
throw new IllegalArgumentException("Attempt to remove value from enable org");
} else {
String name = attr.getName();
try {
org.removeAttributeValues(name, attr.getValue());
log.ok("Removed attribute {0} values {1} from {2}, resulting values: {3}", name, attr.getValue(), org, org.getAttributeValues(name, Object.class));
} catch (SchemaViolationException e) {
// The framework should deal with it ... somehow
throw new IllegalArgumentException(e.getMessage(), e);
}
}
}
} else {
throw new ConnectorException("Unknown object class " + objectClass);
}
} catch (ConnectException e) {
log.info("removeAttributeValues::exception " + e);
throw new ConnectionFailedException(e.getMessage(), e);
} catch (FileNotFoundException e) {
log.info("removeAttributeValues::exception " + e);
throw new ConnectorIOException(e.getMessage(), e);
} catch (SchemaViolationException e) {
log.info("removeAttributeValues::exception " + e);
throw new InvalidAttributeValueException(e.getMessage(), e);
} catch (ConflictException e) {
log.info("removeAttributeValues::exception " + e);
throw new AlreadyExistsException(e);
}
return uid;
}
use of com.evolveum.icf.dummy.resource.DummyGroup in project midpoint by Evolveum.
the class DummyConnector method sync.
/**
* {@inheritDoc}
*/
public void sync(ObjectClass objectClass, SyncToken token, SyncResultsHandler handler, final OperationOptions options) {
log.info("sync::begin");
validate(objectClass);
Collection<String> attributesToGet = getAttrsToGet(options);
try {
int syncToken = (Integer) token.getValue();
List<DummyDelta> deltas = resource.getDeltasSince(syncToken);
for (DummyDelta delta : deltas) {
Class<? extends DummyObject> deltaObjectClass = delta.getObjectClass();
if (objectClass.is(ObjectClass.ALL_NAME)) {
// take all changes
} else if (objectClass.is(ObjectClass.ACCOUNT_NAME)) {
if (deltaObjectClass != DummyAccount.class) {
log.ok("Skipping delta {0} because of objectclass mismatch", delta);
continue;
}
} else if (objectClass.is(ObjectClass.GROUP_NAME)) {
if (deltaObjectClass != DummyGroup.class) {
log.ok("Skipping delta {0} because of objectclass mismatch", delta);
continue;
}
}
SyncDeltaBuilder deltaBuilder = new SyncDeltaBuilder();
if (deltaObjectClass == DummyAccount.class) {
deltaBuilder.setObjectClass(ObjectClass.ACCOUNT);
} else if (deltaObjectClass == DummyGroup.class) {
deltaBuilder.setObjectClass(ObjectClass.GROUP);
} else if (deltaObjectClass == DummyPrivilege.class) {
deltaBuilder.setObjectClass(new ObjectClass(OBJECTCLASS_PRIVILEGE_NAME));
} else if (deltaObjectClass == DummyOrg.class) {
deltaBuilder.setObjectClass(new ObjectClass(OBJECTCLASS_ORG_NAME));
} else {
throw new IllegalArgumentException("Unknown delta objectClass " + deltaObjectClass);
}
SyncDeltaType deltaType;
if (delta.getType() == DummyDeltaType.ADD || delta.getType() == DummyDeltaType.MODIFY) {
if (resource.getSyncStyle() == DummySyncStyle.DUMB) {
deltaType = SyncDeltaType.CREATE_OR_UPDATE;
} else {
if (delta.getType() == DummyDeltaType.ADD) {
deltaType = SyncDeltaType.CREATE;
} else {
deltaType = SyncDeltaType.UPDATE;
}
}
if (deltaObjectClass == DummyAccount.class) {
DummyAccount account = resource.getAccountById(delta.getObjectId());
if (account == null) {
throw new IllegalStateException("We have delta for account '" + delta.getObjectId() + "' but such account does not exist");
}
ConnectorObject cobject = convertToConnectorObject(account, attributesToGet);
deltaBuilder.setObject(cobject);
} else if (deltaObjectClass == DummyGroup.class) {
DummyGroup group = resource.getGroupById(delta.getObjectId());
if (group == null) {
throw new IllegalStateException("We have delta for group '" + delta.getObjectId() + "' but such group does not exist");
}
ConnectorObject cobject = convertToConnectorObject(group, attributesToGet);
deltaBuilder.setObject(cobject);
} else if (deltaObjectClass == DummyPrivilege.class) {
DummyPrivilege privilege = resource.getPrivilegeById(delta.getObjectId());
if (privilege == null) {
throw new IllegalStateException("We have privilege for group '" + delta.getObjectId() + "' but such privilege does not exist");
}
ConnectorObject cobject = convertToConnectorObject(privilege, attributesToGet);
deltaBuilder.setObject(cobject);
} else {
throw new IllegalArgumentException("Unknown delta objectClass " + deltaObjectClass);
}
} else if (delta.getType() == DummyDeltaType.DELETE) {
deltaType = SyncDeltaType.DELETE;
} else {
throw new IllegalStateException("Unknown delta type " + delta.getType());
}
deltaBuilder.setDeltaType(deltaType);
deltaBuilder.setToken(new SyncToken(delta.getSyncToken()));
Uid uid;
if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_NAME)) {
uid = new Uid(delta.getObjectName());
} else if (configuration.getUidMode().equals(DummyConfiguration.UID_MODE_UUID)) {
if (nameHintChecksEnabled()) {
uid = new Uid(delta.getObjectId(), new Name(delta.getObjectName()));
} else {
uid = new Uid(delta.getObjectId());
}
} else {
throw new IllegalStateException("Unknown UID mode " + configuration.getUidMode());
}
deltaBuilder.setUid(uid);
SyncDelta syncDelta = deltaBuilder.build();
log.info("sync::handle {0}", syncDelta);
handler.handle(syncDelta);
}
} catch (ConnectException e) {
log.info("sync::exception " + e);
throw new ConnectionFailedException(e.getMessage(), e);
} catch (FileNotFoundException e) {
log.info("sync::exception " + e);
throw new ConnectorIOException(e.getMessage(), e);
} catch (SchemaViolationException e) {
log.info("sync::exception " + e);
throw new InvalidAttributeValueException(e.getMessage(), e);
} catch (ConflictException e) {
log.info("sync::exception " + e);
throw new AlreadyExistsException(e);
}
log.info("sync::end");
}
use of com.evolveum.icf.dummy.resource.DummyGroup in project midpoint by Evolveum.
the class DummyConnector method convertToGroup.
private DummyGroup convertToGroup(Set<Attribute> createAttributes) throws ConnectException, FileNotFoundException, SchemaViolationException, ConflictException {
String icfName = Utils.getMandatoryStringAttribute(createAttributes, Name.NAME);
if (configuration.getUpCaseName()) {
icfName = StringUtils.upperCase(icfName);
}
final DummyGroup newGroup = new DummyGroup(icfName);
Boolean enabled = null;
for (Attribute attr : createAttributes) {
if (attr.is(Uid.NAME)) {
throw new IllegalArgumentException("UID explicitly specified in the group attributes");
} else if (attr.is(Name.NAME)) {
// Skip, already processed
} else if (attr.is(OperationalAttributeInfos.PASSWORD.getName())) {
throw new IllegalArgumentException("Password specified for a group");
} else if (attr.is(OperationalAttributeInfos.ENABLE.getName())) {
enabled = getBooleanNotNull(attr);
newGroup.setEnabled(enabled);
} else if (attr.is(OperationalAttributeInfos.ENABLE_DATE.getName())) {
if (configuration.getSupportValidity()) {
newGroup.setValidFrom(getDate(attr));
} else {
throw new IllegalArgumentException("ENABLE_DATE specified in the group attributes while not supporting it");
}
} else if (attr.is(OperationalAttributeInfos.DISABLE_DATE.getName())) {
if (configuration.getSupportValidity()) {
newGroup.setValidTo(getDate(attr));
} else {
throw new IllegalArgumentException("DISABLE_DATE specified in the group attributes while not supporting it");
}
} else {
String name = attr.getName();
try {
newGroup.replaceAttributeValues(name, attr.getValue());
} catch (SchemaViolationException e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
}
}
return newGroup;
}
use of com.evolveum.icf.dummy.resource.DummyGroup in project midpoint by Evolveum.
the class TestIntegrationObjectWrapperFactory method test220AssignRoleLandluberToWally.
@Test
public void test220AssignRoleLandluberToWally() throws Exception {
final String TEST_NAME = "test220AssignRoleLandluberToWally";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestIntegrationObjectWrapperFactory.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
DummyGroup mapmakers = new DummyGroup(GROUP_DUMMY_MAPMAKERS_NAME);
dummyResource.addGroup(mapmakers);
PrismObject<UserType> user = createUser(USER_WALLY_NAME, USER_WALLY_FULLNAME, true);
addObject(user);
userWallyOid = user.getOid();
assignRole(userWallyOid, ROLE_MAPMAKER_OID, task, result);
// preconditions
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userAfter = getUser(userWallyOid);
display("User after change execution", userAfter);
accountWallyOid = getSingleLinkOid(userAfter);
PrismObject<ShadowType> shadow = getShadowModel(accountWallyOid);
shadow.findReference(ShadowType.F_RESOURCE_REF).getValue().setObject(resourceDummy);
display("Shadow", shadow);
DummyGroup dummyGroup = dummyResource.getGroupByName(GROUP_DUMMY_MAPMAKERS_NAME);
assertNotNull("No group on dummy resource", dummyGroup);
display("Group", dummyGroup);
assertGroupMember(dummyGroup, USER_WALLY_NAME);
// WHEN
TestUtil.displayWhen(TEST_NAME);
ObjectWrapperFactory factory = new ObjectWrapperFactory(getServiceLocator());
ObjectWrapper<ShadowType> objectWrapper = factory.createObjectWrapper("shadow display name", "shadow description", shadow, ContainerStatus.MODIFYING, task);
// THEN
TestUtil.displayThen(TEST_NAME);
display("Wrapper after", objectWrapper);
WrapperTestUtil.assertWrapper(objectWrapper, "shadow display name", "shadow description", shadow, ContainerStatus.MODIFYING);
assertEquals("wrong number of containers in " + objectWrapper, 9, objectWrapper.getContainers().size());
ContainerWrapper attributesContainerWrapper = objectWrapper.findContainerWrapper(new ItemPath(ShadowType.F_ATTRIBUTES));
WrapperTestUtil.assertWrapper(attributesContainerWrapper, "prismContainer.shadow.mainPanelDisplayName", new ItemPath(ShadowType.F_ATTRIBUTES), shadow.findContainer(ShadowType.F_ATTRIBUTES), true, ContainerStatus.MODIFYING);
WrapperTestUtil.assertPropertyWrapper(attributesContainerWrapper, dummyResourceCtl.getAttributeFullnameQName(), USER_WALLY_FULLNAME);
WrapperTestUtil.assertPropertyWrapper(attributesContainerWrapper, SchemaConstants.ICFS_NAME, USER_WALLY_NAME);
assertEquals("wrong number of items in " + attributesContainerWrapper, 16, attributesContainerWrapper.getItems().size());
ContainerWrapper<ActivationType> activationContainerWrapper = objectWrapper.findContainerWrapper(new ItemPath(UserType.F_ACTIVATION));
WrapperTestUtil.assertWrapper(activationContainerWrapper, "ShadowType.activation", UserType.F_ACTIVATION, shadow, ContainerStatus.MODIFYING);
WrapperTestUtil.assertPropertyWrapper(activationContainerWrapper, ActivationType.F_ADMINISTRATIVE_STATUS, ActivationStatusType.ENABLED);
WrapperTestUtil.assertPropertyWrapper(activationContainerWrapper, ActivationType.F_LOCKOUT_STATUS, null);
ContainerWrapper<ShadowAssociationType> associationContainerWrapper = objectWrapper.findContainerWrapper(new ItemPath(ShadowType.F_ASSOCIATION));
assertNotNull("No association container wrapper", associationContainerWrapper);
assertEquals("wrong number of items in " + associationContainerWrapper, 2, associationContainerWrapper.getItems().size());
ItemWrapper groupAssociationWrapper = associationContainerWrapper.findPropertyWrapper(RESOURCE_DUMMY_ASSOCIATION_GROUP_QNAME);
assertNotNull("No group association property wrapper", groupAssociationWrapper);
assertTrue("Wrong type of group association property wrapper: " + groupAssociationWrapper.getClass(), groupAssociationWrapper instanceof AssociationWrapper);
List<ValueWrapper> groupAssociationValues = groupAssociationWrapper.getValues();
assertEquals("wrong number of values in " + groupAssociationWrapper, 1, groupAssociationValues.size());
ValueWrapper groupAssociationValue = groupAssociationValues.get(0);
PrismContainerValue<ShadowAssociationType> groupAssociationValuePVal = (PrismContainerValue<ShadowAssociationType>) groupAssociationValue.getValue();
display("groupAssociationValuePVal", groupAssociationValuePVal);
assertEquals("wrong number of values in " + groupAssociationValue, ValueStatus.NOT_CHANGED, groupAssociationValue.getStatus());
assertEquals("Wrong group association name", RESOURCE_DUMMY_ASSOCIATION_GROUP_QNAME, groupAssociationValuePVal.findProperty(ShadowAssociationType.F_NAME).getRealValue());
PrismContainer<ShadowIdentifiersType> groupAssociationValueIdentifiers = groupAssociationValuePVal.findContainer(ShadowAssociationType.F_IDENTIFIERS);
PrismProperty<String> groupAssociationUidProp = groupAssociationValueIdentifiers.findProperty(new QName(null, "uid"));
PrismAsserts.assertPropertyValue(groupAssociationUidProp, GROUP_DUMMY_MAPMAKERS_NAME);
}
use of com.evolveum.icf.dummy.resource.DummyGroup in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method assertDummyGroupMember.
protected void assertDummyGroupMember(String dummyInstanceName, String dummyGroupName, String accountId) throws ConnectException, FileNotFoundException, SchemaViolationException, ConflictException {
DummyResource dummyResource = DummyResource.getInstance(dummyInstanceName);
DummyGroup group = dummyResource.getGroupByName(dummyGroupName);
assertNotNull("No dummy group " + dummyGroupName, group);
IntegrationTestTools.assertGroupMember(group, accountId);
}
Aggregations