| | |
| | | import org.opends.server.api.Backend; |
| | | import org.opends.server.api.plugin.DirectoryServerPlugin; |
| | | import org.opends.server.api.plugin.PluginType; |
| | | import org.opends.server.api.plugin.PreOperationPluginResult; |
| | | import org.opends.server.api.plugin.PluginResult; |
| | | import org.opends.server.config.ConfigException; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | |
| | | |
| | | |
| | | /** |
| | | * The pre-operation plugin result that should be returned if an operation |
| | | * would have resulted in a unique attribute conflict. |
| | | */ |
| | | private static final PreOperationPluginResult FAILED_PREOP_RESULT = |
| | | new PreOperationPluginResult(false, false, false, true); |
| | | |
| | | |
| | | |
| | | /** |
| | | * The set of attributes that will be requested when performing internal |
| | | * search operations. This indicates that no attributes should be returned. |
| | | */ |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | public final PreOperationPluginResult |
| | | public final PluginResult.PreOperation |
| | | doPreOperation(PreOperationAddOperation addOperation) |
| | | { |
| | | UniqueAttributePluginCfg config = currentConfiguration; |
| | |
| | | if (baseDNs == null) |
| | | { |
| | | // The entry is outside the scope of this plugin. |
| | | return PreOperationPluginResult.SUCCESS; |
| | | return PluginResult.PreOperation.continueOperationProcessing(); |
| | | } |
| | | |
| | | for (AttributeType t : config.getType()) |
| | |
| | | config, v); |
| | | if (conflictDN != null) |
| | | { |
| | | addOperation.appendErrorMessage( |
| | | ERR_PLUGIN_UNIQUEATTR_ATTR_NOT_UNIQUE.get(t.getNameOrOID(), |
| | | v.getStringValue(), conflictDN.toString())); |
| | | addOperation.setResultCode(ResultCode.CONSTRAINT_VIOLATION); |
| | | return FAILED_PREOP_RESULT; |
| | | Message msg = ERR_PLUGIN_UNIQUEATTR_ATTR_NOT_UNIQUE.get( |
| | | t.getNameOrOID(), v.getStringValue(), |
| | | conflictDN.toString()); |
| | | return PluginResult.PreOperation.stopProcessing( |
| | | ResultCode.CONSTRAINT_VIOLATION, msg); |
| | | } |
| | | } |
| | | catch (DirectoryException de) |
| | |
| | | de.getResultCode().toString(), |
| | | de.getMessageObject()); |
| | | |
| | | addOperation.setResultCode( |
| | | DirectoryServer.getServerErrorResultCode()); |
| | | addOperation.appendErrorMessage(m); |
| | | return FAILED_PREOP_RESULT; |
| | | return PluginResult.PreOperation.stopProcessing( |
| | | DirectoryServer.getServerErrorResultCode(), m); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | return PreOperationPluginResult.SUCCESS; |
| | | return PluginResult.PreOperation.continueOperationProcessing(); |
| | | } |
| | | |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | public final PreOperationPluginResult |
| | | public final PluginResult.PreOperation |
| | | doPreOperation(PreOperationModifyOperation modifyOperation) |
| | | { |
| | | UniqueAttributePluginCfg config = currentConfiguration; |
| | |
| | | if (baseDNs == null) |
| | | { |
| | | // The entry is outside the scope of this plugin. |
| | | return PreOperationPluginResult.SUCCESS; |
| | | return PluginResult.PreOperation.continueOperationProcessing(); |
| | | } |
| | | |
| | | for (Modification m : modifyOperation.getModifications()) |
| | |
| | | v); |
| | | if (conflictDN != null) |
| | | { |
| | | modifyOperation.appendErrorMessage( |
| | | ERR_PLUGIN_UNIQUEATTR_ATTR_NOT_UNIQUE.get(t.getNameOrOID(), |
| | | v.getStringValue(), conflictDN.toString())); |
| | | modifyOperation.setResultCode(ResultCode.CONSTRAINT_VIOLATION); |
| | | return FAILED_PREOP_RESULT; |
| | | Message msg = ERR_PLUGIN_UNIQUEATTR_ATTR_NOT_UNIQUE.get( |
| | | t.getNameOrOID(), v.getStringValue(), |
| | | conflictDN.toString()); |
| | | return PluginResult.PreOperation.stopProcessing( |
| | | ResultCode.CONSTRAINT_VIOLATION, msg); |
| | | } |
| | | } |
| | | catch (DirectoryException de) |
| | |
| | | de.getResultCode().toString(), |
| | | de.getMessageObject()); |
| | | |
| | | modifyOperation.setResultCode( |
| | | DirectoryServer.getServerErrorResultCode()); |
| | | modifyOperation.appendErrorMessage(message); |
| | | return FAILED_PREOP_RESULT; |
| | | return PluginResult.PreOperation.stopProcessing( |
| | | DirectoryServer.getServerErrorResultCode(), message); |
| | | } |
| | | } |
| | | break; |
| | |
| | | config, v); |
| | | if (conflictDN != null) |
| | | { |
| | | modifyOperation.appendErrorMessage( |
| | | ERR_PLUGIN_UNIQUEATTR_ATTR_NOT_UNIQUE.get( |
| | | t.getNameOrOID(), v.getStringValue(), |
| | | conflictDN.toString())); |
| | | modifyOperation.setResultCode( |
| | | ResultCode.CONSTRAINT_VIOLATION); |
| | | return FAILED_PREOP_RESULT; |
| | | Message msg = ERR_PLUGIN_UNIQUEATTR_ATTR_NOT_UNIQUE.get( |
| | | t.getNameOrOID(), v.getStringValue(), |
| | | conflictDN.toString()); |
| | | return PluginResult.PreOperation.stopProcessing( |
| | | ResultCode.CONSTRAINT_VIOLATION, msg); |
| | | } |
| | | } |
| | | catch (DirectoryException de) |
| | |
| | | de.getResultCode().toString(), |
| | | de.getMessageObject()); |
| | | |
| | | modifyOperation.setResultCode( |
| | | DirectoryServer.getServerErrorResultCode()); |
| | | modifyOperation.appendErrorMessage(message); |
| | | return FAILED_PREOP_RESULT; |
| | | return PluginResult.PreOperation.stopProcessing( |
| | | DirectoryServer.getServerErrorResultCode(), message); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | return PreOperationPluginResult.SUCCESS; |
| | | return PluginResult.PreOperation.continueOperationProcessing(); |
| | | } |
| | | |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override() |
| | | public final PreOperationPluginResult doPreOperation( |
| | | public final PluginResult.PreOperation doPreOperation( |
| | | PreOperationModifyDNOperation modifyDNOperation) |
| | | { |
| | | UniqueAttributePluginCfg config = currentConfiguration; |
| | |
| | | if (baseDNs == null) |
| | | { |
| | | // The entry is outside the scope of this plugin. |
| | | return PreOperationPluginResult.SUCCESS; |
| | | return PluginResult.PreOperation.continueOperationProcessing(); |
| | | } |
| | | |
| | | RDN newRDN = modifyDNOperation.getNewRDN(); |
| | |
| | | { |
| | | AttributeValue v = newRDN.getAttributeValue(i); |
| | | DN conflictDN = getConflictingEntryDN(baseDNs, |
| | | modifyDNOperation.getEntryDN(), config, v); |
| | | modifyDNOperation.getEntryDN(), config, v); |
| | | if (conflictDN != null) |
| | | { |
| | | modifyDNOperation.appendErrorMessage( |
| | | ERR_PLUGIN_UNIQUEATTR_ATTR_NOT_UNIQUE.get(t.getNameOrOID(), |
| | | v.getStringValue(), conflictDN.toString())); |
| | | modifyDNOperation.setResultCode(ResultCode.CONSTRAINT_VIOLATION); |
| | | return FAILED_PREOP_RESULT; |
| | | Message msg = ERR_PLUGIN_UNIQUEATTR_ATTR_NOT_UNIQUE.get( |
| | | t.getNameOrOID(), v.getStringValue(), |
| | | conflictDN.toString()); |
| | | return PluginResult.PreOperation.stopProcessing( |
| | | ResultCode.CONSTRAINT_VIOLATION, msg); |
| | | } |
| | | } |
| | | catch (DirectoryException de) |
| | |
| | | de.getResultCode().toString(), |
| | | de.getMessageObject()); |
| | | |
| | | modifyDNOperation.setResultCode( |
| | | DirectoryServer.getServerErrorResultCode()); |
| | | modifyDNOperation.appendErrorMessage(m); |
| | | return FAILED_PREOP_RESULT; |
| | | return PluginResult.PreOperation.stopProcessing( |
| | | DirectoryServer.getServerErrorResultCode(), m); |
| | | } |
| | | } |
| | | |
| | | return PreOperationPluginResult.SUCCESS; |
| | | return PluginResult.PreOperation.continueOperationProcessing(); |
| | | } |
| | | |
| | | |