Skip to content

Commit

Permalink
Fixing endless loop (stack overflow) in consistency (MID-3451)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Oct 10, 2016
1 parent 736f25e commit ab5109c
Show file tree
Hide file tree
Showing 33 changed files with 497 additions and 227 deletions.
Expand Up @@ -71,6 +71,7 @@
import org.identityconnectors.framework.spi.operations.TestOp;
import org.identityconnectors.framework.spi.operations.UpdateAttributeValuesOp;

import com.evolveum.icf.dummy.resource.ConflictException;
import com.evolveum.icf.dummy.resource.DummyAccount;
import com.evolveum.icf.dummy.resource.DummyAttributeDefinition;
import com.evolveum.icf.dummy.resource.DummyDelta;
Expand Down Expand Up @@ -268,6 +269,8 @@ public Uid create(final ObjectClass objectClass, final Set<Attribute> createAttr
throw new ConnectorIOException(e.getMessage(), e);
} catch (SchemaViolationException e) {
throw new InvalidAttributeValueException(e);
} catch (ConflictException e) {
throw new AlreadyExistsException(e);
}

String id;
Expand Down Expand Up @@ -505,6 +508,9 @@ public Uid update(ObjectClass objectClass, Uid uid, Set<Attribute> replaceAttrib
} catch (SchemaViolationException e) {
log.info("update::exception "+e);
throw new InvalidAttributeValueException(e.getMessage(), e);
} catch (ConflictException e) {
log.info("update::exception "+e);
throw new AlreadyExistsException(e);
}

log.info("update::end");
Expand Down Expand Up @@ -698,6 +704,9 @@ public Uid addAttributeValues(ObjectClass objectClass, Uid uid, Set<Attribute> v
} catch (SchemaViolationException e) {
log.info("addAttributeValues::exception "+e);
throw new InvalidAttributeValueException(e.getMessage(), e);
} catch (ConflictException e) {
log.info("addAttributeValues::exception "+e);
throw new AlreadyExistsException(e);
}

return uid;
Expand Down Expand Up @@ -874,6 +883,9 @@ public Uid removeAttributeValues(ObjectClass objectClass, Uid uid, Set<Attribute
} 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;
Expand Down Expand Up @@ -942,6 +954,9 @@ public void delete(final ObjectClass objectClass, final Uid uid, final Operation
} catch (SchemaViolationException e) {
log.info("delete::exception "+e);
throw new InvalidAttributeValueException(e.getMessage(), e);
} catch (ConflictException e) {
log.info("delete::exception "+e);
throw new AlreadyExistsException(e);
}

log.info("delete::end");
Expand Down Expand Up @@ -972,6 +987,8 @@ public Schema schema() {

} catch (SchemaViolationException e) {
throw new InvalidAttributeValueException(e.getMessage(), e);
} catch (ConflictException e) {
throw new AlreadyExistsException(e);
}

if (configuration.isSupportReturnDefaultAttributes()) {
Expand Down Expand Up @@ -1030,7 +1047,7 @@ private ObjectClassInfoBuilder createCommonObjectClassBuilder(String typeName,
return objClassBuilder;
}

private ObjectClassInfo createAccountObjectClass(boolean supportsActivation) throws SchemaViolationException {
private ObjectClassInfo createAccountObjectClass(boolean supportsActivation) throws SchemaViolationException, ConflictException {
// __ACCOUNT__ objectclass

DummyObjectClass dummyAccountObjectClass;
Expand Down Expand Up @@ -1226,6 +1243,9 @@ public void executeQuery(ObjectClass objectClass, Filter query, ResultsHandler h
} catch (SchemaViolationException e) {
log.info("executeQuery::exception "+e);
throw new InvalidAttributeValueException(e.getMessage(), e);
} catch (ConflictException e) {
log.info("executeQuery::exception "+e);
throw new AlreadyExistsException(e);
}

log.info("executeQuery::end");
Expand Down Expand Up @@ -1473,6 +1493,9 @@ public void sync(ObjectClass objectClass, SyncToken token, SyncResultsHandler ha
} 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");
Expand Down Expand Up @@ -1623,6 +1646,9 @@ private ConnectorObject convertToConnectorObject(DummyAccount account, Collectio
} catch (FileNotFoundException e) {
log.error(e, e.getMessage());
throw new ConnectorIOException(e.getMessage(), e);
} catch (ConflictException e) {
log.error(e, e.getMessage());
throw new AlreadyExistsException(e);
}

ConnectorObjectBuilder builder = createConnectorObjectBuilderCommon(account, objectClass, attributesToGet, true);
Expand Down Expand Up @@ -1663,7 +1689,7 @@ private ConnectorObject convertToConnectorObject(DummyOrg org, Collection<String
return builder.build();
}

private DummyAccount convertToAccount(Set<Attribute> createAttributes) throws ConnectException, FileNotFoundException, SchemaViolationException {
private DummyAccount convertToAccount(Set<Attribute> createAttributes) throws ConnectException, FileNotFoundException, SchemaViolationException, ConflictException {
log.ok("Create attributes: {0}", createAttributes);
String userName = Utils.getMandatoryStringAttribute(createAttributes, Name.NAME);
if (configuration.getUpCaseName()) {
Expand Down Expand Up @@ -1725,7 +1751,7 @@ private DummyAccount convertToAccount(Set<Attribute> createAttributes) throws Co
return newAccount;
}

private DummyGroup convertToGroup(Set<Attribute> createAttributes) throws ConnectException, FileNotFoundException, SchemaViolationException {
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);
Expand Down Expand Up @@ -1774,7 +1800,7 @@ private DummyGroup convertToGroup(Set<Attribute> createAttributes) throws Connec
return newGroup;
}

private DummyPrivilege convertToPriv(Set<Attribute> createAttributes) throws ConnectException, FileNotFoundException {
private DummyPrivilege convertToPriv(Set<Attribute> createAttributes) throws ConnectException, FileNotFoundException, ConflictException {
String icfName = Utils.getMandatoryStringAttribute(createAttributes,Name.NAME);
if (configuration.getUpCaseName()) {
icfName = StringUtils.upperCase(icfName);
Expand Down Expand Up @@ -1807,7 +1833,7 @@ private DummyPrivilege convertToPriv(Set<Attribute> createAttributes) throws Con
return newPriv;
}

private DummyOrg convertToOrg(Set<Attribute> createAttributes) throws ConnectException, FileNotFoundException {
private DummyOrg convertToOrg(Set<Attribute> createAttributes) throws ConnectException, FileNotFoundException, ConflictException {
String icfName = Utils.getMandatoryStringAttribute(createAttributes,Name.NAME);
if (configuration.getUpCaseName()) {
icfName = StringUtils.upperCase(icfName);
Expand Down Expand Up @@ -1879,7 +1905,7 @@ private Date getDate(Attribute attr) {
}


private void changePassword(final DummyAccount account, Attribute attr) throws ConnectException, FileNotFoundException, SchemaViolationException {
private void changePassword(final DummyAccount account, Attribute attr) throws ConnectException, FileNotFoundException, SchemaViolationException, ConflictException {
final String[] passwdArray = { null };
if (attr.getValue() != null && !attr.getValue().isEmpty()) {
Object passwdObject = attr.getValue().get(0);
Expand Down
Expand Up @@ -25,6 +25,7 @@ public enum BreakMode {
NETWORK,
IO,
SCHEMA,
CONFLICT, // results in AlreadyExists exceptions
GENERIC,
UNSUPPORTED,
RUNTIME;
Expand Down
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.icf.dummy.resource;

/**
* @author semancik
*
*/
public class ConflictException extends Exception {

public ConflictException() {
super();
}

public ConflictException(String message, Throwable cause) {
super(message, cause);
}

public ConflictException(String message) {
super(message);
}

public ConflictException(Throwable cause) {
super(cause);
}

}
Expand Up @@ -55,7 +55,7 @@ public String getPassword() {
return password;
}

public void setPassword(String password) throws ConnectException, FileNotFoundException, SchemaViolationException {
public void setPassword(String password) throws ConnectException, FileNotFoundException, SchemaViolationException, ConflictException {
checkModifyBreak();
this.password = password;
}
Expand All @@ -64,13 +64,13 @@ public Boolean isLockout() {
return lockout;
}

public void setLockout(boolean lockout) throws ConnectException, FileNotFoundException, SchemaViolationException {
public void setLockout(boolean lockout) throws ConnectException, FileNotFoundException, SchemaViolationException, ConflictException {
checkModifyBreak();
this.lockout = lockout;
}

@Override
protected DummyObjectClass getObjectClass() throws ConnectException, FileNotFoundException, SchemaViolationException {
protected DummyObjectClass getObjectClass() throws ConnectException, FileNotFoundException, SchemaViolationException, ConflictException {
return resource.getAccountObjectClass();
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2013 Evolveum
* Copyright (c) 2010-2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -48,7 +48,7 @@ public Collection<String> getMembers() {
return getAttributeValues(ATTR_MEMBERS_NAME, String.class);
}

public void addMember(String newMember) throws SchemaViolationException, ConnectException, FileNotFoundException {
public void addMember(String newMember) throws SchemaViolationException, ConnectException, FileNotFoundException, ConflictException {
addAttributeValue(ATTR_MEMBERS_NAME, newMember);
}

Expand All @@ -60,7 +60,7 @@ public boolean containsMember(String member) {
return members.contains(member); // TODO ok? what about case ignoring scenarios?
}

public void removeMember(String newMember) throws SchemaViolationException, ConnectException, FileNotFoundException {
public void removeMember(String newMember) throws SchemaViolationException, ConnectException, FileNotFoundException, ConflictException {
removeAttributeValue(ATTR_MEMBERS_NAME, newMember);
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2014 Evolveum
* Copyright (c) 2010-2016 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -88,7 +88,7 @@ public Boolean isEnabled() {
return enabled;
}

public void setEnabled(Boolean enabled) throws ConnectException, FileNotFoundException, SchemaViolationException {
public void setEnabled(Boolean enabled) throws ConnectException, FileNotFoundException, SchemaViolationException, ConflictException {
checkModifyBreak();
this.enabled = enabled;
}
Expand All @@ -97,7 +97,7 @@ public Date getValidFrom() {
return validFrom;
}

public void setValidFrom(Date validFrom) throws ConnectException, FileNotFoundException, SchemaViolationException {
public void setValidFrom(Date validFrom) throws ConnectException, FileNotFoundException, SchemaViolationException, ConflictException {
checkModifyBreak();
this.validFrom = validFrom;
}
Expand All @@ -106,7 +106,7 @@ public Date getValidTo() {
return validTo;
}

public void setValidTo(Date validTo) throws ConnectException, FileNotFoundException, SchemaViolationException {
public void setValidTo(Date validTo) throws ConnectException, FileNotFoundException, SchemaViolationException, ConflictException {
checkModifyBreak();
this.validTo = validTo;
}
Expand Down Expand Up @@ -143,13 +143,13 @@ public String getAttributeValue(String attrName) {
return getAttributeValue(attrName,String.class);
}

public void replaceAttributeValue(String name, Object value) throws SchemaViolationException, ConnectException, FileNotFoundException, SchemaViolationException {
public void replaceAttributeValue(String name, Object value) throws SchemaViolationException, ConnectException, FileNotFoundException, SchemaViolationException, ConflictException {
Collection<Object> values = new ArrayList<Object>(1);
values.add(value);
replaceAttributeValues(name, values);
}

public void replaceAttributeValues(String name, Collection<Object> values) throws SchemaViolationException, ConnectException, FileNotFoundException, SchemaViolationException {
public void replaceAttributeValues(String name, Collection<Object> values) throws SchemaViolationException, ConnectException, FileNotFoundException, SchemaViolationException, ConflictException {
checkModifyBreak();
Set<Object> currentValues = attributes.get(name);
if (currentValues == null) {
Expand All @@ -163,7 +163,7 @@ public void replaceAttributeValues(String name, Collection<Object> values) throw
recordModify();
}

public void replaceAttributeValues(String name, Object... values) throws SchemaViolationException, ConnectException, FileNotFoundException, SchemaViolationException {
public void replaceAttributeValues(String name, Object... values) throws SchemaViolationException, ConnectException, FileNotFoundException, SchemaViolationException, ConflictException {
checkModifyBreak();
Set<Object> currentValues = attributes.get(name);
if (currentValues == null) {
Expand All @@ -181,13 +181,13 @@ public void replaceAttributeValues(String name, Object... values) throws SchemaV
recordModify();
}

public void addAttributeValue(String name, Object value) throws SchemaViolationException, ConnectException, FileNotFoundException, SchemaViolationException {
public void addAttributeValue(String name, Object value) throws SchemaViolationException, ConnectException, FileNotFoundException, SchemaViolationException, ConflictException {
Collection<Object> values = new ArrayList<Object>(1);
values.add(value);
addAttributeValues(name, values);
}

public void addAttributeValues(String name, Collection<Object> valuesToAdd) throws SchemaViolationException, ConnectException, FileNotFoundException, SchemaViolationException {
public void addAttributeValues(String name, Collection<Object> valuesToAdd) throws SchemaViolationException, ConnectException, FileNotFoundException, SchemaViolationException, ConflictException {
checkModifyBreak();
Set<Object> currentValues = attributes.get(name);
if (currentValues == null) {
Expand All @@ -200,7 +200,7 @@ public void addAttributeValues(String name, Collection<Object> valuesToAdd) thro
recordModify();
}

public void addAttributeValues(String name, String... valuesToAdd) throws SchemaViolationException, ConnectException, FileNotFoundException, SchemaViolationException {
public void addAttributeValues(String name, String... valuesToAdd) throws SchemaViolationException, ConnectException, FileNotFoundException, SchemaViolationException, ConflictException {
checkModifyBreak();
Set<Object> currentValues = attributes.get(name);
if (currentValues == null) {
Expand All @@ -213,7 +213,7 @@ public void addAttributeValues(String name, String... valuesToAdd) throws Schema
recordModify();
}

private void addAttributeValue(String attrName, Set<Object> currentValues, Object valueToAdd) throws SchemaViolationException, ConnectException, FileNotFoundException, SchemaViolationException {
private void addAttributeValue(String attrName, Set<Object> currentValues, Object valueToAdd) throws SchemaViolationException, ConnectException, FileNotFoundException, SchemaViolationException, ConflictException {
checkModifyBreak();
if (resource != null && !resource.isTolerateDuplicateValues()) {
for (Object currentValue: currentValues) {
Expand All @@ -236,13 +236,13 @@ private void addAttributeValue(String attrName, Set<Object> currentValues, Objec
currentValues.add(valueToAdd);
}

public void removeAttributeValue(String name, Object value) throws SchemaViolationException, ConnectException, FileNotFoundException, SchemaViolationException {
public void removeAttributeValue(String name, Object value) throws SchemaViolationException, ConnectException, FileNotFoundException, SchemaViolationException, ConflictException {
Collection<Object> values = new ArrayList<Object>();
values.add(value);
removeAttributeValues(name, values);
}

public void removeAttributeValues(String name, Collection<Object> values) throws SchemaViolationException, ConnectException, FileNotFoundException, SchemaViolationException {
public void removeAttributeValues(String name, Collection<Object> values) throws SchemaViolationException, ConnectException, FileNotFoundException, SchemaViolationException, ConflictException {
checkModifyBreak();
Set<Object> currentValues = attributes.get(name);
if (currentValues == null) {
Expand Down Expand Up @@ -335,7 +335,7 @@ private void checkIfExist(Collection<Object> valuesToDelete, Set<Object> current
}
}

protected void checkModifyBreak() throws ConnectException, FileNotFoundException, SchemaViolationException {
protected void checkModifyBreak() throws ConnectException, FileNotFoundException, SchemaViolationException, ConflictException {
if (resource == null) {
return;
}
Expand All @@ -351,6 +351,8 @@ protected void checkModifyBreak() throws ConnectException, FileNotFoundException
throw new FileNotFoundException("IO error (simulated error)");
} else if (modifyBreakMode == BreakMode.SCHEMA) {
throw new SchemaViolationException("Schema violation (simulated error)");
} else if (modifyBreakMode == BreakMode.CONFLICT) {
throw new ConflictException("Conflict (simulated error)");
} else if (modifyBreakMode == BreakMode.GENERIC) {
// The connector will react with generic exception
throw new IllegalArgumentException("Generic error (simulated error)");
Expand Down Expand Up @@ -416,7 +418,7 @@ public DummyAttributeDefinition getAttributeDefinition(String attrName) {
return null;
}

abstract protected DummyObjectClass getObjectClass() throws ConnectException, FileNotFoundException, SchemaViolationException;
abstract protected DummyObjectClass getObjectClass() throws ConnectException, FileNotFoundException, SchemaViolationException, ConflictException;

abstract protected DummyObjectClass getObjectClassNoExceptions();

Expand Down

0 comments on commit ab5109c

Please sign in to comment.